001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.SQLQuery;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.sanitizer.Sanitizer;
031    import com.liferay.portal.kernel.sanitizer.SanitizerException;
032    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
033    import com.liferay.portal.kernel.util.ArrayUtil;
034    import com.liferay.portal.kernel.util.ContentTypes;
035    import com.liferay.portal.kernel.util.GetterUtil;
036    import com.liferay.portal.kernel.util.InstanceFactory;
037    import com.liferay.portal.kernel.util.OrderByComparator;
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    
061    /**
062     * The persistence implementation for the message-boards message service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see MBMessagePersistence
070     * @see MBMessageUtil
071     * @generated
072     */
073    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
074            implements MBMessagePersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * 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.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
086                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
089                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
092                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
095                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097                            new String[] {
098                                    String.class.getName(),
099                                    
100                            Integer.class.getName(), Integer.class.getName(),
101                                    OrderByComparator.class.getName()
102                            });
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
108                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
110                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112                            new String[] { String.class.getName() });
113    
114            /**
115             * Returns all the message-boards messages where uuid = &#63;.
116             *
117             * @param uuid the uuid
118             * @return the matching message-boards messages
119             * @throws SystemException if a system exception occurred
120             */
121            public List<MBMessage> findByUuid(String uuid) throws SystemException {
122                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123            }
124    
125            /**
126             * Returns a range of all the message-boards messages where uuid = &#63;.
127             *
128             * <p>
129             * 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.
130             * </p>
131             *
132             * @param uuid the uuid
133             * @param start the lower bound of the range of message-boards messages
134             * @param end the upper bound of the range of message-boards messages (not inclusive)
135             * @return the range of matching message-boards messages
136             * @throws SystemException if a system exception occurred
137             */
138            public List<MBMessage> findByUuid(String uuid, int start, int end)
139                    throws SystemException {
140                    return findByUuid(uuid, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
145             *
146             * <p>
147             * 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.
148             * </p>
149             *
150             * @param uuid the uuid
151             * @param start the lower bound of the range of message-boards messages
152             * @param end the upper bound of the range of message-boards messages (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching message-boards messages
155             * @throws SystemException if a system exception occurred
156             */
157            public List<MBMessage> findByUuid(String uuid, int start, int end,
158                    OrderByComparator orderByComparator) throws SystemException {
159                    boolean pagination = true;
160                    FinderPath finderPath = null;
161                    Object[] finderArgs = null;
162    
163                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164                                    (orderByComparator == null)) {
165                            pagination = false;
166                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167                            finderArgs = new Object[] { uuid };
168                    }
169                    else {
170                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
172                    }
173    
174                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
175                                    finderArgs, this);
176    
177                    if ((list != null) && !list.isEmpty()) {
178                            for (MBMessage mbMessage : list) {
179                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
180                                            list = null;
181    
182                                            break;
183                                    }
184                            }
185                    }
186    
187                    if (list == null) {
188                            StringBundler query = null;
189    
190                            if (orderByComparator != null) {
191                                    query = new StringBundler(3 +
192                                                    (orderByComparator.getOrderByFields().length * 3));
193                            }
194                            else {
195                                    query = new StringBundler(3);
196                            }
197    
198                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
199    
200                            if (uuid == null) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
202                            }
203                            else {
204                                    if (uuid.equals(StringPool.BLANK)) {
205                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
206                                    }
207                                    else {
208                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
209                                    }
210                            }
211    
212                            if (orderByComparator != null) {
213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
214                                            orderByComparator);
215                            }
216                            else
217                             if (pagination) {
218                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
219                            }
220    
221                            String sql = query.toString();
222    
223                            Session session = null;
224    
225                            try {
226                                    session = openSession();
227    
228                                    Query q = session.createQuery(sql);
229    
230                                    QueryPos qPos = QueryPos.getInstance(q);
231    
232                                    if (uuid != null) {
233                                            qPos.add(uuid);
234                                    }
235    
236                                    if (!pagination) {
237                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
238                                                            start, end, false);
239    
240                                            Collections.sort(list);
241    
242                                            list = new UnmodifiableList<MBMessage>(list);
243                                    }
244                                    else {
245                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
246                                                            start, end);
247                                    }
248    
249                                    cacheResult(list);
250    
251                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
252                            }
253                            catch (Exception e) {
254                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
255    
256                                    throw processException(e);
257                            }
258                            finally {
259                                    closeSession(session);
260                            }
261                    }
262    
263                    return list;
264            }
265    
266            /**
267             * Returns the first message-boards message in the ordered set where uuid = &#63;.
268             *
269             * @param uuid the uuid
270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
271             * @return the first matching message-boards message
272             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
273             * @throws SystemException if a system exception occurred
274             */
275            public MBMessage findByUuid_First(String uuid,
276                    OrderByComparator orderByComparator)
277                    throws NoSuchMessageException, SystemException {
278                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
279    
280                    if (mbMessage != null) {
281                            return mbMessage;
282                    }
283    
284                    StringBundler msg = new StringBundler(4);
285    
286                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
287    
288                    msg.append("uuid=");
289                    msg.append(uuid);
290    
291                    msg.append(StringPool.CLOSE_CURLY_BRACE);
292    
293                    throw new NoSuchMessageException(msg.toString());
294            }
295    
296            /**
297             * Returns the first message-boards message in the ordered set where uuid = &#63;.
298             *
299             * @param uuid the uuid
300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
301             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
302             * @throws SystemException if a system exception occurred
303             */
304            public MBMessage fetchByUuid_First(String uuid,
305                    OrderByComparator orderByComparator) throws SystemException {
306                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
307    
308                    if (!list.isEmpty()) {
309                            return list.get(0);
310                    }
311    
312                    return null;
313            }
314    
315            /**
316             * Returns the last message-boards message in the ordered set where uuid = &#63;.
317             *
318             * @param uuid the uuid
319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
320             * @return the last matching message-boards message
321             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
322             * @throws SystemException if a system exception occurred
323             */
324            public MBMessage findByUuid_Last(String uuid,
325                    OrderByComparator orderByComparator)
326                    throws NoSuchMessageException, SystemException {
327                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
328    
329                    if (mbMessage != null) {
330                            return mbMessage;
331                    }
332    
333                    StringBundler msg = new StringBundler(4);
334    
335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336    
337                    msg.append("uuid=");
338                    msg.append(uuid);
339    
340                    msg.append(StringPool.CLOSE_CURLY_BRACE);
341    
342                    throw new NoSuchMessageException(msg.toString());
343            }
344    
345            /**
346             * Returns the last message-boards message in the ordered set where uuid = &#63;.
347             *
348             * @param uuid the uuid
349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
350             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
351             * @throws SystemException if a system exception occurred
352             */
353            public MBMessage fetchByUuid_Last(String uuid,
354                    OrderByComparator orderByComparator) throws SystemException {
355                    int count = countByUuid(uuid);
356    
357                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
369             *
370             * @param messageId the primary key of the current message-boards message
371             * @param uuid the uuid
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next message-boards message
374             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
378                    OrderByComparator orderByComparator)
379                    throws NoSuchMessageException, SystemException {
380                    MBMessage mbMessage = findByPrimaryKey(messageId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            MBMessage[] array = new MBMessageImpl[3];
388    
389                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
390                                            orderByComparator, true);
391    
392                            array[1] = mbMessage;
393    
394                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
395                                            orderByComparator, false);
396    
397                            return array;
398                    }
399                    catch (Exception e) {
400                            throw processException(e);
401                    }
402                    finally {
403                            closeSession(session);
404                    }
405            }
406    
407            protected MBMessage getByUuid_PrevAndNext(Session session,
408                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
409                    boolean previous) {
410                    StringBundler query = null;
411    
412                    if (orderByComparator != null) {
413                            query = new StringBundler(6 +
414                                            (orderByComparator.getOrderByFields().length * 6));
415                    }
416                    else {
417                            query = new StringBundler(3);
418                    }
419    
420                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
421    
422                    if (uuid == null) {
423                            query.append(_FINDER_COLUMN_UUID_UUID_1);
424                    }
425                    else {
426                            if (uuid.equals(StringPool.BLANK)) {
427                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
428                            }
429                            else {
430                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
431                            }
432                    }
433    
434                    if (orderByComparator != null) {
435                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436    
437                            if (orderByConditionFields.length > 0) {
438                                    query.append(WHERE_AND);
439                            }
440    
441                            for (int i = 0; i < orderByConditionFields.length; i++) {
442                                    query.append(_ORDER_BY_ENTITY_ALIAS);
443                                    query.append(orderByConditionFields[i]);
444    
445                                    if ((i + 1) < orderByConditionFields.length) {
446                                            if (orderByComparator.isAscending() ^ previous) {
447                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
448                                            }
449                                            else {
450                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
451                                            }
452                                    }
453                                    else {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(WHERE_GREATER_THAN);
456                                            }
457                                            else {
458                                                    query.append(WHERE_LESSER_THAN);
459                                            }
460                                    }
461                            }
462    
463                            query.append(ORDER_BY_CLAUSE);
464    
465                            String[] orderByFields = orderByComparator.getOrderByFields();
466    
467                            for (int i = 0; i < orderByFields.length; i++) {
468                                    query.append(_ORDER_BY_ENTITY_ALIAS);
469                                    query.append(orderByFields[i]);
470    
471                                    if ((i + 1) < orderByFields.length) {
472                                            if (orderByComparator.isAscending() ^ previous) {
473                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
474                                            }
475                                            else {
476                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
477                                            }
478                                    }
479                                    else {
480                                            if (orderByComparator.isAscending() ^ previous) {
481                                                    query.append(ORDER_BY_ASC);
482                                            }
483                                            else {
484                                                    query.append(ORDER_BY_DESC);
485                                            }
486                                    }
487                            }
488                    }
489                    else {
490                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
491                    }
492    
493                    String sql = query.toString();
494    
495                    Query q = session.createQuery(sql);
496    
497                    q.setFirstResult(0);
498                    q.setMaxResults(2);
499    
500                    QueryPos qPos = QueryPos.getInstance(q);
501    
502                    if (uuid != null) {
503                            qPos.add(uuid);
504                    }
505    
506                    if (orderByComparator != null) {
507                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
508    
509                            for (Object value : values) {
510                                    qPos.add(value);
511                            }
512                    }
513    
514                    List<MBMessage> list = q.list();
515    
516                    if (list.size() == 2) {
517                            return list.get(1);
518                    }
519                    else {
520                            return null;
521                    }
522            }
523    
524            /**
525             * Removes all the message-boards messages where uuid = &#63; from the database.
526             *
527             * @param uuid the uuid
528             * @throws SystemException if a system exception occurred
529             */
530            public void removeByUuid(String uuid) throws SystemException {
531                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
532                                    QueryUtil.ALL_POS, null)) {
533                            remove(mbMessage);
534                    }
535            }
536    
537            /**
538             * Returns the number of message-boards messages where uuid = &#63;.
539             *
540             * @param uuid the uuid
541             * @return the number of matching message-boards messages
542             * @throws SystemException if a system exception occurred
543             */
544            public int countByUuid(String uuid) throws SystemException {
545                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
546    
547                    Object[] finderArgs = new Object[] { uuid };
548    
549                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
550                                    this);
551    
552                    if (count == null) {
553                            StringBundler query = new StringBundler(2);
554    
555                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
556    
557                            if (uuid == null) {
558                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
559                            }
560                            else {
561                                    if (uuid.equals(StringPool.BLANK)) {
562                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
563                                    }
564                                    else {
565                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
566                                    }
567                            }
568    
569                            String sql = query.toString();
570    
571                            Session session = null;
572    
573                            try {
574                                    session = openSession();
575    
576                                    Query q = session.createQuery(sql);
577    
578                                    QueryPos qPos = QueryPos.getInstance(q);
579    
580                                    if (uuid != null) {
581                                            qPos.add(uuid);
582                                    }
583    
584                                    count = (Long)q.uniqueResult();
585    
586                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
587                            }
588                            catch (Exception e) {
589                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
590    
591                                    throw processException(e);
592                            }
593                            finally {
594                                    closeSession(session);
595                            }
596                    }
597    
598                    return count.intValue();
599            }
600    
601            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
602            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
603            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
604            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
605                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
606                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
607                            new String[] { String.class.getName(), Long.class.getName() },
608                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
609                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
610            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
611                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
612                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
613                            new String[] { String.class.getName(), Long.class.getName() });
614    
615            /**
616             * 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.
617             *
618             * @param uuid the uuid
619             * @param groupId the group ID
620             * @return the matching message-boards message
621             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
622             * @throws SystemException if a system exception occurred
623             */
624            public MBMessage findByUUID_G(String uuid, long groupId)
625                    throws NoSuchMessageException, SystemException {
626                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
627    
628                    if (mbMessage == null) {
629                            StringBundler msg = new StringBundler(6);
630    
631                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
632    
633                            msg.append("uuid=");
634                            msg.append(uuid);
635    
636                            msg.append(", groupId=");
637                            msg.append(groupId);
638    
639                            msg.append(StringPool.CLOSE_CURLY_BRACE);
640    
641                            if (_log.isWarnEnabled()) {
642                                    _log.warn(msg.toString());
643                            }
644    
645                            throw new NoSuchMessageException(msg.toString());
646                    }
647    
648                    return mbMessage;
649            }
650    
651            /**
652             * 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.
653             *
654             * @param uuid the uuid
655             * @param groupId the group ID
656             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
657             * @throws SystemException if a system exception occurred
658             */
659            public MBMessage fetchByUUID_G(String uuid, long groupId)
660                    throws SystemException {
661                    return fetchByUUID_G(uuid, groupId, true);
662            }
663    
664            /**
665             * 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.
666             *
667             * @param uuid the uuid
668             * @param groupId the group ID
669             * @param retrieveFromCache whether to use the finder cache
670             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
671             * @throws SystemException if a system exception occurred
672             */
673            public MBMessage fetchByUUID_G(String uuid, long groupId,
674                    boolean retrieveFromCache) throws SystemException {
675                    Object[] finderArgs = new Object[] { uuid, groupId };
676    
677                    Object result = null;
678    
679                    if (retrieveFromCache) {
680                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
681                                            finderArgs, this);
682                    }
683    
684                    if (result instanceof MBMessage) {
685                            MBMessage mbMessage = (MBMessage)result;
686    
687                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
688                                            (groupId != mbMessage.getGroupId())) {
689                                    result = null;
690                            }
691                    }
692    
693                    if (result == null) {
694                            StringBundler query = new StringBundler(4);
695    
696                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
697    
698                            if (uuid == null) {
699                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
700                            }
701                            else {
702                                    if (uuid.equals(StringPool.BLANK)) {
703                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
704                                    }
705                                    else {
706                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
707                                    }
708                            }
709    
710                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
711    
712                            String sql = query.toString();
713    
714                            Session session = null;
715    
716                            try {
717                                    session = openSession();
718    
719                                    Query q = session.createQuery(sql);
720    
721                                    QueryPos qPos = QueryPos.getInstance(q);
722    
723                                    if (uuid != null) {
724                                            qPos.add(uuid);
725                                    }
726    
727                                    qPos.add(groupId);
728    
729                                    List<MBMessage> list = q.list();
730    
731                                    if (list.isEmpty()) {
732                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
733                                                    finderArgs, list);
734                                    }
735                                    else {
736                                            MBMessage mbMessage = list.get(0);
737    
738                                            result = mbMessage;
739    
740                                            cacheResult(mbMessage);
741    
742                                            if ((mbMessage.getUuid() == null) ||
743                                                            !mbMessage.getUuid().equals(uuid) ||
744                                                            (mbMessage.getGroupId() != groupId)) {
745                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
746                                                            finderArgs, mbMessage);
747                                            }
748                                    }
749                            }
750                            catch (Exception e) {
751                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
752                                            finderArgs);
753    
754                                    throw processException(e);
755                            }
756                            finally {
757                                    closeSession(session);
758                            }
759                    }
760    
761                    if (result instanceof List<?>) {
762                            return null;
763                    }
764                    else {
765                            return (MBMessage)result;
766                    }
767            }
768    
769            /**
770             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
771             *
772             * @param uuid the uuid
773             * @param groupId the group ID
774             * @return the message-boards message that was removed
775             * @throws SystemException if a system exception occurred
776             */
777            public MBMessage removeByUUID_G(String uuid, long groupId)
778                    throws NoSuchMessageException, SystemException {
779                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
780    
781                    return remove(mbMessage);
782            }
783    
784            /**
785             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
786             *
787             * @param uuid the uuid
788             * @param groupId the group ID
789             * @return the number of matching message-boards messages
790             * @throws SystemException if a system exception occurred
791             */
792            public int countByUUID_G(String uuid, long groupId)
793                    throws SystemException {
794                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
795    
796                    Object[] finderArgs = new Object[] { uuid, groupId };
797    
798                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
799                                    this);
800    
801                    if (count == null) {
802                            StringBundler query = new StringBundler(3);
803    
804                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
805    
806                            if (uuid == null) {
807                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
808                            }
809                            else {
810                                    if (uuid.equals(StringPool.BLANK)) {
811                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
812                                    }
813                                    else {
814                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
815                                    }
816                            }
817    
818                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
819    
820                            String sql = query.toString();
821    
822                            Session session = null;
823    
824                            try {
825                                    session = openSession();
826    
827                                    Query q = session.createQuery(sql);
828    
829                                    QueryPos qPos = QueryPos.getInstance(q);
830    
831                                    if (uuid != null) {
832                                            qPos.add(uuid);
833                                    }
834    
835                                    qPos.add(groupId);
836    
837                                    count = (Long)q.uniqueResult();
838    
839                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
840                            }
841                            catch (Exception e) {
842                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
843    
844                                    throw processException(e);
845                            }
846                            finally {
847                                    closeSession(session);
848                            }
849                    }
850    
851                    return count.intValue();
852            }
853    
854            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
855            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
856            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
857            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
858            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
859                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
860                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
861                            new String[] {
862                                    String.class.getName(), Long.class.getName(),
863                                    
864                            Integer.class.getName(), Integer.class.getName(),
865                                    OrderByComparator.class.getName()
866                            });
867            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
868                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
869                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
870                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
871                            new String[] { String.class.getName(), Long.class.getName() },
872                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
873                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
874                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
875            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
876                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
877                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
878                            new String[] { String.class.getName(), Long.class.getName() });
879    
880            /**
881             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
882             *
883             * @param uuid the uuid
884             * @param companyId the company ID
885             * @return the matching message-boards messages
886             * @throws SystemException if a system exception occurred
887             */
888            public List<MBMessage> findByUuid_C(String uuid, long companyId)
889                    throws SystemException {
890                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
891                            QueryUtil.ALL_POS, null);
892            }
893    
894            /**
895             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
896             *
897             * <p>
898             * 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.
899             * </p>
900             *
901             * @param uuid the uuid
902             * @param companyId the company ID
903             * @param start the lower bound of the range of message-boards messages
904             * @param end the upper bound of the range of message-boards messages (not inclusive)
905             * @return the range of matching message-boards messages
906             * @throws SystemException if a system exception occurred
907             */
908            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
909                    int end) throws SystemException {
910                    return findByUuid_C(uuid, companyId, start, end, null);
911            }
912    
913            /**
914             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
915             *
916             * <p>
917             * 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.
918             * </p>
919             *
920             * @param uuid the uuid
921             * @param companyId the company ID
922             * @param start the lower bound of the range of message-boards messages
923             * @param end the upper bound of the range of message-boards messages (not inclusive)
924             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
925             * @return the ordered range of matching message-boards messages
926             * @throws SystemException if a system exception occurred
927             */
928            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
929                    int end, OrderByComparator orderByComparator) throws SystemException {
930                    boolean pagination = true;
931                    FinderPath finderPath = null;
932                    Object[] finderArgs = null;
933    
934                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
935                                    (orderByComparator == null)) {
936                            pagination = false;
937                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
938                            finderArgs = new Object[] { uuid, companyId };
939                    }
940                    else {
941                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
942                            finderArgs = new Object[] {
943                                            uuid, companyId,
944                                            
945                                            start, end, orderByComparator
946                                    };
947                    }
948    
949                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
950                                    finderArgs, this);
951    
952                    if ((list != null) && !list.isEmpty()) {
953                            for (MBMessage mbMessage : list) {
954                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
955                                                    (companyId != mbMessage.getCompanyId())) {
956                                            list = null;
957    
958                                            break;
959                                    }
960                            }
961                    }
962    
963                    if (list == null) {
964                            StringBundler query = null;
965    
966                            if (orderByComparator != null) {
967                                    query = new StringBundler(4 +
968                                                    (orderByComparator.getOrderByFields().length * 3));
969                            }
970                            else {
971                                    query = new StringBundler(4);
972                            }
973    
974                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
975    
976                            if (uuid == null) {
977                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
978                            }
979                            else {
980                                    if (uuid.equals(StringPool.BLANK)) {
981                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
982                                    }
983                                    else {
984                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
985                                    }
986                            }
987    
988                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
989    
990                            if (orderByComparator != null) {
991                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
992                                            orderByComparator);
993                            }
994                            else
995                             if (pagination) {
996                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
997                            }
998    
999                            String sql = query.toString();
1000    
1001                            Session session = null;
1002    
1003                            try {
1004                                    session = openSession();
1005    
1006                                    Query q = session.createQuery(sql);
1007    
1008                                    QueryPos qPos = QueryPos.getInstance(q);
1009    
1010                                    if (uuid != null) {
1011                                            qPos.add(uuid);
1012                                    }
1013    
1014                                    qPos.add(companyId);
1015    
1016                                    if (!pagination) {
1017                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1018                                                            start, end, false);
1019    
1020                                            Collections.sort(list);
1021    
1022                                            list = new UnmodifiableList<MBMessage>(list);
1023                                    }
1024                                    else {
1025                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1026                                                            start, end);
1027                                    }
1028    
1029                                    cacheResult(list);
1030    
1031                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1032                            }
1033                            catch (Exception e) {
1034                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1035    
1036                                    throw processException(e);
1037                            }
1038                            finally {
1039                                    closeSession(session);
1040                            }
1041                    }
1042    
1043                    return list;
1044            }
1045    
1046            /**
1047             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1048             *
1049             * @param uuid the uuid
1050             * @param companyId the company ID
1051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1052             * @return the first matching message-boards message
1053             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1054             * @throws SystemException if a system exception occurred
1055             */
1056            public MBMessage findByUuid_C_First(String uuid, long companyId,
1057                    OrderByComparator orderByComparator)
1058                    throws NoSuchMessageException, SystemException {
1059                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1060                                    orderByComparator);
1061    
1062                    if (mbMessage != null) {
1063                            return mbMessage;
1064                    }
1065    
1066                    StringBundler msg = new StringBundler(6);
1067    
1068                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1069    
1070                    msg.append("uuid=");
1071                    msg.append(uuid);
1072    
1073                    msg.append(", companyId=");
1074                    msg.append(companyId);
1075    
1076                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1077    
1078                    throw new NoSuchMessageException(msg.toString());
1079            }
1080    
1081            /**
1082             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1083             *
1084             * @param uuid the uuid
1085             * @param companyId the company ID
1086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1087             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1088             * @throws SystemException if a system exception occurred
1089             */
1090            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1091                    OrderByComparator orderByComparator) throws SystemException {
1092                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1093                                    orderByComparator);
1094    
1095                    if (!list.isEmpty()) {
1096                            return list.get(0);
1097                    }
1098    
1099                    return null;
1100            }
1101    
1102            /**
1103             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1104             *
1105             * @param uuid the uuid
1106             * @param companyId the company ID
1107             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1108             * @return the last matching message-boards message
1109             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1110             * @throws SystemException if a system exception occurred
1111             */
1112            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1113                    OrderByComparator orderByComparator)
1114                    throws NoSuchMessageException, SystemException {
1115                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1116                                    orderByComparator);
1117    
1118                    if (mbMessage != null) {
1119                            return mbMessage;
1120                    }
1121    
1122                    StringBundler msg = new StringBundler(6);
1123    
1124                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1125    
1126                    msg.append("uuid=");
1127                    msg.append(uuid);
1128    
1129                    msg.append(", companyId=");
1130                    msg.append(companyId);
1131    
1132                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1133    
1134                    throw new NoSuchMessageException(msg.toString());
1135            }
1136    
1137            /**
1138             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1139             *
1140             * @param uuid the uuid
1141             * @param companyId the company ID
1142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1143             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1144             * @throws SystemException if a system exception occurred
1145             */
1146            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1147                    OrderByComparator orderByComparator) throws SystemException {
1148                    int count = countByUuid_C(uuid, companyId);
1149    
1150                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1151                                    orderByComparator);
1152    
1153                    if (!list.isEmpty()) {
1154                            return list.get(0);
1155                    }
1156    
1157                    return null;
1158            }
1159    
1160            /**
1161             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1162             *
1163             * @param messageId the primary key of the current message-boards message
1164             * @param uuid the uuid
1165             * @param companyId the company ID
1166             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1167             * @return the previous, current, and next message-boards message
1168             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1169             * @throws SystemException if a system exception occurred
1170             */
1171            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1172                    long companyId, OrderByComparator orderByComparator)
1173                    throws NoSuchMessageException, SystemException {
1174                    MBMessage mbMessage = findByPrimaryKey(messageId);
1175    
1176                    Session session = null;
1177    
1178                    try {
1179                            session = openSession();
1180    
1181                            MBMessage[] array = new MBMessageImpl[3];
1182    
1183                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1184                                            companyId, orderByComparator, true);
1185    
1186                            array[1] = mbMessage;
1187    
1188                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1189                                            companyId, orderByComparator, false);
1190    
1191                            return array;
1192                    }
1193                    catch (Exception e) {
1194                            throw processException(e);
1195                    }
1196                    finally {
1197                            closeSession(session);
1198                    }
1199            }
1200    
1201            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1202                    MBMessage mbMessage, String uuid, long companyId,
1203                    OrderByComparator orderByComparator, boolean previous) {
1204                    StringBundler query = null;
1205    
1206                    if (orderByComparator != null) {
1207                            query = new StringBundler(6 +
1208                                            (orderByComparator.getOrderByFields().length * 6));
1209                    }
1210                    else {
1211                            query = new StringBundler(3);
1212                    }
1213    
1214                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1215    
1216                    if (uuid == null) {
1217                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1218                    }
1219                    else {
1220                            if (uuid.equals(StringPool.BLANK)) {
1221                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1222                            }
1223                            else {
1224                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1225                            }
1226                    }
1227    
1228                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1229    
1230                    if (orderByComparator != null) {
1231                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1232    
1233                            if (orderByConditionFields.length > 0) {
1234                                    query.append(WHERE_AND);
1235                            }
1236    
1237                            for (int i = 0; i < orderByConditionFields.length; i++) {
1238                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1239                                    query.append(orderByConditionFields[i]);
1240    
1241                                    if ((i + 1) < orderByConditionFields.length) {
1242                                            if (orderByComparator.isAscending() ^ previous) {
1243                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1244                                            }
1245                                            else {
1246                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1247                                            }
1248                                    }
1249                                    else {
1250                                            if (orderByComparator.isAscending() ^ previous) {
1251                                                    query.append(WHERE_GREATER_THAN);
1252                                            }
1253                                            else {
1254                                                    query.append(WHERE_LESSER_THAN);
1255                                            }
1256                                    }
1257                            }
1258    
1259                            query.append(ORDER_BY_CLAUSE);
1260    
1261                            String[] orderByFields = orderByComparator.getOrderByFields();
1262    
1263                            for (int i = 0; i < orderByFields.length; i++) {
1264                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1265                                    query.append(orderByFields[i]);
1266    
1267                                    if ((i + 1) < orderByFields.length) {
1268                                            if (orderByComparator.isAscending() ^ previous) {
1269                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1270                                            }
1271                                            else {
1272                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1273                                            }
1274                                    }
1275                                    else {
1276                                            if (orderByComparator.isAscending() ^ previous) {
1277                                                    query.append(ORDER_BY_ASC);
1278                                            }
1279                                            else {
1280                                                    query.append(ORDER_BY_DESC);
1281                                            }
1282                                    }
1283                            }
1284                    }
1285                    else {
1286                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1287                    }
1288    
1289                    String sql = query.toString();
1290    
1291                    Query q = session.createQuery(sql);
1292    
1293                    q.setFirstResult(0);
1294                    q.setMaxResults(2);
1295    
1296                    QueryPos qPos = QueryPos.getInstance(q);
1297    
1298                    if (uuid != null) {
1299                            qPos.add(uuid);
1300                    }
1301    
1302                    qPos.add(companyId);
1303    
1304                    if (orderByComparator != null) {
1305                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1306    
1307                            for (Object value : values) {
1308                                    qPos.add(value);
1309                            }
1310                    }
1311    
1312                    List<MBMessage> list = q.list();
1313    
1314                    if (list.size() == 2) {
1315                            return list.get(1);
1316                    }
1317                    else {
1318                            return null;
1319                    }
1320            }
1321    
1322            /**
1323             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1324             *
1325             * @param uuid the uuid
1326             * @param companyId the company ID
1327             * @throws SystemException if a system exception occurred
1328             */
1329            public void removeByUuid_C(String uuid, long companyId)
1330                    throws SystemException {
1331                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1332                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1333                            remove(mbMessage);
1334                    }
1335            }
1336    
1337            /**
1338             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1339             *
1340             * @param uuid the uuid
1341             * @param companyId the company ID
1342             * @return the number of matching message-boards messages
1343             * @throws SystemException if a system exception occurred
1344             */
1345            public int countByUuid_C(String uuid, long companyId)
1346                    throws SystemException {
1347                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1348    
1349                    Object[] finderArgs = new Object[] { uuid, companyId };
1350    
1351                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1352                                    this);
1353    
1354                    if (count == null) {
1355                            StringBundler query = new StringBundler(3);
1356    
1357                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1358    
1359                            if (uuid == null) {
1360                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1361                            }
1362                            else {
1363                                    if (uuid.equals(StringPool.BLANK)) {
1364                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1365                                    }
1366                                    else {
1367                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1368                                    }
1369                            }
1370    
1371                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1372    
1373                            String sql = query.toString();
1374    
1375                            Session session = null;
1376    
1377                            try {
1378                                    session = openSession();
1379    
1380                                    Query q = session.createQuery(sql);
1381    
1382                                    QueryPos qPos = QueryPos.getInstance(q);
1383    
1384                                    if (uuid != null) {
1385                                            qPos.add(uuid);
1386                                    }
1387    
1388                                    qPos.add(companyId);
1389    
1390                                    count = (Long)q.uniqueResult();
1391    
1392                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1393                            }
1394                            catch (Exception e) {
1395                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1396    
1397                                    throw processException(e);
1398                            }
1399                            finally {
1400                                    closeSession(session);
1401                            }
1402                    }
1403    
1404                    return count.intValue();
1405            }
1406    
1407            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1408            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1409            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
1410            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1411            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1412                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1413                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1414                            new String[] {
1415                                    Long.class.getName(),
1416                                    
1417                            Integer.class.getName(), Integer.class.getName(),
1418                                    OrderByComparator.class.getName()
1419                            });
1420            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1421                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1422                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1423                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1424                            new String[] { Long.class.getName() },
1425                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1426                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1427            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1428                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1429                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1430                            new String[] { Long.class.getName() });
1431    
1432            /**
1433             * Returns all the message-boards messages where groupId = &#63;.
1434             *
1435             * @param groupId the group ID
1436             * @return the matching message-boards messages
1437             * @throws SystemException if a system exception occurred
1438             */
1439            public List<MBMessage> findByGroupId(long groupId)
1440                    throws SystemException {
1441                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1442            }
1443    
1444            /**
1445             * Returns a range of all the message-boards messages where groupId = &#63;.
1446             *
1447             * <p>
1448             * 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.
1449             * </p>
1450             *
1451             * @param groupId the group ID
1452             * @param start the lower bound of the range of message-boards messages
1453             * @param end the upper bound of the range of message-boards messages (not inclusive)
1454             * @return the range of matching message-boards messages
1455             * @throws SystemException if a system exception occurred
1456             */
1457            public List<MBMessage> findByGroupId(long groupId, int start, int end)
1458                    throws SystemException {
1459                    return findByGroupId(groupId, start, end, null);
1460            }
1461    
1462            /**
1463             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1464             *
1465             * <p>
1466             * 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.
1467             * </p>
1468             *
1469             * @param groupId the group ID
1470             * @param start the lower bound of the range of message-boards messages
1471             * @param end the upper bound of the range of message-boards messages (not inclusive)
1472             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1473             * @return the ordered range of matching message-boards messages
1474             * @throws SystemException if a system exception occurred
1475             */
1476            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1477                    OrderByComparator orderByComparator) throws SystemException {
1478                    boolean pagination = true;
1479                    FinderPath finderPath = null;
1480                    Object[] finderArgs = null;
1481    
1482                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1483                                    (orderByComparator == null)) {
1484                            pagination = false;
1485                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1486                            finderArgs = new Object[] { groupId };
1487                    }
1488                    else {
1489                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1490                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1491                    }
1492    
1493                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1494                                    finderArgs, this);
1495    
1496                    if ((list != null) && !list.isEmpty()) {
1497                            for (MBMessage mbMessage : list) {
1498                                    if ((groupId != mbMessage.getGroupId())) {
1499                                            list = null;
1500    
1501                                            break;
1502                                    }
1503                            }
1504                    }
1505    
1506                    if (list == null) {
1507                            StringBundler query = null;
1508    
1509                            if (orderByComparator != null) {
1510                                    query = new StringBundler(3 +
1511                                                    (orderByComparator.getOrderByFields().length * 3));
1512                            }
1513                            else {
1514                                    query = new StringBundler(3);
1515                            }
1516    
1517                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1518    
1519                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1520    
1521                            if (orderByComparator != null) {
1522                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1523                                            orderByComparator);
1524                            }
1525                            else
1526                             if (pagination) {
1527                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1528                            }
1529    
1530                            String sql = query.toString();
1531    
1532                            Session session = null;
1533    
1534                            try {
1535                                    session = openSession();
1536    
1537                                    Query q = session.createQuery(sql);
1538    
1539                                    QueryPos qPos = QueryPos.getInstance(q);
1540    
1541                                    qPos.add(groupId);
1542    
1543                                    if (!pagination) {
1544                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1545                                                            start, end, false);
1546    
1547                                            Collections.sort(list);
1548    
1549                                            list = new UnmodifiableList<MBMessage>(list);
1550                                    }
1551                                    else {
1552                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1553                                                            start, end);
1554                                    }
1555    
1556                                    cacheResult(list);
1557    
1558                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1559                            }
1560                            catch (Exception e) {
1561                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1562    
1563                                    throw processException(e);
1564                            }
1565                            finally {
1566                                    closeSession(session);
1567                            }
1568                    }
1569    
1570                    return list;
1571            }
1572    
1573            /**
1574             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1575             *
1576             * @param groupId the group ID
1577             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1578             * @return the first matching message-boards message
1579             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1580             * @throws SystemException if a system exception occurred
1581             */
1582            public MBMessage findByGroupId_First(long groupId,
1583                    OrderByComparator orderByComparator)
1584                    throws NoSuchMessageException, SystemException {
1585                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1586    
1587                    if (mbMessage != null) {
1588                            return mbMessage;
1589                    }
1590    
1591                    StringBundler msg = new StringBundler(4);
1592    
1593                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1594    
1595                    msg.append("groupId=");
1596                    msg.append(groupId);
1597    
1598                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1599    
1600                    throw new NoSuchMessageException(msg.toString());
1601            }
1602    
1603            /**
1604             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1605             *
1606             * @param groupId the group ID
1607             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1608             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1609             * @throws SystemException if a system exception occurred
1610             */
1611            public MBMessage fetchByGroupId_First(long groupId,
1612                    OrderByComparator orderByComparator) throws SystemException {
1613                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1614    
1615                    if (!list.isEmpty()) {
1616                            return list.get(0);
1617                    }
1618    
1619                    return null;
1620            }
1621    
1622            /**
1623             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1624             *
1625             * @param groupId the group ID
1626             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1627             * @return the last matching message-boards message
1628             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public MBMessage findByGroupId_Last(long groupId,
1632                    OrderByComparator orderByComparator)
1633                    throws NoSuchMessageException, SystemException {
1634                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1635    
1636                    if (mbMessage != null) {
1637                            return mbMessage;
1638                    }
1639    
1640                    StringBundler msg = new StringBundler(4);
1641    
1642                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1643    
1644                    msg.append("groupId=");
1645                    msg.append(groupId);
1646    
1647                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1648    
1649                    throw new NoSuchMessageException(msg.toString());
1650            }
1651    
1652            /**
1653             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1654             *
1655             * @param groupId the group ID
1656             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1657             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1658             * @throws SystemException if a system exception occurred
1659             */
1660            public MBMessage fetchByGroupId_Last(long groupId,
1661                    OrderByComparator orderByComparator) throws SystemException {
1662                    int count = countByGroupId(groupId);
1663    
1664                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1665                                    orderByComparator);
1666    
1667                    if (!list.isEmpty()) {
1668                            return list.get(0);
1669                    }
1670    
1671                    return null;
1672            }
1673    
1674            /**
1675             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1676             *
1677             * @param messageId the primary key of the current message-boards message
1678             * @param groupId the group ID
1679             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1680             * @return the previous, current, and next message-boards message
1681             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1682             * @throws SystemException if a system exception occurred
1683             */
1684            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1685                    OrderByComparator orderByComparator)
1686                    throws NoSuchMessageException, SystemException {
1687                    MBMessage mbMessage = findByPrimaryKey(messageId);
1688    
1689                    Session session = null;
1690    
1691                    try {
1692                            session = openSession();
1693    
1694                            MBMessage[] array = new MBMessageImpl[3];
1695    
1696                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1697                                            orderByComparator, true);
1698    
1699                            array[1] = mbMessage;
1700    
1701                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1702                                            orderByComparator, false);
1703    
1704                            return array;
1705                    }
1706                    catch (Exception e) {
1707                            throw processException(e);
1708                    }
1709                    finally {
1710                            closeSession(session);
1711                    }
1712            }
1713    
1714            protected MBMessage getByGroupId_PrevAndNext(Session session,
1715                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1716                    boolean previous) {
1717                    StringBundler query = null;
1718    
1719                    if (orderByComparator != null) {
1720                            query = new StringBundler(6 +
1721                                            (orderByComparator.getOrderByFields().length * 6));
1722                    }
1723                    else {
1724                            query = new StringBundler(3);
1725                    }
1726    
1727                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1728    
1729                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1730    
1731                    if (orderByComparator != null) {
1732                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1733    
1734                            if (orderByConditionFields.length > 0) {
1735                                    query.append(WHERE_AND);
1736                            }
1737    
1738                            for (int i = 0; i < orderByConditionFields.length; i++) {
1739                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1740                                    query.append(orderByConditionFields[i]);
1741    
1742                                    if ((i + 1) < orderByConditionFields.length) {
1743                                            if (orderByComparator.isAscending() ^ previous) {
1744                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1745                                            }
1746                                            else {
1747                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1748                                            }
1749                                    }
1750                                    else {
1751                                            if (orderByComparator.isAscending() ^ previous) {
1752                                                    query.append(WHERE_GREATER_THAN);
1753                                            }
1754                                            else {
1755                                                    query.append(WHERE_LESSER_THAN);
1756                                            }
1757                                    }
1758                            }
1759    
1760                            query.append(ORDER_BY_CLAUSE);
1761    
1762                            String[] orderByFields = orderByComparator.getOrderByFields();
1763    
1764                            for (int i = 0; i < orderByFields.length; i++) {
1765                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1766                                    query.append(orderByFields[i]);
1767    
1768                                    if ((i + 1) < orderByFields.length) {
1769                                            if (orderByComparator.isAscending() ^ previous) {
1770                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1771                                            }
1772                                            else {
1773                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1774                                            }
1775                                    }
1776                                    else {
1777                                            if (orderByComparator.isAscending() ^ previous) {
1778                                                    query.append(ORDER_BY_ASC);
1779                                            }
1780                                            else {
1781                                                    query.append(ORDER_BY_DESC);
1782                                            }
1783                                    }
1784                            }
1785                    }
1786                    else {
1787                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1788                    }
1789    
1790                    String sql = query.toString();
1791    
1792                    Query q = session.createQuery(sql);
1793    
1794                    q.setFirstResult(0);
1795                    q.setMaxResults(2);
1796    
1797                    QueryPos qPos = QueryPos.getInstance(q);
1798    
1799                    qPos.add(groupId);
1800    
1801                    if (orderByComparator != null) {
1802                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1803    
1804                            for (Object value : values) {
1805                                    qPos.add(value);
1806                            }
1807                    }
1808    
1809                    List<MBMessage> list = q.list();
1810    
1811                    if (list.size() == 2) {
1812                            return list.get(1);
1813                    }
1814                    else {
1815                            return null;
1816                    }
1817            }
1818    
1819            /**
1820             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1821             *
1822             * @param groupId the group ID
1823             * @return the matching message-boards messages that the user has permission to view
1824             * @throws SystemException if a system exception occurred
1825             */
1826            public List<MBMessage> filterFindByGroupId(long groupId)
1827                    throws SystemException {
1828                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1829                            QueryUtil.ALL_POS, null);
1830            }
1831    
1832            /**
1833             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1834             *
1835             * <p>
1836             * 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.
1837             * </p>
1838             *
1839             * @param groupId the group ID
1840             * @param start the lower bound of the range of message-boards messages
1841             * @param end the upper bound of the range of message-boards messages (not inclusive)
1842             * @return the range of matching message-boards messages that the user has permission to view
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1846                    throws SystemException {
1847                    return filterFindByGroupId(groupId, start, end, null);
1848            }
1849    
1850            /**
1851             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1852             *
1853             * <p>
1854             * 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.
1855             * </p>
1856             *
1857             * @param groupId the group ID
1858             * @param start the lower bound of the range of message-boards messages
1859             * @param end the upper bound of the range of message-boards messages (not inclusive)
1860             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1861             * @return the ordered range of matching message-boards messages that the user has permission to view
1862             * @throws SystemException if a system exception occurred
1863             */
1864            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1865                    int end, OrderByComparator orderByComparator) throws SystemException {
1866                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1867                            return findByGroupId(groupId, start, end, orderByComparator);
1868                    }
1869    
1870                    StringBundler query = null;
1871    
1872                    if (orderByComparator != null) {
1873                            query = new StringBundler(3 +
1874                                            (orderByComparator.getOrderByFields().length * 3));
1875                    }
1876                    else {
1877                            query = new StringBundler(3);
1878                    }
1879    
1880                    if (getDB().isSupportsInlineDistinct()) {
1881                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1882                    }
1883                    else {
1884                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1885                    }
1886    
1887                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1888    
1889                    if (!getDB().isSupportsInlineDistinct()) {
1890                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1891                    }
1892    
1893                    if (orderByComparator != null) {
1894                            if (getDB().isSupportsInlineDistinct()) {
1895                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1896                                            orderByComparator);
1897                            }
1898                            else {
1899                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1900                                            orderByComparator);
1901                            }
1902                    }
1903                    else {
1904                            if (getDB().isSupportsInlineDistinct()) {
1905                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1906                            }
1907                            else {
1908                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
1909                            }
1910                    }
1911    
1912                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1913                                    MBMessage.class.getName(),
1914                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1915    
1916                    Session session = null;
1917    
1918                    try {
1919                            session = openSession();
1920    
1921                            SQLQuery q = session.createSQLQuery(sql);
1922    
1923                            if (getDB().isSupportsInlineDistinct()) {
1924                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1925                            }
1926                            else {
1927                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1928                            }
1929    
1930                            QueryPos qPos = QueryPos.getInstance(q);
1931    
1932                            qPos.add(groupId);
1933    
1934                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1935                    }
1936                    catch (Exception e) {
1937                            throw processException(e);
1938                    }
1939                    finally {
1940                            closeSession(session);
1941                    }
1942            }
1943    
1944            /**
1945             * 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;.
1946             *
1947             * @param messageId the primary key of the current message-boards message
1948             * @param groupId the group ID
1949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1950             * @return the previous, current, and next message-boards message
1951             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1952             * @throws SystemException if a system exception occurred
1953             */
1954            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
1955                    long groupId, OrderByComparator orderByComparator)
1956                    throws NoSuchMessageException, SystemException {
1957                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1958                            return findByGroupId_PrevAndNext(messageId, groupId,
1959                                    orderByComparator);
1960                    }
1961    
1962                    MBMessage mbMessage = findByPrimaryKey(messageId);
1963    
1964                    Session session = null;
1965    
1966                    try {
1967                            session = openSession();
1968    
1969                            MBMessage[] array = new MBMessageImpl[3];
1970    
1971                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1972                                            groupId, orderByComparator, true);
1973    
1974                            array[1] = mbMessage;
1975    
1976                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1977                                            groupId, orderByComparator, false);
1978    
1979                            return array;
1980                    }
1981                    catch (Exception e) {
1982                            throw processException(e);
1983                    }
1984                    finally {
1985                            closeSession(session);
1986                    }
1987            }
1988    
1989            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
1990                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1991                    boolean previous) {
1992                    StringBundler query = null;
1993    
1994                    if (orderByComparator != null) {
1995                            query = new StringBundler(6 +
1996                                            (orderByComparator.getOrderByFields().length * 6));
1997                    }
1998                    else {
1999                            query = new StringBundler(3);
2000                    }
2001    
2002                    if (getDB().isSupportsInlineDistinct()) {
2003                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2004                    }
2005                    else {
2006                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2007                    }
2008    
2009                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2010    
2011                    if (!getDB().isSupportsInlineDistinct()) {
2012                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2013                    }
2014    
2015                    if (orderByComparator != null) {
2016                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2017    
2018                            if (orderByConditionFields.length > 0) {
2019                                    query.append(WHERE_AND);
2020                            }
2021    
2022                            for (int i = 0; i < orderByConditionFields.length; i++) {
2023                                    if (getDB().isSupportsInlineDistinct()) {
2024                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2025                                    }
2026                                    else {
2027                                            query.append(_ORDER_BY_ENTITY_TABLE);
2028                                    }
2029    
2030                                    query.append(orderByConditionFields[i]);
2031    
2032                                    if ((i + 1) < orderByConditionFields.length) {
2033                                            if (orderByComparator.isAscending() ^ previous) {
2034                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2035                                            }
2036                                            else {
2037                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2038                                            }
2039                                    }
2040                                    else {
2041                                            if (orderByComparator.isAscending() ^ previous) {
2042                                                    query.append(WHERE_GREATER_THAN);
2043                                            }
2044                                            else {
2045                                                    query.append(WHERE_LESSER_THAN);
2046                                            }
2047                                    }
2048                            }
2049    
2050                            query.append(ORDER_BY_CLAUSE);
2051    
2052                            String[] orderByFields = orderByComparator.getOrderByFields();
2053    
2054                            for (int i = 0; i < orderByFields.length; i++) {
2055                                    if (getDB().isSupportsInlineDistinct()) {
2056                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2057                                    }
2058                                    else {
2059                                            query.append(_ORDER_BY_ENTITY_TABLE);
2060                                    }
2061    
2062                                    query.append(orderByFields[i]);
2063    
2064                                    if ((i + 1) < orderByFields.length) {
2065                                            if (orderByComparator.isAscending() ^ previous) {
2066                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2067                                            }
2068                                            else {
2069                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2070                                            }
2071                                    }
2072                                    else {
2073                                            if (orderByComparator.isAscending() ^ previous) {
2074                                                    query.append(ORDER_BY_ASC);
2075                                            }
2076                                            else {
2077                                                    query.append(ORDER_BY_DESC);
2078                                            }
2079                                    }
2080                            }
2081                    }
2082                    else {
2083                            if (getDB().isSupportsInlineDistinct()) {
2084                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2085                            }
2086                            else {
2087                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2088                            }
2089                    }
2090    
2091                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2092                                    MBMessage.class.getName(),
2093                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2094    
2095                    SQLQuery q = session.createSQLQuery(sql);
2096    
2097                    q.setFirstResult(0);
2098                    q.setMaxResults(2);
2099    
2100                    if (getDB().isSupportsInlineDistinct()) {
2101                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2102                    }
2103                    else {
2104                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2105                    }
2106    
2107                    QueryPos qPos = QueryPos.getInstance(q);
2108    
2109                    qPos.add(groupId);
2110    
2111                    if (orderByComparator != null) {
2112                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2113    
2114                            for (Object value : values) {
2115                                    qPos.add(value);
2116                            }
2117                    }
2118    
2119                    List<MBMessage> list = q.list();
2120    
2121                    if (list.size() == 2) {
2122                            return list.get(1);
2123                    }
2124                    else {
2125                            return null;
2126                    }
2127            }
2128    
2129            /**
2130             * Removes all the message-boards messages where groupId = &#63; from the database.
2131             *
2132             * @param groupId the group ID
2133             * @throws SystemException if a system exception occurred
2134             */
2135            public void removeByGroupId(long groupId) throws SystemException {
2136                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2137                                    QueryUtil.ALL_POS, null)) {
2138                            remove(mbMessage);
2139                    }
2140            }
2141    
2142            /**
2143             * Returns the number of message-boards messages where groupId = &#63;.
2144             *
2145             * @param groupId the group ID
2146             * @return the number of matching message-boards messages
2147             * @throws SystemException if a system exception occurred
2148             */
2149            public int countByGroupId(long groupId) throws SystemException {
2150                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2151    
2152                    Object[] finderArgs = new Object[] { groupId };
2153    
2154                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2155                                    this);
2156    
2157                    if (count == null) {
2158                            StringBundler query = new StringBundler(2);
2159    
2160                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2161    
2162                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2163    
2164                            String sql = query.toString();
2165    
2166                            Session session = null;
2167    
2168                            try {
2169                                    session = openSession();
2170    
2171                                    Query q = session.createQuery(sql);
2172    
2173                                    QueryPos qPos = QueryPos.getInstance(q);
2174    
2175                                    qPos.add(groupId);
2176    
2177                                    count = (Long)q.uniqueResult();
2178    
2179                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2180                            }
2181                            catch (Exception e) {
2182                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2183    
2184                                    throw processException(e);
2185                            }
2186                            finally {
2187                                    closeSession(session);
2188                            }
2189                    }
2190    
2191                    return count.intValue();
2192            }
2193    
2194            /**
2195             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2196             *
2197             * @param groupId the group ID
2198             * @return the number of matching message-boards messages that the user has permission to view
2199             * @throws SystemException if a system exception occurred
2200             */
2201            public int filterCountByGroupId(long groupId) throws SystemException {
2202                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2203                            return countByGroupId(groupId);
2204                    }
2205    
2206                    StringBundler query = new StringBundler(2);
2207    
2208                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2209    
2210                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2211    
2212                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2213                                    MBMessage.class.getName(),
2214                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2215    
2216                    Session session = null;
2217    
2218                    try {
2219                            session = openSession();
2220    
2221                            SQLQuery q = session.createSQLQuery(sql);
2222    
2223                            q.addScalar(COUNT_COLUMN_NAME,
2224                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2225    
2226                            QueryPos qPos = QueryPos.getInstance(q);
2227    
2228                            qPos.add(groupId);
2229    
2230                            Long count = (Long)q.uniqueResult();
2231    
2232                            return count.intValue();
2233                    }
2234                    catch (Exception e) {
2235                            throw processException(e);
2236                    }
2237                    finally {
2238                            closeSession(session);
2239                    }
2240            }
2241    
2242            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2243            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2244                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2245                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2246                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2247                            new String[] {
2248                                    Long.class.getName(),
2249                                    
2250                            Integer.class.getName(), Integer.class.getName(),
2251                                    OrderByComparator.class.getName()
2252                            });
2253            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2254                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2255                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2256                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2257                            new String[] { Long.class.getName() },
2258                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2259                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2260            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2261                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2263                            new String[] { Long.class.getName() });
2264    
2265            /**
2266             * Returns all the message-boards messages where companyId = &#63;.
2267             *
2268             * @param companyId the company ID
2269             * @return the matching message-boards messages
2270             * @throws SystemException if a system exception occurred
2271             */
2272            public List<MBMessage> findByCompanyId(long companyId)
2273                    throws SystemException {
2274                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2275                            null);
2276            }
2277    
2278            /**
2279             * Returns a range of all the message-boards messages where companyId = &#63;.
2280             *
2281             * <p>
2282             * 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.
2283             * </p>
2284             *
2285             * @param companyId the company ID
2286             * @param start the lower bound of the range of message-boards messages
2287             * @param end the upper bound of the range of message-boards messages (not inclusive)
2288             * @return the range of matching message-boards messages
2289             * @throws SystemException if a system exception occurred
2290             */
2291            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2292                    throws SystemException {
2293                    return findByCompanyId(companyId, start, end, null);
2294            }
2295    
2296            /**
2297             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2298             *
2299             * <p>
2300             * 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.
2301             * </p>
2302             *
2303             * @param companyId the company ID
2304             * @param start the lower bound of the range of message-boards messages
2305             * @param end the upper bound of the range of message-boards messages (not inclusive)
2306             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2307             * @return the ordered range of matching message-boards messages
2308             * @throws SystemException if a system exception occurred
2309             */
2310            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2311                    OrderByComparator orderByComparator) throws SystemException {
2312                    boolean pagination = true;
2313                    FinderPath finderPath = null;
2314                    Object[] finderArgs = null;
2315    
2316                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2317                                    (orderByComparator == null)) {
2318                            pagination = false;
2319                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2320                            finderArgs = new Object[] { companyId };
2321                    }
2322                    else {
2323                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2324                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2325                    }
2326    
2327                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2328                                    finderArgs, this);
2329    
2330                    if ((list != null) && !list.isEmpty()) {
2331                            for (MBMessage mbMessage : list) {
2332                                    if ((companyId != mbMessage.getCompanyId())) {
2333                                            list = null;
2334    
2335                                            break;
2336                                    }
2337                            }
2338                    }
2339    
2340                    if (list == null) {
2341                            StringBundler query = null;
2342    
2343                            if (orderByComparator != null) {
2344                                    query = new StringBundler(3 +
2345                                                    (orderByComparator.getOrderByFields().length * 3));
2346                            }
2347                            else {
2348                                    query = new StringBundler(3);
2349                            }
2350    
2351                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2352    
2353                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2354    
2355                            if (orderByComparator != null) {
2356                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2357                                            orderByComparator);
2358                            }
2359                            else
2360                             if (pagination) {
2361                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2362                            }
2363    
2364                            String sql = query.toString();
2365    
2366                            Session session = null;
2367    
2368                            try {
2369                                    session = openSession();
2370    
2371                                    Query q = session.createQuery(sql);
2372    
2373                                    QueryPos qPos = QueryPos.getInstance(q);
2374    
2375                                    qPos.add(companyId);
2376    
2377                                    if (!pagination) {
2378                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2379                                                            start, end, false);
2380    
2381                                            Collections.sort(list);
2382    
2383                                            list = new UnmodifiableList<MBMessage>(list);
2384                                    }
2385                                    else {
2386                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2387                                                            start, end);
2388                                    }
2389    
2390                                    cacheResult(list);
2391    
2392                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2393                            }
2394                            catch (Exception e) {
2395                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2396    
2397                                    throw processException(e);
2398                            }
2399                            finally {
2400                                    closeSession(session);
2401                            }
2402                    }
2403    
2404                    return list;
2405            }
2406    
2407            /**
2408             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2409             *
2410             * @param companyId the company ID
2411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2412             * @return the first matching message-boards message
2413             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2414             * @throws SystemException if a system exception occurred
2415             */
2416            public MBMessage findByCompanyId_First(long companyId,
2417                    OrderByComparator orderByComparator)
2418                    throws NoSuchMessageException, SystemException {
2419                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2420                                    orderByComparator);
2421    
2422                    if (mbMessage != null) {
2423                            return mbMessage;
2424                    }
2425    
2426                    StringBundler msg = new StringBundler(4);
2427    
2428                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2429    
2430                    msg.append("companyId=");
2431                    msg.append(companyId);
2432    
2433                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2434    
2435                    throw new NoSuchMessageException(msg.toString());
2436            }
2437    
2438            /**
2439             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2440             *
2441             * @param companyId the company ID
2442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2443             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2444             * @throws SystemException if a system exception occurred
2445             */
2446            public MBMessage fetchByCompanyId_First(long companyId,
2447                    OrderByComparator orderByComparator) throws SystemException {
2448                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2449                                    orderByComparator);
2450    
2451                    if (!list.isEmpty()) {
2452                            return list.get(0);
2453                    }
2454    
2455                    return null;
2456            }
2457    
2458            /**
2459             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2460             *
2461             * @param companyId the company ID
2462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2463             * @return the last matching message-boards message
2464             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2465             * @throws SystemException if a system exception occurred
2466             */
2467            public MBMessage findByCompanyId_Last(long companyId,
2468                    OrderByComparator orderByComparator)
2469                    throws NoSuchMessageException, SystemException {
2470                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2471    
2472                    if (mbMessage != null) {
2473                            return mbMessage;
2474                    }
2475    
2476                    StringBundler msg = new StringBundler(4);
2477    
2478                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2479    
2480                    msg.append("companyId=");
2481                    msg.append(companyId);
2482    
2483                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2484    
2485                    throw new NoSuchMessageException(msg.toString());
2486            }
2487    
2488            /**
2489             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2490             *
2491             * @param companyId the company ID
2492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2493             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2494             * @throws SystemException if a system exception occurred
2495             */
2496            public MBMessage fetchByCompanyId_Last(long companyId,
2497                    OrderByComparator orderByComparator) throws SystemException {
2498                    int count = countByCompanyId(companyId);
2499    
2500                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2501                                    orderByComparator);
2502    
2503                    if (!list.isEmpty()) {
2504                            return list.get(0);
2505                    }
2506    
2507                    return null;
2508            }
2509    
2510            /**
2511             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2512             *
2513             * @param messageId the primary key of the current message-boards message
2514             * @param companyId the company ID
2515             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2516             * @return the previous, current, and next message-boards message
2517             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2518             * @throws SystemException if a system exception occurred
2519             */
2520            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2521                    long companyId, OrderByComparator orderByComparator)
2522                    throws NoSuchMessageException, SystemException {
2523                    MBMessage mbMessage = findByPrimaryKey(messageId);
2524    
2525                    Session session = null;
2526    
2527                    try {
2528                            session = openSession();
2529    
2530                            MBMessage[] array = new MBMessageImpl[3];
2531    
2532                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2533                                            companyId, orderByComparator, true);
2534    
2535                            array[1] = mbMessage;
2536    
2537                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2538                                            companyId, orderByComparator, false);
2539    
2540                            return array;
2541                    }
2542                    catch (Exception e) {
2543                            throw processException(e);
2544                    }
2545                    finally {
2546                            closeSession(session);
2547                    }
2548            }
2549    
2550            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2551                    MBMessage mbMessage, long companyId,
2552                    OrderByComparator orderByComparator, boolean previous) {
2553                    StringBundler query = null;
2554    
2555                    if (orderByComparator != null) {
2556                            query = new StringBundler(6 +
2557                                            (orderByComparator.getOrderByFields().length * 6));
2558                    }
2559                    else {
2560                            query = new StringBundler(3);
2561                    }
2562    
2563                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2564    
2565                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2566    
2567                    if (orderByComparator != null) {
2568                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2569    
2570                            if (orderByConditionFields.length > 0) {
2571                                    query.append(WHERE_AND);
2572                            }
2573    
2574                            for (int i = 0; i < orderByConditionFields.length; i++) {
2575                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2576                                    query.append(orderByConditionFields[i]);
2577    
2578                                    if ((i + 1) < orderByConditionFields.length) {
2579                                            if (orderByComparator.isAscending() ^ previous) {
2580                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2581                                            }
2582                                            else {
2583                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2584                                            }
2585                                    }
2586                                    else {
2587                                            if (orderByComparator.isAscending() ^ previous) {
2588                                                    query.append(WHERE_GREATER_THAN);
2589                                            }
2590                                            else {
2591                                                    query.append(WHERE_LESSER_THAN);
2592                                            }
2593                                    }
2594                            }
2595    
2596                            query.append(ORDER_BY_CLAUSE);
2597    
2598                            String[] orderByFields = orderByComparator.getOrderByFields();
2599    
2600                            for (int i = 0; i < orderByFields.length; i++) {
2601                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2602                                    query.append(orderByFields[i]);
2603    
2604                                    if ((i + 1) < orderByFields.length) {
2605                                            if (orderByComparator.isAscending() ^ previous) {
2606                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2607                                            }
2608                                            else {
2609                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2610                                            }
2611                                    }
2612                                    else {
2613                                            if (orderByComparator.isAscending() ^ previous) {
2614                                                    query.append(ORDER_BY_ASC);
2615                                            }
2616                                            else {
2617                                                    query.append(ORDER_BY_DESC);
2618                                            }
2619                                    }
2620                            }
2621                    }
2622                    else {
2623                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2624                    }
2625    
2626                    String sql = query.toString();
2627    
2628                    Query q = session.createQuery(sql);
2629    
2630                    q.setFirstResult(0);
2631                    q.setMaxResults(2);
2632    
2633                    QueryPos qPos = QueryPos.getInstance(q);
2634    
2635                    qPos.add(companyId);
2636    
2637                    if (orderByComparator != null) {
2638                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2639    
2640                            for (Object value : values) {
2641                                    qPos.add(value);
2642                            }
2643                    }
2644    
2645                    List<MBMessage> list = q.list();
2646    
2647                    if (list.size() == 2) {
2648                            return list.get(1);
2649                    }
2650                    else {
2651                            return null;
2652                    }
2653            }
2654    
2655            /**
2656             * Removes all the message-boards messages where companyId = &#63; from the database.
2657             *
2658             * @param companyId the company ID
2659             * @throws SystemException if a system exception occurred
2660             */
2661            public void removeByCompanyId(long companyId) throws SystemException {
2662                    for (MBMessage mbMessage : findByCompanyId(companyId,
2663                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2664                            remove(mbMessage);
2665                    }
2666            }
2667    
2668            /**
2669             * Returns the number of message-boards messages where companyId = &#63;.
2670             *
2671             * @param companyId the company ID
2672             * @return the number of matching message-boards messages
2673             * @throws SystemException if a system exception occurred
2674             */
2675            public int countByCompanyId(long companyId) throws SystemException {
2676                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2677    
2678                    Object[] finderArgs = new Object[] { companyId };
2679    
2680                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2681                                    this);
2682    
2683                    if (count == null) {
2684                            StringBundler query = new StringBundler(2);
2685    
2686                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2687    
2688                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2689    
2690                            String sql = query.toString();
2691    
2692                            Session session = null;
2693    
2694                            try {
2695                                    session = openSession();
2696    
2697                                    Query q = session.createQuery(sql);
2698    
2699                                    QueryPos qPos = QueryPos.getInstance(q);
2700    
2701                                    qPos.add(companyId);
2702    
2703                                    count = (Long)q.uniqueResult();
2704    
2705                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2706                            }
2707                            catch (Exception e) {
2708                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2709    
2710                                    throw processException(e);
2711                            }
2712                            finally {
2713                                    closeSession(session);
2714                            }
2715                    }
2716    
2717                    return count.intValue();
2718            }
2719    
2720            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2721            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2722                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2723                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
2724                            new String[] {
2725                                    Long.class.getName(),
2726                                    
2727                            Integer.class.getName(), Integer.class.getName(),
2728                                    OrderByComparator.class.getName()
2729                            });
2730            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
2731                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2732                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2733                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
2734                            new String[] { Long.class.getName() },
2735                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
2736                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2737            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2738                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2739                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
2740                            new String[] { Long.class.getName() });
2741    
2742            /**
2743             * Returns all the message-boards messages where threadId = &#63;.
2744             *
2745             * @param threadId the thread ID
2746             * @return the matching message-boards messages
2747             * @throws SystemException if a system exception occurred
2748             */
2749            public List<MBMessage> findByThreadId(long threadId)
2750                    throws SystemException {
2751                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2752                            null);
2753            }
2754    
2755            /**
2756             * Returns a range of all the message-boards messages where threadId = &#63;.
2757             *
2758             * <p>
2759             * 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.
2760             * </p>
2761             *
2762             * @param threadId the thread ID
2763             * @param start the lower bound of the range of message-boards messages
2764             * @param end the upper bound of the range of message-boards messages (not inclusive)
2765             * @return the range of matching message-boards messages
2766             * @throws SystemException if a system exception occurred
2767             */
2768            public List<MBMessage> findByThreadId(long threadId, int start, int end)
2769                    throws SystemException {
2770                    return findByThreadId(threadId, start, end, null);
2771            }
2772    
2773            /**
2774             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
2775             *
2776             * <p>
2777             * 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.
2778             * </p>
2779             *
2780             * @param threadId the thread ID
2781             * @param start the lower bound of the range of message-boards messages
2782             * @param end the upper bound of the range of message-boards messages (not inclusive)
2783             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2784             * @return the ordered range of matching message-boards messages
2785             * @throws SystemException if a system exception occurred
2786             */
2787            public List<MBMessage> findByThreadId(long threadId, int start, int end,
2788                    OrderByComparator orderByComparator) throws SystemException {
2789                    boolean pagination = true;
2790                    FinderPath finderPath = null;
2791                    Object[] finderArgs = null;
2792    
2793                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2794                                    (orderByComparator == null)) {
2795                            pagination = false;
2796                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
2797                            finderArgs = new Object[] { threadId };
2798                    }
2799                    else {
2800                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
2801                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
2802                    }
2803    
2804                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2805                                    finderArgs, this);
2806    
2807                    if ((list != null) && !list.isEmpty()) {
2808                            for (MBMessage mbMessage : list) {
2809                                    if ((threadId != mbMessage.getThreadId())) {
2810                                            list = null;
2811    
2812                                            break;
2813                                    }
2814                            }
2815                    }
2816    
2817                    if (list == null) {
2818                            StringBundler query = null;
2819    
2820                            if (orderByComparator != null) {
2821                                    query = new StringBundler(3 +
2822                                                    (orderByComparator.getOrderByFields().length * 3));
2823                            }
2824                            else {
2825                                    query = new StringBundler(3);
2826                            }
2827    
2828                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2829    
2830                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2831    
2832                            if (orderByComparator != null) {
2833                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2834                                            orderByComparator);
2835                            }
2836                            else
2837                             if (pagination) {
2838                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2839                            }
2840    
2841                            String sql = query.toString();
2842    
2843                            Session session = null;
2844    
2845                            try {
2846                                    session = openSession();
2847    
2848                                    Query q = session.createQuery(sql);
2849    
2850                                    QueryPos qPos = QueryPos.getInstance(q);
2851    
2852                                    qPos.add(threadId);
2853    
2854                                    if (!pagination) {
2855                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2856                                                            start, end, false);
2857    
2858                                            Collections.sort(list);
2859    
2860                                            list = new UnmodifiableList<MBMessage>(list);
2861                                    }
2862                                    else {
2863                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2864                                                            start, end);
2865                                    }
2866    
2867                                    cacheResult(list);
2868    
2869                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2870                            }
2871                            catch (Exception e) {
2872                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2873    
2874                                    throw processException(e);
2875                            }
2876                            finally {
2877                                    closeSession(session);
2878                            }
2879                    }
2880    
2881                    return list;
2882            }
2883    
2884            /**
2885             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2886             *
2887             * @param threadId the thread ID
2888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2889             * @return the first matching message-boards message
2890             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2891             * @throws SystemException if a system exception occurred
2892             */
2893            public MBMessage findByThreadId_First(long threadId,
2894                    OrderByComparator orderByComparator)
2895                    throws NoSuchMessageException, SystemException {
2896                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
2897    
2898                    if (mbMessage != null) {
2899                            return mbMessage;
2900                    }
2901    
2902                    StringBundler msg = new StringBundler(4);
2903    
2904                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2905    
2906                    msg.append("threadId=");
2907                    msg.append(threadId);
2908    
2909                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2910    
2911                    throw new NoSuchMessageException(msg.toString());
2912            }
2913    
2914            /**
2915             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2916             *
2917             * @param threadId the thread ID
2918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2919             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2920             * @throws SystemException if a system exception occurred
2921             */
2922            public MBMessage fetchByThreadId_First(long threadId,
2923                    OrderByComparator orderByComparator) throws SystemException {
2924                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
2925    
2926                    if (!list.isEmpty()) {
2927                            return list.get(0);
2928                    }
2929    
2930                    return null;
2931            }
2932    
2933            /**
2934             * Returns the last message-boards message in the ordered set where threadId = &#63;.
2935             *
2936             * @param threadId the thread ID
2937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2938             * @return the last matching message-boards message
2939             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2940             * @throws SystemException if a system exception occurred
2941             */
2942            public MBMessage findByThreadId_Last(long threadId,
2943                    OrderByComparator orderByComparator)
2944                    throws NoSuchMessageException, SystemException {
2945                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
2946    
2947                    if (mbMessage != null) {
2948                            return mbMessage;
2949                    }
2950    
2951                    StringBundler msg = new StringBundler(4);
2952    
2953                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2954    
2955                    msg.append("threadId=");
2956                    msg.append(threadId);
2957    
2958                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2959    
2960                    throw new NoSuchMessageException(msg.toString());
2961            }
2962    
2963            /**
2964             * Returns the last message-boards message in the ordered set where threadId = &#63;.
2965             *
2966             * @param threadId the thread ID
2967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2968             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2969             * @throws SystemException if a system exception occurred
2970             */
2971            public MBMessage fetchByThreadId_Last(long threadId,
2972                    OrderByComparator orderByComparator) throws SystemException {
2973                    int count = countByThreadId(threadId);
2974    
2975                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
2976                                    orderByComparator);
2977    
2978                    if (!list.isEmpty()) {
2979                            return list.get(0);
2980                    }
2981    
2982                    return null;
2983            }
2984    
2985            /**
2986             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
2987             *
2988             * @param messageId the primary key of the current message-boards message
2989             * @param threadId the thread ID
2990             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2991             * @return the previous, current, and next message-boards message
2992             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2993             * @throws SystemException if a system exception occurred
2994             */
2995            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
2996                    long threadId, OrderByComparator orderByComparator)
2997                    throws NoSuchMessageException, SystemException {
2998                    MBMessage mbMessage = findByPrimaryKey(messageId);
2999    
3000                    Session session = null;
3001    
3002                    try {
3003                            session = openSession();
3004    
3005                            MBMessage[] array = new MBMessageImpl[3];
3006    
3007                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3008                                            orderByComparator, true);
3009    
3010                            array[1] = mbMessage;
3011    
3012                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3013                                            orderByComparator, false);
3014    
3015                            return array;
3016                    }
3017                    catch (Exception e) {
3018                            throw processException(e);
3019                    }
3020                    finally {
3021                            closeSession(session);
3022                    }
3023            }
3024    
3025            protected MBMessage getByThreadId_PrevAndNext(Session session,
3026                    MBMessage mbMessage, long threadId,
3027                    OrderByComparator orderByComparator, boolean previous) {
3028                    StringBundler query = null;
3029    
3030                    if (orderByComparator != null) {
3031                            query = new StringBundler(6 +
3032                                            (orderByComparator.getOrderByFields().length * 6));
3033                    }
3034                    else {
3035                            query = new StringBundler(3);
3036                    }
3037    
3038                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3039    
3040                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3041    
3042                    if (orderByComparator != null) {
3043                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3044    
3045                            if (orderByConditionFields.length > 0) {
3046                                    query.append(WHERE_AND);
3047                            }
3048    
3049                            for (int i = 0; i < orderByConditionFields.length; i++) {
3050                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3051                                    query.append(orderByConditionFields[i]);
3052    
3053                                    if ((i + 1) < orderByConditionFields.length) {
3054                                            if (orderByComparator.isAscending() ^ previous) {
3055                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3056                                            }
3057                                            else {
3058                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3059                                            }
3060                                    }
3061                                    else {
3062                                            if (orderByComparator.isAscending() ^ previous) {
3063                                                    query.append(WHERE_GREATER_THAN);
3064                                            }
3065                                            else {
3066                                                    query.append(WHERE_LESSER_THAN);
3067                                            }
3068                                    }
3069                            }
3070    
3071                            query.append(ORDER_BY_CLAUSE);
3072    
3073                            String[] orderByFields = orderByComparator.getOrderByFields();
3074    
3075                            for (int i = 0; i < orderByFields.length; i++) {
3076                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3077                                    query.append(orderByFields[i]);
3078    
3079                                    if ((i + 1) < orderByFields.length) {
3080                                            if (orderByComparator.isAscending() ^ previous) {
3081                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3082                                            }
3083                                            else {
3084                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3085                                            }
3086                                    }
3087                                    else {
3088                                            if (orderByComparator.isAscending() ^ previous) {
3089                                                    query.append(ORDER_BY_ASC);
3090                                            }
3091                                            else {
3092                                                    query.append(ORDER_BY_DESC);
3093                                            }
3094                                    }
3095                            }
3096                    }
3097                    else {
3098                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3099                    }
3100    
3101                    String sql = query.toString();
3102    
3103                    Query q = session.createQuery(sql);
3104    
3105                    q.setFirstResult(0);
3106                    q.setMaxResults(2);
3107    
3108                    QueryPos qPos = QueryPos.getInstance(q);
3109    
3110                    qPos.add(threadId);
3111    
3112                    if (orderByComparator != null) {
3113                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3114    
3115                            for (Object value : values) {
3116                                    qPos.add(value);
3117                            }
3118                    }
3119    
3120                    List<MBMessage> list = q.list();
3121    
3122                    if (list.size() == 2) {
3123                            return list.get(1);
3124                    }
3125                    else {
3126                            return null;
3127                    }
3128            }
3129    
3130            /**
3131             * Removes all the message-boards messages where threadId = &#63; from the database.
3132             *
3133             * @param threadId the thread ID
3134             * @throws SystemException if a system exception occurred
3135             */
3136            public void removeByThreadId(long threadId) throws SystemException {
3137                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3138                                    QueryUtil.ALL_POS, null)) {
3139                            remove(mbMessage);
3140                    }
3141            }
3142    
3143            /**
3144             * Returns the number of message-boards messages where threadId = &#63;.
3145             *
3146             * @param threadId the thread ID
3147             * @return the number of matching message-boards messages
3148             * @throws SystemException if a system exception occurred
3149             */
3150            public int countByThreadId(long threadId) throws SystemException {
3151                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3152    
3153                    Object[] finderArgs = new Object[] { threadId };
3154    
3155                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3156                                    this);
3157    
3158                    if (count == null) {
3159                            StringBundler query = new StringBundler(2);
3160    
3161                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3162    
3163                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3164    
3165                            String sql = query.toString();
3166    
3167                            Session session = null;
3168    
3169                            try {
3170                                    session = openSession();
3171    
3172                                    Query q = session.createQuery(sql);
3173    
3174                                    QueryPos qPos = QueryPos.getInstance(q);
3175    
3176                                    qPos.add(threadId);
3177    
3178                                    count = (Long)q.uniqueResult();
3179    
3180                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3181                            }
3182                            catch (Exception e) {
3183                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3184    
3185                                    throw processException(e);
3186                            }
3187                            finally {
3188                                    closeSession(session);
3189                            }
3190                    }
3191    
3192                    return count.intValue();
3193            }
3194    
3195            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3196            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3197                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3199                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3200                            new String[] {
3201                                    Long.class.getName(),
3202                                    
3203                            Integer.class.getName(), Integer.class.getName(),
3204                                    OrderByComparator.class.getName()
3205                            });
3206            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3207                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3210                            new String[] { Long.class.getName() },
3211                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3212                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3213            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3214                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3215                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3216                            new String[] { Long.class.getName() });
3217    
3218            /**
3219             * Returns all the message-boards messages where threadId = &#63;.
3220             *
3221             * @param threadId the thread ID
3222             * @return the matching message-boards messages
3223             * @throws SystemException if a system exception occurred
3224             */
3225            public List<MBMessage> findByThreadReplies(long threadId)
3226                    throws SystemException {
3227                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3228                            QueryUtil.ALL_POS, null);
3229            }
3230    
3231            /**
3232             * Returns a range of all the message-boards messages where threadId = &#63;.
3233             *
3234             * <p>
3235             * 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.
3236             * </p>
3237             *
3238             * @param threadId the thread ID
3239             * @param start the lower bound of the range of message-boards messages
3240             * @param end the upper bound of the range of message-boards messages (not inclusive)
3241             * @return the range of matching message-boards messages
3242             * @throws SystemException if a system exception occurred
3243             */
3244            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3245                    throws SystemException {
3246                    return findByThreadReplies(threadId, start, end, null);
3247            }
3248    
3249            /**
3250             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3251             *
3252             * <p>
3253             * 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.
3254             * </p>
3255             *
3256             * @param threadId the thread ID
3257             * @param start the lower bound of the range of message-boards messages
3258             * @param end the upper bound of the range of message-boards messages (not inclusive)
3259             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3260             * @return the ordered range of matching message-boards messages
3261             * @throws SystemException if a system exception occurred
3262             */
3263            public List<MBMessage> findByThreadReplies(long threadId, int start,
3264                    int end, OrderByComparator orderByComparator) throws SystemException {
3265                    boolean pagination = true;
3266                    FinderPath finderPath = null;
3267                    Object[] finderArgs = null;
3268    
3269                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3270                                    (orderByComparator == null)) {
3271                            pagination = false;
3272                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3273                            finderArgs = new Object[] { threadId };
3274                    }
3275                    else {
3276                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3277                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3278                    }
3279    
3280                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3281                                    finderArgs, this);
3282    
3283                    if ((list != null) && !list.isEmpty()) {
3284                            for (MBMessage mbMessage : list) {
3285                                    if ((threadId != mbMessage.getThreadId())) {
3286                                            list = null;
3287    
3288                                            break;
3289                                    }
3290                            }
3291                    }
3292    
3293                    if (list == null) {
3294                            StringBundler query = null;
3295    
3296                            if (orderByComparator != null) {
3297                                    query = new StringBundler(3 +
3298                                                    (orderByComparator.getOrderByFields().length * 3));
3299                            }
3300                            else {
3301                                    query = new StringBundler(3);
3302                            }
3303    
3304                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3305    
3306                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3307    
3308                            if (orderByComparator != null) {
3309                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3310                                            orderByComparator);
3311                            }
3312                            else
3313                             if (pagination) {
3314                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3315                            }
3316    
3317                            String sql = query.toString();
3318    
3319                            Session session = null;
3320    
3321                            try {
3322                                    session = openSession();
3323    
3324                                    Query q = session.createQuery(sql);
3325    
3326                                    QueryPos qPos = QueryPos.getInstance(q);
3327    
3328                                    qPos.add(threadId);
3329    
3330                                    if (!pagination) {
3331                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3332                                                            start, end, false);
3333    
3334                                            Collections.sort(list);
3335    
3336                                            list = new UnmodifiableList<MBMessage>(list);
3337                                    }
3338                                    else {
3339                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3340                                                            start, end);
3341                                    }
3342    
3343                                    cacheResult(list);
3344    
3345                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3346                            }
3347                            catch (Exception e) {
3348                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3349    
3350                                    throw processException(e);
3351                            }
3352                            finally {
3353                                    closeSession(session);
3354                            }
3355                    }
3356    
3357                    return list;
3358            }
3359    
3360            /**
3361             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3362             *
3363             * @param threadId the thread ID
3364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3365             * @return the first matching message-boards message
3366             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3367             * @throws SystemException if a system exception occurred
3368             */
3369            public MBMessage findByThreadReplies_First(long threadId,
3370                    OrderByComparator orderByComparator)
3371                    throws NoSuchMessageException, SystemException {
3372                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3373                                    orderByComparator);
3374    
3375                    if (mbMessage != null) {
3376                            return mbMessage;
3377                    }
3378    
3379                    StringBundler msg = new StringBundler(4);
3380    
3381                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3382    
3383                    msg.append("threadId=");
3384                    msg.append(threadId);
3385    
3386                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3387    
3388                    throw new NoSuchMessageException(msg.toString());
3389            }
3390    
3391            /**
3392             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3393             *
3394             * @param threadId the thread ID
3395             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3396             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3397             * @throws SystemException if a system exception occurred
3398             */
3399            public MBMessage fetchByThreadReplies_First(long threadId,
3400                    OrderByComparator orderByComparator) throws SystemException {
3401                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3402                                    orderByComparator);
3403    
3404                    if (!list.isEmpty()) {
3405                            return list.get(0);
3406                    }
3407    
3408                    return null;
3409            }
3410    
3411            /**
3412             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3413             *
3414             * @param threadId the thread ID
3415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3416             * @return the last matching message-boards message
3417             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3418             * @throws SystemException if a system exception occurred
3419             */
3420            public MBMessage findByThreadReplies_Last(long threadId,
3421                    OrderByComparator orderByComparator)
3422                    throws NoSuchMessageException, SystemException {
3423                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3424                                    orderByComparator);
3425    
3426                    if (mbMessage != null) {
3427                            return mbMessage;
3428                    }
3429    
3430                    StringBundler msg = new StringBundler(4);
3431    
3432                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3433    
3434                    msg.append("threadId=");
3435                    msg.append(threadId);
3436    
3437                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3438    
3439                    throw new NoSuchMessageException(msg.toString());
3440            }
3441    
3442            /**
3443             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3444             *
3445             * @param threadId the thread ID
3446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3447             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3448             * @throws SystemException if a system exception occurred
3449             */
3450            public MBMessage fetchByThreadReplies_Last(long threadId,
3451                    OrderByComparator orderByComparator) throws SystemException {
3452                    int count = countByThreadReplies(threadId);
3453    
3454                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3455                                    orderByComparator);
3456    
3457                    if (!list.isEmpty()) {
3458                            return list.get(0);
3459                    }
3460    
3461                    return null;
3462            }
3463    
3464            /**
3465             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3466             *
3467             * @param messageId the primary key of the current message-boards message
3468             * @param threadId the thread ID
3469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3470             * @return the previous, current, and next message-boards message
3471             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3472             * @throws SystemException if a system exception occurred
3473             */
3474            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3475                    long threadId, OrderByComparator orderByComparator)
3476                    throws NoSuchMessageException, SystemException {
3477                    MBMessage mbMessage = findByPrimaryKey(messageId);
3478    
3479                    Session session = null;
3480    
3481                    try {
3482                            session = openSession();
3483    
3484                            MBMessage[] array = new MBMessageImpl[3];
3485    
3486                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3487                                            threadId, orderByComparator, true);
3488    
3489                            array[1] = mbMessage;
3490    
3491                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3492                                            threadId, orderByComparator, false);
3493    
3494                            return array;
3495                    }
3496                    catch (Exception e) {
3497                            throw processException(e);
3498                    }
3499                    finally {
3500                            closeSession(session);
3501                    }
3502            }
3503    
3504            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3505                    MBMessage mbMessage, long threadId,
3506                    OrderByComparator orderByComparator, boolean previous) {
3507                    StringBundler query = null;
3508    
3509                    if (orderByComparator != null) {
3510                            query = new StringBundler(6 +
3511                                            (orderByComparator.getOrderByFields().length * 6));
3512                    }
3513                    else {
3514                            query = new StringBundler(3);
3515                    }
3516    
3517                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3518    
3519                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3520    
3521                    if (orderByComparator != null) {
3522                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3523    
3524                            if (orderByConditionFields.length > 0) {
3525                                    query.append(WHERE_AND);
3526                            }
3527    
3528                            for (int i = 0; i < orderByConditionFields.length; i++) {
3529                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3530                                    query.append(orderByConditionFields[i]);
3531    
3532                                    if ((i + 1) < orderByConditionFields.length) {
3533                                            if (orderByComparator.isAscending() ^ previous) {
3534                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3535                                            }
3536                                            else {
3537                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3538                                            }
3539                                    }
3540                                    else {
3541                                            if (orderByComparator.isAscending() ^ previous) {
3542                                                    query.append(WHERE_GREATER_THAN);
3543                                            }
3544                                            else {
3545                                                    query.append(WHERE_LESSER_THAN);
3546                                            }
3547                                    }
3548                            }
3549    
3550                            query.append(ORDER_BY_CLAUSE);
3551    
3552                            String[] orderByFields = orderByComparator.getOrderByFields();
3553    
3554                            for (int i = 0; i < orderByFields.length; i++) {
3555                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3556                                    query.append(orderByFields[i]);
3557    
3558                                    if ((i + 1) < orderByFields.length) {
3559                                            if (orderByComparator.isAscending() ^ previous) {
3560                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3561                                            }
3562                                            else {
3563                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3564                                            }
3565                                    }
3566                                    else {
3567                                            if (orderByComparator.isAscending() ^ previous) {
3568                                                    query.append(ORDER_BY_ASC);
3569                                            }
3570                                            else {
3571                                                    query.append(ORDER_BY_DESC);
3572                                            }
3573                                    }
3574                            }
3575                    }
3576                    else {
3577                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3578                    }
3579    
3580                    String sql = query.toString();
3581    
3582                    Query q = session.createQuery(sql);
3583    
3584                    q.setFirstResult(0);
3585                    q.setMaxResults(2);
3586    
3587                    QueryPos qPos = QueryPos.getInstance(q);
3588    
3589                    qPos.add(threadId);
3590    
3591                    if (orderByComparator != null) {
3592                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3593    
3594                            for (Object value : values) {
3595                                    qPos.add(value);
3596                            }
3597                    }
3598    
3599                    List<MBMessage> list = q.list();
3600    
3601                    if (list.size() == 2) {
3602                            return list.get(1);
3603                    }
3604                    else {
3605                            return null;
3606                    }
3607            }
3608    
3609            /**
3610             * Removes all the message-boards messages where threadId = &#63; from the database.
3611             *
3612             * @param threadId the thread ID
3613             * @throws SystemException if a system exception occurred
3614             */
3615            public void removeByThreadReplies(long threadId) throws SystemException {
3616                    for (MBMessage mbMessage : findByThreadReplies(threadId,
3617                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3618                            remove(mbMessage);
3619                    }
3620            }
3621    
3622            /**
3623             * Returns the number of message-boards messages where threadId = &#63;.
3624             *
3625             * @param threadId the thread ID
3626             * @return the number of matching message-boards messages
3627             * @throws SystemException if a system exception occurred
3628             */
3629            public int countByThreadReplies(long threadId) throws SystemException {
3630                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
3631    
3632                    Object[] finderArgs = new Object[] { threadId };
3633    
3634                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3635                                    this);
3636    
3637                    if (count == null) {
3638                            StringBundler query = new StringBundler(2);
3639    
3640                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3641    
3642                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3643    
3644                            String sql = query.toString();
3645    
3646                            Session session = null;
3647    
3648                            try {
3649                                    session = openSession();
3650    
3651                                    Query q = session.createQuery(sql);
3652    
3653                                    QueryPos qPos = QueryPos.getInstance(q);
3654    
3655                                    qPos.add(threadId);
3656    
3657                                    count = (Long)q.uniqueResult();
3658    
3659                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3660                            }
3661                            catch (Exception e) {
3662                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3663    
3664                                    throw processException(e);
3665                            }
3666                            finally {
3667                                    closeSession(session);
3668                            }
3669                    }
3670    
3671                    return count.intValue();
3672            }
3673    
3674            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
3675            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3676                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3677                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
3678                            new String[] {
3679                                    Long.class.getName(),
3680                                    
3681                            Integer.class.getName(), Integer.class.getName(),
3682                                    OrderByComparator.class.getName()
3683                            });
3684            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
3685                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3686                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3687                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
3688                            new String[] { Long.class.getName() },
3689                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
3690                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3691            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3692                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3693                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
3694                            new String[] { Long.class.getName() });
3695    
3696            /**
3697             * Returns all the message-boards messages where userId = &#63;.
3698             *
3699             * @param userId the user ID
3700             * @return the matching message-boards messages
3701             * @throws SystemException if a system exception occurred
3702             */
3703            public List<MBMessage> findByUserId(long userId) throws SystemException {
3704                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3705            }
3706    
3707            /**
3708             * Returns a range of all the message-boards messages where userId = &#63;.
3709             *
3710             * <p>
3711             * 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.
3712             * </p>
3713             *
3714             * @param userId the user ID
3715             * @param start the lower bound of the range of message-boards messages
3716             * @param end the upper bound of the range of message-boards messages (not inclusive)
3717             * @return the range of matching message-boards messages
3718             * @throws SystemException if a system exception occurred
3719             */
3720            public List<MBMessage> findByUserId(long userId, int start, int end)
3721                    throws SystemException {
3722                    return findByUserId(userId, start, end, null);
3723            }
3724    
3725            /**
3726             * Returns an ordered range of all the message-boards messages where userId = &#63;.
3727             *
3728             * <p>
3729             * 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.
3730             * </p>
3731             *
3732             * @param userId the user ID
3733             * @param start the lower bound of the range of message-boards messages
3734             * @param end the upper bound of the range of message-boards messages (not inclusive)
3735             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3736             * @return the ordered range of matching message-boards messages
3737             * @throws SystemException if a system exception occurred
3738             */
3739            public List<MBMessage> findByUserId(long userId, int start, int end,
3740                    OrderByComparator orderByComparator) throws SystemException {
3741                    boolean pagination = true;
3742                    FinderPath finderPath = null;
3743                    Object[] finderArgs = null;
3744    
3745                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3746                                    (orderByComparator == null)) {
3747                            pagination = false;
3748                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3749                            finderArgs = new Object[] { userId };
3750                    }
3751                    else {
3752                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3753                            finderArgs = new Object[] { userId, start, end, orderByComparator };
3754                    }
3755    
3756                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3757                                    finderArgs, this);
3758    
3759                    if ((list != null) && !list.isEmpty()) {
3760                            for (MBMessage mbMessage : list) {
3761                                    if ((userId != mbMessage.getUserId())) {
3762                                            list = null;
3763    
3764                                            break;
3765                                    }
3766                            }
3767                    }
3768    
3769                    if (list == null) {
3770                            StringBundler query = null;
3771    
3772                            if (orderByComparator != null) {
3773                                    query = new StringBundler(3 +
3774                                                    (orderByComparator.getOrderByFields().length * 3));
3775                            }
3776                            else {
3777                                    query = new StringBundler(3);
3778                            }
3779    
3780                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3781    
3782                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3783    
3784                            if (orderByComparator != null) {
3785                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3786                                            orderByComparator);
3787                            }
3788                            else
3789                             if (pagination) {
3790                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3791                            }
3792    
3793                            String sql = query.toString();
3794    
3795                            Session session = null;
3796    
3797                            try {
3798                                    session = openSession();
3799    
3800                                    Query q = session.createQuery(sql);
3801    
3802                                    QueryPos qPos = QueryPos.getInstance(q);
3803    
3804                                    qPos.add(userId);
3805    
3806                                    if (!pagination) {
3807                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3808                                                            start, end, false);
3809    
3810                                            Collections.sort(list);
3811    
3812                                            list = new UnmodifiableList<MBMessage>(list);
3813                                    }
3814                                    else {
3815                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3816                                                            start, end);
3817                                    }
3818    
3819                                    cacheResult(list);
3820    
3821                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3822                            }
3823                            catch (Exception e) {
3824                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3825    
3826                                    throw processException(e);
3827                            }
3828                            finally {
3829                                    closeSession(session);
3830                            }
3831                    }
3832    
3833                    return list;
3834            }
3835    
3836            /**
3837             * Returns the first message-boards message in the ordered set where userId = &#63;.
3838             *
3839             * @param userId the user ID
3840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3841             * @return the first matching message-boards message
3842             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3843             * @throws SystemException if a system exception occurred
3844             */
3845            public MBMessage findByUserId_First(long userId,
3846                    OrderByComparator orderByComparator)
3847                    throws NoSuchMessageException, SystemException {
3848                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3849    
3850                    if (mbMessage != null) {
3851                            return mbMessage;
3852                    }
3853    
3854                    StringBundler msg = new StringBundler(4);
3855    
3856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3857    
3858                    msg.append("userId=");
3859                    msg.append(userId);
3860    
3861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3862    
3863                    throw new NoSuchMessageException(msg.toString());
3864            }
3865    
3866            /**
3867             * Returns the first message-boards message in the ordered set where userId = &#63;.
3868             *
3869             * @param userId the user ID
3870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3871             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3872             * @throws SystemException if a system exception occurred
3873             */
3874            public MBMessage fetchByUserId_First(long userId,
3875                    OrderByComparator orderByComparator) throws SystemException {
3876                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3877    
3878                    if (!list.isEmpty()) {
3879                            return list.get(0);
3880                    }
3881    
3882                    return null;
3883            }
3884    
3885            /**
3886             * Returns the last message-boards message in the ordered set where userId = &#63;.
3887             *
3888             * @param userId the user ID
3889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3890             * @return the last matching message-boards message
3891             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3892             * @throws SystemException if a system exception occurred
3893             */
3894            public MBMessage findByUserId_Last(long userId,
3895                    OrderByComparator orderByComparator)
3896                    throws NoSuchMessageException, SystemException {
3897                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3898    
3899                    if (mbMessage != null) {
3900                            return mbMessage;
3901                    }
3902    
3903                    StringBundler msg = new StringBundler(4);
3904    
3905                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3906    
3907                    msg.append("userId=");
3908                    msg.append(userId);
3909    
3910                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3911    
3912                    throw new NoSuchMessageException(msg.toString());
3913            }
3914    
3915            /**
3916             * Returns the last message-boards message in the ordered set where userId = &#63;.
3917             *
3918             * @param userId the user ID
3919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3920             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3921             * @throws SystemException if a system exception occurred
3922             */
3923            public MBMessage fetchByUserId_Last(long userId,
3924                    OrderByComparator orderByComparator) throws SystemException {
3925                    int count = countByUserId(userId);
3926    
3927                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3928                                    orderByComparator);
3929    
3930                    if (!list.isEmpty()) {
3931                            return list.get(0);
3932                    }
3933    
3934                    return null;
3935            }
3936    
3937            /**
3938             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3939             *
3940             * @param messageId the primary key of the current message-boards message
3941             * @param userId the user ID
3942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3943             * @return the previous, current, and next message-boards message
3944             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3945             * @throws SystemException if a system exception occurred
3946             */
3947            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3948                    OrderByComparator orderByComparator)
3949                    throws NoSuchMessageException, SystemException {
3950                    MBMessage mbMessage = findByPrimaryKey(messageId);
3951    
3952                    Session session = null;
3953    
3954                    try {
3955                            session = openSession();
3956    
3957                            MBMessage[] array = new MBMessageImpl[3];
3958    
3959                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3960                                            orderByComparator, true);
3961    
3962                            array[1] = mbMessage;
3963    
3964                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3965                                            orderByComparator, false);
3966    
3967                            return array;
3968                    }
3969                    catch (Exception e) {
3970                            throw processException(e);
3971                    }
3972                    finally {
3973                            closeSession(session);
3974                    }
3975            }
3976    
3977            protected MBMessage getByUserId_PrevAndNext(Session session,
3978                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
3979                    boolean previous) {
3980                    StringBundler query = null;
3981    
3982                    if (orderByComparator != null) {
3983                            query = new StringBundler(6 +
3984                                            (orderByComparator.getOrderByFields().length * 6));
3985                    }
3986                    else {
3987                            query = new StringBundler(3);
3988                    }
3989    
3990                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3991    
3992                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3993    
3994                    if (orderByComparator != null) {
3995                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3996    
3997                            if (orderByConditionFields.length > 0) {
3998                                    query.append(WHERE_AND);
3999                            }
4000    
4001                            for (int i = 0; i < orderByConditionFields.length; i++) {
4002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4003                                    query.append(orderByConditionFields[i]);
4004    
4005                                    if ((i + 1) < orderByConditionFields.length) {
4006                                            if (orderByComparator.isAscending() ^ previous) {
4007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4008                                            }
4009                                            else {
4010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4011                                            }
4012                                    }
4013                                    else {
4014                                            if (orderByComparator.isAscending() ^ previous) {
4015                                                    query.append(WHERE_GREATER_THAN);
4016                                            }
4017                                            else {
4018                                                    query.append(WHERE_LESSER_THAN);
4019                                            }
4020                                    }
4021                            }
4022    
4023                            query.append(ORDER_BY_CLAUSE);
4024    
4025                            String[] orderByFields = orderByComparator.getOrderByFields();
4026    
4027                            for (int i = 0; i < orderByFields.length; i++) {
4028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4029                                    query.append(orderByFields[i]);
4030    
4031                                    if ((i + 1) < orderByFields.length) {
4032                                            if (orderByComparator.isAscending() ^ previous) {
4033                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4034                                            }
4035                                            else {
4036                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4037                                            }
4038                                    }
4039                                    else {
4040                                            if (orderByComparator.isAscending() ^ previous) {
4041                                                    query.append(ORDER_BY_ASC);
4042                                            }
4043                                            else {
4044                                                    query.append(ORDER_BY_DESC);
4045                                            }
4046                                    }
4047                            }
4048                    }
4049                    else {
4050                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4051                    }
4052    
4053                    String sql = query.toString();
4054    
4055                    Query q = session.createQuery(sql);
4056    
4057                    q.setFirstResult(0);
4058                    q.setMaxResults(2);
4059    
4060                    QueryPos qPos = QueryPos.getInstance(q);
4061    
4062                    qPos.add(userId);
4063    
4064                    if (orderByComparator != null) {
4065                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4066    
4067                            for (Object value : values) {
4068                                    qPos.add(value);
4069                            }
4070                    }
4071    
4072                    List<MBMessage> list = q.list();
4073    
4074                    if (list.size() == 2) {
4075                            return list.get(1);
4076                    }
4077                    else {
4078                            return null;
4079                    }
4080            }
4081    
4082            /**
4083             * Removes all the message-boards messages where userId = &#63; from the database.
4084             *
4085             * @param userId the user ID
4086             * @throws SystemException if a system exception occurred
4087             */
4088            public void removeByUserId(long userId) throws SystemException {
4089                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
4090                                    QueryUtil.ALL_POS, null)) {
4091                            remove(mbMessage);
4092                    }
4093            }
4094    
4095            /**
4096             * Returns the number of message-boards messages where userId = &#63;.
4097             *
4098             * @param userId the user ID
4099             * @return the number of matching message-boards messages
4100             * @throws SystemException if a system exception occurred
4101             */
4102            public int countByUserId(long userId) throws SystemException {
4103                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
4104    
4105                    Object[] finderArgs = new Object[] { userId };
4106    
4107                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4108                                    this);
4109    
4110                    if (count == null) {
4111                            StringBundler query = new StringBundler(2);
4112    
4113                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4114    
4115                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4116    
4117                            String sql = query.toString();
4118    
4119                            Session session = null;
4120    
4121                            try {
4122                                    session = openSession();
4123    
4124                                    Query q = session.createQuery(sql);
4125    
4126                                    QueryPos qPos = QueryPos.getInstance(q);
4127    
4128                                    qPos.add(userId);
4129    
4130                                    count = (Long)q.uniqueResult();
4131    
4132                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4133                            }
4134                            catch (Exception e) {
4135                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4136    
4137                                    throw processException(e);
4138                            }
4139                            finally {
4140                                    closeSession(session);
4141                            }
4142                    }
4143    
4144                    return count.intValue();
4145            }
4146    
4147            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
4148            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4149                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4150                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4151                            new String[] {
4152                                    Long.class.getName(), Long.class.getName(),
4153                                    
4154                            Integer.class.getName(), Integer.class.getName(),
4155                                    OrderByComparator.class.getName()
4156                            });
4157            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4158                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4160                            new String[] { Long.class.getName(), Long.class.getName() },
4161                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4162                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4163                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4164            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4165                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4167                            new String[] { Long.class.getName(), Long.class.getName() });
4168    
4169            /**
4170             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4171             *
4172             * @param groupId the group ID
4173             * @param userId the user ID
4174             * @return the matching message-boards messages
4175             * @throws SystemException if a system exception occurred
4176             */
4177            public List<MBMessage> findByG_U(long groupId, long userId)
4178                    throws SystemException {
4179                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4180                            null);
4181            }
4182    
4183            /**
4184             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4185             *
4186             * <p>
4187             * 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.
4188             * </p>
4189             *
4190             * @param groupId the group ID
4191             * @param userId the user ID
4192             * @param start the lower bound of the range of message-boards messages
4193             * @param end the upper bound of the range of message-boards messages (not inclusive)
4194             * @return the range of matching message-boards messages
4195             * @throws SystemException if a system exception occurred
4196             */
4197            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4198                    int end) throws SystemException {
4199                    return findByG_U(groupId, userId, start, end, null);
4200            }
4201    
4202            /**
4203             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4204             *
4205             * <p>
4206             * 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.
4207             * </p>
4208             *
4209             * @param groupId the group ID
4210             * @param userId the user ID
4211             * @param start the lower bound of the range of message-boards messages
4212             * @param end the upper bound of the range of message-boards messages (not inclusive)
4213             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4214             * @return the ordered range of matching message-boards messages
4215             * @throws SystemException if a system exception occurred
4216             */
4217            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4218                    int end, OrderByComparator orderByComparator) throws SystemException {
4219                    boolean pagination = true;
4220                    FinderPath finderPath = null;
4221                    Object[] finderArgs = null;
4222    
4223                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4224                                    (orderByComparator == null)) {
4225                            pagination = false;
4226                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4227                            finderArgs = new Object[] { groupId, userId };
4228                    }
4229                    else {
4230                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4231                            finderArgs = new Object[] {
4232                                            groupId, userId,
4233                                            
4234                                            start, end, orderByComparator
4235                                    };
4236                    }
4237    
4238                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4239                                    finderArgs, this);
4240    
4241                    if ((list != null) && !list.isEmpty()) {
4242                            for (MBMessage mbMessage : list) {
4243                                    if ((groupId != mbMessage.getGroupId()) ||
4244                                                    (userId != mbMessage.getUserId())) {
4245                                            list = null;
4246    
4247                                            break;
4248                                    }
4249                            }
4250                    }
4251    
4252                    if (list == null) {
4253                            StringBundler query = null;
4254    
4255                            if (orderByComparator != null) {
4256                                    query = new StringBundler(4 +
4257                                                    (orderByComparator.getOrderByFields().length * 3));
4258                            }
4259                            else {
4260                                    query = new StringBundler(4);
4261                            }
4262    
4263                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4264    
4265                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4266    
4267                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4268    
4269                            if (orderByComparator != null) {
4270                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4271                                            orderByComparator);
4272                            }
4273                            else
4274                             if (pagination) {
4275                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4276                            }
4277    
4278                            String sql = query.toString();
4279    
4280                            Session session = null;
4281    
4282                            try {
4283                                    session = openSession();
4284    
4285                                    Query q = session.createQuery(sql);
4286    
4287                                    QueryPos qPos = QueryPos.getInstance(q);
4288    
4289                                    qPos.add(groupId);
4290    
4291                                    qPos.add(userId);
4292    
4293                                    if (!pagination) {
4294                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4295                                                            start, end, false);
4296    
4297                                            Collections.sort(list);
4298    
4299                                            list = new UnmodifiableList<MBMessage>(list);
4300                                    }
4301                                    else {
4302                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4303                                                            start, end);
4304                                    }
4305    
4306                                    cacheResult(list);
4307    
4308                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4309                            }
4310                            catch (Exception e) {
4311                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4312    
4313                                    throw processException(e);
4314                            }
4315                            finally {
4316                                    closeSession(session);
4317                            }
4318                    }
4319    
4320                    return list;
4321            }
4322    
4323            /**
4324             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4325             *
4326             * @param groupId the group ID
4327             * @param userId the user ID
4328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4329             * @return the first matching message-boards message
4330             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4331             * @throws SystemException if a system exception occurred
4332             */
4333            public MBMessage findByG_U_First(long groupId, long userId,
4334                    OrderByComparator orderByComparator)
4335                    throws NoSuchMessageException, SystemException {
4336                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4337                                    orderByComparator);
4338    
4339                    if (mbMessage != null) {
4340                            return mbMessage;
4341                    }
4342    
4343                    StringBundler msg = new StringBundler(6);
4344    
4345                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4346    
4347                    msg.append("groupId=");
4348                    msg.append(groupId);
4349    
4350                    msg.append(", userId=");
4351                    msg.append(userId);
4352    
4353                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4354    
4355                    throw new NoSuchMessageException(msg.toString());
4356            }
4357    
4358            /**
4359             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4360             *
4361             * @param groupId the group ID
4362             * @param userId the user ID
4363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4364             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4365             * @throws SystemException if a system exception occurred
4366             */
4367            public MBMessage fetchByG_U_First(long groupId, long userId,
4368                    OrderByComparator orderByComparator) throws SystemException {
4369                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4370                                    orderByComparator);
4371    
4372                    if (!list.isEmpty()) {
4373                            return list.get(0);
4374                    }
4375    
4376                    return null;
4377            }
4378    
4379            /**
4380             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4381             *
4382             * @param groupId the group ID
4383             * @param userId the user ID
4384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4385             * @return the last matching message-boards message
4386             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4387             * @throws SystemException if a system exception occurred
4388             */
4389            public MBMessage findByG_U_Last(long groupId, long userId,
4390                    OrderByComparator orderByComparator)
4391                    throws NoSuchMessageException, SystemException {
4392                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4393    
4394                    if (mbMessage != null) {
4395                            return mbMessage;
4396                    }
4397    
4398                    StringBundler msg = new StringBundler(6);
4399    
4400                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4401    
4402                    msg.append("groupId=");
4403                    msg.append(groupId);
4404    
4405                    msg.append(", userId=");
4406                    msg.append(userId);
4407    
4408                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4409    
4410                    throw new NoSuchMessageException(msg.toString());
4411            }
4412    
4413            /**
4414             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4415             *
4416             * @param groupId the group ID
4417             * @param userId the user ID
4418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4419             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4420             * @throws SystemException if a system exception occurred
4421             */
4422            public MBMessage fetchByG_U_Last(long groupId, long userId,
4423                    OrderByComparator orderByComparator) throws SystemException {
4424                    int count = countByG_U(groupId, userId);
4425    
4426                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4427                                    orderByComparator);
4428    
4429                    if (!list.isEmpty()) {
4430                            return list.get(0);
4431                    }
4432    
4433                    return null;
4434            }
4435    
4436            /**
4437             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4438             *
4439             * @param messageId the primary key of the current message-boards message
4440             * @param groupId the group ID
4441             * @param userId the user ID
4442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4443             * @return the previous, current, and next message-boards message
4444             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4445             * @throws SystemException if a system exception occurred
4446             */
4447            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4448                    long userId, OrderByComparator orderByComparator)
4449                    throws NoSuchMessageException, SystemException {
4450                    MBMessage mbMessage = findByPrimaryKey(messageId);
4451    
4452                    Session session = null;
4453    
4454                    try {
4455                            session = openSession();
4456    
4457                            MBMessage[] array = new MBMessageImpl[3];
4458    
4459                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4460                                            userId, orderByComparator, true);
4461    
4462                            array[1] = mbMessage;
4463    
4464                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4465                                            userId, orderByComparator, false);
4466    
4467                            return array;
4468                    }
4469                    catch (Exception e) {
4470                            throw processException(e);
4471                    }
4472                    finally {
4473                            closeSession(session);
4474                    }
4475            }
4476    
4477            protected MBMessage getByG_U_PrevAndNext(Session session,
4478                    MBMessage mbMessage, long groupId, long userId,
4479                    OrderByComparator orderByComparator, boolean previous) {
4480                    StringBundler query = null;
4481    
4482                    if (orderByComparator != null) {
4483                            query = new StringBundler(6 +
4484                                            (orderByComparator.getOrderByFields().length * 6));
4485                    }
4486                    else {
4487                            query = new StringBundler(3);
4488                    }
4489    
4490                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4491    
4492                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4493    
4494                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4495    
4496                    if (orderByComparator != null) {
4497                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4498    
4499                            if (orderByConditionFields.length > 0) {
4500                                    query.append(WHERE_AND);
4501                            }
4502    
4503                            for (int i = 0; i < orderByConditionFields.length; i++) {
4504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4505                                    query.append(orderByConditionFields[i]);
4506    
4507                                    if ((i + 1) < orderByConditionFields.length) {
4508                                            if (orderByComparator.isAscending() ^ previous) {
4509                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4510                                            }
4511                                            else {
4512                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4513                                            }
4514                                    }
4515                                    else {
4516                                            if (orderByComparator.isAscending() ^ previous) {
4517                                                    query.append(WHERE_GREATER_THAN);
4518                                            }
4519                                            else {
4520                                                    query.append(WHERE_LESSER_THAN);
4521                                            }
4522                                    }
4523                            }
4524    
4525                            query.append(ORDER_BY_CLAUSE);
4526    
4527                            String[] orderByFields = orderByComparator.getOrderByFields();
4528    
4529                            for (int i = 0; i < orderByFields.length; i++) {
4530                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4531                                    query.append(orderByFields[i]);
4532    
4533                                    if ((i + 1) < orderByFields.length) {
4534                                            if (orderByComparator.isAscending() ^ previous) {
4535                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4536                                            }
4537                                            else {
4538                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4539                                            }
4540                                    }
4541                                    else {
4542                                            if (orderByComparator.isAscending() ^ previous) {
4543                                                    query.append(ORDER_BY_ASC);
4544                                            }
4545                                            else {
4546                                                    query.append(ORDER_BY_DESC);
4547                                            }
4548                                    }
4549                            }
4550                    }
4551                    else {
4552                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4553                    }
4554    
4555                    String sql = query.toString();
4556    
4557                    Query q = session.createQuery(sql);
4558    
4559                    q.setFirstResult(0);
4560                    q.setMaxResults(2);
4561    
4562                    QueryPos qPos = QueryPos.getInstance(q);
4563    
4564                    qPos.add(groupId);
4565    
4566                    qPos.add(userId);
4567    
4568                    if (orderByComparator != null) {
4569                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4570    
4571                            for (Object value : values) {
4572                                    qPos.add(value);
4573                            }
4574                    }
4575    
4576                    List<MBMessage> list = q.list();
4577    
4578                    if (list.size() == 2) {
4579                            return list.get(1);
4580                    }
4581                    else {
4582                            return null;
4583                    }
4584            }
4585    
4586            /**
4587             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4588             *
4589             * @param groupId the group ID
4590             * @param userId the user ID
4591             * @return the matching message-boards messages that the user has permission to view
4592             * @throws SystemException if a system exception occurred
4593             */
4594            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4595                    throws SystemException {
4596                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4597                            QueryUtil.ALL_POS, null);
4598            }
4599    
4600            /**
4601             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4602             *
4603             * <p>
4604             * 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.
4605             * </p>
4606             *
4607             * @param groupId the group ID
4608             * @param userId the user ID
4609             * @param start the lower bound of the range of message-boards messages
4610             * @param end the upper bound of the range of message-boards messages (not inclusive)
4611             * @return the range of matching message-boards messages that the user has permission to view
4612             * @throws SystemException if a system exception occurred
4613             */
4614            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4615                    int start, int end) throws SystemException {
4616                    return filterFindByG_U(groupId, userId, start, end, null);
4617            }
4618    
4619            /**
4620             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4621             *
4622             * <p>
4623             * 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.
4624             * </p>
4625             *
4626             * @param groupId the group ID
4627             * @param userId the user ID
4628             * @param start the lower bound of the range of message-boards messages
4629             * @param end the upper bound of the range of message-boards messages (not inclusive)
4630             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4631             * @return the ordered range of matching message-boards messages that the user has permission to view
4632             * @throws SystemException if a system exception occurred
4633             */
4634            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4635                    int start, int end, OrderByComparator orderByComparator)
4636                    throws SystemException {
4637                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4638                            return findByG_U(groupId, userId, start, end, orderByComparator);
4639                    }
4640    
4641                    StringBundler query = null;
4642    
4643                    if (orderByComparator != null) {
4644                            query = new StringBundler(4 +
4645                                            (orderByComparator.getOrderByFields().length * 3));
4646                    }
4647                    else {
4648                            query = new StringBundler(4);
4649                    }
4650    
4651                    if (getDB().isSupportsInlineDistinct()) {
4652                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4653                    }
4654                    else {
4655                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4656                    }
4657    
4658                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4659    
4660                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4661    
4662                    if (!getDB().isSupportsInlineDistinct()) {
4663                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4664                    }
4665    
4666                    if (orderByComparator != null) {
4667                            if (getDB().isSupportsInlineDistinct()) {
4668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4669                                            orderByComparator);
4670                            }
4671                            else {
4672                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4673                                            orderByComparator);
4674                            }
4675                    }
4676                    else {
4677                            if (getDB().isSupportsInlineDistinct()) {
4678                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4679                            }
4680                            else {
4681                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4682                            }
4683                    }
4684    
4685                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4686                                    MBMessage.class.getName(),
4687                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4688    
4689                    Session session = null;
4690    
4691                    try {
4692                            session = openSession();
4693    
4694                            SQLQuery q = session.createSQLQuery(sql);
4695    
4696                            if (getDB().isSupportsInlineDistinct()) {
4697                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4698                            }
4699                            else {
4700                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4701                            }
4702    
4703                            QueryPos qPos = QueryPos.getInstance(q);
4704    
4705                            qPos.add(groupId);
4706    
4707                            qPos.add(userId);
4708    
4709                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4710                    }
4711                    catch (Exception e) {
4712                            throw processException(e);
4713                    }
4714                    finally {
4715                            closeSession(session);
4716                    }
4717            }
4718    
4719            /**
4720             * 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;.
4721             *
4722             * @param messageId the primary key of the current message-boards message
4723             * @param groupId the group ID
4724             * @param userId the user ID
4725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4726             * @return the previous, current, and next message-boards message
4727             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4728             * @throws SystemException if a system exception occurred
4729             */
4730            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4731                    long groupId, long userId, OrderByComparator orderByComparator)
4732                    throws NoSuchMessageException, SystemException {
4733                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4734                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4735                                    orderByComparator);
4736                    }
4737    
4738                    MBMessage mbMessage = findByPrimaryKey(messageId);
4739    
4740                    Session session = null;
4741    
4742                    try {
4743                            session = openSession();
4744    
4745                            MBMessage[] array = new MBMessageImpl[3];
4746    
4747                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4748                                            userId, orderByComparator, true);
4749    
4750                            array[1] = mbMessage;
4751    
4752                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4753                                            userId, orderByComparator, false);
4754    
4755                            return array;
4756                    }
4757                    catch (Exception e) {
4758                            throw processException(e);
4759                    }
4760                    finally {
4761                            closeSession(session);
4762                    }
4763            }
4764    
4765            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4766                    MBMessage mbMessage, long groupId, long userId,
4767                    OrderByComparator orderByComparator, boolean previous) {
4768                    StringBundler query = null;
4769    
4770                    if (orderByComparator != null) {
4771                            query = new StringBundler(6 +
4772                                            (orderByComparator.getOrderByFields().length * 6));
4773                    }
4774                    else {
4775                            query = new StringBundler(3);
4776                    }
4777    
4778                    if (getDB().isSupportsInlineDistinct()) {
4779                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4780                    }
4781                    else {
4782                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4783                    }
4784    
4785                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4786    
4787                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4788    
4789                    if (!getDB().isSupportsInlineDistinct()) {
4790                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4791                    }
4792    
4793                    if (orderByComparator != null) {
4794                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4795    
4796                            if (orderByConditionFields.length > 0) {
4797                                    query.append(WHERE_AND);
4798                            }
4799    
4800                            for (int i = 0; i < orderByConditionFields.length; i++) {
4801                                    if (getDB().isSupportsInlineDistinct()) {
4802                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4803                                    }
4804                                    else {
4805                                            query.append(_ORDER_BY_ENTITY_TABLE);
4806                                    }
4807    
4808                                    query.append(orderByConditionFields[i]);
4809    
4810                                    if ((i + 1) < orderByConditionFields.length) {
4811                                            if (orderByComparator.isAscending() ^ previous) {
4812                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4813                                            }
4814                                            else {
4815                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4816                                            }
4817                                    }
4818                                    else {
4819                                            if (orderByComparator.isAscending() ^ previous) {
4820                                                    query.append(WHERE_GREATER_THAN);
4821                                            }
4822                                            else {
4823                                                    query.append(WHERE_LESSER_THAN);
4824                                            }
4825                                    }
4826                            }
4827    
4828                            query.append(ORDER_BY_CLAUSE);
4829    
4830                            String[] orderByFields = orderByComparator.getOrderByFields();
4831    
4832                            for (int i = 0; i < orderByFields.length; i++) {
4833                                    if (getDB().isSupportsInlineDistinct()) {
4834                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4835                                    }
4836                                    else {
4837                                            query.append(_ORDER_BY_ENTITY_TABLE);
4838                                    }
4839    
4840                                    query.append(orderByFields[i]);
4841    
4842                                    if ((i + 1) < orderByFields.length) {
4843                                            if (orderByComparator.isAscending() ^ previous) {
4844                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4845                                            }
4846                                            else {
4847                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4848                                            }
4849                                    }
4850                                    else {
4851                                            if (orderByComparator.isAscending() ^ previous) {
4852                                                    query.append(ORDER_BY_ASC);
4853                                            }
4854                                            else {
4855                                                    query.append(ORDER_BY_DESC);
4856                                            }
4857                                    }
4858                            }
4859                    }
4860                    else {
4861                            if (getDB().isSupportsInlineDistinct()) {
4862                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4863                            }
4864                            else {
4865                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4866                            }
4867                    }
4868    
4869                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4870                                    MBMessage.class.getName(),
4871                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4872    
4873                    SQLQuery q = session.createSQLQuery(sql);
4874    
4875                    q.setFirstResult(0);
4876                    q.setMaxResults(2);
4877    
4878                    if (getDB().isSupportsInlineDistinct()) {
4879                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4880                    }
4881                    else {
4882                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4883                    }
4884    
4885                    QueryPos qPos = QueryPos.getInstance(q);
4886    
4887                    qPos.add(groupId);
4888    
4889                    qPos.add(userId);
4890    
4891                    if (orderByComparator != null) {
4892                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4893    
4894                            for (Object value : values) {
4895                                    qPos.add(value);
4896                            }
4897                    }
4898    
4899                    List<MBMessage> list = q.list();
4900    
4901                    if (list.size() == 2) {
4902                            return list.get(1);
4903                    }
4904                    else {
4905                            return null;
4906                    }
4907            }
4908    
4909            /**
4910             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
4911             *
4912             * @param groupId the group ID
4913             * @param userId the user ID
4914             * @throws SystemException if a system exception occurred
4915             */
4916            public void removeByG_U(long groupId, long userId)
4917                    throws SystemException {
4918                    for (MBMessage mbMessage : findByG_U(groupId, userId,
4919                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4920                            remove(mbMessage);
4921                    }
4922            }
4923    
4924            /**
4925             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
4926             *
4927             * @param groupId the group ID
4928             * @param userId the user ID
4929             * @return the number of matching message-boards messages
4930             * @throws SystemException if a system exception occurred
4931             */
4932            public int countByG_U(long groupId, long userId) throws SystemException {
4933                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
4934    
4935                    Object[] finderArgs = new Object[] { groupId, userId };
4936    
4937                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4938                                    this);
4939    
4940                    if (count == null) {
4941                            StringBundler query = new StringBundler(3);
4942    
4943                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4944    
4945                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4946    
4947                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4948    
4949                            String sql = query.toString();
4950    
4951                            Session session = null;
4952    
4953                            try {
4954                                    session = openSession();
4955    
4956                                    Query q = session.createQuery(sql);
4957    
4958                                    QueryPos qPos = QueryPos.getInstance(q);
4959    
4960                                    qPos.add(groupId);
4961    
4962                                    qPos.add(userId);
4963    
4964                                    count = (Long)q.uniqueResult();
4965    
4966                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4967                            }
4968                            catch (Exception e) {
4969                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4970    
4971                                    throw processException(e);
4972                            }
4973                            finally {
4974                                    closeSession(session);
4975                            }
4976                    }
4977    
4978                    return count.intValue();
4979            }
4980    
4981            /**
4982             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4983             *
4984             * @param groupId the group ID
4985             * @param userId the user ID
4986             * @return the number of matching message-boards messages that the user has permission to view
4987             * @throws SystemException if a system exception occurred
4988             */
4989            public int filterCountByG_U(long groupId, long userId)
4990                    throws SystemException {
4991                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4992                            return countByG_U(groupId, userId);
4993                    }
4994    
4995                    StringBundler query = new StringBundler(3);
4996    
4997                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
4998    
4999                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5000    
5001                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5002    
5003                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5004                                    MBMessage.class.getName(),
5005                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5006    
5007                    Session session = null;
5008    
5009                    try {
5010                            session = openSession();
5011    
5012                            SQLQuery q = session.createSQLQuery(sql);
5013    
5014                            q.addScalar(COUNT_COLUMN_NAME,
5015                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5016    
5017                            QueryPos qPos = QueryPos.getInstance(q);
5018    
5019                            qPos.add(groupId);
5020    
5021                            qPos.add(userId);
5022    
5023                            Long count = (Long)q.uniqueResult();
5024    
5025                            return count.intValue();
5026                    }
5027                    catch (Exception e) {
5028                            throw processException(e);
5029                    }
5030                    finally {
5031                            closeSession(session);
5032                    }
5033            }
5034    
5035            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5036            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5037            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5038                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5039                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5040                            new String[] {
5041                                    Long.class.getName(), Long.class.getName(),
5042                                    
5043                            Integer.class.getName(), Integer.class.getName(),
5044                                    OrderByComparator.class.getName()
5045                            });
5046            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5047                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5048                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5049                            new String[] { Long.class.getName(), Long.class.getName() },
5050                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5051                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5052                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5053            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5054                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5055                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5056                            new String[] { Long.class.getName(), Long.class.getName() });
5057    
5058            /**
5059             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5060             *
5061             * @param groupId the group ID
5062             * @param categoryId the category ID
5063             * @return the matching message-boards messages
5064             * @throws SystemException if a system exception occurred
5065             */
5066            public List<MBMessage> findByG_C(long groupId, long categoryId)
5067                    throws SystemException {
5068                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5069                            QueryUtil.ALL_POS, null);
5070            }
5071    
5072            /**
5073             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5074             *
5075             * <p>
5076             * 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.
5077             * </p>
5078             *
5079             * @param groupId the group ID
5080             * @param categoryId the category ID
5081             * @param start the lower bound of the range of message-boards messages
5082             * @param end the upper bound of the range of message-boards messages (not inclusive)
5083             * @return the range of matching message-boards messages
5084             * @throws SystemException if a system exception occurred
5085             */
5086            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5087                    int end) throws SystemException {
5088                    return findByG_C(groupId, categoryId, start, end, null);
5089            }
5090    
5091            /**
5092             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5093             *
5094             * <p>
5095             * 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.
5096             * </p>
5097             *
5098             * @param groupId the group ID
5099             * @param categoryId the category ID
5100             * @param start the lower bound of the range of message-boards messages
5101             * @param end the upper bound of the range of message-boards messages (not inclusive)
5102             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5103             * @return the ordered range of matching message-boards messages
5104             * @throws SystemException if a system exception occurred
5105             */
5106            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5107                    int end, OrderByComparator orderByComparator) throws SystemException {
5108                    boolean pagination = true;
5109                    FinderPath finderPath = null;
5110                    Object[] finderArgs = null;
5111    
5112                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5113                                    (orderByComparator == null)) {
5114                            pagination = false;
5115                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5116                            finderArgs = new Object[] { groupId, categoryId };
5117                    }
5118                    else {
5119                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5120                            finderArgs = new Object[] {
5121                                            groupId, categoryId,
5122                                            
5123                                            start, end, orderByComparator
5124                                    };
5125                    }
5126    
5127                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5128                                    finderArgs, this);
5129    
5130                    if ((list != null) && !list.isEmpty()) {
5131                            for (MBMessage mbMessage : list) {
5132                                    if ((groupId != mbMessage.getGroupId()) ||
5133                                                    (categoryId != mbMessage.getCategoryId())) {
5134                                            list = null;
5135    
5136                                            break;
5137                                    }
5138                            }
5139                    }
5140    
5141                    if (list == null) {
5142                            StringBundler query = null;
5143    
5144                            if (orderByComparator != null) {
5145                                    query = new StringBundler(4 +
5146                                                    (orderByComparator.getOrderByFields().length * 3));
5147                            }
5148                            else {
5149                                    query = new StringBundler(4);
5150                            }
5151    
5152                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5153    
5154                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5155    
5156                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5157    
5158                            if (orderByComparator != null) {
5159                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5160                                            orderByComparator);
5161                            }
5162                            else
5163                             if (pagination) {
5164                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5165                            }
5166    
5167                            String sql = query.toString();
5168    
5169                            Session session = null;
5170    
5171                            try {
5172                                    session = openSession();
5173    
5174                                    Query q = session.createQuery(sql);
5175    
5176                                    QueryPos qPos = QueryPos.getInstance(q);
5177    
5178                                    qPos.add(groupId);
5179    
5180                                    qPos.add(categoryId);
5181    
5182                                    if (!pagination) {
5183                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5184                                                            start, end, false);
5185    
5186                                            Collections.sort(list);
5187    
5188                                            list = new UnmodifiableList<MBMessage>(list);
5189                                    }
5190                                    else {
5191                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5192                                                            start, end);
5193                                    }
5194    
5195                                    cacheResult(list);
5196    
5197                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5198                            }
5199                            catch (Exception e) {
5200                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5201    
5202                                    throw processException(e);
5203                            }
5204                            finally {
5205                                    closeSession(session);
5206                            }
5207                    }
5208    
5209                    return list;
5210            }
5211    
5212            /**
5213             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5214             *
5215             * @param groupId the group ID
5216             * @param categoryId the category ID
5217             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5218             * @return the first matching message-boards message
5219             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5220             * @throws SystemException if a system exception occurred
5221             */
5222            public MBMessage findByG_C_First(long groupId, long categoryId,
5223                    OrderByComparator orderByComparator)
5224                    throws NoSuchMessageException, SystemException {
5225                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5226                                    orderByComparator);
5227    
5228                    if (mbMessage != null) {
5229                            return mbMessage;
5230                    }
5231    
5232                    StringBundler msg = new StringBundler(6);
5233    
5234                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5235    
5236                    msg.append("groupId=");
5237                    msg.append(groupId);
5238    
5239                    msg.append(", categoryId=");
5240                    msg.append(categoryId);
5241    
5242                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5243    
5244                    throw new NoSuchMessageException(msg.toString());
5245            }
5246    
5247            /**
5248             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5249             *
5250             * @param groupId the group ID
5251             * @param categoryId the category ID
5252             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5253             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5254             * @throws SystemException if a system exception occurred
5255             */
5256            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5257                    OrderByComparator orderByComparator) throws SystemException {
5258                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5259                                    orderByComparator);
5260    
5261                    if (!list.isEmpty()) {
5262                            return list.get(0);
5263                    }
5264    
5265                    return null;
5266            }
5267    
5268            /**
5269             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5270             *
5271             * @param groupId the group ID
5272             * @param categoryId the category ID
5273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5274             * @return the last matching message-boards message
5275             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5276             * @throws SystemException if a system exception occurred
5277             */
5278            public MBMessage findByG_C_Last(long groupId, long categoryId,
5279                    OrderByComparator orderByComparator)
5280                    throws NoSuchMessageException, SystemException {
5281                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5282                                    orderByComparator);
5283    
5284                    if (mbMessage != null) {
5285                            return mbMessage;
5286                    }
5287    
5288                    StringBundler msg = new StringBundler(6);
5289    
5290                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5291    
5292                    msg.append("groupId=");
5293                    msg.append(groupId);
5294    
5295                    msg.append(", categoryId=");
5296                    msg.append(categoryId);
5297    
5298                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5299    
5300                    throw new NoSuchMessageException(msg.toString());
5301            }
5302    
5303            /**
5304             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5305             *
5306             * @param groupId the group ID
5307             * @param categoryId the category ID
5308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5309             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5310             * @throws SystemException if a system exception occurred
5311             */
5312            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5313                    OrderByComparator orderByComparator) throws SystemException {
5314                    int count = countByG_C(groupId, categoryId);
5315    
5316                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5317                                    orderByComparator);
5318    
5319                    if (!list.isEmpty()) {
5320                            return list.get(0);
5321                    }
5322    
5323                    return null;
5324            }
5325    
5326            /**
5327             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5328             *
5329             * @param messageId the primary key of the current message-boards message
5330             * @param groupId the group ID
5331             * @param categoryId the category ID
5332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5333             * @return the previous, current, and next message-boards message
5334             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5335             * @throws SystemException if a system exception occurred
5336             */
5337            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5338                    long categoryId, OrderByComparator orderByComparator)
5339                    throws NoSuchMessageException, SystemException {
5340                    MBMessage mbMessage = findByPrimaryKey(messageId);
5341    
5342                    Session session = null;
5343    
5344                    try {
5345                            session = openSession();
5346    
5347                            MBMessage[] array = new MBMessageImpl[3];
5348    
5349                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5350                                            categoryId, orderByComparator, true);
5351    
5352                            array[1] = mbMessage;
5353    
5354                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5355                                            categoryId, orderByComparator, false);
5356    
5357                            return array;
5358                    }
5359                    catch (Exception e) {
5360                            throw processException(e);
5361                    }
5362                    finally {
5363                            closeSession(session);
5364                    }
5365            }
5366    
5367            protected MBMessage getByG_C_PrevAndNext(Session session,
5368                    MBMessage mbMessage, long groupId, long categoryId,
5369                    OrderByComparator orderByComparator, boolean previous) {
5370                    StringBundler query = null;
5371    
5372                    if (orderByComparator != null) {
5373                            query = new StringBundler(6 +
5374                                            (orderByComparator.getOrderByFields().length * 6));
5375                    }
5376                    else {
5377                            query = new StringBundler(3);
5378                    }
5379    
5380                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5381    
5382                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5383    
5384                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5385    
5386                    if (orderByComparator != null) {
5387                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5388    
5389                            if (orderByConditionFields.length > 0) {
5390                                    query.append(WHERE_AND);
5391                            }
5392    
5393                            for (int i = 0; i < orderByConditionFields.length; i++) {
5394                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5395                                    query.append(orderByConditionFields[i]);
5396    
5397                                    if ((i + 1) < orderByConditionFields.length) {
5398                                            if (orderByComparator.isAscending() ^ previous) {
5399                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5400                                            }
5401                                            else {
5402                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5403                                            }
5404                                    }
5405                                    else {
5406                                            if (orderByComparator.isAscending() ^ previous) {
5407                                                    query.append(WHERE_GREATER_THAN);
5408                                            }
5409                                            else {
5410                                                    query.append(WHERE_LESSER_THAN);
5411                                            }
5412                                    }
5413                            }
5414    
5415                            query.append(ORDER_BY_CLAUSE);
5416    
5417                            String[] orderByFields = orderByComparator.getOrderByFields();
5418    
5419                            for (int i = 0; i < orderByFields.length; i++) {
5420                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5421                                    query.append(orderByFields[i]);
5422    
5423                                    if ((i + 1) < orderByFields.length) {
5424                                            if (orderByComparator.isAscending() ^ previous) {
5425                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5426                                            }
5427                                            else {
5428                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5429                                            }
5430                                    }
5431                                    else {
5432                                            if (orderByComparator.isAscending() ^ previous) {
5433                                                    query.append(ORDER_BY_ASC);
5434                                            }
5435                                            else {
5436                                                    query.append(ORDER_BY_DESC);
5437                                            }
5438                                    }
5439                            }
5440                    }
5441                    else {
5442                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5443                    }
5444    
5445                    String sql = query.toString();
5446    
5447                    Query q = session.createQuery(sql);
5448    
5449                    q.setFirstResult(0);
5450                    q.setMaxResults(2);
5451    
5452                    QueryPos qPos = QueryPos.getInstance(q);
5453    
5454                    qPos.add(groupId);
5455    
5456                    qPos.add(categoryId);
5457    
5458                    if (orderByComparator != null) {
5459                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5460    
5461                            for (Object value : values) {
5462                                    qPos.add(value);
5463                            }
5464                    }
5465    
5466                    List<MBMessage> list = q.list();
5467    
5468                    if (list.size() == 2) {
5469                            return list.get(1);
5470                    }
5471                    else {
5472                            return null;
5473                    }
5474            }
5475    
5476            /**
5477             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5478             *
5479             * @param groupId the group ID
5480             * @param categoryId the category ID
5481             * @return the matching message-boards messages that the user has permission to view
5482             * @throws SystemException if a system exception occurred
5483             */
5484            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5485                    throws SystemException {
5486                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5487                            QueryUtil.ALL_POS, null);
5488            }
5489    
5490            /**
5491             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5492             *
5493             * <p>
5494             * 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.
5495             * </p>
5496             *
5497             * @param groupId the group ID
5498             * @param categoryId the category ID
5499             * @param start the lower bound of the range of message-boards messages
5500             * @param end the upper bound of the range of message-boards messages (not inclusive)
5501             * @return the range of matching message-boards messages that the user has permission to view
5502             * @throws SystemException if a system exception occurred
5503             */
5504            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5505                    int start, int end) throws SystemException {
5506                    return filterFindByG_C(groupId, categoryId, start, end, null);
5507            }
5508    
5509            /**
5510             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5511             *
5512             * <p>
5513             * 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.
5514             * </p>
5515             *
5516             * @param groupId the group ID
5517             * @param categoryId the category ID
5518             * @param start the lower bound of the range of message-boards messages
5519             * @param end the upper bound of the range of message-boards messages (not inclusive)
5520             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5521             * @return the ordered range of matching message-boards messages that the user has permission to view
5522             * @throws SystemException if a system exception occurred
5523             */
5524            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5525                    int start, int end, OrderByComparator orderByComparator)
5526                    throws SystemException {
5527                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5528                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5529                    }
5530    
5531                    StringBundler query = null;
5532    
5533                    if (orderByComparator != null) {
5534                            query = new StringBundler(4 +
5535                                            (orderByComparator.getOrderByFields().length * 3));
5536                    }
5537                    else {
5538                            query = new StringBundler(4);
5539                    }
5540    
5541                    if (getDB().isSupportsInlineDistinct()) {
5542                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5543                    }
5544                    else {
5545                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5546                    }
5547    
5548                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5549    
5550                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5551    
5552                    if (!getDB().isSupportsInlineDistinct()) {
5553                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5554                    }
5555    
5556                    if (orderByComparator != null) {
5557                            if (getDB().isSupportsInlineDistinct()) {
5558                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5559                                            orderByComparator);
5560                            }
5561                            else {
5562                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5563                                            orderByComparator);
5564                            }
5565                    }
5566                    else {
5567                            if (getDB().isSupportsInlineDistinct()) {
5568                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5569                            }
5570                            else {
5571                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5572                            }
5573                    }
5574    
5575                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5576                                    MBMessage.class.getName(),
5577                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5578    
5579                    Session session = null;
5580    
5581                    try {
5582                            session = openSession();
5583    
5584                            SQLQuery q = session.createSQLQuery(sql);
5585    
5586                            if (getDB().isSupportsInlineDistinct()) {
5587                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5588                            }
5589                            else {
5590                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5591                            }
5592    
5593                            QueryPos qPos = QueryPos.getInstance(q);
5594    
5595                            qPos.add(groupId);
5596    
5597                            qPos.add(categoryId);
5598    
5599                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5600                    }
5601                    catch (Exception e) {
5602                            throw processException(e);
5603                    }
5604                    finally {
5605                            closeSession(session);
5606                    }
5607            }
5608    
5609            /**
5610             * 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;.
5611             *
5612             * @param messageId the primary key of the current message-boards message
5613             * @param groupId the group ID
5614             * @param categoryId the category ID
5615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5616             * @return the previous, current, and next message-boards message
5617             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5618             * @throws SystemException if a system exception occurred
5619             */
5620            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5621                    long groupId, long categoryId, OrderByComparator orderByComparator)
5622                    throws NoSuchMessageException, SystemException {
5623                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5624                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5625                                    orderByComparator);
5626                    }
5627    
5628                    MBMessage mbMessage = findByPrimaryKey(messageId);
5629    
5630                    Session session = null;
5631    
5632                    try {
5633                            session = openSession();
5634    
5635                            MBMessage[] array = new MBMessageImpl[3];
5636    
5637                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5638                                            categoryId, orderByComparator, true);
5639    
5640                            array[1] = mbMessage;
5641    
5642                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5643                                            categoryId, orderByComparator, false);
5644    
5645                            return array;
5646                    }
5647                    catch (Exception e) {
5648                            throw processException(e);
5649                    }
5650                    finally {
5651                            closeSession(session);
5652                    }
5653            }
5654    
5655            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5656                    MBMessage mbMessage, long groupId, long categoryId,
5657                    OrderByComparator orderByComparator, boolean previous) {
5658                    StringBundler query = null;
5659    
5660                    if (orderByComparator != null) {
5661                            query = new StringBundler(6 +
5662                                            (orderByComparator.getOrderByFields().length * 6));
5663                    }
5664                    else {
5665                            query = new StringBundler(3);
5666                    }
5667    
5668                    if (getDB().isSupportsInlineDistinct()) {
5669                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5670                    }
5671                    else {
5672                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5673                    }
5674    
5675                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5676    
5677                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5678    
5679                    if (!getDB().isSupportsInlineDistinct()) {
5680                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5681                    }
5682    
5683                    if (orderByComparator != null) {
5684                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5685    
5686                            if (orderByConditionFields.length > 0) {
5687                                    query.append(WHERE_AND);
5688                            }
5689    
5690                            for (int i = 0; i < orderByConditionFields.length; i++) {
5691                                    if (getDB().isSupportsInlineDistinct()) {
5692                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5693                                    }
5694                                    else {
5695                                            query.append(_ORDER_BY_ENTITY_TABLE);
5696                                    }
5697    
5698                                    query.append(orderByConditionFields[i]);
5699    
5700                                    if ((i + 1) < orderByConditionFields.length) {
5701                                            if (orderByComparator.isAscending() ^ previous) {
5702                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5703                                            }
5704                                            else {
5705                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5706                                            }
5707                                    }
5708                                    else {
5709                                            if (orderByComparator.isAscending() ^ previous) {
5710                                                    query.append(WHERE_GREATER_THAN);
5711                                            }
5712                                            else {
5713                                                    query.append(WHERE_LESSER_THAN);
5714                                            }
5715                                    }
5716                            }
5717    
5718                            query.append(ORDER_BY_CLAUSE);
5719    
5720                            String[] orderByFields = orderByComparator.getOrderByFields();
5721    
5722                            for (int i = 0; i < orderByFields.length; i++) {
5723                                    if (getDB().isSupportsInlineDistinct()) {
5724                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5725                                    }
5726                                    else {
5727                                            query.append(_ORDER_BY_ENTITY_TABLE);
5728                                    }
5729    
5730                                    query.append(orderByFields[i]);
5731    
5732                                    if ((i + 1) < orderByFields.length) {
5733                                            if (orderByComparator.isAscending() ^ previous) {
5734                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5735                                            }
5736                                            else {
5737                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5738                                            }
5739                                    }
5740                                    else {
5741                                            if (orderByComparator.isAscending() ^ previous) {
5742                                                    query.append(ORDER_BY_ASC);
5743                                            }
5744                                            else {
5745                                                    query.append(ORDER_BY_DESC);
5746                                            }
5747                                    }
5748                            }
5749                    }
5750                    else {
5751                            if (getDB().isSupportsInlineDistinct()) {
5752                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5753                            }
5754                            else {
5755                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5756                            }
5757                    }
5758    
5759                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5760                                    MBMessage.class.getName(),
5761                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5762    
5763                    SQLQuery q = session.createSQLQuery(sql);
5764    
5765                    q.setFirstResult(0);
5766                    q.setMaxResults(2);
5767    
5768                    if (getDB().isSupportsInlineDistinct()) {
5769                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5770                    }
5771                    else {
5772                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5773                    }
5774    
5775                    QueryPos qPos = QueryPos.getInstance(q);
5776    
5777                    qPos.add(groupId);
5778    
5779                    qPos.add(categoryId);
5780    
5781                    if (orderByComparator != null) {
5782                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5783    
5784                            for (Object value : values) {
5785                                    qPos.add(value);
5786                            }
5787                    }
5788    
5789                    List<MBMessage> list = q.list();
5790    
5791                    if (list.size() == 2) {
5792                            return list.get(1);
5793                    }
5794                    else {
5795                            return null;
5796                    }
5797            }
5798    
5799            /**
5800             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
5801             *
5802             * @param groupId the group ID
5803             * @param categoryId the category ID
5804             * @throws SystemException if a system exception occurred
5805             */
5806            public void removeByG_C(long groupId, long categoryId)
5807                    throws SystemException {
5808                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5809                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5810                            remove(mbMessage);
5811                    }
5812            }
5813    
5814            /**
5815             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
5816             *
5817             * @param groupId the group ID
5818             * @param categoryId the category ID
5819             * @return the number of matching message-boards messages
5820             * @throws SystemException if a system exception occurred
5821             */
5822            public int countByG_C(long groupId, long categoryId)
5823                    throws SystemException {
5824                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5825    
5826                    Object[] finderArgs = new Object[] { groupId, categoryId };
5827    
5828                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5829                                    this);
5830    
5831                    if (count == null) {
5832                            StringBundler query = new StringBundler(3);
5833    
5834                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5835    
5836                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5837    
5838                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5839    
5840                            String sql = query.toString();
5841    
5842                            Session session = null;
5843    
5844                            try {
5845                                    session = openSession();
5846    
5847                                    Query q = session.createQuery(sql);
5848    
5849                                    QueryPos qPos = QueryPos.getInstance(q);
5850    
5851                                    qPos.add(groupId);
5852    
5853                                    qPos.add(categoryId);
5854    
5855                                    count = (Long)q.uniqueResult();
5856    
5857                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5858                            }
5859                            catch (Exception e) {
5860                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5861    
5862                                    throw processException(e);
5863                            }
5864                            finally {
5865                                    closeSession(session);
5866                            }
5867                    }
5868    
5869                    return count.intValue();
5870            }
5871    
5872            /**
5873             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5874             *
5875             * @param groupId the group ID
5876             * @param categoryId the category ID
5877             * @return the number of matching message-boards messages that the user has permission to view
5878             * @throws SystemException if a system exception occurred
5879             */
5880            public int filterCountByG_C(long groupId, long categoryId)
5881                    throws SystemException {
5882                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5883                            return countByG_C(groupId, categoryId);
5884                    }
5885    
5886                    StringBundler query = new StringBundler(3);
5887    
5888                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5889    
5890                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5891    
5892                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5893    
5894                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5895                                    MBMessage.class.getName(),
5896                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5897    
5898                    Session session = null;
5899    
5900                    try {
5901                            session = openSession();
5902    
5903                            SQLQuery q = session.createSQLQuery(sql);
5904    
5905                            q.addScalar(COUNT_COLUMN_NAME,
5906                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5907    
5908                            QueryPos qPos = QueryPos.getInstance(q);
5909    
5910                            qPos.add(groupId);
5911    
5912                            qPos.add(categoryId);
5913    
5914                            Long count = (Long)q.uniqueResult();
5915    
5916                            return count.intValue();
5917                    }
5918                    catch (Exception e) {
5919                            throw processException(e);
5920                    }
5921                    finally {
5922                            closeSession(session);
5923                    }
5924            }
5925    
5926            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
5927            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
5928            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5929                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5930                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
5931                            new String[] {
5932                                    Long.class.getName(), Integer.class.getName(),
5933                                    
5934                            Integer.class.getName(), Integer.class.getName(),
5935                                    OrderByComparator.class.getName()
5936                            });
5937            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5938                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5939                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
5940                            new String[] { Long.class.getName(), Integer.class.getName() },
5941                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5942                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
5943                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5944            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5945                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5946                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
5947                            new String[] { Long.class.getName(), Integer.class.getName() });
5948    
5949            /**
5950             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5951             *
5952             * @param groupId the group ID
5953             * @param status the status
5954             * @return the matching message-boards messages
5955             * @throws SystemException if a system exception occurred
5956             */
5957            public List<MBMessage> findByG_S(long groupId, int status)
5958                    throws SystemException {
5959                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5960                            null);
5961            }
5962    
5963            /**
5964             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5965             *
5966             * <p>
5967             * 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.
5968             * </p>
5969             *
5970             * @param groupId the group ID
5971             * @param status the status
5972             * @param start the lower bound of the range of message-boards messages
5973             * @param end the upper bound of the range of message-boards messages (not inclusive)
5974             * @return the range of matching message-boards messages
5975             * @throws SystemException if a system exception occurred
5976             */
5977            public List<MBMessage> findByG_S(long groupId, int status, int start,
5978                    int end) throws SystemException {
5979                    return findByG_S(groupId, status, start, end, null);
5980            }
5981    
5982            /**
5983             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
5984             *
5985             * <p>
5986             * 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.
5987             * </p>
5988             *
5989             * @param groupId the group ID
5990             * @param status the status
5991             * @param start the lower bound of the range of message-boards messages
5992             * @param end the upper bound of the range of message-boards messages (not inclusive)
5993             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5994             * @return the ordered range of matching message-boards messages
5995             * @throws SystemException if a system exception occurred
5996             */
5997            public List<MBMessage> findByG_S(long groupId, int status, int start,
5998                    int end, OrderByComparator orderByComparator) throws SystemException {
5999                    boolean pagination = true;
6000                    FinderPath finderPath = null;
6001                    Object[] finderArgs = null;
6002    
6003                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6004                                    (orderByComparator == null)) {
6005                            pagination = false;
6006                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6007                            finderArgs = new Object[] { groupId, status };
6008                    }
6009                    else {
6010                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6011                            finderArgs = new Object[] {
6012                                            groupId, status,
6013                                            
6014                                            start, end, orderByComparator
6015                                    };
6016                    }
6017    
6018                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6019                                    finderArgs, this);
6020    
6021                    if ((list != null) && !list.isEmpty()) {
6022                            for (MBMessage mbMessage : list) {
6023                                    if ((groupId != mbMessage.getGroupId()) ||
6024                                                    (status != mbMessage.getStatus())) {
6025                                            list = null;
6026    
6027                                            break;
6028                                    }
6029                            }
6030                    }
6031    
6032                    if (list == null) {
6033                            StringBundler query = null;
6034    
6035                            if (orderByComparator != null) {
6036                                    query = new StringBundler(4 +
6037                                                    (orderByComparator.getOrderByFields().length * 3));
6038                            }
6039                            else {
6040                                    query = new StringBundler(4);
6041                            }
6042    
6043                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6044    
6045                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6046    
6047                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6048    
6049                            if (orderByComparator != null) {
6050                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6051                                            orderByComparator);
6052                            }
6053                            else
6054                             if (pagination) {
6055                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6056                            }
6057    
6058                            String sql = query.toString();
6059    
6060                            Session session = null;
6061    
6062                            try {
6063                                    session = openSession();
6064    
6065                                    Query q = session.createQuery(sql);
6066    
6067                                    QueryPos qPos = QueryPos.getInstance(q);
6068    
6069                                    qPos.add(groupId);
6070    
6071                                    qPos.add(status);
6072    
6073                                    if (!pagination) {
6074                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6075                                                            start, end, false);
6076    
6077                                            Collections.sort(list);
6078    
6079                                            list = new UnmodifiableList<MBMessage>(list);
6080                                    }
6081                                    else {
6082                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6083                                                            start, end);
6084                                    }
6085    
6086                                    cacheResult(list);
6087    
6088                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6089                            }
6090                            catch (Exception e) {
6091                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6092    
6093                                    throw processException(e);
6094                            }
6095                            finally {
6096                                    closeSession(session);
6097                            }
6098                    }
6099    
6100                    return list;
6101            }
6102    
6103            /**
6104             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6105             *
6106             * @param groupId the group ID
6107             * @param status the status
6108             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6109             * @return the first matching message-boards message
6110             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6111             * @throws SystemException if a system exception occurred
6112             */
6113            public MBMessage findByG_S_First(long groupId, int status,
6114                    OrderByComparator orderByComparator)
6115                    throws NoSuchMessageException, SystemException {
6116                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6117                                    orderByComparator);
6118    
6119                    if (mbMessage != null) {
6120                            return mbMessage;
6121                    }
6122    
6123                    StringBundler msg = new StringBundler(6);
6124    
6125                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6126    
6127                    msg.append("groupId=");
6128                    msg.append(groupId);
6129    
6130                    msg.append(", status=");
6131                    msg.append(status);
6132    
6133                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6134    
6135                    throw new NoSuchMessageException(msg.toString());
6136            }
6137    
6138            /**
6139             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6140             *
6141             * @param groupId the group ID
6142             * @param status the status
6143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6144             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6145             * @throws SystemException if a system exception occurred
6146             */
6147            public MBMessage fetchByG_S_First(long groupId, int status,
6148                    OrderByComparator orderByComparator) throws SystemException {
6149                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6150                                    orderByComparator);
6151    
6152                    if (!list.isEmpty()) {
6153                            return list.get(0);
6154                    }
6155    
6156                    return null;
6157            }
6158    
6159            /**
6160             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6161             *
6162             * @param groupId the group ID
6163             * @param status the status
6164             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6165             * @return the last matching message-boards message
6166             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6167             * @throws SystemException if a system exception occurred
6168             */
6169            public MBMessage findByG_S_Last(long groupId, int status,
6170                    OrderByComparator orderByComparator)
6171                    throws NoSuchMessageException, SystemException {
6172                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6173    
6174                    if (mbMessage != null) {
6175                            return mbMessage;
6176                    }
6177    
6178                    StringBundler msg = new StringBundler(6);
6179    
6180                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6181    
6182                    msg.append("groupId=");
6183                    msg.append(groupId);
6184    
6185                    msg.append(", status=");
6186                    msg.append(status);
6187    
6188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6189    
6190                    throw new NoSuchMessageException(msg.toString());
6191            }
6192    
6193            /**
6194             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6195             *
6196             * @param groupId the group ID
6197             * @param status the status
6198             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6199             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6200             * @throws SystemException if a system exception occurred
6201             */
6202            public MBMessage fetchByG_S_Last(long groupId, int status,
6203                    OrderByComparator orderByComparator) throws SystemException {
6204                    int count = countByG_S(groupId, status);
6205    
6206                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6207                                    orderByComparator);
6208    
6209                    if (!list.isEmpty()) {
6210                            return list.get(0);
6211                    }
6212    
6213                    return null;
6214            }
6215    
6216            /**
6217             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6218             *
6219             * @param messageId the primary key of the current message-boards message
6220             * @param groupId the group ID
6221             * @param status the status
6222             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6223             * @return the previous, current, and next message-boards message
6224             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6225             * @throws SystemException if a system exception occurred
6226             */
6227            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6228                    int status, OrderByComparator orderByComparator)
6229                    throws NoSuchMessageException, SystemException {
6230                    MBMessage mbMessage = findByPrimaryKey(messageId);
6231    
6232                    Session session = null;
6233    
6234                    try {
6235                            session = openSession();
6236    
6237                            MBMessage[] array = new MBMessageImpl[3];
6238    
6239                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6240                                            status, orderByComparator, true);
6241    
6242                            array[1] = mbMessage;
6243    
6244                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6245                                            status, orderByComparator, false);
6246    
6247                            return array;
6248                    }
6249                    catch (Exception e) {
6250                            throw processException(e);
6251                    }
6252                    finally {
6253                            closeSession(session);
6254                    }
6255            }
6256    
6257            protected MBMessage getByG_S_PrevAndNext(Session session,
6258                    MBMessage mbMessage, long groupId, int status,
6259                    OrderByComparator orderByComparator, boolean previous) {
6260                    StringBundler query = null;
6261    
6262                    if (orderByComparator != null) {
6263                            query = new StringBundler(6 +
6264                                            (orderByComparator.getOrderByFields().length * 6));
6265                    }
6266                    else {
6267                            query = new StringBundler(3);
6268                    }
6269    
6270                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6271    
6272                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6273    
6274                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6275    
6276                    if (orderByComparator != null) {
6277                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6278    
6279                            if (orderByConditionFields.length > 0) {
6280                                    query.append(WHERE_AND);
6281                            }
6282    
6283                            for (int i = 0; i < orderByConditionFields.length; i++) {
6284                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6285                                    query.append(orderByConditionFields[i]);
6286    
6287                                    if ((i + 1) < orderByConditionFields.length) {
6288                                            if (orderByComparator.isAscending() ^ previous) {
6289                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6290                                            }
6291                                            else {
6292                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6293                                            }
6294                                    }
6295                                    else {
6296                                            if (orderByComparator.isAscending() ^ previous) {
6297                                                    query.append(WHERE_GREATER_THAN);
6298                                            }
6299                                            else {
6300                                                    query.append(WHERE_LESSER_THAN);
6301                                            }
6302                                    }
6303                            }
6304    
6305                            query.append(ORDER_BY_CLAUSE);
6306    
6307                            String[] orderByFields = orderByComparator.getOrderByFields();
6308    
6309                            for (int i = 0; i < orderByFields.length; i++) {
6310                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6311                                    query.append(orderByFields[i]);
6312    
6313                                    if ((i + 1) < orderByFields.length) {
6314                                            if (orderByComparator.isAscending() ^ previous) {
6315                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6316                                            }
6317                                            else {
6318                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6319                                            }
6320                                    }
6321                                    else {
6322                                            if (orderByComparator.isAscending() ^ previous) {
6323                                                    query.append(ORDER_BY_ASC);
6324                                            }
6325                                            else {
6326                                                    query.append(ORDER_BY_DESC);
6327                                            }
6328                                    }
6329                            }
6330                    }
6331                    else {
6332                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6333                    }
6334    
6335                    String sql = query.toString();
6336    
6337                    Query q = session.createQuery(sql);
6338    
6339                    q.setFirstResult(0);
6340                    q.setMaxResults(2);
6341    
6342                    QueryPos qPos = QueryPos.getInstance(q);
6343    
6344                    qPos.add(groupId);
6345    
6346                    qPos.add(status);
6347    
6348                    if (orderByComparator != null) {
6349                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6350    
6351                            for (Object value : values) {
6352                                    qPos.add(value);
6353                            }
6354                    }
6355    
6356                    List<MBMessage> list = q.list();
6357    
6358                    if (list.size() == 2) {
6359                            return list.get(1);
6360                    }
6361                    else {
6362                            return null;
6363                    }
6364            }
6365    
6366            /**
6367             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6368             *
6369             * @param groupId the group ID
6370             * @param status the status
6371             * @return the matching message-boards messages that the user has permission to view
6372             * @throws SystemException if a system exception occurred
6373             */
6374            public List<MBMessage> filterFindByG_S(long groupId, int status)
6375                    throws SystemException {
6376                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6377                            QueryUtil.ALL_POS, null);
6378            }
6379    
6380            /**
6381             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6382             *
6383             * <p>
6384             * 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.
6385             * </p>
6386             *
6387             * @param groupId the group ID
6388             * @param status the status
6389             * @param start the lower bound of the range of message-boards messages
6390             * @param end the upper bound of the range of message-boards messages (not inclusive)
6391             * @return the range of matching message-boards messages that the user has permission to view
6392             * @throws SystemException if a system exception occurred
6393             */
6394            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6395                    int end) throws SystemException {
6396                    return filterFindByG_S(groupId, status, start, end, null);
6397            }
6398    
6399            /**
6400             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6401             *
6402             * <p>
6403             * 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.
6404             * </p>
6405             *
6406             * @param groupId the group ID
6407             * @param status the status
6408             * @param start the lower bound of the range of message-boards messages
6409             * @param end the upper bound of the range of message-boards messages (not inclusive)
6410             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6411             * @return the ordered range of matching message-boards messages that the user has permission to view
6412             * @throws SystemException if a system exception occurred
6413             */
6414            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6415                    int end, OrderByComparator orderByComparator) throws SystemException {
6416                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6417                            return findByG_S(groupId, status, start, end, orderByComparator);
6418                    }
6419    
6420                    StringBundler query = null;
6421    
6422                    if (orderByComparator != null) {
6423                            query = new StringBundler(4 +
6424                                            (orderByComparator.getOrderByFields().length * 3));
6425                    }
6426                    else {
6427                            query = new StringBundler(4);
6428                    }
6429    
6430                    if (getDB().isSupportsInlineDistinct()) {
6431                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6432                    }
6433                    else {
6434                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6435                    }
6436    
6437                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6438    
6439                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6440    
6441                    if (!getDB().isSupportsInlineDistinct()) {
6442                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6443                    }
6444    
6445                    if (orderByComparator != null) {
6446                            if (getDB().isSupportsInlineDistinct()) {
6447                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6448                                            orderByComparator);
6449                            }
6450                            else {
6451                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6452                                            orderByComparator);
6453                            }
6454                    }
6455                    else {
6456                            if (getDB().isSupportsInlineDistinct()) {
6457                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6458                            }
6459                            else {
6460                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6461                            }
6462                    }
6463    
6464                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6465                                    MBMessage.class.getName(),
6466                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6467    
6468                    Session session = null;
6469    
6470                    try {
6471                            session = openSession();
6472    
6473                            SQLQuery q = session.createSQLQuery(sql);
6474    
6475                            if (getDB().isSupportsInlineDistinct()) {
6476                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6477                            }
6478                            else {
6479                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6480                            }
6481    
6482                            QueryPos qPos = QueryPos.getInstance(q);
6483    
6484                            qPos.add(groupId);
6485    
6486                            qPos.add(status);
6487    
6488                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6489                    }
6490                    catch (Exception e) {
6491                            throw processException(e);
6492                    }
6493                    finally {
6494                            closeSession(session);
6495                    }
6496            }
6497    
6498            /**
6499             * 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;.
6500             *
6501             * @param messageId the primary key of the current message-boards message
6502             * @param groupId the group ID
6503             * @param status the status
6504             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6505             * @return the previous, current, and next message-boards message
6506             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6507             * @throws SystemException if a system exception occurred
6508             */
6509            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6510                    long groupId, int status, OrderByComparator orderByComparator)
6511                    throws NoSuchMessageException, SystemException {
6512                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6513                            return findByG_S_PrevAndNext(messageId, groupId, status,
6514                                    orderByComparator);
6515                    }
6516    
6517                    MBMessage mbMessage = findByPrimaryKey(messageId);
6518    
6519                    Session session = null;
6520    
6521                    try {
6522                            session = openSession();
6523    
6524                            MBMessage[] array = new MBMessageImpl[3];
6525    
6526                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6527                                            status, orderByComparator, true);
6528    
6529                            array[1] = mbMessage;
6530    
6531                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6532                                            status, orderByComparator, false);
6533    
6534                            return array;
6535                    }
6536                    catch (Exception e) {
6537                            throw processException(e);
6538                    }
6539                    finally {
6540                            closeSession(session);
6541                    }
6542            }
6543    
6544            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6545                    MBMessage mbMessage, long groupId, int status,
6546                    OrderByComparator orderByComparator, boolean previous) {
6547                    StringBundler query = null;
6548    
6549                    if (orderByComparator != null) {
6550                            query = new StringBundler(6 +
6551                                            (orderByComparator.getOrderByFields().length * 6));
6552                    }
6553                    else {
6554                            query = new StringBundler(3);
6555                    }
6556    
6557                    if (getDB().isSupportsInlineDistinct()) {
6558                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6559                    }
6560                    else {
6561                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6562                    }
6563    
6564                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6565    
6566                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6567    
6568                    if (!getDB().isSupportsInlineDistinct()) {
6569                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6570                    }
6571    
6572                    if (orderByComparator != null) {
6573                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6574    
6575                            if (orderByConditionFields.length > 0) {
6576                                    query.append(WHERE_AND);
6577                            }
6578    
6579                            for (int i = 0; i < orderByConditionFields.length; i++) {
6580                                    if (getDB().isSupportsInlineDistinct()) {
6581                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6582                                    }
6583                                    else {
6584                                            query.append(_ORDER_BY_ENTITY_TABLE);
6585                                    }
6586    
6587                                    query.append(orderByConditionFields[i]);
6588    
6589                                    if ((i + 1) < orderByConditionFields.length) {
6590                                            if (orderByComparator.isAscending() ^ previous) {
6591                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6592                                            }
6593                                            else {
6594                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6595                                            }
6596                                    }
6597                                    else {
6598                                            if (orderByComparator.isAscending() ^ previous) {
6599                                                    query.append(WHERE_GREATER_THAN);
6600                                            }
6601                                            else {
6602                                                    query.append(WHERE_LESSER_THAN);
6603                                            }
6604                                    }
6605                            }
6606    
6607                            query.append(ORDER_BY_CLAUSE);
6608    
6609                            String[] orderByFields = orderByComparator.getOrderByFields();
6610    
6611                            for (int i = 0; i < orderByFields.length; i++) {
6612                                    if (getDB().isSupportsInlineDistinct()) {
6613                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6614                                    }
6615                                    else {
6616                                            query.append(_ORDER_BY_ENTITY_TABLE);
6617                                    }
6618    
6619                                    query.append(orderByFields[i]);
6620    
6621                                    if ((i + 1) < orderByFields.length) {
6622                                            if (orderByComparator.isAscending() ^ previous) {
6623                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6624                                            }
6625                                            else {
6626                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6627                                            }
6628                                    }
6629                                    else {
6630                                            if (orderByComparator.isAscending() ^ previous) {
6631                                                    query.append(ORDER_BY_ASC);
6632                                            }
6633                                            else {
6634                                                    query.append(ORDER_BY_DESC);
6635                                            }
6636                                    }
6637                            }
6638                    }
6639                    else {
6640                            if (getDB().isSupportsInlineDistinct()) {
6641                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6642                            }
6643                            else {
6644                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6645                            }
6646                    }
6647    
6648                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6649                                    MBMessage.class.getName(),
6650                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6651    
6652                    SQLQuery q = session.createSQLQuery(sql);
6653    
6654                    q.setFirstResult(0);
6655                    q.setMaxResults(2);
6656    
6657                    if (getDB().isSupportsInlineDistinct()) {
6658                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6659                    }
6660                    else {
6661                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6662                    }
6663    
6664                    QueryPos qPos = QueryPos.getInstance(q);
6665    
6666                    qPos.add(groupId);
6667    
6668                    qPos.add(status);
6669    
6670                    if (orderByComparator != null) {
6671                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6672    
6673                            for (Object value : values) {
6674                                    qPos.add(value);
6675                            }
6676                    }
6677    
6678                    List<MBMessage> list = q.list();
6679    
6680                    if (list.size() == 2) {
6681                            return list.get(1);
6682                    }
6683                    else {
6684                            return null;
6685                    }
6686            }
6687    
6688            /**
6689             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6690             *
6691             * @param groupId the group ID
6692             * @param status the status
6693             * @throws SystemException if a system exception occurred
6694             */
6695            public void removeByG_S(long groupId, int status) throws SystemException {
6696                    for (MBMessage mbMessage : findByG_S(groupId, status,
6697                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6698                            remove(mbMessage);
6699                    }
6700            }
6701    
6702            /**
6703             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6704             *
6705             * @param groupId the group ID
6706             * @param status the status
6707             * @return the number of matching message-boards messages
6708             * @throws SystemException if a system exception occurred
6709             */
6710            public int countByG_S(long groupId, int status) throws SystemException {
6711                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6712    
6713                    Object[] finderArgs = new Object[] { groupId, status };
6714    
6715                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6716                                    this);
6717    
6718                    if (count == null) {
6719                            StringBundler query = new StringBundler(3);
6720    
6721                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6722    
6723                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6724    
6725                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6726    
6727                            String sql = query.toString();
6728    
6729                            Session session = null;
6730    
6731                            try {
6732                                    session = openSession();
6733    
6734                                    Query q = session.createQuery(sql);
6735    
6736                                    QueryPos qPos = QueryPos.getInstance(q);
6737    
6738                                    qPos.add(groupId);
6739    
6740                                    qPos.add(status);
6741    
6742                                    count = (Long)q.uniqueResult();
6743    
6744                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6745                            }
6746                            catch (Exception e) {
6747                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6748    
6749                                    throw processException(e);
6750                            }
6751                            finally {
6752                                    closeSession(session);
6753                            }
6754                    }
6755    
6756                    return count.intValue();
6757            }
6758    
6759            /**
6760             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6761             *
6762             * @param groupId the group ID
6763             * @param status the status
6764             * @return the number of matching message-boards messages that the user has permission to view
6765             * @throws SystemException if a system exception occurred
6766             */
6767            public int filterCountByG_S(long groupId, int status)
6768                    throws SystemException {
6769                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6770                            return countByG_S(groupId, status);
6771                    }
6772    
6773                    StringBundler query = new StringBundler(3);
6774    
6775                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6776    
6777                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6778    
6779                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6780    
6781                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6782                                    MBMessage.class.getName(),
6783                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6784    
6785                    Session session = null;
6786    
6787                    try {
6788                            session = openSession();
6789    
6790                            SQLQuery q = session.createSQLQuery(sql);
6791    
6792                            q.addScalar(COUNT_COLUMN_NAME,
6793                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6794    
6795                            QueryPos qPos = QueryPos.getInstance(q);
6796    
6797                            qPos.add(groupId);
6798    
6799                            qPos.add(status);
6800    
6801                            Long count = (Long)q.uniqueResult();
6802    
6803                            return count.intValue();
6804                    }
6805                    catch (Exception e) {
6806                            throw processException(e);
6807                    }
6808                    finally {
6809                            closeSession(session);
6810                    }
6811            }
6812    
6813            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6814            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6815            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6816                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6817                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
6818                            new String[] {
6819                                    Long.class.getName(), Integer.class.getName(),
6820                                    
6821                            Integer.class.getName(), Integer.class.getName(),
6822                                    OrderByComparator.class.getName()
6823                            });
6824            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6825                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6826                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
6827                            new String[] { Long.class.getName(), Integer.class.getName() },
6828                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
6829                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6830                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6831            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6832                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6833                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
6834                            new String[] { Long.class.getName(), Integer.class.getName() });
6835    
6836            /**
6837             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6838             *
6839             * @param companyId the company ID
6840             * @param status the status
6841             * @return the matching message-boards messages
6842             * @throws SystemException if a system exception occurred
6843             */
6844            public List<MBMessage> findByC_S(long companyId, int status)
6845                    throws SystemException {
6846                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6847                            QueryUtil.ALL_POS, null);
6848            }
6849    
6850            /**
6851             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6852             *
6853             * <p>
6854             * 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.
6855             * </p>
6856             *
6857             * @param companyId the company ID
6858             * @param status the status
6859             * @param start the lower bound of the range of message-boards messages
6860             * @param end the upper bound of the range of message-boards messages (not inclusive)
6861             * @return the range of matching message-boards messages
6862             * @throws SystemException if a system exception occurred
6863             */
6864            public List<MBMessage> findByC_S(long companyId, int status, int start,
6865                    int end) throws SystemException {
6866                    return findByC_S(companyId, status, start, end, null);
6867            }
6868    
6869            /**
6870             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6871             *
6872             * <p>
6873             * 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.
6874             * </p>
6875             *
6876             * @param companyId the company ID
6877             * @param status the status
6878             * @param start the lower bound of the range of message-boards messages
6879             * @param end the upper bound of the range of message-boards messages (not inclusive)
6880             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6881             * @return the ordered range of matching message-boards messages
6882             * @throws SystemException if a system exception occurred
6883             */
6884            public List<MBMessage> findByC_S(long companyId, int status, int start,
6885                    int end, OrderByComparator orderByComparator) throws SystemException {
6886                    boolean pagination = true;
6887                    FinderPath finderPath = null;
6888                    Object[] finderArgs = null;
6889    
6890                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6891                                    (orderByComparator == null)) {
6892                            pagination = false;
6893                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6894                            finderArgs = new Object[] { companyId, status };
6895                    }
6896                    else {
6897                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6898                            finderArgs = new Object[] {
6899                                            companyId, status,
6900                                            
6901                                            start, end, orderByComparator
6902                                    };
6903                    }
6904    
6905                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6906                                    finderArgs, this);
6907    
6908                    if ((list != null) && !list.isEmpty()) {
6909                            for (MBMessage mbMessage : list) {
6910                                    if ((companyId != mbMessage.getCompanyId()) ||
6911                                                    (status != mbMessage.getStatus())) {
6912                                            list = null;
6913    
6914                                            break;
6915                                    }
6916                            }
6917                    }
6918    
6919                    if (list == null) {
6920                            StringBundler query = null;
6921    
6922                            if (orderByComparator != null) {
6923                                    query = new StringBundler(4 +
6924                                                    (orderByComparator.getOrderByFields().length * 3));
6925                            }
6926                            else {
6927                                    query = new StringBundler(4);
6928                            }
6929    
6930                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6931    
6932                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6933    
6934                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6935    
6936                            if (orderByComparator != null) {
6937                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6938                                            orderByComparator);
6939                            }
6940                            else
6941                             if (pagination) {
6942                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6943                            }
6944    
6945                            String sql = query.toString();
6946    
6947                            Session session = null;
6948    
6949                            try {
6950                                    session = openSession();
6951    
6952                                    Query q = session.createQuery(sql);
6953    
6954                                    QueryPos qPos = QueryPos.getInstance(q);
6955    
6956                                    qPos.add(companyId);
6957    
6958                                    qPos.add(status);
6959    
6960                                    if (!pagination) {
6961                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6962                                                            start, end, false);
6963    
6964                                            Collections.sort(list);
6965    
6966                                            list = new UnmodifiableList<MBMessage>(list);
6967                                    }
6968                                    else {
6969                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6970                                                            start, end);
6971                                    }
6972    
6973                                    cacheResult(list);
6974    
6975                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6976                            }
6977                            catch (Exception e) {
6978                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6979    
6980                                    throw processException(e);
6981                            }
6982                            finally {
6983                                    closeSession(session);
6984                            }
6985                    }
6986    
6987                    return list;
6988            }
6989    
6990            /**
6991             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6992             *
6993             * @param companyId the company ID
6994             * @param status the status
6995             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6996             * @return the first matching message-boards message
6997             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6998             * @throws SystemException if a system exception occurred
6999             */
7000            public MBMessage findByC_S_First(long companyId, int status,
7001                    OrderByComparator orderByComparator)
7002                    throws NoSuchMessageException, SystemException {
7003                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7004                                    orderByComparator);
7005    
7006                    if (mbMessage != null) {
7007                            return mbMessage;
7008                    }
7009    
7010                    StringBundler msg = new StringBundler(6);
7011    
7012                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7013    
7014                    msg.append("companyId=");
7015                    msg.append(companyId);
7016    
7017                    msg.append(", status=");
7018                    msg.append(status);
7019    
7020                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7021    
7022                    throw new NoSuchMessageException(msg.toString());
7023            }
7024    
7025            /**
7026             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7027             *
7028             * @param companyId the company ID
7029             * @param status the status
7030             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7031             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7032             * @throws SystemException if a system exception occurred
7033             */
7034            public MBMessage fetchByC_S_First(long companyId, int status,
7035                    OrderByComparator orderByComparator) throws SystemException {
7036                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7037                                    orderByComparator);
7038    
7039                    if (!list.isEmpty()) {
7040                            return list.get(0);
7041                    }
7042    
7043                    return null;
7044            }
7045    
7046            /**
7047             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7048             *
7049             * @param companyId the company ID
7050             * @param status the status
7051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7052             * @return the last matching message-boards message
7053             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7054             * @throws SystemException if a system exception occurred
7055             */
7056            public MBMessage findByC_S_Last(long companyId, int status,
7057                    OrderByComparator orderByComparator)
7058                    throws NoSuchMessageException, SystemException {
7059                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7060                                    orderByComparator);
7061    
7062                    if (mbMessage != null) {
7063                            return mbMessage;
7064                    }
7065    
7066                    StringBundler msg = new StringBundler(6);
7067    
7068                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7069    
7070                    msg.append("companyId=");
7071                    msg.append(companyId);
7072    
7073                    msg.append(", status=");
7074                    msg.append(status);
7075    
7076                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7077    
7078                    throw new NoSuchMessageException(msg.toString());
7079            }
7080    
7081            /**
7082             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7083             *
7084             * @param companyId the company ID
7085             * @param status the status
7086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7087             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7088             * @throws SystemException if a system exception occurred
7089             */
7090            public MBMessage fetchByC_S_Last(long companyId, int status,
7091                    OrderByComparator orderByComparator) throws SystemException {
7092                    int count = countByC_S(companyId, status);
7093    
7094                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7095                                    orderByComparator);
7096    
7097                    if (!list.isEmpty()) {
7098                            return list.get(0);
7099                    }
7100    
7101                    return null;
7102            }
7103    
7104            /**
7105             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7106             *
7107             * @param messageId the primary key of the current message-boards message
7108             * @param companyId the company ID
7109             * @param status the status
7110             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7111             * @return the previous, current, and next message-boards message
7112             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7113             * @throws SystemException if a system exception occurred
7114             */
7115            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7116                    int status, OrderByComparator orderByComparator)
7117                    throws NoSuchMessageException, SystemException {
7118                    MBMessage mbMessage = findByPrimaryKey(messageId);
7119    
7120                    Session session = null;
7121    
7122                    try {
7123                            session = openSession();
7124    
7125                            MBMessage[] array = new MBMessageImpl[3];
7126    
7127                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7128                                            status, orderByComparator, true);
7129    
7130                            array[1] = mbMessage;
7131    
7132                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7133                                            status, orderByComparator, false);
7134    
7135                            return array;
7136                    }
7137                    catch (Exception e) {
7138                            throw processException(e);
7139                    }
7140                    finally {
7141                            closeSession(session);
7142                    }
7143            }
7144    
7145            protected MBMessage getByC_S_PrevAndNext(Session session,
7146                    MBMessage mbMessage, long companyId, int status,
7147                    OrderByComparator orderByComparator, boolean previous) {
7148                    StringBundler query = null;
7149    
7150                    if (orderByComparator != null) {
7151                            query = new StringBundler(6 +
7152                                            (orderByComparator.getOrderByFields().length * 6));
7153                    }
7154                    else {
7155                            query = new StringBundler(3);
7156                    }
7157    
7158                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7159    
7160                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7161    
7162                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7163    
7164                    if (orderByComparator != null) {
7165                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7166    
7167                            if (orderByConditionFields.length > 0) {
7168                                    query.append(WHERE_AND);
7169                            }
7170    
7171                            for (int i = 0; i < orderByConditionFields.length; i++) {
7172                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7173                                    query.append(orderByConditionFields[i]);
7174    
7175                                    if ((i + 1) < orderByConditionFields.length) {
7176                                            if (orderByComparator.isAscending() ^ previous) {
7177                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7178                                            }
7179                                            else {
7180                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7181                                            }
7182                                    }
7183                                    else {
7184                                            if (orderByComparator.isAscending() ^ previous) {
7185                                                    query.append(WHERE_GREATER_THAN);
7186                                            }
7187                                            else {
7188                                                    query.append(WHERE_LESSER_THAN);
7189                                            }
7190                                    }
7191                            }
7192    
7193                            query.append(ORDER_BY_CLAUSE);
7194    
7195                            String[] orderByFields = orderByComparator.getOrderByFields();
7196    
7197                            for (int i = 0; i < orderByFields.length; i++) {
7198                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7199                                    query.append(orderByFields[i]);
7200    
7201                                    if ((i + 1) < orderByFields.length) {
7202                                            if (orderByComparator.isAscending() ^ previous) {
7203                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7204                                            }
7205                                            else {
7206                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7207                                            }
7208                                    }
7209                                    else {
7210                                            if (orderByComparator.isAscending() ^ previous) {
7211                                                    query.append(ORDER_BY_ASC);
7212                                            }
7213                                            else {
7214                                                    query.append(ORDER_BY_DESC);
7215                                            }
7216                                    }
7217                            }
7218                    }
7219                    else {
7220                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7221                    }
7222    
7223                    String sql = query.toString();
7224    
7225                    Query q = session.createQuery(sql);
7226    
7227                    q.setFirstResult(0);
7228                    q.setMaxResults(2);
7229    
7230                    QueryPos qPos = QueryPos.getInstance(q);
7231    
7232                    qPos.add(companyId);
7233    
7234                    qPos.add(status);
7235    
7236                    if (orderByComparator != null) {
7237                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7238    
7239                            for (Object value : values) {
7240                                    qPos.add(value);
7241                            }
7242                    }
7243    
7244                    List<MBMessage> list = q.list();
7245    
7246                    if (list.size() == 2) {
7247                            return list.get(1);
7248                    }
7249                    else {
7250                            return null;
7251                    }
7252            }
7253    
7254            /**
7255             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7256             *
7257             * @param companyId the company ID
7258             * @param status the status
7259             * @throws SystemException if a system exception occurred
7260             */
7261            public void removeByC_S(long companyId, int status)
7262                    throws SystemException {
7263                    for (MBMessage mbMessage : findByC_S(companyId, status,
7264                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7265                            remove(mbMessage);
7266                    }
7267            }
7268    
7269            /**
7270             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7271             *
7272             * @param companyId the company ID
7273             * @param status the status
7274             * @return the number of matching message-boards messages
7275             * @throws SystemException if a system exception occurred
7276             */
7277            public int countByC_S(long companyId, int status) throws SystemException {
7278                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7279    
7280                    Object[] finderArgs = new Object[] { companyId, status };
7281    
7282                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7283                                    this);
7284    
7285                    if (count == null) {
7286                            StringBundler query = new StringBundler(3);
7287    
7288                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7289    
7290                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7291    
7292                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7293    
7294                            String sql = query.toString();
7295    
7296                            Session session = null;
7297    
7298                            try {
7299                                    session = openSession();
7300    
7301                                    Query q = session.createQuery(sql);
7302    
7303                                    QueryPos qPos = QueryPos.getInstance(q);
7304    
7305                                    qPos.add(companyId);
7306    
7307                                    qPos.add(status);
7308    
7309                                    count = (Long)q.uniqueResult();
7310    
7311                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7312                            }
7313                            catch (Exception e) {
7314                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7315    
7316                                    throw processException(e);
7317                            }
7318                            finally {
7319                                    closeSession(session);
7320                            }
7321                    }
7322    
7323                    return count.intValue();
7324            }
7325    
7326            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7327            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7328            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7329                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7330                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7331                            new String[] {
7332                                    Long.class.getName(), Long.class.getName(),
7333                                    
7334                            Integer.class.getName(), Integer.class.getName(),
7335                                    OrderByComparator.class.getName()
7336                            });
7337            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7338                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7339                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7340                            new String[] { Long.class.getName(), Long.class.getName() },
7341                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7342                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7343                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7344            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7345                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7346                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7347                            new String[] { Long.class.getName(), Long.class.getName() });
7348            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7349                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7350                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7351                            new String[] { Long.class.getName(), Long.class.getName() });
7352    
7353            /**
7354             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7355             *
7356             * @param userId the user ID
7357             * @param classNameId the class name ID
7358             * @return the matching message-boards messages
7359             * @throws SystemException if a system exception occurred
7360             */
7361            public List<MBMessage> findByU_C(long userId, long classNameId)
7362                    throws SystemException {
7363                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7364                            QueryUtil.ALL_POS, null);
7365            }
7366    
7367            /**
7368             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7369             *
7370             * <p>
7371             * 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.
7372             * </p>
7373             *
7374             * @param userId the user ID
7375             * @param classNameId the class name ID
7376             * @param start the lower bound of the range of message-boards messages
7377             * @param end the upper bound of the range of message-boards messages (not inclusive)
7378             * @return the range of matching message-boards messages
7379             * @throws SystemException if a system exception occurred
7380             */
7381            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7382                    int end) throws SystemException {
7383                    return findByU_C(userId, classNameId, start, end, null);
7384            }
7385    
7386            /**
7387             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7388             *
7389             * <p>
7390             * 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.
7391             * </p>
7392             *
7393             * @param userId the user ID
7394             * @param classNameId the class name ID
7395             * @param start the lower bound of the range of message-boards messages
7396             * @param end the upper bound of the range of message-boards messages (not inclusive)
7397             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7398             * @return the ordered range of matching message-boards messages
7399             * @throws SystemException if a system exception occurred
7400             */
7401            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7402                    int end, OrderByComparator orderByComparator) throws SystemException {
7403                    boolean pagination = true;
7404                    FinderPath finderPath = null;
7405                    Object[] finderArgs = null;
7406    
7407                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7408                                    (orderByComparator == null)) {
7409                            pagination = false;
7410                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7411                            finderArgs = new Object[] { userId, classNameId };
7412                    }
7413                    else {
7414                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7415                            finderArgs = new Object[] {
7416                                            userId, classNameId,
7417                                            
7418                                            start, end, orderByComparator
7419                                    };
7420                    }
7421    
7422                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7423                                    finderArgs, this);
7424    
7425                    if ((list != null) && !list.isEmpty()) {
7426                            for (MBMessage mbMessage : list) {
7427                                    if ((userId != mbMessage.getUserId()) ||
7428                                                    (classNameId != mbMessage.getClassNameId())) {
7429                                            list = null;
7430    
7431                                            break;
7432                                    }
7433                            }
7434                    }
7435    
7436                    if (list == null) {
7437                            StringBundler query = null;
7438    
7439                            if (orderByComparator != null) {
7440                                    query = new StringBundler(4 +
7441                                                    (orderByComparator.getOrderByFields().length * 3));
7442                            }
7443                            else {
7444                                    query = new StringBundler(4);
7445                            }
7446    
7447                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7448    
7449                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7450    
7451                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7452    
7453                            if (orderByComparator != null) {
7454                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7455                                            orderByComparator);
7456                            }
7457                            else
7458                             if (pagination) {
7459                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7460                            }
7461    
7462                            String sql = query.toString();
7463    
7464                            Session session = null;
7465    
7466                            try {
7467                                    session = openSession();
7468    
7469                                    Query q = session.createQuery(sql);
7470    
7471                                    QueryPos qPos = QueryPos.getInstance(q);
7472    
7473                                    qPos.add(userId);
7474    
7475                                    qPos.add(classNameId);
7476    
7477                                    if (!pagination) {
7478                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7479                                                            start, end, false);
7480    
7481                                            Collections.sort(list);
7482    
7483                                            list = new UnmodifiableList<MBMessage>(list);
7484                                    }
7485                                    else {
7486                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7487                                                            start, end);
7488                                    }
7489    
7490                                    cacheResult(list);
7491    
7492                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7493                            }
7494                            catch (Exception e) {
7495                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7496    
7497                                    throw processException(e);
7498                            }
7499                            finally {
7500                                    closeSession(session);
7501                            }
7502                    }
7503    
7504                    return list;
7505            }
7506    
7507            /**
7508             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7509             *
7510             * @param userId the user ID
7511             * @param classNameId the class name ID
7512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7513             * @return the first matching message-boards message
7514             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7515             * @throws SystemException if a system exception occurred
7516             */
7517            public MBMessage findByU_C_First(long userId, long classNameId,
7518                    OrderByComparator orderByComparator)
7519                    throws NoSuchMessageException, SystemException {
7520                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7521                                    orderByComparator);
7522    
7523                    if (mbMessage != null) {
7524                            return mbMessage;
7525                    }
7526    
7527                    StringBundler msg = new StringBundler(6);
7528    
7529                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7530    
7531                    msg.append("userId=");
7532                    msg.append(userId);
7533    
7534                    msg.append(", classNameId=");
7535                    msg.append(classNameId);
7536    
7537                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7538    
7539                    throw new NoSuchMessageException(msg.toString());
7540            }
7541    
7542            /**
7543             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7544             *
7545             * @param userId the user ID
7546             * @param classNameId the class name ID
7547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7548             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7549             * @throws SystemException if a system exception occurred
7550             */
7551            public MBMessage fetchByU_C_First(long userId, long classNameId,
7552                    OrderByComparator orderByComparator) throws SystemException {
7553                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7554                                    orderByComparator);
7555    
7556                    if (!list.isEmpty()) {
7557                            return list.get(0);
7558                    }
7559    
7560                    return null;
7561            }
7562    
7563            /**
7564             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7565             *
7566             * @param userId the user ID
7567             * @param classNameId the class name ID
7568             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7569             * @return the last matching message-boards message
7570             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7571             * @throws SystemException if a system exception occurred
7572             */
7573            public MBMessage findByU_C_Last(long userId, long classNameId,
7574                    OrderByComparator orderByComparator)
7575                    throws NoSuchMessageException, SystemException {
7576                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7577                                    orderByComparator);
7578    
7579                    if (mbMessage != null) {
7580                            return mbMessage;
7581                    }
7582    
7583                    StringBundler msg = new StringBundler(6);
7584    
7585                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7586    
7587                    msg.append("userId=");
7588                    msg.append(userId);
7589    
7590                    msg.append(", classNameId=");
7591                    msg.append(classNameId);
7592    
7593                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7594    
7595                    throw new NoSuchMessageException(msg.toString());
7596            }
7597    
7598            /**
7599             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7600             *
7601             * @param userId the user ID
7602             * @param classNameId the class name ID
7603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7604             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7605             * @throws SystemException if a system exception occurred
7606             */
7607            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7608                    OrderByComparator orderByComparator) throws SystemException {
7609                    int count = countByU_C(userId, classNameId);
7610    
7611                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7612                                    orderByComparator);
7613    
7614                    if (!list.isEmpty()) {
7615                            return list.get(0);
7616                    }
7617    
7618                    return null;
7619            }
7620    
7621            /**
7622             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7623             *
7624             * @param messageId the primary key of the current message-boards message
7625             * @param userId the user ID
7626             * @param classNameId the class name ID
7627             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7628             * @return the previous, current, and next message-boards message
7629             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7630             * @throws SystemException if a system exception occurred
7631             */
7632            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7633                    long classNameId, OrderByComparator orderByComparator)
7634                    throws NoSuchMessageException, SystemException {
7635                    MBMessage mbMessage = findByPrimaryKey(messageId);
7636    
7637                    Session session = null;
7638    
7639                    try {
7640                            session = openSession();
7641    
7642                            MBMessage[] array = new MBMessageImpl[3];
7643    
7644                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7645                                            classNameId, orderByComparator, true);
7646    
7647                            array[1] = mbMessage;
7648    
7649                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7650                                            classNameId, orderByComparator, false);
7651    
7652                            return array;
7653                    }
7654                    catch (Exception e) {
7655                            throw processException(e);
7656                    }
7657                    finally {
7658                            closeSession(session);
7659                    }
7660            }
7661    
7662            protected MBMessage getByU_C_PrevAndNext(Session session,
7663                    MBMessage mbMessage, long userId, long classNameId,
7664                    OrderByComparator orderByComparator, boolean previous) {
7665                    StringBundler query = null;
7666    
7667                    if (orderByComparator != null) {
7668                            query = new StringBundler(6 +
7669                                            (orderByComparator.getOrderByFields().length * 6));
7670                    }
7671                    else {
7672                            query = new StringBundler(3);
7673                    }
7674    
7675                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7676    
7677                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7678    
7679                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7680    
7681                    if (orderByComparator != null) {
7682                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7683    
7684                            if (orderByConditionFields.length > 0) {
7685                                    query.append(WHERE_AND);
7686                            }
7687    
7688                            for (int i = 0; i < orderByConditionFields.length; i++) {
7689                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7690                                    query.append(orderByConditionFields[i]);
7691    
7692                                    if ((i + 1) < orderByConditionFields.length) {
7693                                            if (orderByComparator.isAscending() ^ previous) {
7694                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7695                                            }
7696                                            else {
7697                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7698                                            }
7699                                    }
7700                                    else {
7701                                            if (orderByComparator.isAscending() ^ previous) {
7702                                                    query.append(WHERE_GREATER_THAN);
7703                                            }
7704                                            else {
7705                                                    query.append(WHERE_LESSER_THAN);
7706                                            }
7707                                    }
7708                            }
7709    
7710                            query.append(ORDER_BY_CLAUSE);
7711    
7712                            String[] orderByFields = orderByComparator.getOrderByFields();
7713    
7714                            for (int i = 0; i < orderByFields.length; i++) {
7715                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7716                                    query.append(orderByFields[i]);
7717    
7718                                    if ((i + 1) < orderByFields.length) {
7719                                            if (orderByComparator.isAscending() ^ previous) {
7720                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7721                                            }
7722                                            else {
7723                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7724                                            }
7725                                    }
7726                                    else {
7727                                            if (orderByComparator.isAscending() ^ previous) {
7728                                                    query.append(ORDER_BY_ASC);
7729                                            }
7730                                            else {
7731                                                    query.append(ORDER_BY_DESC);
7732                                            }
7733                                    }
7734                            }
7735                    }
7736                    else {
7737                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7738                    }
7739    
7740                    String sql = query.toString();
7741    
7742                    Query q = session.createQuery(sql);
7743    
7744                    q.setFirstResult(0);
7745                    q.setMaxResults(2);
7746    
7747                    QueryPos qPos = QueryPos.getInstance(q);
7748    
7749                    qPos.add(userId);
7750    
7751                    qPos.add(classNameId);
7752    
7753                    if (orderByComparator != null) {
7754                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7755    
7756                            for (Object value : values) {
7757                                    qPos.add(value);
7758                            }
7759                    }
7760    
7761                    List<MBMessage> list = q.list();
7762    
7763                    if (list.size() == 2) {
7764                            return list.get(1);
7765                    }
7766                    else {
7767                            return null;
7768                    }
7769            }
7770    
7771            /**
7772             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7773             *
7774             * <p>
7775             * 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.
7776             * </p>
7777             *
7778             * @param userId the user ID
7779             * @param classNameIds the class name IDs
7780             * @return the matching message-boards messages
7781             * @throws SystemException if a system exception occurred
7782             */
7783            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7784                    throws SystemException {
7785                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7786                            QueryUtil.ALL_POS, null);
7787            }
7788    
7789            /**
7790             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7791             *
7792             * <p>
7793             * 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.
7794             * </p>
7795             *
7796             * @param userId the user ID
7797             * @param classNameIds the class name IDs
7798             * @param start the lower bound of the range of message-boards messages
7799             * @param end the upper bound of the range of message-boards messages (not inclusive)
7800             * @return the range of matching message-boards messages
7801             * @throws SystemException if a system exception occurred
7802             */
7803            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7804                    int start, int end) throws SystemException {
7805                    return findByU_C(userId, classNameIds, start, end, null);
7806            }
7807    
7808            /**
7809             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7810             *
7811             * <p>
7812             * 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.
7813             * </p>
7814             *
7815             * @param userId the user ID
7816             * @param classNameIds the class name IDs
7817             * @param start the lower bound of the range of message-boards messages
7818             * @param end the upper bound of the range of message-boards messages (not inclusive)
7819             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7820             * @return the ordered range of matching message-boards messages
7821             * @throws SystemException if a system exception occurred
7822             */
7823            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7824                    int start, int end, OrderByComparator orderByComparator)
7825                    throws SystemException {
7826                    if ((classNameIds != null) && (classNameIds.length == 1)) {
7827                            return findByU_C(userId, classNameIds[0], start, end,
7828                                    orderByComparator);
7829                    }
7830    
7831                    boolean pagination = true;
7832                    Object[] finderArgs = null;
7833    
7834                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7835                                    (orderByComparator == null)) {
7836                            pagination = false;
7837                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7838                    }
7839                    else {
7840                            finderArgs = new Object[] {
7841                                            userId, StringUtil.merge(classNameIds),
7842                                            
7843                                            start, end, orderByComparator
7844                                    };
7845                    }
7846    
7847                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7848                                    finderArgs, this);
7849    
7850                    if ((list != null) && !list.isEmpty()) {
7851                            for (MBMessage mbMessage : list) {
7852                                    if ((userId != mbMessage.getUserId()) ||
7853                                                    !ArrayUtil.contains(classNameIds,
7854                                                            mbMessage.getClassNameId())) {
7855                                            list = null;
7856    
7857                                            break;
7858                                    }
7859                            }
7860                    }
7861    
7862                    if (list == null) {
7863                            StringBundler query = new StringBundler();
7864    
7865                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7866    
7867                            boolean conjunctionable = false;
7868    
7869                            if (conjunctionable) {
7870                                    query.append(WHERE_AND);
7871                            }
7872    
7873                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7874    
7875                            conjunctionable = true;
7876    
7877                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7878                                    if (conjunctionable) {
7879                                            query.append(WHERE_AND);
7880                                    }
7881    
7882                                    query.append(StringPool.OPEN_PARENTHESIS);
7883    
7884                                    for (int i = 0; i < classNameIds.length; i++) {
7885                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7886    
7887                                            if ((i + 1) < classNameIds.length) {
7888                                                    query.append(WHERE_OR);
7889                                            }
7890                                    }
7891    
7892                                    query.append(StringPool.CLOSE_PARENTHESIS);
7893    
7894                                    conjunctionable = true;
7895                            }
7896    
7897                            if (orderByComparator != null) {
7898                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7899                                            orderByComparator);
7900                            }
7901                            else
7902                             if (pagination) {
7903                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7904                            }
7905    
7906                            String sql = query.toString();
7907    
7908                            Session session = null;
7909    
7910                            try {
7911                                    session = openSession();
7912    
7913                                    Query q = session.createQuery(sql);
7914    
7915                                    QueryPos qPos = QueryPos.getInstance(q);
7916    
7917                                    qPos.add(userId);
7918    
7919                                    if (classNameIds != null) {
7920                                            qPos.add(classNameIds);
7921                                    }
7922    
7923                                    if (!pagination) {
7924                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7925                                                            start, end, false);
7926    
7927                                            Collections.sort(list);
7928    
7929                                            list = new UnmodifiableList<MBMessage>(list);
7930                                    }
7931                                    else {
7932                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7933                                                            start, end);
7934                                    }
7935    
7936                                    cacheResult(list);
7937    
7938                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7939                                            finderArgs, list);
7940                            }
7941                            catch (Exception e) {
7942                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7943                                            finderArgs);
7944    
7945                                    throw processException(e);
7946                            }
7947                            finally {
7948                                    closeSession(session);
7949                            }
7950                    }
7951    
7952                    return list;
7953            }
7954    
7955            /**
7956             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
7957             *
7958             * @param userId the user ID
7959             * @param classNameId the class name ID
7960             * @throws SystemException if a system exception occurred
7961             */
7962            public void removeByU_C(long userId, long classNameId)
7963                    throws SystemException {
7964                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
7965                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7966                            remove(mbMessage);
7967                    }
7968            }
7969    
7970            /**
7971             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
7972             *
7973             * @param userId the user ID
7974             * @param classNameId the class name ID
7975             * @return the number of matching message-boards messages
7976             * @throws SystemException if a system exception occurred
7977             */
7978            public int countByU_C(long userId, long classNameId)
7979                    throws SystemException {
7980                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
7981    
7982                    Object[] finderArgs = new Object[] { userId, classNameId };
7983    
7984                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7985                                    this);
7986    
7987                    if (count == null) {
7988                            StringBundler query = new StringBundler(3);
7989    
7990                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7991    
7992                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7993    
7994                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7995    
7996                            String sql = query.toString();
7997    
7998                            Session session = null;
7999    
8000                            try {
8001                                    session = openSession();
8002    
8003                                    Query q = session.createQuery(sql);
8004    
8005                                    QueryPos qPos = QueryPos.getInstance(q);
8006    
8007                                    qPos.add(userId);
8008    
8009                                    qPos.add(classNameId);
8010    
8011                                    count = (Long)q.uniqueResult();
8012    
8013                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8014                            }
8015                            catch (Exception e) {
8016                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8017    
8018                                    throw processException(e);
8019                            }
8020                            finally {
8021                                    closeSession(session);
8022                            }
8023                    }
8024    
8025                    return count.intValue();
8026            }
8027    
8028            /**
8029             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8030             *
8031             * @param userId the user ID
8032             * @param classNameIds the class name IDs
8033             * @return the number of matching message-boards messages
8034             * @throws SystemException if a system exception occurred
8035             */
8036            public int countByU_C(long userId, long[] classNameIds)
8037                    throws SystemException {
8038                    Object[] finderArgs = new Object[] {
8039                                    userId, StringUtil.merge(classNameIds)
8040                            };
8041    
8042                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8043                                    finderArgs, this);
8044    
8045                    if (count == null) {
8046                            StringBundler query = new StringBundler();
8047    
8048                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8049    
8050                            boolean conjunctionable = false;
8051    
8052                            if (conjunctionable) {
8053                                    query.append(WHERE_AND);
8054                            }
8055    
8056                            query.append(_FINDER_COLUMN_U_C_USERID_5);
8057    
8058                            conjunctionable = true;
8059    
8060                            if ((classNameIds == null) || (classNameIds.length > 0)) {
8061                                    if (conjunctionable) {
8062                                            query.append(WHERE_AND);
8063                                    }
8064    
8065                                    query.append(StringPool.OPEN_PARENTHESIS);
8066    
8067                                    for (int i = 0; i < classNameIds.length; i++) {
8068                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8069    
8070                                            if ((i + 1) < classNameIds.length) {
8071                                                    query.append(WHERE_OR);
8072                                            }
8073                                    }
8074    
8075                                    query.append(StringPool.CLOSE_PARENTHESIS);
8076    
8077                                    conjunctionable = true;
8078                            }
8079    
8080                            String sql = query.toString();
8081    
8082                            Session session = null;
8083    
8084                            try {
8085                                    session = openSession();
8086    
8087                                    Query q = session.createQuery(sql);
8088    
8089                                    QueryPos qPos = QueryPos.getInstance(q);
8090    
8091                                    qPos.add(userId);
8092    
8093                                    if (classNameIds != null) {
8094                                            qPos.add(classNameIds);
8095                                    }
8096    
8097                                    count = (Long)q.uniqueResult();
8098    
8099                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8100                                            finderArgs, count);
8101                            }
8102                            catch (Exception e) {
8103                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8104                                            finderArgs);
8105    
8106                                    throw processException(e);
8107                            }
8108                            finally {
8109                                    closeSession(session);
8110                            }
8111                    }
8112    
8113                    return count.intValue();
8114            }
8115    
8116            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8117            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
8118                    _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
8119            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8120            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
8121                    _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
8122            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8123                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8124                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8125                            new String[] {
8126                                    Long.class.getName(), Long.class.getName(),
8127                                    
8128                            Integer.class.getName(), Integer.class.getName(),
8129                                    OrderByComparator.class.getName()
8130                            });
8131            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8132                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8134                            new String[] { Long.class.getName(), Long.class.getName() },
8135                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8136                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8137                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8138            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8139                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8141                            new String[] { Long.class.getName(), Long.class.getName() });
8142    
8143            /**
8144             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8145             *
8146             * @param classNameId the class name ID
8147             * @param classPK the class p k
8148             * @return the matching message-boards messages
8149             * @throws SystemException if a system exception occurred
8150             */
8151            public List<MBMessage> findByC_C(long classNameId, long classPK)
8152                    throws SystemException {
8153                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8154                            QueryUtil.ALL_POS, null);
8155            }
8156    
8157            /**
8158             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8159             *
8160             * <p>
8161             * 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.
8162             * </p>
8163             *
8164             * @param classNameId the class name ID
8165             * @param classPK the class p k
8166             * @param start the lower bound of the range of message-boards messages
8167             * @param end the upper bound of the range of message-boards messages (not inclusive)
8168             * @return the range of matching message-boards messages
8169             * @throws SystemException if a system exception occurred
8170             */
8171            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8172                    int end) throws SystemException {
8173                    return findByC_C(classNameId, classPK, start, end, null);
8174            }
8175    
8176            /**
8177             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8178             *
8179             * <p>
8180             * 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.
8181             * </p>
8182             *
8183             * @param classNameId the class name ID
8184             * @param classPK the class p k
8185             * @param start the lower bound of the range of message-boards messages
8186             * @param end the upper bound of the range of message-boards messages (not inclusive)
8187             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8188             * @return the ordered range of matching message-boards messages
8189             * @throws SystemException if a system exception occurred
8190             */
8191            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8192                    int end, OrderByComparator orderByComparator) throws SystemException {
8193                    boolean pagination = true;
8194                    FinderPath finderPath = null;
8195                    Object[] finderArgs = null;
8196    
8197                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8198                                    (orderByComparator == null)) {
8199                            pagination = false;
8200                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8201                            finderArgs = new Object[] { classNameId, classPK };
8202                    }
8203                    else {
8204                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8205                            finderArgs = new Object[] {
8206                                            classNameId, classPK,
8207                                            
8208                                            start, end, orderByComparator
8209                                    };
8210                    }
8211    
8212                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8213                                    finderArgs, this);
8214    
8215                    if ((list != null) && !list.isEmpty()) {
8216                            for (MBMessage mbMessage : list) {
8217                                    if ((classNameId != mbMessage.getClassNameId()) ||
8218                                                    (classPK != mbMessage.getClassPK())) {
8219                                            list = null;
8220    
8221                                            break;
8222                                    }
8223                            }
8224                    }
8225    
8226                    if (list == null) {
8227                            StringBundler query = null;
8228    
8229                            if (orderByComparator != null) {
8230                                    query = new StringBundler(4 +
8231                                                    (orderByComparator.getOrderByFields().length * 3));
8232                            }
8233                            else {
8234                                    query = new StringBundler(4);
8235                            }
8236    
8237                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8238    
8239                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8240    
8241                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8242    
8243                            if (orderByComparator != null) {
8244                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8245                                            orderByComparator);
8246                            }
8247                            else
8248                             if (pagination) {
8249                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8250                            }
8251    
8252                            String sql = query.toString();
8253    
8254                            Session session = null;
8255    
8256                            try {
8257                                    session = openSession();
8258    
8259                                    Query q = session.createQuery(sql);
8260    
8261                                    QueryPos qPos = QueryPos.getInstance(q);
8262    
8263                                    qPos.add(classNameId);
8264    
8265                                    qPos.add(classPK);
8266    
8267                                    if (!pagination) {
8268                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8269                                                            start, end, false);
8270    
8271                                            Collections.sort(list);
8272    
8273                                            list = new UnmodifiableList<MBMessage>(list);
8274                                    }
8275                                    else {
8276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8277                                                            start, end);
8278                                    }
8279    
8280                                    cacheResult(list);
8281    
8282                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8283                            }
8284                            catch (Exception e) {
8285                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8286    
8287                                    throw processException(e);
8288                            }
8289                            finally {
8290                                    closeSession(session);
8291                            }
8292                    }
8293    
8294                    return list;
8295            }
8296    
8297            /**
8298             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8299             *
8300             * @param classNameId the class name ID
8301             * @param classPK the class p k
8302             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8303             * @return the first matching message-boards message
8304             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8305             * @throws SystemException if a system exception occurred
8306             */
8307            public MBMessage findByC_C_First(long classNameId, long classPK,
8308                    OrderByComparator orderByComparator)
8309                    throws NoSuchMessageException, SystemException {
8310                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8311                                    orderByComparator);
8312    
8313                    if (mbMessage != null) {
8314                            return mbMessage;
8315                    }
8316    
8317                    StringBundler msg = new StringBundler(6);
8318    
8319                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8320    
8321                    msg.append("classNameId=");
8322                    msg.append(classNameId);
8323    
8324                    msg.append(", classPK=");
8325                    msg.append(classPK);
8326    
8327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8328    
8329                    throw new NoSuchMessageException(msg.toString());
8330            }
8331    
8332            /**
8333             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8334             *
8335             * @param classNameId the class name ID
8336             * @param classPK the class p k
8337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8338             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8339             * @throws SystemException if a system exception occurred
8340             */
8341            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8342                    OrderByComparator orderByComparator) throws SystemException {
8343                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8344                                    orderByComparator);
8345    
8346                    if (!list.isEmpty()) {
8347                            return list.get(0);
8348                    }
8349    
8350                    return null;
8351            }
8352    
8353            /**
8354             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8355             *
8356             * @param classNameId the class name ID
8357             * @param classPK the class p k
8358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8359             * @return the last matching message-boards message
8360             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8361             * @throws SystemException if a system exception occurred
8362             */
8363            public MBMessage findByC_C_Last(long classNameId, long classPK,
8364                    OrderByComparator orderByComparator)
8365                    throws NoSuchMessageException, SystemException {
8366                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8367                                    orderByComparator);
8368    
8369                    if (mbMessage != null) {
8370                            return mbMessage;
8371                    }
8372    
8373                    StringBundler msg = new StringBundler(6);
8374    
8375                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8376    
8377                    msg.append("classNameId=");
8378                    msg.append(classNameId);
8379    
8380                    msg.append(", classPK=");
8381                    msg.append(classPK);
8382    
8383                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8384    
8385                    throw new NoSuchMessageException(msg.toString());
8386            }
8387    
8388            /**
8389             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8390             *
8391             * @param classNameId the class name ID
8392             * @param classPK the class p k
8393             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8394             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8395             * @throws SystemException if a system exception occurred
8396             */
8397            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8398                    OrderByComparator orderByComparator) throws SystemException {
8399                    int count = countByC_C(classNameId, classPK);
8400    
8401                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8402                                    count, orderByComparator);
8403    
8404                    if (!list.isEmpty()) {
8405                            return list.get(0);
8406                    }
8407    
8408                    return null;
8409            }
8410    
8411            /**
8412             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8413             *
8414             * @param messageId the primary key of the current message-boards message
8415             * @param classNameId the class name ID
8416             * @param classPK the class p k
8417             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8418             * @return the previous, current, and next message-boards message
8419             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8420             * @throws SystemException if a system exception occurred
8421             */
8422            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8423                    long classPK, OrderByComparator orderByComparator)
8424                    throws NoSuchMessageException, SystemException {
8425                    MBMessage mbMessage = findByPrimaryKey(messageId);
8426    
8427                    Session session = null;
8428    
8429                    try {
8430                            session = openSession();
8431    
8432                            MBMessage[] array = new MBMessageImpl[3];
8433    
8434                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8435                                            classPK, orderByComparator, true);
8436    
8437                            array[1] = mbMessage;
8438    
8439                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8440                                            classPK, orderByComparator, false);
8441    
8442                            return array;
8443                    }
8444                    catch (Exception e) {
8445                            throw processException(e);
8446                    }
8447                    finally {
8448                            closeSession(session);
8449                    }
8450            }
8451    
8452            protected MBMessage getByC_C_PrevAndNext(Session session,
8453                    MBMessage mbMessage, long classNameId, long classPK,
8454                    OrderByComparator orderByComparator, boolean previous) {
8455                    StringBundler query = null;
8456    
8457                    if (orderByComparator != null) {
8458                            query = new StringBundler(6 +
8459                                            (orderByComparator.getOrderByFields().length * 6));
8460                    }
8461                    else {
8462                            query = new StringBundler(3);
8463                    }
8464    
8465                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8466    
8467                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8468    
8469                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8470    
8471                    if (orderByComparator != null) {
8472                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8473    
8474                            if (orderByConditionFields.length > 0) {
8475                                    query.append(WHERE_AND);
8476                            }
8477    
8478                            for (int i = 0; i < orderByConditionFields.length; i++) {
8479                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8480                                    query.append(orderByConditionFields[i]);
8481    
8482                                    if ((i + 1) < orderByConditionFields.length) {
8483                                            if (orderByComparator.isAscending() ^ previous) {
8484                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8485                                            }
8486                                            else {
8487                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8488                                            }
8489                                    }
8490                                    else {
8491                                            if (orderByComparator.isAscending() ^ previous) {
8492                                                    query.append(WHERE_GREATER_THAN);
8493                                            }
8494                                            else {
8495                                                    query.append(WHERE_LESSER_THAN);
8496                                            }
8497                                    }
8498                            }
8499    
8500                            query.append(ORDER_BY_CLAUSE);
8501    
8502                            String[] orderByFields = orderByComparator.getOrderByFields();
8503    
8504                            for (int i = 0; i < orderByFields.length; i++) {
8505                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8506                                    query.append(orderByFields[i]);
8507    
8508                                    if ((i + 1) < orderByFields.length) {
8509                                            if (orderByComparator.isAscending() ^ previous) {
8510                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8511                                            }
8512                                            else {
8513                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8514                                            }
8515                                    }
8516                                    else {
8517                                            if (orderByComparator.isAscending() ^ previous) {
8518                                                    query.append(ORDER_BY_ASC);
8519                                            }
8520                                            else {
8521                                                    query.append(ORDER_BY_DESC);
8522                                            }
8523                                    }
8524                            }
8525                    }
8526                    else {
8527                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8528                    }
8529    
8530                    String sql = query.toString();
8531    
8532                    Query q = session.createQuery(sql);
8533    
8534                    q.setFirstResult(0);
8535                    q.setMaxResults(2);
8536    
8537                    QueryPos qPos = QueryPos.getInstance(q);
8538    
8539                    qPos.add(classNameId);
8540    
8541                    qPos.add(classPK);
8542    
8543                    if (orderByComparator != null) {
8544                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8545    
8546                            for (Object value : values) {
8547                                    qPos.add(value);
8548                            }
8549                    }
8550    
8551                    List<MBMessage> list = q.list();
8552    
8553                    if (list.size() == 2) {
8554                            return list.get(1);
8555                    }
8556                    else {
8557                            return null;
8558                    }
8559            }
8560    
8561            /**
8562             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8563             *
8564             * @param classNameId the class name ID
8565             * @param classPK the class p k
8566             * @throws SystemException if a system exception occurred
8567             */
8568            public void removeByC_C(long classNameId, long classPK)
8569                    throws SystemException {
8570                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8571                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8572                            remove(mbMessage);
8573                    }
8574            }
8575    
8576            /**
8577             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8578             *
8579             * @param classNameId the class name ID
8580             * @param classPK the class p k
8581             * @return the number of matching message-boards messages
8582             * @throws SystemException if a system exception occurred
8583             */
8584            public int countByC_C(long classNameId, long classPK)
8585                    throws SystemException {
8586                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8587    
8588                    Object[] finderArgs = new Object[] { classNameId, classPK };
8589    
8590                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8591                                    this);
8592    
8593                    if (count == null) {
8594                            StringBundler query = new StringBundler(3);
8595    
8596                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8597    
8598                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8599    
8600                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8601    
8602                            String sql = query.toString();
8603    
8604                            Session session = null;
8605    
8606                            try {
8607                                    session = openSession();
8608    
8609                                    Query q = session.createQuery(sql);
8610    
8611                                    QueryPos qPos = QueryPos.getInstance(q);
8612    
8613                                    qPos.add(classNameId);
8614    
8615                                    qPos.add(classPK);
8616    
8617                                    count = (Long)q.uniqueResult();
8618    
8619                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8620                            }
8621                            catch (Exception e) {
8622                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8623    
8624                                    throw processException(e);
8625                            }
8626                            finally {
8627                                    closeSession(session);
8628                            }
8629                    }
8630    
8631                    return count.intValue();
8632            }
8633    
8634            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8635            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8636            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8637                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8638                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8639                            new String[] {
8640                                    Long.class.getName(), Long.class.getName(),
8641                                    
8642                            Integer.class.getName(), Integer.class.getName(),
8643                                    OrderByComparator.class.getName()
8644                            });
8645            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8646                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8647                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8648                            new String[] { Long.class.getName(), Long.class.getName() },
8649                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8650                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8651                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8652            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8653                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8654                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8655                            new String[] { Long.class.getName(), Long.class.getName() });
8656    
8657            /**
8658             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8659             *
8660             * @param threadId the thread ID
8661             * @param parentMessageId the parent message ID
8662             * @return the matching message-boards messages
8663             * @throws SystemException if a system exception occurred
8664             */
8665            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8666                    throws SystemException {
8667                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8668                            QueryUtil.ALL_POS, null);
8669            }
8670    
8671            /**
8672             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8673             *
8674             * <p>
8675             * 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.
8676             * </p>
8677             *
8678             * @param threadId the thread ID
8679             * @param parentMessageId the parent message ID
8680             * @param start the lower bound of the range of message-boards messages
8681             * @param end the upper bound of the range of message-boards messages (not inclusive)
8682             * @return the range of matching message-boards messages
8683             * @throws SystemException if a system exception occurred
8684             */
8685            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8686                    int start, int end) throws SystemException {
8687                    return findByT_P(threadId, parentMessageId, start, end, null);
8688            }
8689    
8690            /**
8691             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8692             *
8693             * <p>
8694             * 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.
8695             * </p>
8696             *
8697             * @param threadId the thread ID
8698             * @param parentMessageId the parent message ID
8699             * @param start the lower bound of the range of message-boards messages
8700             * @param end the upper bound of the range of message-boards messages (not inclusive)
8701             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8702             * @return the ordered range of matching message-boards messages
8703             * @throws SystemException if a system exception occurred
8704             */
8705            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8706                    int start, int end, OrderByComparator orderByComparator)
8707                    throws SystemException {
8708                    boolean pagination = true;
8709                    FinderPath finderPath = null;
8710                    Object[] finderArgs = null;
8711    
8712                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8713                                    (orderByComparator == null)) {
8714                            pagination = false;
8715                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8716                            finderArgs = new Object[] { threadId, parentMessageId };
8717                    }
8718                    else {
8719                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8720                            finderArgs = new Object[] {
8721                                            threadId, parentMessageId,
8722                                            
8723                                            start, end, orderByComparator
8724                                    };
8725                    }
8726    
8727                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8728                                    finderArgs, this);
8729    
8730                    if ((list != null) && !list.isEmpty()) {
8731                            for (MBMessage mbMessage : list) {
8732                                    if ((threadId != mbMessage.getThreadId()) ||
8733                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8734                                            list = null;
8735    
8736                                            break;
8737                                    }
8738                            }
8739                    }
8740    
8741                    if (list == null) {
8742                            StringBundler query = null;
8743    
8744                            if (orderByComparator != null) {
8745                                    query = new StringBundler(4 +
8746                                                    (orderByComparator.getOrderByFields().length * 3));
8747                            }
8748                            else {
8749                                    query = new StringBundler(4);
8750                            }
8751    
8752                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8753    
8754                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8755    
8756                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8757    
8758                            if (orderByComparator != null) {
8759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8760                                            orderByComparator);
8761                            }
8762                            else
8763                             if (pagination) {
8764                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8765                            }
8766    
8767                            String sql = query.toString();
8768    
8769                            Session session = null;
8770    
8771                            try {
8772                                    session = openSession();
8773    
8774                                    Query q = session.createQuery(sql);
8775    
8776                                    QueryPos qPos = QueryPos.getInstance(q);
8777    
8778                                    qPos.add(threadId);
8779    
8780                                    qPos.add(parentMessageId);
8781    
8782                                    if (!pagination) {
8783                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8784                                                            start, end, false);
8785    
8786                                            Collections.sort(list);
8787    
8788                                            list = new UnmodifiableList<MBMessage>(list);
8789                                    }
8790                                    else {
8791                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8792                                                            start, end);
8793                                    }
8794    
8795                                    cacheResult(list);
8796    
8797                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8798                            }
8799                            catch (Exception e) {
8800                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8801    
8802                                    throw processException(e);
8803                            }
8804                            finally {
8805                                    closeSession(session);
8806                            }
8807                    }
8808    
8809                    return list;
8810            }
8811    
8812            /**
8813             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8814             *
8815             * @param threadId the thread ID
8816             * @param parentMessageId the parent message ID
8817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8818             * @return the first matching message-boards message
8819             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8820             * @throws SystemException if a system exception occurred
8821             */
8822            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8823                    OrderByComparator orderByComparator)
8824                    throws NoSuchMessageException, SystemException {
8825                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8826                                    orderByComparator);
8827    
8828                    if (mbMessage != null) {
8829                            return mbMessage;
8830                    }
8831    
8832                    StringBundler msg = new StringBundler(6);
8833    
8834                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8835    
8836                    msg.append("threadId=");
8837                    msg.append(threadId);
8838    
8839                    msg.append(", parentMessageId=");
8840                    msg.append(parentMessageId);
8841    
8842                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8843    
8844                    throw new NoSuchMessageException(msg.toString());
8845            }
8846    
8847            /**
8848             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8849             *
8850             * @param threadId the thread ID
8851             * @param parentMessageId the parent message ID
8852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8853             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8854             * @throws SystemException if a system exception occurred
8855             */
8856            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8857                    OrderByComparator orderByComparator) throws SystemException {
8858                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8859                                    orderByComparator);
8860    
8861                    if (!list.isEmpty()) {
8862                            return list.get(0);
8863                    }
8864    
8865                    return null;
8866            }
8867    
8868            /**
8869             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8870             *
8871             * @param threadId the thread ID
8872             * @param parentMessageId the parent message ID
8873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8874             * @return the last matching message-boards message
8875             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8876             * @throws SystemException if a system exception occurred
8877             */
8878            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8879                    OrderByComparator orderByComparator)
8880                    throws NoSuchMessageException, SystemException {
8881                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8882                                    orderByComparator);
8883    
8884                    if (mbMessage != null) {
8885                            return mbMessage;
8886                    }
8887    
8888                    StringBundler msg = new StringBundler(6);
8889    
8890                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8891    
8892                    msg.append("threadId=");
8893                    msg.append(threadId);
8894    
8895                    msg.append(", parentMessageId=");
8896                    msg.append(parentMessageId);
8897    
8898                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8899    
8900                    throw new NoSuchMessageException(msg.toString());
8901            }
8902    
8903            /**
8904             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8905             *
8906             * @param threadId the thread ID
8907             * @param parentMessageId the parent message ID
8908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8909             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8910             * @throws SystemException if a system exception occurred
8911             */
8912            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8913                    OrderByComparator orderByComparator) throws SystemException {
8914                    int count = countByT_P(threadId, parentMessageId);
8915    
8916                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8917                                    count, orderByComparator);
8918    
8919                    if (!list.isEmpty()) {
8920                            return list.get(0);
8921                    }
8922    
8923                    return null;
8924            }
8925    
8926            /**
8927             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8928             *
8929             * @param messageId the primary key of the current message-boards message
8930             * @param threadId the thread ID
8931             * @param parentMessageId the parent message ID
8932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8933             * @return the previous, current, and next message-boards message
8934             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8935             * @throws SystemException if a system exception occurred
8936             */
8937            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8938                    long parentMessageId, OrderByComparator orderByComparator)
8939                    throws NoSuchMessageException, SystemException {
8940                    MBMessage mbMessage = findByPrimaryKey(messageId);
8941    
8942                    Session session = null;
8943    
8944                    try {
8945                            session = openSession();
8946    
8947                            MBMessage[] array = new MBMessageImpl[3];
8948    
8949                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8950                                            parentMessageId, orderByComparator, true);
8951    
8952                            array[1] = mbMessage;
8953    
8954                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8955                                            parentMessageId, orderByComparator, false);
8956    
8957                            return array;
8958                    }
8959                    catch (Exception e) {
8960                            throw processException(e);
8961                    }
8962                    finally {
8963                            closeSession(session);
8964                    }
8965            }
8966    
8967            protected MBMessage getByT_P_PrevAndNext(Session session,
8968                    MBMessage mbMessage, long threadId, long parentMessageId,
8969                    OrderByComparator orderByComparator, boolean previous) {
8970                    StringBundler query = null;
8971    
8972                    if (orderByComparator != null) {
8973                            query = new StringBundler(6 +
8974                                            (orderByComparator.getOrderByFields().length * 6));
8975                    }
8976                    else {
8977                            query = new StringBundler(3);
8978                    }
8979    
8980                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8981    
8982                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8983    
8984                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8985    
8986                    if (orderByComparator != null) {
8987                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8988    
8989                            if (orderByConditionFields.length > 0) {
8990                                    query.append(WHERE_AND);
8991                            }
8992    
8993                            for (int i = 0; i < orderByConditionFields.length; i++) {
8994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8995                                    query.append(orderByConditionFields[i]);
8996    
8997                                    if ((i + 1) < orderByConditionFields.length) {
8998                                            if (orderByComparator.isAscending() ^ previous) {
8999                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9000                                            }
9001                                            else {
9002                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9003                                            }
9004                                    }
9005                                    else {
9006                                            if (orderByComparator.isAscending() ^ previous) {
9007                                                    query.append(WHERE_GREATER_THAN);
9008                                            }
9009                                            else {
9010                                                    query.append(WHERE_LESSER_THAN);
9011                                            }
9012                                    }
9013                            }
9014    
9015                            query.append(ORDER_BY_CLAUSE);
9016    
9017                            String[] orderByFields = orderByComparator.getOrderByFields();
9018    
9019                            for (int i = 0; i < orderByFields.length; i++) {
9020                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9021                                    query.append(orderByFields[i]);
9022    
9023                                    if ((i + 1) < orderByFields.length) {
9024                                            if (orderByComparator.isAscending() ^ previous) {
9025                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9026                                            }
9027                                            else {
9028                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9029                                            }
9030                                    }
9031                                    else {
9032                                            if (orderByComparator.isAscending() ^ previous) {
9033                                                    query.append(ORDER_BY_ASC);
9034                                            }
9035                                            else {
9036                                                    query.append(ORDER_BY_DESC);
9037                                            }
9038                                    }
9039                            }
9040                    }
9041                    else {
9042                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9043                    }
9044    
9045                    String sql = query.toString();
9046    
9047                    Query q = session.createQuery(sql);
9048    
9049                    q.setFirstResult(0);
9050                    q.setMaxResults(2);
9051    
9052                    QueryPos qPos = QueryPos.getInstance(q);
9053    
9054                    qPos.add(threadId);
9055    
9056                    qPos.add(parentMessageId);
9057    
9058                    if (orderByComparator != null) {
9059                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9060    
9061                            for (Object value : values) {
9062                                    qPos.add(value);
9063                            }
9064                    }
9065    
9066                    List<MBMessage> list = q.list();
9067    
9068                    if (list.size() == 2) {
9069                            return list.get(1);
9070                    }
9071                    else {
9072                            return null;
9073                    }
9074            }
9075    
9076            /**
9077             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9078             *
9079             * @param threadId the thread ID
9080             * @param parentMessageId the parent message ID
9081             * @throws SystemException if a system exception occurred
9082             */
9083            public void removeByT_P(long threadId, long parentMessageId)
9084                    throws SystemException {
9085                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9086                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9087                            remove(mbMessage);
9088                    }
9089            }
9090    
9091            /**
9092             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9093             *
9094             * @param threadId the thread ID
9095             * @param parentMessageId the parent message ID
9096             * @return the number of matching message-boards messages
9097             * @throws SystemException if a system exception occurred
9098             */
9099            public int countByT_P(long threadId, long parentMessageId)
9100                    throws SystemException {
9101                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9102    
9103                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9104    
9105                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9106                                    this);
9107    
9108                    if (count == null) {
9109                            StringBundler query = new StringBundler(3);
9110    
9111                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9112    
9113                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9114    
9115                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9116    
9117                            String sql = query.toString();
9118    
9119                            Session session = null;
9120    
9121                            try {
9122                                    session = openSession();
9123    
9124                                    Query q = session.createQuery(sql);
9125    
9126                                    QueryPos qPos = QueryPos.getInstance(q);
9127    
9128                                    qPos.add(threadId);
9129    
9130                                    qPos.add(parentMessageId);
9131    
9132                                    count = (Long)q.uniqueResult();
9133    
9134                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9135                            }
9136                            catch (Exception e) {
9137                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9138    
9139                                    throw processException(e);
9140                            }
9141                            finally {
9142                                    closeSession(session);
9143                            }
9144                    }
9145    
9146                    return count.intValue();
9147            }
9148    
9149            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9150            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9151            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9152                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9153                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9154                            new String[] {
9155                                    Long.class.getName(), Boolean.class.getName(),
9156                                    
9157                            Integer.class.getName(), Integer.class.getName(),
9158                                    OrderByComparator.class.getName()
9159                            });
9160            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9161                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9162                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9163                            new String[] { Long.class.getName(), Boolean.class.getName() },
9164                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9165                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9166                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9167            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9168                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9169                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9170                            new String[] { Long.class.getName(), Boolean.class.getName() });
9171    
9172            /**
9173             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9174             *
9175             * @param threadId the thread ID
9176             * @param answer the answer
9177             * @return the matching message-boards messages
9178             * @throws SystemException if a system exception occurred
9179             */
9180            public List<MBMessage> findByT_A(long threadId, boolean answer)
9181                    throws SystemException {
9182                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9183                            QueryUtil.ALL_POS, null);
9184            }
9185    
9186            /**
9187             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9188             *
9189             * <p>
9190             * 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.
9191             * </p>
9192             *
9193             * @param threadId the thread ID
9194             * @param answer the answer
9195             * @param start the lower bound of the range of message-boards messages
9196             * @param end the upper bound of the range of message-boards messages (not inclusive)
9197             * @return the range of matching message-boards messages
9198             * @throws SystemException if a system exception occurred
9199             */
9200            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9201                    int end) throws SystemException {
9202                    return findByT_A(threadId, answer, start, end, null);
9203            }
9204    
9205            /**
9206             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9207             *
9208             * <p>
9209             * 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.
9210             * </p>
9211             *
9212             * @param threadId the thread ID
9213             * @param answer the answer
9214             * @param start the lower bound of the range of message-boards messages
9215             * @param end the upper bound of the range of message-boards messages (not inclusive)
9216             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9217             * @return the ordered range of matching message-boards messages
9218             * @throws SystemException if a system exception occurred
9219             */
9220            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9221                    int end, OrderByComparator orderByComparator) throws SystemException {
9222                    boolean pagination = true;
9223                    FinderPath finderPath = null;
9224                    Object[] finderArgs = null;
9225    
9226                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9227                                    (orderByComparator == null)) {
9228                            pagination = false;
9229                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9230                            finderArgs = new Object[] { threadId, answer };
9231                    }
9232                    else {
9233                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9234                            finderArgs = new Object[] {
9235                                            threadId, answer,
9236                                            
9237                                            start, end, orderByComparator
9238                                    };
9239                    }
9240    
9241                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9242                                    finderArgs, this);
9243    
9244                    if ((list != null) && !list.isEmpty()) {
9245                            for (MBMessage mbMessage : list) {
9246                                    if ((threadId != mbMessage.getThreadId()) ||
9247                                                    (answer != mbMessage.getAnswer())) {
9248                                            list = null;
9249    
9250                                            break;
9251                                    }
9252                            }
9253                    }
9254    
9255                    if (list == null) {
9256                            StringBundler query = null;
9257    
9258                            if (orderByComparator != null) {
9259                                    query = new StringBundler(4 +
9260                                                    (orderByComparator.getOrderByFields().length * 3));
9261                            }
9262                            else {
9263                                    query = new StringBundler(4);
9264                            }
9265    
9266                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9267    
9268                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9269    
9270                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9271    
9272                            if (orderByComparator != null) {
9273                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9274                                            orderByComparator);
9275                            }
9276                            else
9277                             if (pagination) {
9278                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9279                            }
9280    
9281                            String sql = query.toString();
9282    
9283                            Session session = null;
9284    
9285                            try {
9286                                    session = openSession();
9287    
9288                                    Query q = session.createQuery(sql);
9289    
9290                                    QueryPos qPos = QueryPos.getInstance(q);
9291    
9292                                    qPos.add(threadId);
9293    
9294                                    qPos.add(answer);
9295    
9296                                    if (!pagination) {
9297                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9298                                                            start, end, false);
9299    
9300                                            Collections.sort(list);
9301    
9302                                            list = new UnmodifiableList<MBMessage>(list);
9303                                    }
9304                                    else {
9305                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9306                                                            start, end);
9307                                    }
9308    
9309                                    cacheResult(list);
9310    
9311                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9312                            }
9313                            catch (Exception e) {
9314                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9315    
9316                                    throw processException(e);
9317                            }
9318                            finally {
9319                                    closeSession(session);
9320                            }
9321                    }
9322    
9323                    return list;
9324            }
9325    
9326            /**
9327             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9328             *
9329             * @param threadId the thread ID
9330             * @param answer the answer
9331             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9332             * @return the first matching message-boards message
9333             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9334             * @throws SystemException if a system exception occurred
9335             */
9336            public MBMessage findByT_A_First(long threadId, boolean answer,
9337                    OrderByComparator orderByComparator)
9338                    throws NoSuchMessageException, SystemException {
9339                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9340                                    orderByComparator);
9341    
9342                    if (mbMessage != null) {
9343                            return mbMessage;
9344                    }
9345    
9346                    StringBundler msg = new StringBundler(6);
9347    
9348                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9349    
9350                    msg.append("threadId=");
9351                    msg.append(threadId);
9352    
9353                    msg.append(", answer=");
9354                    msg.append(answer);
9355    
9356                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9357    
9358                    throw new NoSuchMessageException(msg.toString());
9359            }
9360    
9361            /**
9362             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9363             *
9364             * @param threadId the thread ID
9365             * @param answer the answer
9366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9367             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9368             * @throws SystemException if a system exception occurred
9369             */
9370            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9371                    OrderByComparator orderByComparator) throws SystemException {
9372                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9373                                    orderByComparator);
9374    
9375                    if (!list.isEmpty()) {
9376                            return list.get(0);
9377                    }
9378    
9379                    return null;
9380            }
9381    
9382            /**
9383             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9384             *
9385             * @param threadId the thread ID
9386             * @param answer the answer
9387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9388             * @return the last matching message-boards message
9389             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9390             * @throws SystemException if a system exception occurred
9391             */
9392            public MBMessage findByT_A_Last(long threadId, boolean answer,
9393                    OrderByComparator orderByComparator)
9394                    throws NoSuchMessageException, SystemException {
9395                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9396                                    orderByComparator);
9397    
9398                    if (mbMessage != null) {
9399                            return mbMessage;
9400                    }
9401    
9402                    StringBundler msg = new StringBundler(6);
9403    
9404                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9405    
9406                    msg.append("threadId=");
9407                    msg.append(threadId);
9408    
9409                    msg.append(", answer=");
9410                    msg.append(answer);
9411    
9412                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9413    
9414                    throw new NoSuchMessageException(msg.toString());
9415            }
9416    
9417            /**
9418             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9419             *
9420             * @param threadId the thread ID
9421             * @param answer the answer
9422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9423             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9424             * @throws SystemException if a system exception occurred
9425             */
9426            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9427                    OrderByComparator orderByComparator) throws SystemException {
9428                    int count = countByT_A(threadId, answer);
9429    
9430                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9431                                    orderByComparator);
9432    
9433                    if (!list.isEmpty()) {
9434                            return list.get(0);
9435                    }
9436    
9437                    return null;
9438            }
9439    
9440            /**
9441             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9442             *
9443             * @param messageId the primary key of the current message-boards message
9444             * @param threadId the thread ID
9445             * @param answer the answer
9446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9447             * @return the previous, current, and next message-boards message
9448             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9449             * @throws SystemException if a system exception occurred
9450             */
9451            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9452                    boolean answer, OrderByComparator orderByComparator)
9453                    throws NoSuchMessageException, SystemException {
9454                    MBMessage mbMessage = findByPrimaryKey(messageId);
9455    
9456                    Session session = null;
9457    
9458                    try {
9459                            session = openSession();
9460    
9461                            MBMessage[] array = new MBMessageImpl[3];
9462    
9463                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9464                                            answer, orderByComparator, true);
9465    
9466                            array[1] = mbMessage;
9467    
9468                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9469                                            answer, orderByComparator, false);
9470    
9471                            return array;
9472                    }
9473                    catch (Exception e) {
9474                            throw processException(e);
9475                    }
9476                    finally {
9477                            closeSession(session);
9478                    }
9479            }
9480    
9481            protected MBMessage getByT_A_PrevAndNext(Session session,
9482                    MBMessage mbMessage, long threadId, boolean answer,
9483                    OrderByComparator orderByComparator, boolean previous) {
9484                    StringBundler query = null;
9485    
9486                    if (orderByComparator != null) {
9487                            query = new StringBundler(6 +
9488                                            (orderByComparator.getOrderByFields().length * 6));
9489                    }
9490                    else {
9491                            query = new StringBundler(3);
9492                    }
9493    
9494                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9495    
9496                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9497    
9498                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9499    
9500                    if (orderByComparator != null) {
9501                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9502    
9503                            if (orderByConditionFields.length > 0) {
9504                                    query.append(WHERE_AND);
9505                            }
9506    
9507                            for (int i = 0; i < orderByConditionFields.length; i++) {
9508                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9509                                    query.append(orderByConditionFields[i]);
9510    
9511                                    if ((i + 1) < orderByConditionFields.length) {
9512                                            if (orderByComparator.isAscending() ^ previous) {
9513                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9514                                            }
9515                                            else {
9516                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9517                                            }
9518                                    }
9519                                    else {
9520                                            if (orderByComparator.isAscending() ^ previous) {
9521                                                    query.append(WHERE_GREATER_THAN);
9522                                            }
9523                                            else {
9524                                                    query.append(WHERE_LESSER_THAN);
9525                                            }
9526                                    }
9527                            }
9528    
9529                            query.append(ORDER_BY_CLAUSE);
9530    
9531                            String[] orderByFields = orderByComparator.getOrderByFields();
9532    
9533                            for (int i = 0; i < orderByFields.length; i++) {
9534                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9535                                    query.append(orderByFields[i]);
9536    
9537                                    if ((i + 1) < orderByFields.length) {
9538                                            if (orderByComparator.isAscending() ^ previous) {
9539                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9540                                            }
9541                                            else {
9542                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9543                                            }
9544                                    }
9545                                    else {
9546                                            if (orderByComparator.isAscending() ^ previous) {
9547                                                    query.append(ORDER_BY_ASC);
9548                                            }
9549                                            else {
9550                                                    query.append(ORDER_BY_DESC);
9551                                            }
9552                                    }
9553                            }
9554                    }
9555                    else {
9556                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9557                    }
9558    
9559                    String sql = query.toString();
9560    
9561                    Query q = session.createQuery(sql);
9562    
9563                    q.setFirstResult(0);
9564                    q.setMaxResults(2);
9565    
9566                    QueryPos qPos = QueryPos.getInstance(q);
9567    
9568                    qPos.add(threadId);
9569    
9570                    qPos.add(answer);
9571    
9572                    if (orderByComparator != null) {
9573                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9574    
9575                            for (Object value : values) {
9576                                    qPos.add(value);
9577                            }
9578                    }
9579    
9580                    List<MBMessage> list = q.list();
9581    
9582                    if (list.size() == 2) {
9583                            return list.get(1);
9584                    }
9585                    else {
9586                            return null;
9587                    }
9588            }
9589    
9590            /**
9591             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
9592             *
9593             * @param threadId the thread ID
9594             * @param answer the answer
9595             * @throws SystemException if a system exception occurred
9596             */
9597            public void removeByT_A(long threadId, boolean answer)
9598                    throws SystemException {
9599                    for (MBMessage mbMessage : findByT_A(threadId, answer,
9600                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9601                            remove(mbMessage);
9602                    }
9603            }
9604    
9605            /**
9606             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
9607             *
9608             * @param threadId the thread ID
9609             * @param answer the answer
9610             * @return the number of matching message-boards messages
9611             * @throws SystemException if a system exception occurred
9612             */
9613            public int countByT_A(long threadId, boolean answer)
9614                    throws SystemException {
9615                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9616    
9617                    Object[] finderArgs = new Object[] { threadId, answer };
9618    
9619                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9620                                    this);
9621    
9622                    if (count == null) {
9623                            StringBundler query = new StringBundler(3);
9624    
9625                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9626    
9627                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9628    
9629                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9630    
9631                            String sql = query.toString();
9632    
9633                            Session session = null;
9634    
9635                            try {
9636                                    session = openSession();
9637    
9638                                    Query q = session.createQuery(sql);
9639    
9640                                    QueryPos qPos = QueryPos.getInstance(q);
9641    
9642                                    qPos.add(threadId);
9643    
9644                                    qPos.add(answer);
9645    
9646                                    count = (Long)q.uniqueResult();
9647    
9648                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9649                            }
9650                            catch (Exception e) {
9651                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9652    
9653                                    throw processException(e);
9654                            }
9655                            finally {
9656                                    closeSession(session);
9657                            }
9658                    }
9659    
9660                    return count.intValue();
9661            }
9662    
9663            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9664            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9665            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9666                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9667                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9668                            new String[] {
9669                                    Long.class.getName(), Integer.class.getName(),
9670                                    
9671                            Integer.class.getName(), Integer.class.getName(),
9672                                    OrderByComparator.class.getName()
9673                            });
9674            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9675                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9676                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9677                            new String[] { Long.class.getName(), Integer.class.getName() },
9678                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9679                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9680                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9681            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9682                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9683                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9684                            new String[] { Long.class.getName(), Integer.class.getName() });
9685    
9686            /**
9687             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9688             *
9689             * @param threadId the thread ID
9690             * @param status the status
9691             * @return the matching message-boards messages
9692             * @throws SystemException if a system exception occurred
9693             */
9694            public List<MBMessage> findByT_S(long threadId, int status)
9695                    throws SystemException {
9696                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9697                            QueryUtil.ALL_POS, null);
9698            }
9699    
9700            /**
9701             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9702             *
9703             * <p>
9704             * 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.
9705             * </p>
9706             *
9707             * @param threadId the thread ID
9708             * @param status the status
9709             * @param start the lower bound of the range of message-boards messages
9710             * @param end the upper bound of the range of message-boards messages (not inclusive)
9711             * @return the range of matching message-boards messages
9712             * @throws SystemException if a system exception occurred
9713             */
9714            public List<MBMessage> findByT_S(long threadId, int status, int start,
9715                    int end) throws SystemException {
9716                    return findByT_S(threadId, status, start, end, null);
9717            }
9718    
9719            /**
9720             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9721             *
9722             * <p>
9723             * 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.
9724             * </p>
9725             *
9726             * @param threadId the thread ID
9727             * @param status the status
9728             * @param start the lower bound of the range of message-boards messages
9729             * @param end the upper bound of the range of message-boards messages (not inclusive)
9730             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9731             * @return the ordered range of matching message-boards messages
9732             * @throws SystemException if a system exception occurred
9733             */
9734            public List<MBMessage> findByT_S(long threadId, int status, int start,
9735                    int end, OrderByComparator orderByComparator) throws SystemException {
9736                    boolean pagination = true;
9737                    FinderPath finderPath = null;
9738                    Object[] finderArgs = null;
9739    
9740                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9741                                    (orderByComparator == null)) {
9742                            pagination = false;
9743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9744                            finderArgs = new Object[] { threadId, status };
9745                    }
9746                    else {
9747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9748                            finderArgs = new Object[] {
9749                                            threadId, status,
9750                                            
9751                                            start, end, orderByComparator
9752                                    };
9753                    }
9754    
9755                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9756                                    finderArgs, this);
9757    
9758                    if ((list != null) && !list.isEmpty()) {
9759                            for (MBMessage mbMessage : list) {
9760                                    if ((threadId != mbMessage.getThreadId()) ||
9761                                                    (status != mbMessage.getStatus())) {
9762                                            list = null;
9763    
9764                                            break;
9765                                    }
9766                            }
9767                    }
9768    
9769                    if (list == null) {
9770                            StringBundler query = null;
9771    
9772                            if (orderByComparator != null) {
9773                                    query = new StringBundler(4 +
9774                                                    (orderByComparator.getOrderByFields().length * 3));
9775                            }
9776                            else {
9777                                    query = new StringBundler(4);
9778                            }
9779    
9780                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9781    
9782                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
9783    
9784                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
9785    
9786                            if (orderByComparator != null) {
9787                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9788                                            orderByComparator);
9789                            }
9790                            else
9791                             if (pagination) {
9792                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9793                            }
9794    
9795                            String sql = query.toString();
9796    
9797                            Session session = null;
9798    
9799                            try {
9800                                    session = openSession();
9801    
9802                                    Query q = session.createQuery(sql);
9803    
9804                                    QueryPos qPos = QueryPos.getInstance(q);
9805    
9806                                    qPos.add(threadId);
9807    
9808                                    qPos.add(status);
9809    
9810                                    if (!pagination) {
9811                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9812                                                            start, end, false);
9813    
9814                                            Collections.sort(list);
9815    
9816                                            list = new UnmodifiableList<MBMessage>(list);
9817                                    }
9818                                    else {
9819                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9820                                                            start, end);
9821                                    }
9822    
9823                                    cacheResult(list);
9824    
9825                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9826                            }
9827                            catch (Exception e) {
9828                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9829    
9830                                    throw processException(e);
9831                            }
9832                            finally {
9833                                    closeSession(session);
9834                            }
9835                    }
9836    
9837                    return list;
9838            }
9839    
9840            /**
9841             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9842             *
9843             * @param threadId the thread ID
9844             * @param status the status
9845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9846             * @return the first matching message-boards message
9847             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9848             * @throws SystemException if a system exception occurred
9849             */
9850            public MBMessage findByT_S_First(long threadId, int status,
9851                    OrderByComparator orderByComparator)
9852                    throws NoSuchMessageException, SystemException {
9853                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9854                                    orderByComparator);
9855    
9856                    if (mbMessage != null) {
9857                            return mbMessage;
9858                    }
9859    
9860                    StringBundler msg = new StringBundler(6);
9861    
9862                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9863    
9864                    msg.append("threadId=");
9865                    msg.append(threadId);
9866    
9867                    msg.append(", status=");
9868                    msg.append(status);
9869    
9870                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9871    
9872                    throw new NoSuchMessageException(msg.toString());
9873            }
9874    
9875            /**
9876             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9877             *
9878             * @param threadId the thread ID
9879             * @param status the status
9880             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9881             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9882             * @throws SystemException if a system exception occurred
9883             */
9884            public MBMessage fetchByT_S_First(long threadId, int status,
9885                    OrderByComparator orderByComparator) throws SystemException {
9886                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9887                                    orderByComparator);
9888    
9889                    if (!list.isEmpty()) {
9890                            return list.get(0);
9891                    }
9892    
9893                    return null;
9894            }
9895    
9896            /**
9897             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9898             *
9899             * @param threadId the thread ID
9900             * @param status the status
9901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9902             * @return the last matching message-boards message
9903             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9904             * @throws SystemException if a system exception occurred
9905             */
9906            public MBMessage findByT_S_Last(long threadId, int status,
9907                    OrderByComparator orderByComparator)
9908                    throws NoSuchMessageException, SystemException {
9909                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9910                                    orderByComparator);
9911    
9912                    if (mbMessage != null) {
9913                            return mbMessage;
9914                    }
9915    
9916                    StringBundler msg = new StringBundler(6);
9917    
9918                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9919    
9920                    msg.append("threadId=");
9921                    msg.append(threadId);
9922    
9923                    msg.append(", status=");
9924                    msg.append(status);
9925    
9926                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9927    
9928                    throw new NoSuchMessageException(msg.toString());
9929            }
9930    
9931            /**
9932             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9933             *
9934             * @param threadId the thread ID
9935             * @param status the status
9936             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9937             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9938             * @throws SystemException if a system exception occurred
9939             */
9940            public MBMessage fetchByT_S_Last(long threadId, int status,
9941                    OrderByComparator orderByComparator) throws SystemException {
9942                    int count = countByT_S(threadId, status);
9943    
9944                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9945                                    orderByComparator);
9946    
9947                    if (!list.isEmpty()) {
9948                            return list.get(0);
9949                    }
9950    
9951                    return null;
9952            }
9953    
9954            /**
9955             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9956             *
9957             * @param messageId the primary key of the current message-boards message
9958             * @param threadId the thread ID
9959             * @param status the status
9960             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9961             * @return the previous, current, and next message-boards message
9962             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9963             * @throws SystemException if a system exception occurred
9964             */
9965            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9966                    int status, OrderByComparator orderByComparator)
9967                    throws NoSuchMessageException, SystemException {
9968                    MBMessage mbMessage = findByPrimaryKey(messageId);
9969    
9970                    Session session = null;
9971    
9972                    try {
9973                            session = openSession();
9974    
9975                            MBMessage[] array = new MBMessageImpl[3];
9976    
9977                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9978                                            status, orderByComparator, true);
9979    
9980                            array[1] = mbMessage;
9981    
9982                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9983                                            status, orderByComparator, false);
9984    
9985                            return array;
9986                    }
9987                    catch (Exception e) {
9988                            throw processException(e);
9989                    }
9990                    finally {
9991                            closeSession(session);
9992                    }
9993            }
9994    
9995            protected MBMessage getByT_S_PrevAndNext(Session session,
9996                    MBMessage mbMessage, long threadId, int status,
9997                    OrderByComparator orderByComparator, boolean previous) {
9998                    StringBundler query = null;
9999    
10000                    if (orderByComparator != null) {
10001                            query = new StringBundler(6 +
10002                                            (orderByComparator.getOrderByFields().length * 6));
10003                    }
10004                    else {
10005                            query = new StringBundler(3);
10006                    }
10007    
10008                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10009    
10010                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10011    
10012                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10013    
10014                    if (orderByComparator != null) {
10015                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10016    
10017                            if (orderByConditionFields.length > 0) {
10018                                    query.append(WHERE_AND);
10019                            }
10020    
10021                            for (int i = 0; i < orderByConditionFields.length; i++) {
10022                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10023                                    query.append(orderByConditionFields[i]);
10024    
10025                                    if ((i + 1) < orderByConditionFields.length) {
10026                                            if (orderByComparator.isAscending() ^ previous) {
10027                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10028                                            }
10029                                            else {
10030                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10031                                            }
10032                                    }
10033                                    else {
10034                                            if (orderByComparator.isAscending() ^ previous) {
10035                                                    query.append(WHERE_GREATER_THAN);
10036                                            }
10037                                            else {
10038                                                    query.append(WHERE_LESSER_THAN);
10039                                            }
10040                                    }
10041                            }
10042    
10043                            query.append(ORDER_BY_CLAUSE);
10044    
10045                            String[] orderByFields = orderByComparator.getOrderByFields();
10046    
10047                            for (int i = 0; i < orderByFields.length; i++) {
10048                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10049                                    query.append(orderByFields[i]);
10050    
10051                                    if ((i + 1) < orderByFields.length) {
10052                                            if (orderByComparator.isAscending() ^ previous) {
10053                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10054                                            }
10055                                            else {
10056                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10057                                            }
10058                                    }
10059                                    else {
10060                                            if (orderByComparator.isAscending() ^ previous) {
10061                                                    query.append(ORDER_BY_ASC);
10062                                            }
10063                                            else {
10064                                                    query.append(ORDER_BY_DESC);
10065                                            }
10066                                    }
10067                            }
10068                    }
10069                    else {
10070                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10071                    }
10072    
10073                    String sql = query.toString();
10074    
10075                    Query q = session.createQuery(sql);
10076    
10077                    q.setFirstResult(0);
10078                    q.setMaxResults(2);
10079    
10080                    QueryPos qPos = QueryPos.getInstance(q);
10081    
10082                    qPos.add(threadId);
10083    
10084                    qPos.add(status);
10085    
10086                    if (orderByComparator != null) {
10087                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10088    
10089                            for (Object value : values) {
10090                                    qPos.add(value);
10091                            }
10092                    }
10093    
10094                    List<MBMessage> list = q.list();
10095    
10096                    if (list.size() == 2) {
10097                            return list.get(1);
10098                    }
10099                    else {
10100                            return null;
10101                    }
10102            }
10103    
10104            /**
10105             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10106             *
10107             * @param threadId the thread ID
10108             * @param status the status
10109             * @throws SystemException if a system exception occurred
10110             */
10111            public void removeByT_S(long threadId, int status)
10112                    throws SystemException {
10113                    for (MBMessage mbMessage : findByT_S(threadId, status,
10114                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10115                            remove(mbMessage);
10116                    }
10117            }
10118    
10119            /**
10120             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10121             *
10122             * @param threadId the thread ID
10123             * @param status the status
10124             * @return the number of matching message-boards messages
10125             * @throws SystemException if a system exception occurred
10126             */
10127            public int countByT_S(long threadId, int status) throws SystemException {
10128                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10129    
10130                    Object[] finderArgs = new Object[] { threadId, status };
10131    
10132                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10133                                    this);
10134    
10135                    if (count == null) {
10136                            StringBundler query = new StringBundler(3);
10137    
10138                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10139    
10140                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10141    
10142                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10143    
10144                            String sql = query.toString();
10145    
10146                            Session session = null;
10147    
10148                            try {
10149                                    session = openSession();
10150    
10151                                    Query q = session.createQuery(sql);
10152    
10153                                    QueryPos qPos = QueryPos.getInstance(q);
10154    
10155                                    qPos.add(threadId);
10156    
10157                                    qPos.add(status);
10158    
10159                                    count = (Long)q.uniqueResult();
10160    
10161                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10162                            }
10163                            catch (Exception e) {
10164                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10165    
10166                                    throw processException(e);
10167                            }
10168                            finally {
10169                                    closeSession(session);
10170                            }
10171                    }
10172    
10173                    return count.intValue();
10174            }
10175    
10176            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10177            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10178            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10179                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10180                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10181                            new String[] {
10182                                    Long.class.getName(), Integer.class.getName(),
10183                                    
10184                            Integer.class.getName(), Integer.class.getName(),
10185                                    OrderByComparator.class.getName()
10186                            });
10187            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10188                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10189                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10190                            new String[] { Long.class.getName(), Integer.class.getName() },
10191                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10192                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10193                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10194            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10195                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10197                            new String[] { Long.class.getName(), Integer.class.getName() });
10198    
10199            /**
10200             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10201             *
10202             * @param threadId the thread ID
10203             * @param status the status
10204             * @return the matching message-boards messages
10205             * @throws SystemException if a system exception occurred
10206             */
10207            public List<MBMessage> findByTR_S(long threadId, int status)
10208                    throws SystemException {
10209                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10210                            QueryUtil.ALL_POS, null);
10211            }
10212    
10213            /**
10214             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10215             *
10216             * <p>
10217             * 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.
10218             * </p>
10219             *
10220             * @param threadId the thread ID
10221             * @param status the status
10222             * @param start the lower bound of the range of message-boards messages
10223             * @param end the upper bound of the range of message-boards messages (not inclusive)
10224             * @return the range of matching message-boards messages
10225             * @throws SystemException if a system exception occurred
10226             */
10227            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10228                    int end) throws SystemException {
10229                    return findByTR_S(threadId, status, start, end, null);
10230            }
10231    
10232            /**
10233             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10234             *
10235             * <p>
10236             * 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.
10237             * </p>
10238             *
10239             * @param threadId the thread ID
10240             * @param status the status
10241             * @param start the lower bound of the range of message-boards messages
10242             * @param end the upper bound of the range of message-boards messages (not inclusive)
10243             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10244             * @return the ordered range of matching message-boards messages
10245             * @throws SystemException if a system exception occurred
10246             */
10247            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10248                    int end, OrderByComparator orderByComparator) throws SystemException {
10249                    boolean pagination = true;
10250                    FinderPath finderPath = null;
10251                    Object[] finderArgs = null;
10252    
10253                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10254                                    (orderByComparator == null)) {
10255                            pagination = false;
10256                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10257                            finderArgs = new Object[] { threadId, status };
10258                    }
10259                    else {
10260                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10261                            finderArgs = new Object[] {
10262                                            threadId, status,
10263                                            
10264                                            start, end, orderByComparator
10265                                    };
10266                    }
10267    
10268                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10269                                    finderArgs, this);
10270    
10271                    if ((list != null) && !list.isEmpty()) {
10272                            for (MBMessage mbMessage : list) {
10273                                    if ((threadId != mbMessage.getThreadId()) ||
10274                                                    (status != mbMessage.getStatus())) {
10275                                            list = null;
10276    
10277                                            break;
10278                                    }
10279                            }
10280                    }
10281    
10282                    if (list == null) {
10283                            StringBundler query = null;
10284    
10285                            if (orderByComparator != null) {
10286                                    query = new StringBundler(4 +
10287                                                    (orderByComparator.getOrderByFields().length * 3));
10288                            }
10289                            else {
10290                                    query = new StringBundler(4);
10291                            }
10292    
10293                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10294    
10295                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10296    
10297                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10298    
10299                            if (orderByComparator != null) {
10300                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10301                                            orderByComparator);
10302                            }
10303                            else
10304                             if (pagination) {
10305                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10306                            }
10307    
10308                            String sql = query.toString();
10309    
10310                            Session session = null;
10311    
10312                            try {
10313                                    session = openSession();
10314    
10315                                    Query q = session.createQuery(sql);
10316    
10317                                    QueryPos qPos = QueryPos.getInstance(q);
10318    
10319                                    qPos.add(threadId);
10320    
10321                                    qPos.add(status);
10322    
10323                                    if (!pagination) {
10324                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10325                                                            start, end, false);
10326    
10327                                            Collections.sort(list);
10328    
10329                                            list = new UnmodifiableList<MBMessage>(list);
10330                                    }
10331                                    else {
10332                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10333                                                            start, end);
10334                                    }
10335    
10336                                    cacheResult(list);
10337    
10338                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10339                            }
10340                            catch (Exception e) {
10341                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10342    
10343                                    throw processException(e);
10344                            }
10345                            finally {
10346                                    closeSession(session);
10347                            }
10348                    }
10349    
10350                    return list;
10351            }
10352    
10353            /**
10354             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10355             *
10356             * @param threadId the thread ID
10357             * @param status the status
10358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10359             * @return the first matching message-boards message
10360             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10361             * @throws SystemException if a system exception occurred
10362             */
10363            public MBMessage findByTR_S_First(long threadId, int status,
10364                    OrderByComparator orderByComparator)
10365                    throws NoSuchMessageException, SystemException {
10366                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10367                                    orderByComparator);
10368    
10369                    if (mbMessage != null) {
10370                            return mbMessage;
10371                    }
10372    
10373                    StringBundler msg = new StringBundler(6);
10374    
10375                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10376    
10377                    msg.append("threadId=");
10378                    msg.append(threadId);
10379    
10380                    msg.append(", status=");
10381                    msg.append(status);
10382    
10383                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10384    
10385                    throw new NoSuchMessageException(msg.toString());
10386            }
10387    
10388            /**
10389             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10390             *
10391             * @param threadId the thread ID
10392             * @param status the status
10393             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10394             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10395             * @throws SystemException if a system exception occurred
10396             */
10397            public MBMessage fetchByTR_S_First(long threadId, int status,
10398                    OrderByComparator orderByComparator) throws SystemException {
10399                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10400                                    orderByComparator);
10401    
10402                    if (!list.isEmpty()) {
10403                            return list.get(0);
10404                    }
10405    
10406                    return null;
10407            }
10408    
10409            /**
10410             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10411             *
10412             * @param threadId the thread ID
10413             * @param status the status
10414             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10415             * @return the last matching message-boards message
10416             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10417             * @throws SystemException if a system exception occurred
10418             */
10419            public MBMessage findByTR_S_Last(long threadId, int status,
10420                    OrderByComparator orderByComparator)
10421                    throws NoSuchMessageException, SystemException {
10422                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10423                                    orderByComparator);
10424    
10425                    if (mbMessage != null) {
10426                            return mbMessage;
10427                    }
10428    
10429                    StringBundler msg = new StringBundler(6);
10430    
10431                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10432    
10433                    msg.append("threadId=");
10434                    msg.append(threadId);
10435    
10436                    msg.append(", status=");
10437                    msg.append(status);
10438    
10439                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10440    
10441                    throw new NoSuchMessageException(msg.toString());
10442            }
10443    
10444            /**
10445             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10446             *
10447             * @param threadId the thread ID
10448             * @param status the status
10449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10450             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10451             * @throws SystemException if a system exception occurred
10452             */
10453            public MBMessage fetchByTR_S_Last(long threadId, int status,
10454                    OrderByComparator orderByComparator) throws SystemException {
10455                    int count = countByTR_S(threadId, status);
10456    
10457                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10458                                    orderByComparator);
10459    
10460                    if (!list.isEmpty()) {
10461                            return list.get(0);
10462                    }
10463    
10464                    return null;
10465            }
10466    
10467            /**
10468             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10469             *
10470             * @param messageId the primary key of the current message-boards message
10471             * @param threadId the thread ID
10472             * @param status the status
10473             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10474             * @return the previous, current, and next message-boards message
10475             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10476             * @throws SystemException if a system exception occurred
10477             */
10478            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10479                    int status, OrderByComparator orderByComparator)
10480                    throws NoSuchMessageException, SystemException {
10481                    MBMessage mbMessage = findByPrimaryKey(messageId);
10482    
10483                    Session session = null;
10484    
10485                    try {
10486                            session = openSession();
10487    
10488                            MBMessage[] array = new MBMessageImpl[3];
10489    
10490                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10491                                            status, orderByComparator, true);
10492    
10493                            array[1] = mbMessage;
10494    
10495                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10496                                            status, orderByComparator, false);
10497    
10498                            return array;
10499                    }
10500                    catch (Exception e) {
10501                            throw processException(e);
10502                    }
10503                    finally {
10504                            closeSession(session);
10505                    }
10506            }
10507    
10508            protected MBMessage getByTR_S_PrevAndNext(Session session,
10509                    MBMessage mbMessage, long threadId, int status,
10510                    OrderByComparator orderByComparator, boolean previous) {
10511                    StringBundler query = null;
10512    
10513                    if (orderByComparator != null) {
10514                            query = new StringBundler(6 +
10515                                            (orderByComparator.getOrderByFields().length * 6));
10516                    }
10517                    else {
10518                            query = new StringBundler(3);
10519                    }
10520    
10521                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10522    
10523                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10524    
10525                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10526    
10527                    if (orderByComparator != null) {
10528                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10529    
10530                            if (orderByConditionFields.length > 0) {
10531                                    query.append(WHERE_AND);
10532                            }
10533    
10534                            for (int i = 0; i < orderByConditionFields.length; i++) {
10535                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10536                                    query.append(orderByConditionFields[i]);
10537    
10538                                    if ((i + 1) < orderByConditionFields.length) {
10539                                            if (orderByComparator.isAscending() ^ previous) {
10540                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10541                                            }
10542                                            else {
10543                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10544                                            }
10545                                    }
10546                                    else {
10547                                            if (orderByComparator.isAscending() ^ previous) {
10548                                                    query.append(WHERE_GREATER_THAN);
10549                                            }
10550                                            else {
10551                                                    query.append(WHERE_LESSER_THAN);
10552                                            }
10553                                    }
10554                            }
10555    
10556                            query.append(ORDER_BY_CLAUSE);
10557    
10558                            String[] orderByFields = orderByComparator.getOrderByFields();
10559    
10560                            for (int i = 0; i < orderByFields.length; i++) {
10561                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10562                                    query.append(orderByFields[i]);
10563    
10564                                    if ((i + 1) < orderByFields.length) {
10565                                            if (orderByComparator.isAscending() ^ previous) {
10566                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10567                                            }
10568                                            else {
10569                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10570                                            }
10571                                    }
10572                                    else {
10573                                            if (orderByComparator.isAscending() ^ previous) {
10574                                                    query.append(ORDER_BY_ASC);
10575                                            }
10576                                            else {
10577                                                    query.append(ORDER_BY_DESC);
10578                                            }
10579                                    }
10580                            }
10581                    }
10582                    else {
10583                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10584                    }
10585    
10586                    String sql = query.toString();
10587    
10588                    Query q = session.createQuery(sql);
10589    
10590                    q.setFirstResult(0);
10591                    q.setMaxResults(2);
10592    
10593                    QueryPos qPos = QueryPos.getInstance(q);
10594    
10595                    qPos.add(threadId);
10596    
10597                    qPos.add(status);
10598    
10599                    if (orderByComparator != null) {
10600                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10601    
10602                            for (Object value : values) {
10603                                    qPos.add(value);
10604                            }
10605                    }
10606    
10607                    List<MBMessage> list = q.list();
10608    
10609                    if (list.size() == 2) {
10610                            return list.get(1);
10611                    }
10612                    else {
10613                            return null;
10614                    }
10615            }
10616    
10617            /**
10618             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10619             *
10620             * @param threadId the thread ID
10621             * @param status the status
10622             * @throws SystemException if a system exception occurred
10623             */
10624            public void removeByTR_S(long threadId, int status)
10625                    throws SystemException {
10626                    for (MBMessage mbMessage : findByTR_S(threadId, status,
10627                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10628                            remove(mbMessage);
10629                    }
10630            }
10631    
10632            /**
10633             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10634             *
10635             * @param threadId the thread ID
10636             * @param status the status
10637             * @return the number of matching message-boards messages
10638             * @throws SystemException if a system exception occurred
10639             */
10640            public int countByTR_S(long threadId, int status) throws SystemException {
10641                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10642    
10643                    Object[] finderArgs = new Object[] { threadId, status };
10644    
10645                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10646                                    this);
10647    
10648                    if (count == null) {
10649                            StringBundler query = new StringBundler(3);
10650    
10651                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10652    
10653                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10654    
10655                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10656    
10657                            String sql = query.toString();
10658    
10659                            Session session = null;
10660    
10661                            try {
10662                                    session = openSession();
10663    
10664                                    Query q = session.createQuery(sql);
10665    
10666                                    QueryPos qPos = QueryPos.getInstance(q);
10667    
10668                                    qPos.add(threadId);
10669    
10670                                    qPos.add(status);
10671    
10672                                    count = (Long)q.uniqueResult();
10673    
10674                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10675                            }
10676                            catch (Exception e) {
10677                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10678    
10679                                    throw processException(e);
10680                            }
10681                            finally {
10682                                    closeSession(session);
10683                            }
10684                    }
10685    
10686                    return count.intValue();
10687            }
10688    
10689            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10690            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10691            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10692                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10693                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10694                            new String[] {
10695                                    Long.class.getName(), Long.class.getName(),
10696                                    Integer.class.getName(),
10697                                    
10698                            Integer.class.getName(), Integer.class.getName(),
10699                                    OrderByComparator.class.getName()
10700                            });
10701            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10702                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10703                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10704                            new String[] {
10705                                    Long.class.getName(), Long.class.getName(),
10706                                    Integer.class.getName()
10707                            },
10708                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10709                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
10710                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10711                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10712            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10713                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10714                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10715                            new String[] {
10716                                    Long.class.getName(), Long.class.getName(),
10717                                    Integer.class.getName()
10718                            });
10719    
10720            /**
10721             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10722             *
10723             * @param groupId the group ID
10724             * @param userId the user ID
10725             * @param status the status
10726             * @return the matching message-boards messages
10727             * @throws SystemException if a system exception occurred
10728             */
10729            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
10730                    throws SystemException {
10731                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10732                            QueryUtil.ALL_POS, null);
10733            }
10734    
10735            /**
10736             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10737             *
10738             * <p>
10739             * 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.
10740             * </p>
10741             *
10742             * @param groupId the group ID
10743             * @param userId the user ID
10744             * @param status the status
10745             * @param start the lower bound of the range of message-boards messages
10746             * @param end the upper bound of the range of message-boards messages (not inclusive)
10747             * @return the range of matching message-boards messages
10748             * @throws SystemException if a system exception occurred
10749             */
10750            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10751                    int start, int end) throws SystemException {
10752                    return findByG_U_S(groupId, userId, status, start, end, null);
10753            }
10754    
10755            /**
10756             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10757             *
10758             * <p>
10759             * 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.
10760             * </p>
10761             *
10762             * @param groupId the group ID
10763             * @param userId the user ID
10764             * @param status the status
10765             * @param start the lower bound of the range of message-boards messages
10766             * @param end the upper bound of the range of message-boards messages (not inclusive)
10767             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10768             * @return the ordered range of matching message-boards messages
10769             * @throws SystemException if a system exception occurred
10770             */
10771            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10772                    int start, int end, OrderByComparator orderByComparator)
10773                    throws SystemException {
10774                    boolean pagination = true;
10775                    FinderPath finderPath = null;
10776                    Object[] finderArgs = null;
10777    
10778                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10779                                    (orderByComparator == null)) {
10780                            pagination = false;
10781                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10782                            finderArgs = new Object[] { groupId, userId, status };
10783                    }
10784                    else {
10785                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10786                            finderArgs = new Object[] {
10787                                            groupId, userId, status,
10788                                            
10789                                            start, end, orderByComparator
10790                                    };
10791                    }
10792    
10793                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10794                                    finderArgs, this);
10795    
10796                    if ((list != null) && !list.isEmpty()) {
10797                            for (MBMessage mbMessage : list) {
10798                                    if ((groupId != mbMessage.getGroupId()) ||
10799                                                    (userId != mbMessage.getUserId()) ||
10800                                                    (status != mbMessage.getStatus())) {
10801                                            list = null;
10802    
10803                                            break;
10804                                    }
10805                            }
10806                    }
10807    
10808                    if (list == null) {
10809                            StringBundler query = null;
10810    
10811                            if (orderByComparator != null) {
10812                                    query = new StringBundler(5 +
10813                                                    (orderByComparator.getOrderByFields().length * 3));
10814                            }
10815                            else {
10816                                    query = new StringBundler(5);
10817                            }
10818    
10819                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10820    
10821                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10822    
10823                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10824    
10825                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10826    
10827                            if (orderByComparator != null) {
10828                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10829                                            orderByComparator);
10830                            }
10831                            else
10832                             if (pagination) {
10833                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10834                            }
10835    
10836                            String sql = query.toString();
10837    
10838                            Session session = null;
10839    
10840                            try {
10841                                    session = openSession();
10842    
10843                                    Query q = session.createQuery(sql);
10844    
10845                                    QueryPos qPos = QueryPos.getInstance(q);
10846    
10847                                    qPos.add(groupId);
10848    
10849                                    qPos.add(userId);
10850    
10851                                    qPos.add(status);
10852    
10853                                    if (!pagination) {
10854                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10855                                                            start, end, false);
10856    
10857                                            Collections.sort(list);
10858    
10859                                            list = new UnmodifiableList<MBMessage>(list);
10860                                    }
10861                                    else {
10862                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10863                                                            start, end);
10864                                    }
10865    
10866                                    cacheResult(list);
10867    
10868                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10869                            }
10870                            catch (Exception e) {
10871                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10872    
10873                                    throw processException(e);
10874                            }
10875                            finally {
10876                                    closeSession(session);
10877                            }
10878                    }
10879    
10880                    return list;
10881            }
10882    
10883            /**
10884             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10885             *
10886             * @param groupId the group ID
10887             * @param userId the user ID
10888             * @param status the status
10889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10890             * @return the first matching message-boards message
10891             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10892             * @throws SystemException if a system exception occurred
10893             */
10894            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10895                    OrderByComparator orderByComparator)
10896                    throws NoSuchMessageException, SystemException {
10897                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10898                                    orderByComparator);
10899    
10900                    if (mbMessage != null) {
10901                            return mbMessage;
10902                    }
10903    
10904                    StringBundler msg = new StringBundler(8);
10905    
10906                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10907    
10908                    msg.append("groupId=");
10909                    msg.append(groupId);
10910    
10911                    msg.append(", userId=");
10912                    msg.append(userId);
10913    
10914                    msg.append(", status=");
10915                    msg.append(status);
10916    
10917                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10918    
10919                    throw new NoSuchMessageException(msg.toString());
10920            }
10921    
10922            /**
10923             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10924             *
10925             * @param groupId the group ID
10926             * @param userId the user ID
10927             * @param status the status
10928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10929             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10930             * @throws SystemException if a system exception occurred
10931             */
10932            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10933                    OrderByComparator orderByComparator) throws SystemException {
10934                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10935                                    orderByComparator);
10936    
10937                    if (!list.isEmpty()) {
10938                            return list.get(0);
10939                    }
10940    
10941                    return null;
10942            }
10943    
10944            /**
10945             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10946             *
10947             * @param groupId the group ID
10948             * @param userId the user ID
10949             * @param status the status
10950             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10951             * @return the last matching message-boards message
10952             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10953             * @throws SystemException if a system exception occurred
10954             */
10955            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10956                    OrderByComparator orderByComparator)
10957                    throws NoSuchMessageException, SystemException {
10958                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10959                                    orderByComparator);
10960    
10961                    if (mbMessage != null) {
10962                            return mbMessage;
10963                    }
10964    
10965                    StringBundler msg = new StringBundler(8);
10966    
10967                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10968    
10969                    msg.append("groupId=");
10970                    msg.append(groupId);
10971    
10972                    msg.append(", userId=");
10973                    msg.append(userId);
10974    
10975                    msg.append(", status=");
10976                    msg.append(status);
10977    
10978                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10979    
10980                    throw new NoSuchMessageException(msg.toString());
10981            }
10982    
10983            /**
10984             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10985             *
10986             * @param groupId the group ID
10987             * @param userId the user ID
10988             * @param status the status
10989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10990             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10991             * @throws SystemException if a system exception occurred
10992             */
10993            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
10994                    OrderByComparator orderByComparator) throws SystemException {
10995                    int count = countByG_U_S(groupId, userId, status);
10996    
10997                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
10998                                    count, orderByComparator);
10999    
11000                    if (!list.isEmpty()) {
11001                            return list.get(0);
11002                    }
11003    
11004                    return null;
11005            }
11006    
11007            /**
11008             * 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;.
11009             *
11010             * @param messageId the primary key of the current message-boards message
11011             * @param groupId the group ID
11012             * @param userId the user ID
11013             * @param status the status
11014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11015             * @return the previous, current, and next message-boards message
11016             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11017             * @throws SystemException if a system exception occurred
11018             */
11019            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11020                    long userId, int status, OrderByComparator orderByComparator)
11021                    throws NoSuchMessageException, SystemException {
11022                    MBMessage mbMessage = findByPrimaryKey(messageId);
11023    
11024                    Session session = null;
11025    
11026                    try {
11027                            session = openSession();
11028    
11029                            MBMessage[] array = new MBMessageImpl[3];
11030    
11031                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11032                                            userId, status, orderByComparator, true);
11033    
11034                            array[1] = mbMessage;
11035    
11036                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11037                                            userId, status, orderByComparator, false);
11038    
11039                            return array;
11040                    }
11041                    catch (Exception e) {
11042                            throw processException(e);
11043                    }
11044                    finally {
11045                            closeSession(session);
11046                    }
11047            }
11048    
11049            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11050                    MBMessage mbMessage, long groupId, long userId, int status,
11051                    OrderByComparator orderByComparator, boolean previous) {
11052                    StringBundler query = null;
11053    
11054                    if (orderByComparator != null) {
11055                            query = new StringBundler(6 +
11056                                            (orderByComparator.getOrderByFields().length * 6));
11057                    }
11058                    else {
11059                            query = new StringBundler(3);
11060                    }
11061    
11062                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11063    
11064                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11065    
11066                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11067    
11068                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11069    
11070                    if (orderByComparator != null) {
11071                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11072    
11073                            if (orderByConditionFields.length > 0) {
11074                                    query.append(WHERE_AND);
11075                            }
11076    
11077                            for (int i = 0; i < orderByConditionFields.length; i++) {
11078                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11079                                    query.append(orderByConditionFields[i]);
11080    
11081                                    if ((i + 1) < orderByConditionFields.length) {
11082                                            if (orderByComparator.isAscending() ^ previous) {
11083                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11084                                            }
11085                                            else {
11086                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11087                                            }
11088                                    }
11089                                    else {
11090                                            if (orderByComparator.isAscending() ^ previous) {
11091                                                    query.append(WHERE_GREATER_THAN);
11092                                            }
11093                                            else {
11094                                                    query.append(WHERE_LESSER_THAN);
11095                                            }
11096                                    }
11097                            }
11098    
11099                            query.append(ORDER_BY_CLAUSE);
11100    
11101                            String[] orderByFields = orderByComparator.getOrderByFields();
11102    
11103                            for (int i = 0; i < orderByFields.length; i++) {
11104                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11105                                    query.append(orderByFields[i]);
11106    
11107                                    if ((i + 1) < orderByFields.length) {
11108                                            if (orderByComparator.isAscending() ^ previous) {
11109                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11110                                            }
11111                                            else {
11112                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11113                                            }
11114                                    }
11115                                    else {
11116                                            if (orderByComparator.isAscending() ^ previous) {
11117                                                    query.append(ORDER_BY_ASC);
11118                                            }
11119                                            else {
11120                                                    query.append(ORDER_BY_DESC);
11121                                            }
11122                                    }
11123                            }
11124                    }
11125                    else {
11126                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11127                    }
11128    
11129                    String sql = query.toString();
11130    
11131                    Query q = session.createQuery(sql);
11132    
11133                    q.setFirstResult(0);
11134                    q.setMaxResults(2);
11135    
11136                    QueryPos qPos = QueryPos.getInstance(q);
11137    
11138                    qPos.add(groupId);
11139    
11140                    qPos.add(userId);
11141    
11142                    qPos.add(status);
11143    
11144                    if (orderByComparator != null) {
11145                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11146    
11147                            for (Object value : values) {
11148                                    qPos.add(value);
11149                            }
11150                    }
11151    
11152                    List<MBMessage> list = q.list();
11153    
11154                    if (list.size() == 2) {
11155                            return list.get(1);
11156                    }
11157                    else {
11158                            return null;
11159                    }
11160            }
11161    
11162            /**
11163             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11164             *
11165             * @param groupId the group ID
11166             * @param userId the user ID
11167             * @param status the status
11168             * @return the matching message-boards messages that the user has permission to view
11169             * @throws SystemException if a system exception occurred
11170             */
11171            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11172                    int status) throws SystemException {
11173                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11174                            QueryUtil.ALL_POS, null);
11175            }
11176    
11177            /**
11178             * 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;.
11179             *
11180             * <p>
11181             * 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.
11182             * </p>
11183             *
11184             * @param groupId the group ID
11185             * @param userId the user ID
11186             * @param status the status
11187             * @param start the lower bound of the range of message-boards messages
11188             * @param end the upper bound of the range of message-boards messages (not inclusive)
11189             * @return the range of matching message-boards messages that the user has permission to view
11190             * @throws SystemException if a system exception occurred
11191             */
11192            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11193                    int status, int start, int end) throws SystemException {
11194                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11195            }
11196    
11197            /**
11198             * 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;.
11199             *
11200             * <p>
11201             * 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.
11202             * </p>
11203             *
11204             * @param groupId the group ID
11205             * @param userId the user ID
11206             * @param status the status
11207             * @param start the lower bound of the range of message-boards messages
11208             * @param end the upper bound of the range of message-boards messages (not inclusive)
11209             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11210             * @return the ordered range of matching message-boards messages that the user has permission to view
11211             * @throws SystemException if a system exception occurred
11212             */
11213            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11214                    int status, int start, int end, OrderByComparator orderByComparator)
11215                    throws SystemException {
11216                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11217                            return findByG_U_S(groupId, userId, status, start, end,
11218                                    orderByComparator);
11219                    }
11220    
11221                    StringBundler query = null;
11222    
11223                    if (orderByComparator != null) {
11224                            query = new StringBundler(5 +
11225                                            (orderByComparator.getOrderByFields().length * 3));
11226                    }
11227                    else {
11228                            query = new StringBundler(5);
11229                    }
11230    
11231                    if (getDB().isSupportsInlineDistinct()) {
11232                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11233                    }
11234                    else {
11235                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11236                    }
11237    
11238                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11239    
11240                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11241    
11242                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11243    
11244                    if (!getDB().isSupportsInlineDistinct()) {
11245                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11246                    }
11247    
11248                    if (orderByComparator != null) {
11249                            if (getDB().isSupportsInlineDistinct()) {
11250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11251                                            orderByComparator);
11252                            }
11253                            else {
11254                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11255                                            orderByComparator);
11256                            }
11257                    }
11258                    else {
11259                            if (getDB().isSupportsInlineDistinct()) {
11260                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11261                            }
11262                            else {
11263                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11264                            }
11265                    }
11266    
11267                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11268                                    MBMessage.class.getName(),
11269                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11270    
11271                    Session session = null;
11272    
11273                    try {
11274                            session = openSession();
11275    
11276                            SQLQuery q = session.createSQLQuery(sql);
11277    
11278                            if (getDB().isSupportsInlineDistinct()) {
11279                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11280                            }
11281                            else {
11282                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11283                            }
11284    
11285                            QueryPos qPos = QueryPos.getInstance(q);
11286    
11287                            qPos.add(groupId);
11288    
11289                            qPos.add(userId);
11290    
11291                            qPos.add(status);
11292    
11293                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11294                    }
11295                    catch (Exception e) {
11296                            throw processException(e);
11297                    }
11298                    finally {
11299                            closeSession(session);
11300                    }
11301            }
11302    
11303            /**
11304             * 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;.
11305             *
11306             * @param messageId the primary key of the current message-boards message
11307             * @param groupId the group ID
11308             * @param userId the user ID
11309             * @param status the status
11310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11311             * @return the previous, current, and next message-boards message
11312             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11313             * @throws SystemException if a system exception occurred
11314             */
11315            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11316                    long groupId, long userId, int status,
11317                    OrderByComparator orderByComparator)
11318                    throws NoSuchMessageException, SystemException {
11319                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11320                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11321                                    orderByComparator);
11322                    }
11323    
11324                    MBMessage mbMessage = findByPrimaryKey(messageId);
11325    
11326                    Session session = null;
11327    
11328                    try {
11329                            session = openSession();
11330    
11331                            MBMessage[] array = new MBMessageImpl[3];
11332    
11333                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11334                                            groupId, userId, status, orderByComparator, true);
11335    
11336                            array[1] = mbMessage;
11337    
11338                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11339                                            groupId, userId, status, orderByComparator, false);
11340    
11341                            return array;
11342                    }
11343                    catch (Exception e) {
11344                            throw processException(e);
11345                    }
11346                    finally {
11347                            closeSession(session);
11348                    }
11349            }
11350    
11351            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11352                    MBMessage mbMessage, long groupId, long userId, int status,
11353                    OrderByComparator orderByComparator, boolean previous) {
11354                    StringBundler query = null;
11355    
11356                    if (orderByComparator != null) {
11357                            query = new StringBundler(6 +
11358                                            (orderByComparator.getOrderByFields().length * 6));
11359                    }
11360                    else {
11361                            query = new StringBundler(3);
11362                    }
11363    
11364                    if (getDB().isSupportsInlineDistinct()) {
11365                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11366                    }
11367                    else {
11368                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11369                    }
11370    
11371                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11372    
11373                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11374    
11375                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11376    
11377                    if (!getDB().isSupportsInlineDistinct()) {
11378                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11379                    }
11380    
11381                    if (orderByComparator != null) {
11382                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11383    
11384                            if (orderByConditionFields.length > 0) {
11385                                    query.append(WHERE_AND);
11386                            }
11387    
11388                            for (int i = 0; i < orderByConditionFields.length; i++) {
11389                                    if (getDB().isSupportsInlineDistinct()) {
11390                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11391                                    }
11392                                    else {
11393                                            query.append(_ORDER_BY_ENTITY_TABLE);
11394                                    }
11395    
11396                                    query.append(orderByConditionFields[i]);
11397    
11398                                    if ((i + 1) < orderByConditionFields.length) {
11399                                            if (orderByComparator.isAscending() ^ previous) {
11400                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11401                                            }
11402                                            else {
11403                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11404                                            }
11405                                    }
11406                                    else {
11407                                            if (orderByComparator.isAscending() ^ previous) {
11408                                                    query.append(WHERE_GREATER_THAN);
11409                                            }
11410                                            else {
11411                                                    query.append(WHERE_LESSER_THAN);
11412                                            }
11413                                    }
11414                            }
11415    
11416                            query.append(ORDER_BY_CLAUSE);
11417    
11418                            String[] orderByFields = orderByComparator.getOrderByFields();
11419    
11420                            for (int i = 0; i < orderByFields.length; i++) {
11421                                    if (getDB().isSupportsInlineDistinct()) {
11422                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11423                                    }
11424                                    else {
11425                                            query.append(_ORDER_BY_ENTITY_TABLE);
11426                                    }
11427    
11428                                    query.append(orderByFields[i]);
11429    
11430                                    if ((i + 1) < orderByFields.length) {
11431                                            if (orderByComparator.isAscending() ^ previous) {
11432                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11433                                            }
11434                                            else {
11435                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11436                                            }
11437                                    }
11438                                    else {
11439                                            if (orderByComparator.isAscending() ^ previous) {
11440                                                    query.append(ORDER_BY_ASC);
11441                                            }
11442                                            else {
11443                                                    query.append(ORDER_BY_DESC);
11444                                            }
11445                                    }
11446                            }
11447                    }
11448                    else {
11449                            if (getDB().isSupportsInlineDistinct()) {
11450                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11451                            }
11452                            else {
11453                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11454                            }
11455                    }
11456    
11457                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11458                                    MBMessage.class.getName(),
11459                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11460    
11461                    SQLQuery q = session.createSQLQuery(sql);
11462    
11463                    q.setFirstResult(0);
11464                    q.setMaxResults(2);
11465    
11466                    if (getDB().isSupportsInlineDistinct()) {
11467                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11468                    }
11469                    else {
11470                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11471                    }
11472    
11473                    QueryPos qPos = QueryPos.getInstance(q);
11474    
11475                    qPos.add(groupId);
11476    
11477                    qPos.add(userId);
11478    
11479                    qPos.add(status);
11480    
11481                    if (orderByComparator != null) {
11482                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11483    
11484                            for (Object value : values) {
11485                                    qPos.add(value);
11486                            }
11487                    }
11488    
11489                    List<MBMessage> list = q.list();
11490    
11491                    if (list.size() == 2) {
11492                            return list.get(1);
11493                    }
11494                    else {
11495                            return null;
11496                    }
11497            }
11498    
11499            /**
11500             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
11501             *
11502             * @param groupId the group ID
11503             * @param userId the user ID
11504             * @param status the status
11505             * @throws SystemException if a system exception occurred
11506             */
11507            public void removeByG_U_S(long groupId, long userId, int status)
11508                    throws SystemException {
11509                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11510                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11511                            remove(mbMessage);
11512                    }
11513            }
11514    
11515            /**
11516             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11517             *
11518             * @param groupId the group ID
11519             * @param userId the user ID
11520             * @param status the status
11521             * @return the number of matching message-boards messages
11522             * @throws SystemException if a system exception occurred
11523             */
11524            public int countByG_U_S(long groupId, long userId, int status)
11525                    throws SystemException {
11526                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11527    
11528                    Object[] finderArgs = new Object[] { groupId, userId, status };
11529    
11530                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11531                                    this);
11532    
11533                    if (count == null) {
11534                            StringBundler query = new StringBundler(4);
11535    
11536                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11537    
11538                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11539    
11540                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11541    
11542                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11543    
11544                            String sql = query.toString();
11545    
11546                            Session session = null;
11547    
11548                            try {
11549                                    session = openSession();
11550    
11551                                    Query q = session.createQuery(sql);
11552    
11553                                    QueryPos qPos = QueryPos.getInstance(q);
11554    
11555                                    qPos.add(groupId);
11556    
11557                                    qPos.add(userId);
11558    
11559                                    qPos.add(status);
11560    
11561                                    count = (Long)q.uniqueResult();
11562    
11563                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11564                            }
11565                            catch (Exception e) {
11566                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11567    
11568                                    throw processException(e);
11569                            }
11570                            finally {
11571                                    closeSession(session);
11572                            }
11573                    }
11574    
11575                    return count.intValue();
11576            }
11577    
11578            /**
11579             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11580             *
11581             * @param groupId the group ID
11582             * @param userId the user ID
11583             * @param status the status
11584             * @return the number of matching message-boards messages that the user has permission to view
11585             * @throws SystemException if a system exception occurred
11586             */
11587            public int filterCountByG_U_S(long groupId, long userId, int status)
11588                    throws SystemException {
11589                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11590                            return countByG_U_S(groupId, userId, status);
11591                    }
11592    
11593                    StringBundler query = new StringBundler(4);
11594    
11595                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11596    
11597                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11598    
11599                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11600    
11601                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11602    
11603                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11604                                    MBMessage.class.getName(),
11605                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11606    
11607                    Session session = null;
11608    
11609                    try {
11610                            session = openSession();
11611    
11612                            SQLQuery q = session.createSQLQuery(sql);
11613    
11614                            q.addScalar(COUNT_COLUMN_NAME,
11615                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11616    
11617                            QueryPos qPos = QueryPos.getInstance(q);
11618    
11619                            qPos.add(groupId);
11620    
11621                            qPos.add(userId);
11622    
11623                            qPos.add(status);
11624    
11625                            Long count = (Long)q.uniqueResult();
11626    
11627                            return count.intValue();
11628                    }
11629                    catch (Exception e) {
11630                            throw processException(e);
11631                    }
11632                    finally {
11633                            closeSession(session);
11634                    }
11635            }
11636    
11637            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11638            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11639            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11640            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11641                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11642                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11643                            new String[] {
11644                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
11645                                    
11646                            Integer.class.getName(), Integer.class.getName(),
11647                                    OrderByComparator.class.getName()
11648                            });
11649            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11650                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11651                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11652                            new String[] {
11653                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11654                            },
11655                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11656                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11657                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11658                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11659            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11660                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11661                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11662                            new String[] {
11663                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11664                            });
11665    
11666            /**
11667             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11668             *
11669             * @param groupId the group ID
11670             * @param categoryId the category ID
11671             * @param threadId the thread ID
11672             * @return the matching message-boards messages
11673             * @throws SystemException if a system exception occurred
11674             */
11675            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11676                    long threadId) throws SystemException {
11677                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11678                            QueryUtil.ALL_POS, null);
11679            }
11680    
11681            /**
11682             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11683             *
11684             * <p>
11685             * 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.
11686             * </p>
11687             *
11688             * @param groupId the group ID
11689             * @param categoryId the category ID
11690             * @param threadId the thread ID
11691             * @param start the lower bound of the range of message-boards messages
11692             * @param end the upper bound of the range of message-boards messages (not inclusive)
11693             * @return the range of matching message-boards messages
11694             * @throws SystemException if a system exception occurred
11695             */
11696            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11697                    long threadId, int start, int end) throws SystemException {
11698                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
11699            }
11700    
11701            /**
11702             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11703             *
11704             * <p>
11705             * 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.
11706             * </p>
11707             *
11708             * @param groupId the group ID
11709             * @param categoryId the category ID
11710             * @param threadId the thread ID
11711             * @param start the lower bound of the range of message-boards messages
11712             * @param end the upper bound of the range of message-boards messages (not inclusive)
11713             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11714             * @return the ordered range of matching message-boards messages
11715             * @throws SystemException if a system exception occurred
11716             */
11717            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11718                    long threadId, int start, int end, OrderByComparator orderByComparator)
11719                    throws SystemException {
11720                    boolean pagination = true;
11721                    FinderPath finderPath = null;
11722                    Object[] finderArgs = null;
11723    
11724                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11725                                    (orderByComparator == null)) {
11726                            pagination = false;
11727                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
11728                            finderArgs = new Object[] { groupId, categoryId, threadId };
11729                    }
11730                    else {
11731                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
11732                            finderArgs = new Object[] {
11733                                            groupId, categoryId, threadId,
11734                                            
11735                                            start, end, orderByComparator
11736                                    };
11737                    }
11738    
11739                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11740                                    finderArgs, this);
11741    
11742                    if ((list != null) && !list.isEmpty()) {
11743                            for (MBMessage mbMessage : list) {
11744                                    if ((groupId != mbMessage.getGroupId()) ||
11745                                                    (categoryId != mbMessage.getCategoryId()) ||
11746                                                    (threadId != mbMessage.getThreadId())) {
11747                                            list = null;
11748    
11749                                            break;
11750                                    }
11751                            }
11752                    }
11753    
11754                    if (list == null) {
11755                            StringBundler query = null;
11756    
11757                            if (orderByComparator != null) {
11758                                    query = new StringBundler(5 +
11759                                                    (orderByComparator.getOrderByFields().length * 3));
11760                            }
11761                            else {
11762                                    query = new StringBundler(5);
11763                            }
11764    
11765                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11766    
11767                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11768    
11769                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11770    
11771                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11772    
11773                            if (orderByComparator != null) {
11774                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11775                                            orderByComparator);
11776                            }
11777                            else
11778                             if (pagination) {
11779                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11780                            }
11781    
11782                            String sql = query.toString();
11783    
11784                            Session session = null;
11785    
11786                            try {
11787                                    session = openSession();
11788    
11789                                    Query q = session.createQuery(sql);
11790    
11791                                    QueryPos qPos = QueryPos.getInstance(q);
11792    
11793                                    qPos.add(groupId);
11794    
11795                                    qPos.add(categoryId);
11796    
11797                                    qPos.add(threadId);
11798    
11799                                    if (!pagination) {
11800                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11801                                                            start, end, false);
11802    
11803                                            Collections.sort(list);
11804    
11805                                            list = new UnmodifiableList<MBMessage>(list);
11806                                    }
11807                                    else {
11808                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11809                                                            start, end);
11810                                    }
11811    
11812                                    cacheResult(list);
11813    
11814                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11815                            }
11816                            catch (Exception e) {
11817                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11818    
11819                                    throw processException(e);
11820                            }
11821                            finally {
11822                                    closeSession(session);
11823                            }
11824                    }
11825    
11826                    return list;
11827            }
11828    
11829            /**
11830             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11831             *
11832             * @param groupId the group ID
11833             * @param categoryId the category ID
11834             * @param threadId the thread ID
11835             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11836             * @return the first matching message-boards message
11837             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11838             * @throws SystemException if a system exception occurred
11839             */
11840            public MBMessage findByG_C_T_First(long groupId, long categoryId,
11841                    long threadId, OrderByComparator orderByComparator)
11842                    throws NoSuchMessageException, SystemException {
11843                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11844                                    orderByComparator);
11845    
11846                    if (mbMessage != null) {
11847                            return mbMessage;
11848                    }
11849    
11850                    StringBundler msg = new StringBundler(8);
11851    
11852                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11853    
11854                    msg.append("groupId=");
11855                    msg.append(groupId);
11856    
11857                    msg.append(", categoryId=");
11858                    msg.append(categoryId);
11859    
11860                    msg.append(", threadId=");
11861                    msg.append(threadId);
11862    
11863                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11864    
11865                    throw new NoSuchMessageException(msg.toString());
11866            }
11867    
11868            /**
11869             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11870             *
11871             * @param groupId the group ID
11872             * @param categoryId the category ID
11873             * @param threadId the thread ID
11874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11875             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11876             * @throws SystemException if a system exception occurred
11877             */
11878            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11879                    long threadId, OrderByComparator orderByComparator)
11880                    throws SystemException {
11881                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11882                                    orderByComparator);
11883    
11884                    if (!list.isEmpty()) {
11885                            return list.get(0);
11886                    }
11887    
11888                    return null;
11889            }
11890    
11891            /**
11892             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11893             *
11894             * @param groupId the group ID
11895             * @param categoryId the category ID
11896             * @param threadId the thread ID
11897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11898             * @return the last matching message-boards message
11899             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11900             * @throws SystemException if a system exception occurred
11901             */
11902            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11903                    long threadId, OrderByComparator orderByComparator)
11904                    throws NoSuchMessageException, SystemException {
11905                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11906                                    orderByComparator);
11907    
11908                    if (mbMessage != null) {
11909                            return mbMessage;
11910                    }
11911    
11912                    StringBundler msg = new StringBundler(8);
11913    
11914                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11915    
11916                    msg.append("groupId=");
11917                    msg.append(groupId);
11918    
11919                    msg.append(", categoryId=");
11920                    msg.append(categoryId);
11921    
11922                    msg.append(", threadId=");
11923                    msg.append(threadId);
11924    
11925                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11926    
11927                    throw new NoSuchMessageException(msg.toString());
11928            }
11929    
11930            /**
11931             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11932             *
11933             * @param groupId the group ID
11934             * @param categoryId the category ID
11935             * @param threadId the thread ID
11936             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11937             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11938             * @throws SystemException if a system exception occurred
11939             */
11940            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11941                    long threadId, OrderByComparator orderByComparator)
11942                    throws SystemException {
11943                    int count = countByG_C_T(groupId, categoryId, threadId);
11944    
11945                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11946                                    count - 1, count, orderByComparator);
11947    
11948                    if (!list.isEmpty()) {
11949                            return list.get(0);
11950                    }
11951    
11952                    return null;
11953            }
11954    
11955            /**
11956             * 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;.
11957             *
11958             * @param messageId the primary key of the current message-boards message
11959             * @param groupId the group ID
11960             * @param categoryId the category ID
11961             * @param threadId the thread ID
11962             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11963             * @return the previous, current, and next message-boards message
11964             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11965             * @throws SystemException if a system exception occurred
11966             */
11967            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11968                    long categoryId, long threadId, OrderByComparator orderByComparator)
11969                    throws NoSuchMessageException, SystemException {
11970                    MBMessage mbMessage = findByPrimaryKey(messageId);
11971    
11972                    Session session = null;
11973    
11974                    try {
11975                            session = openSession();
11976    
11977                            MBMessage[] array = new MBMessageImpl[3];
11978    
11979                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11980                                            categoryId, threadId, orderByComparator, true);
11981    
11982                            array[1] = mbMessage;
11983    
11984                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11985                                            categoryId, threadId, orderByComparator, false);
11986    
11987                            return array;
11988                    }
11989                    catch (Exception e) {
11990                            throw processException(e);
11991                    }
11992                    finally {
11993                            closeSession(session);
11994                    }
11995            }
11996    
11997            protected MBMessage getByG_C_T_PrevAndNext(Session session,
11998                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
11999                    OrderByComparator orderByComparator, boolean previous) {
12000                    StringBundler query = null;
12001    
12002                    if (orderByComparator != null) {
12003                            query = new StringBundler(6 +
12004                                            (orderByComparator.getOrderByFields().length * 6));
12005                    }
12006                    else {
12007                            query = new StringBundler(3);
12008                    }
12009    
12010                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12011    
12012                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12013    
12014                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12015    
12016                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12017    
12018                    if (orderByComparator != null) {
12019                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12020    
12021                            if (orderByConditionFields.length > 0) {
12022                                    query.append(WHERE_AND);
12023                            }
12024    
12025                            for (int i = 0; i < orderByConditionFields.length; i++) {
12026                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12027                                    query.append(orderByConditionFields[i]);
12028    
12029                                    if ((i + 1) < orderByConditionFields.length) {
12030                                            if (orderByComparator.isAscending() ^ previous) {
12031                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12032                                            }
12033                                            else {
12034                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12035                                            }
12036                                    }
12037                                    else {
12038                                            if (orderByComparator.isAscending() ^ previous) {
12039                                                    query.append(WHERE_GREATER_THAN);
12040                                            }
12041                                            else {
12042                                                    query.append(WHERE_LESSER_THAN);
12043                                            }
12044                                    }
12045                            }
12046    
12047                            query.append(ORDER_BY_CLAUSE);
12048    
12049                            String[] orderByFields = orderByComparator.getOrderByFields();
12050    
12051                            for (int i = 0; i < orderByFields.length; i++) {
12052                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12053                                    query.append(orderByFields[i]);
12054    
12055                                    if ((i + 1) < orderByFields.length) {
12056                                            if (orderByComparator.isAscending() ^ previous) {
12057                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12058                                            }
12059                                            else {
12060                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12061                                            }
12062                                    }
12063                                    else {
12064                                            if (orderByComparator.isAscending() ^ previous) {
12065                                                    query.append(ORDER_BY_ASC);
12066                                            }
12067                                            else {
12068                                                    query.append(ORDER_BY_DESC);
12069                                            }
12070                                    }
12071                            }
12072                    }
12073                    else {
12074                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12075                    }
12076    
12077                    String sql = query.toString();
12078    
12079                    Query q = session.createQuery(sql);
12080    
12081                    q.setFirstResult(0);
12082                    q.setMaxResults(2);
12083    
12084                    QueryPos qPos = QueryPos.getInstance(q);
12085    
12086                    qPos.add(groupId);
12087    
12088                    qPos.add(categoryId);
12089    
12090                    qPos.add(threadId);
12091    
12092                    if (orderByComparator != null) {
12093                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12094    
12095                            for (Object value : values) {
12096                                    qPos.add(value);
12097                            }
12098                    }
12099    
12100                    List<MBMessage> list = q.list();
12101    
12102                    if (list.size() == 2) {
12103                            return list.get(1);
12104                    }
12105                    else {
12106                            return null;
12107                    }
12108            }
12109    
12110            /**
12111             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12112             *
12113             * @param groupId the group ID
12114             * @param categoryId the category ID
12115             * @param threadId the thread ID
12116             * @return the matching message-boards messages that the user has permission to view
12117             * @throws SystemException if a system exception occurred
12118             */
12119            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12120                    long threadId) throws SystemException {
12121                    return filterFindByG_C_T(groupId, categoryId, threadId,
12122                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12123            }
12124    
12125            /**
12126             * 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;.
12127             *
12128             * <p>
12129             * 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.
12130             * </p>
12131             *
12132             * @param groupId the group ID
12133             * @param categoryId the category ID
12134             * @param threadId the thread ID
12135             * @param start the lower bound of the range of message-boards messages
12136             * @param end the upper bound of the range of message-boards messages (not inclusive)
12137             * @return the range of matching message-boards messages that the user has permission to view
12138             * @throws SystemException if a system exception occurred
12139             */
12140            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12141                    long threadId, int start, int end) throws SystemException {
12142                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12143            }
12144    
12145            /**
12146             * 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;.
12147             *
12148             * <p>
12149             * 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.
12150             * </p>
12151             *
12152             * @param groupId the group ID
12153             * @param categoryId the category ID
12154             * @param threadId the thread ID
12155             * @param start the lower bound of the range of message-boards messages
12156             * @param end the upper bound of the range of message-boards messages (not inclusive)
12157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12158             * @return the ordered range of matching message-boards messages that the user has permission to view
12159             * @throws SystemException if a system exception occurred
12160             */
12161            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12162                    long threadId, int start, int end, OrderByComparator orderByComparator)
12163                    throws SystemException {
12164                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12165                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12166                                    orderByComparator);
12167                    }
12168    
12169                    StringBundler query = null;
12170    
12171                    if (orderByComparator != null) {
12172                            query = new StringBundler(5 +
12173                                            (orderByComparator.getOrderByFields().length * 3));
12174                    }
12175                    else {
12176                            query = new StringBundler(5);
12177                    }
12178    
12179                    if (getDB().isSupportsInlineDistinct()) {
12180                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12181                    }
12182                    else {
12183                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12184                    }
12185    
12186                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12187    
12188                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12189    
12190                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12191    
12192                    if (!getDB().isSupportsInlineDistinct()) {
12193                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12194                    }
12195    
12196                    if (orderByComparator != null) {
12197                            if (getDB().isSupportsInlineDistinct()) {
12198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12199                                            orderByComparator);
12200                            }
12201                            else {
12202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12203                                            orderByComparator);
12204                            }
12205                    }
12206                    else {
12207                            if (getDB().isSupportsInlineDistinct()) {
12208                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12209                            }
12210                            else {
12211                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12212                            }
12213                    }
12214    
12215                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12216                                    MBMessage.class.getName(),
12217                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12218    
12219                    Session session = null;
12220    
12221                    try {
12222                            session = openSession();
12223    
12224                            SQLQuery q = session.createSQLQuery(sql);
12225    
12226                            if (getDB().isSupportsInlineDistinct()) {
12227                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12228                            }
12229                            else {
12230                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12231                            }
12232    
12233                            QueryPos qPos = QueryPos.getInstance(q);
12234    
12235                            qPos.add(groupId);
12236    
12237                            qPos.add(categoryId);
12238    
12239                            qPos.add(threadId);
12240    
12241                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12242                    }
12243                    catch (Exception e) {
12244                            throw processException(e);
12245                    }
12246                    finally {
12247                            closeSession(session);
12248                    }
12249            }
12250    
12251            /**
12252             * 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;.
12253             *
12254             * @param messageId the primary key of the current message-boards message
12255             * @param groupId the group ID
12256             * @param categoryId the category ID
12257             * @param threadId the thread ID
12258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12259             * @return the previous, current, and next message-boards message
12260             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12261             * @throws SystemException if a system exception occurred
12262             */
12263            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12264                    long groupId, long categoryId, long threadId,
12265                    OrderByComparator orderByComparator)
12266                    throws NoSuchMessageException, SystemException {
12267                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12268                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12269                                    threadId, orderByComparator);
12270                    }
12271    
12272                    MBMessage mbMessage = findByPrimaryKey(messageId);
12273    
12274                    Session session = null;
12275    
12276                    try {
12277                            session = openSession();
12278    
12279                            MBMessage[] array = new MBMessageImpl[3];
12280    
12281                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12282                                            groupId, categoryId, threadId, orderByComparator, true);
12283    
12284                            array[1] = mbMessage;
12285    
12286                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12287                                            groupId, categoryId, threadId, orderByComparator, false);
12288    
12289                            return array;
12290                    }
12291                    catch (Exception e) {
12292                            throw processException(e);
12293                    }
12294                    finally {
12295                            closeSession(session);
12296                    }
12297            }
12298    
12299            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12300                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12301                    OrderByComparator orderByComparator, boolean previous) {
12302                    StringBundler query = null;
12303    
12304                    if (orderByComparator != null) {
12305                            query = new StringBundler(6 +
12306                                            (orderByComparator.getOrderByFields().length * 6));
12307                    }
12308                    else {
12309                            query = new StringBundler(3);
12310                    }
12311    
12312                    if (getDB().isSupportsInlineDistinct()) {
12313                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12314                    }
12315                    else {
12316                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12317                    }
12318    
12319                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12320    
12321                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12322    
12323                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12324    
12325                    if (!getDB().isSupportsInlineDistinct()) {
12326                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12327                    }
12328    
12329                    if (orderByComparator != null) {
12330                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12331    
12332                            if (orderByConditionFields.length > 0) {
12333                                    query.append(WHERE_AND);
12334                            }
12335    
12336                            for (int i = 0; i < orderByConditionFields.length; i++) {
12337                                    if (getDB().isSupportsInlineDistinct()) {
12338                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12339                                    }
12340                                    else {
12341                                            query.append(_ORDER_BY_ENTITY_TABLE);
12342                                    }
12343    
12344                                    query.append(orderByConditionFields[i]);
12345    
12346                                    if ((i + 1) < orderByConditionFields.length) {
12347                                            if (orderByComparator.isAscending() ^ previous) {
12348                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12349                                            }
12350                                            else {
12351                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12352                                            }
12353                                    }
12354                                    else {
12355                                            if (orderByComparator.isAscending() ^ previous) {
12356                                                    query.append(WHERE_GREATER_THAN);
12357                                            }
12358                                            else {
12359                                                    query.append(WHERE_LESSER_THAN);
12360                                            }
12361                                    }
12362                            }
12363    
12364                            query.append(ORDER_BY_CLAUSE);
12365    
12366                            String[] orderByFields = orderByComparator.getOrderByFields();
12367    
12368                            for (int i = 0; i < orderByFields.length; i++) {
12369                                    if (getDB().isSupportsInlineDistinct()) {
12370                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12371                                    }
12372                                    else {
12373                                            query.append(_ORDER_BY_ENTITY_TABLE);
12374                                    }
12375    
12376                                    query.append(orderByFields[i]);
12377    
12378                                    if ((i + 1) < orderByFields.length) {
12379                                            if (orderByComparator.isAscending() ^ previous) {
12380                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12381                                            }
12382                                            else {
12383                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12384                                            }
12385                                    }
12386                                    else {
12387                                            if (orderByComparator.isAscending() ^ previous) {
12388                                                    query.append(ORDER_BY_ASC);
12389                                            }
12390                                            else {
12391                                                    query.append(ORDER_BY_DESC);
12392                                            }
12393                                    }
12394                            }
12395                    }
12396                    else {
12397                            if (getDB().isSupportsInlineDistinct()) {
12398                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12399                            }
12400                            else {
12401                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12402                            }
12403                    }
12404    
12405                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12406                                    MBMessage.class.getName(),
12407                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12408    
12409                    SQLQuery q = session.createSQLQuery(sql);
12410    
12411                    q.setFirstResult(0);
12412                    q.setMaxResults(2);
12413    
12414                    if (getDB().isSupportsInlineDistinct()) {
12415                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12416                    }
12417                    else {
12418                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12419                    }
12420    
12421                    QueryPos qPos = QueryPos.getInstance(q);
12422    
12423                    qPos.add(groupId);
12424    
12425                    qPos.add(categoryId);
12426    
12427                    qPos.add(threadId);
12428    
12429                    if (orderByComparator != null) {
12430                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12431    
12432                            for (Object value : values) {
12433                                    qPos.add(value);
12434                            }
12435                    }
12436    
12437                    List<MBMessage> list = q.list();
12438    
12439                    if (list.size() == 2) {
12440                            return list.get(1);
12441                    }
12442                    else {
12443                            return null;
12444                    }
12445            }
12446    
12447            /**
12448             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12449             *
12450             * @param groupId the group ID
12451             * @param categoryId the category ID
12452             * @param threadId the thread ID
12453             * @throws SystemException if a system exception occurred
12454             */
12455            public void removeByG_C_T(long groupId, long categoryId, long threadId)
12456                    throws SystemException {
12457                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12458                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12459                            remove(mbMessage);
12460                    }
12461            }
12462    
12463            /**
12464             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12465             *
12466             * @param groupId the group ID
12467             * @param categoryId the category ID
12468             * @param threadId the thread ID
12469             * @return the number of matching message-boards messages
12470             * @throws SystemException if a system exception occurred
12471             */
12472            public int countByG_C_T(long groupId, long categoryId, long threadId)
12473                    throws SystemException {
12474                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12475    
12476                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12477    
12478                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12479                                    this);
12480    
12481                    if (count == null) {
12482                            StringBundler query = new StringBundler(4);
12483    
12484                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12485    
12486                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12487    
12488                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12489    
12490                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12491    
12492                            String sql = query.toString();
12493    
12494                            Session session = null;
12495    
12496                            try {
12497                                    session = openSession();
12498    
12499                                    Query q = session.createQuery(sql);
12500    
12501                                    QueryPos qPos = QueryPos.getInstance(q);
12502    
12503                                    qPos.add(groupId);
12504    
12505                                    qPos.add(categoryId);
12506    
12507                                    qPos.add(threadId);
12508    
12509                                    count = (Long)q.uniqueResult();
12510    
12511                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12512                            }
12513                            catch (Exception e) {
12514                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12515    
12516                                    throw processException(e);
12517                            }
12518                            finally {
12519                                    closeSession(session);
12520                            }
12521                    }
12522    
12523                    return count.intValue();
12524            }
12525    
12526            /**
12527             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12528             *
12529             * @param groupId the group ID
12530             * @param categoryId the category ID
12531             * @param threadId the thread ID
12532             * @return the number of matching message-boards messages that the user has permission to view
12533             * @throws SystemException if a system exception occurred
12534             */
12535            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
12536                    throws SystemException {
12537                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12538                            return countByG_C_T(groupId, categoryId, threadId);
12539                    }
12540    
12541                    StringBundler query = new StringBundler(4);
12542    
12543                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12544    
12545                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12546    
12547                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12548    
12549                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12550    
12551                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12552                                    MBMessage.class.getName(),
12553                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12554    
12555                    Session session = null;
12556    
12557                    try {
12558                            session = openSession();
12559    
12560                            SQLQuery q = session.createSQLQuery(sql);
12561    
12562                            q.addScalar(COUNT_COLUMN_NAME,
12563                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12564    
12565                            QueryPos qPos = QueryPos.getInstance(q);
12566    
12567                            qPos.add(groupId);
12568    
12569                            qPos.add(categoryId);
12570    
12571                            qPos.add(threadId);
12572    
12573                            Long count = (Long)q.uniqueResult();
12574    
12575                            return count.intValue();
12576                    }
12577                    catch (Exception e) {
12578                            throw processException(e);
12579                    }
12580                    finally {
12581                            closeSession(session);
12582                    }
12583            }
12584    
12585            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12586            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12587            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12588            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12589                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12590                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12591                            new String[] {
12592                                    Long.class.getName(), Long.class.getName(),
12593                                    Integer.class.getName(),
12594                                    
12595                            Integer.class.getName(), Integer.class.getName(),
12596                                    OrderByComparator.class.getName()
12597                            });
12598            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12599                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12600                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12601                            new String[] {
12602                                    Long.class.getName(), Long.class.getName(),
12603                                    Integer.class.getName()
12604                            },
12605                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12606                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12607                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12608                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12609            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12610                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12612                            new String[] {
12613                                    Long.class.getName(), Long.class.getName(),
12614                                    Integer.class.getName()
12615                            });
12616    
12617            /**
12618             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12619             *
12620             * @param groupId the group ID
12621             * @param categoryId the category ID
12622             * @param status the status
12623             * @return the matching message-boards messages
12624             * @throws SystemException if a system exception occurred
12625             */
12626            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
12627                    throws SystemException {
12628                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12629                            QueryUtil.ALL_POS, null);
12630            }
12631    
12632            /**
12633             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12634             *
12635             * <p>
12636             * 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.
12637             * </p>
12638             *
12639             * @param groupId the group ID
12640             * @param categoryId the category ID
12641             * @param status the status
12642             * @param start the lower bound of the range of message-boards messages
12643             * @param end the upper bound of the range of message-boards messages (not inclusive)
12644             * @return the range of matching message-boards messages
12645             * @throws SystemException if a system exception occurred
12646             */
12647            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12648                    int status, int start, int end) throws SystemException {
12649                    return findByG_C_S(groupId, categoryId, status, start, end, null);
12650            }
12651    
12652            /**
12653             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12654             *
12655             * <p>
12656             * 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.
12657             * </p>
12658             *
12659             * @param groupId the group ID
12660             * @param categoryId the category ID
12661             * @param status the status
12662             * @param start the lower bound of the range of message-boards messages
12663             * @param end the upper bound of the range of message-boards messages (not inclusive)
12664             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12665             * @return the ordered range of matching message-boards messages
12666             * @throws SystemException if a system exception occurred
12667             */
12668            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12669                    int status, int start, int end, OrderByComparator orderByComparator)
12670                    throws SystemException {
12671                    boolean pagination = true;
12672                    FinderPath finderPath = null;
12673                    Object[] finderArgs = null;
12674    
12675                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12676                                    (orderByComparator == null)) {
12677                            pagination = false;
12678                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
12679                            finderArgs = new Object[] { groupId, categoryId, status };
12680                    }
12681                    else {
12682                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
12683                            finderArgs = new Object[] {
12684                                            groupId, categoryId, status,
12685                                            
12686                                            start, end, orderByComparator
12687                                    };
12688                    }
12689    
12690                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12691                                    finderArgs, this);
12692    
12693                    if ((list != null) && !list.isEmpty()) {
12694                            for (MBMessage mbMessage : list) {
12695                                    if ((groupId != mbMessage.getGroupId()) ||
12696                                                    (categoryId != mbMessage.getCategoryId()) ||
12697                                                    (status != mbMessage.getStatus())) {
12698                                            list = null;
12699    
12700                                            break;
12701                                    }
12702                            }
12703                    }
12704    
12705                    if (list == null) {
12706                            StringBundler query = null;
12707    
12708                            if (orderByComparator != null) {
12709                                    query = new StringBundler(5 +
12710                                                    (orderByComparator.getOrderByFields().length * 3));
12711                            }
12712                            else {
12713                                    query = new StringBundler(5);
12714                            }
12715    
12716                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12717    
12718                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12719    
12720                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12721    
12722                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12723    
12724                            if (orderByComparator != null) {
12725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12726                                            orderByComparator);
12727                            }
12728                            else
12729                             if (pagination) {
12730                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12731                            }
12732    
12733                            String sql = query.toString();
12734    
12735                            Session session = null;
12736    
12737                            try {
12738                                    session = openSession();
12739    
12740                                    Query q = session.createQuery(sql);
12741    
12742                                    QueryPos qPos = QueryPos.getInstance(q);
12743    
12744                                    qPos.add(groupId);
12745    
12746                                    qPos.add(categoryId);
12747    
12748                                    qPos.add(status);
12749    
12750                                    if (!pagination) {
12751                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12752                                                            start, end, false);
12753    
12754                                            Collections.sort(list);
12755    
12756                                            list = new UnmodifiableList<MBMessage>(list);
12757                                    }
12758                                    else {
12759                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12760                                                            start, end);
12761                                    }
12762    
12763                                    cacheResult(list);
12764    
12765                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12766                            }
12767                            catch (Exception e) {
12768                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12769    
12770                                    throw processException(e);
12771                            }
12772                            finally {
12773                                    closeSession(session);
12774                            }
12775                    }
12776    
12777                    return list;
12778            }
12779    
12780            /**
12781             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12782             *
12783             * @param groupId the group ID
12784             * @param categoryId the category ID
12785             * @param status the status
12786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12787             * @return the first matching message-boards message
12788             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12789             * @throws SystemException if a system exception occurred
12790             */
12791            public MBMessage findByG_C_S_First(long groupId, long categoryId,
12792                    int status, OrderByComparator orderByComparator)
12793                    throws NoSuchMessageException, SystemException {
12794                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
12795                                    orderByComparator);
12796    
12797                    if (mbMessage != null) {
12798                            return mbMessage;
12799                    }
12800    
12801                    StringBundler msg = new StringBundler(8);
12802    
12803                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12804    
12805                    msg.append("groupId=");
12806                    msg.append(groupId);
12807    
12808                    msg.append(", categoryId=");
12809                    msg.append(categoryId);
12810    
12811                    msg.append(", status=");
12812                    msg.append(status);
12813    
12814                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12815    
12816                    throw new NoSuchMessageException(msg.toString());
12817            }
12818    
12819            /**
12820             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12821             *
12822             * @param groupId the group ID
12823             * @param categoryId the category ID
12824             * @param status the status
12825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12826             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12827             * @throws SystemException if a system exception occurred
12828             */
12829            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
12830                    int status, OrderByComparator orderByComparator)
12831                    throws SystemException {
12832                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
12833                                    orderByComparator);
12834    
12835                    if (!list.isEmpty()) {
12836                            return list.get(0);
12837                    }
12838    
12839                    return null;
12840            }
12841    
12842            /**
12843             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12844             *
12845             * @param groupId the group ID
12846             * @param categoryId the category ID
12847             * @param status the status
12848             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12849             * @return the last matching message-boards message
12850             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12851             * @throws SystemException if a system exception occurred
12852             */
12853            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
12854                    int status, OrderByComparator orderByComparator)
12855                    throws NoSuchMessageException, SystemException {
12856                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
12857                                    orderByComparator);
12858    
12859                    if (mbMessage != null) {
12860                            return mbMessage;
12861                    }
12862    
12863                    StringBundler msg = new StringBundler(8);
12864    
12865                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12866    
12867                    msg.append("groupId=");
12868                    msg.append(groupId);
12869    
12870                    msg.append(", categoryId=");
12871                    msg.append(categoryId);
12872    
12873                    msg.append(", status=");
12874                    msg.append(status);
12875    
12876                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12877    
12878                    throw new NoSuchMessageException(msg.toString());
12879            }
12880    
12881            /**
12882             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12883             *
12884             * @param groupId the group ID
12885             * @param categoryId the category ID
12886             * @param status the status
12887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12888             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12889             * @throws SystemException if a system exception occurred
12890             */
12891            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
12892                    int status, OrderByComparator orderByComparator)
12893                    throws SystemException {
12894                    int count = countByG_C_S(groupId, categoryId, status);
12895    
12896                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
12897                                    count - 1, count, orderByComparator);
12898    
12899                    if (!list.isEmpty()) {
12900                            return list.get(0);
12901                    }
12902    
12903                    return null;
12904            }
12905    
12906            /**
12907             * 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;.
12908             *
12909             * @param messageId the primary key of the current message-boards message
12910             * @param groupId the group ID
12911             * @param categoryId the category ID
12912             * @param status the status
12913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12914             * @return the previous, current, and next message-boards message
12915             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12916             * @throws SystemException if a system exception occurred
12917             */
12918            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
12919                    long categoryId, int status, OrderByComparator orderByComparator)
12920                    throws NoSuchMessageException, SystemException {
12921                    MBMessage mbMessage = findByPrimaryKey(messageId);
12922    
12923                    Session session = null;
12924    
12925                    try {
12926                            session = openSession();
12927    
12928                            MBMessage[] array = new MBMessageImpl[3];
12929    
12930                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12931                                            categoryId, status, orderByComparator, true);
12932    
12933                            array[1] = mbMessage;
12934    
12935                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12936                                            categoryId, status, orderByComparator, false);
12937    
12938                            return array;
12939                    }
12940                    catch (Exception e) {
12941                            throw processException(e);
12942                    }
12943                    finally {
12944                            closeSession(session);
12945                    }
12946            }
12947    
12948            protected MBMessage getByG_C_S_PrevAndNext(Session session,
12949                    MBMessage mbMessage, long groupId, long categoryId, int status,
12950                    OrderByComparator orderByComparator, boolean previous) {
12951                    StringBundler query = null;
12952    
12953                    if (orderByComparator != null) {
12954                            query = new StringBundler(6 +
12955                                            (orderByComparator.getOrderByFields().length * 6));
12956                    }
12957                    else {
12958                            query = new StringBundler(3);
12959                    }
12960    
12961                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12962    
12963                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12964    
12965                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12966    
12967                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12968    
12969                    if (orderByComparator != null) {
12970                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12971    
12972                            if (orderByConditionFields.length > 0) {
12973                                    query.append(WHERE_AND);
12974                            }
12975    
12976                            for (int i = 0; i < orderByConditionFields.length; i++) {
12977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12978                                    query.append(orderByConditionFields[i]);
12979    
12980                                    if ((i + 1) < orderByConditionFields.length) {
12981                                            if (orderByComparator.isAscending() ^ previous) {
12982                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12983                                            }
12984                                            else {
12985                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12986                                            }
12987                                    }
12988                                    else {
12989                                            if (orderByComparator.isAscending() ^ previous) {
12990                                                    query.append(WHERE_GREATER_THAN);
12991                                            }
12992                                            else {
12993                                                    query.append(WHERE_LESSER_THAN);
12994                                            }
12995                                    }
12996                            }
12997    
12998                            query.append(ORDER_BY_CLAUSE);
12999    
13000                            String[] orderByFields = orderByComparator.getOrderByFields();
13001    
13002                            for (int i = 0; i < orderByFields.length; i++) {
13003                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13004                                    query.append(orderByFields[i]);
13005    
13006                                    if ((i + 1) < orderByFields.length) {
13007                                            if (orderByComparator.isAscending() ^ previous) {
13008                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13009                                            }
13010                                            else {
13011                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13012                                            }
13013                                    }
13014                                    else {
13015                                            if (orderByComparator.isAscending() ^ previous) {
13016                                                    query.append(ORDER_BY_ASC);
13017                                            }
13018                                            else {
13019                                                    query.append(ORDER_BY_DESC);
13020                                            }
13021                                    }
13022                            }
13023                    }
13024                    else {
13025                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13026                    }
13027    
13028                    String sql = query.toString();
13029    
13030                    Query q = session.createQuery(sql);
13031    
13032                    q.setFirstResult(0);
13033                    q.setMaxResults(2);
13034    
13035                    QueryPos qPos = QueryPos.getInstance(q);
13036    
13037                    qPos.add(groupId);
13038    
13039                    qPos.add(categoryId);
13040    
13041                    qPos.add(status);
13042    
13043                    if (orderByComparator != null) {
13044                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13045    
13046                            for (Object value : values) {
13047                                    qPos.add(value);
13048                            }
13049                    }
13050    
13051                    List<MBMessage> list = q.list();
13052    
13053                    if (list.size() == 2) {
13054                            return list.get(1);
13055                    }
13056                    else {
13057                            return null;
13058                    }
13059            }
13060    
13061            /**
13062             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13063             *
13064             * @param groupId the group ID
13065             * @param categoryId the category ID
13066             * @param status the status
13067             * @return the matching message-boards messages that the user has permission to view
13068             * @throws SystemException if a system exception occurred
13069             */
13070            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13071                    int status) throws SystemException {
13072                    return filterFindByG_C_S(groupId, categoryId, status,
13073                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13074            }
13075    
13076            /**
13077             * 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;.
13078             *
13079             * <p>
13080             * 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.
13081             * </p>
13082             *
13083             * @param groupId the group ID
13084             * @param categoryId the category ID
13085             * @param status the status
13086             * @param start the lower bound of the range of message-boards messages
13087             * @param end the upper bound of the range of message-boards messages (not inclusive)
13088             * @return the range of matching message-boards messages that the user has permission to view
13089             * @throws SystemException if a system exception occurred
13090             */
13091            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13092                    int status, int start, int end) throws SystemException {
13093                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13094            }
13095    
13096            /**
13097             * 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;.
13098             *
13099             * <p>
13100             * 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.
13101             * </p>
13102             *
13103             * @param groupId the group ID
13104             * @param categoryId the category ID
13105             * @param status the status
13106             * @param start the lower bound of the range of message-boards messages
13107             * @param end the upper bound of the range of message-boards messages (not inclusive)
13108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13109             * @return the ordered range of matching message-boards messages that the user has permission to view
13110             * @throws SystemException if a system exception occurred
13111             */
13112            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13113                    int status, int start, int end, OrderByComparator orderByComparator)
13114                    throws SystemException {
13115                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13116                            return findByG_C_S(groupId, categoryId, status, start, end,
13117                                    orderByComparator);
13118                    }
13119    
13120                    StringBundler query = null;
13121    
13122                    if (orderByComparator != null) {
13123                            query = new StringBundler(5 +
13124                                            (orderByComparator.getOrderByFields().length * 3));
13125                    }
13126                    else {
13127                            query = new StringBundler(5);
13128                    }
13129    
13130                    if (getDB().isSupportsInlineDistinct()) {
13131                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13132                    }
13133                    else {
13134                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13135                    }
13136    
13137                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13138    
13139                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13140    
13141                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13142    
13143                    if (!getDB().isSupportsInlineDistinct()) {
13144                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13145                    }
13146    
13147                    if (orderByComparator != null) {
13148                            if (getDB().isSupportsInlineDistinct()) {
13149                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13150                                            orderByComparator);
13151                            }
13152                            else {
13153                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13154                                            orderByComparator);
13155                            }
13156                    }
13157                    else {
13158                            if (getDB().isSupportsInlineDistinct()) {
13159                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13160                            }
13161                            else {
13162                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13163                            }
13164                    }
13165    
13166                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13167                                    MBMessage.class.getName(),
13168                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13169    
13170                    Session session = null;
13171    
13172                    try {
13173                            session = openSession();
13174    
13175                            SQLQuery q = session.createSQLQuery(sql);
13176    
13177                            if (getDB().isSupportsInlineDistinct()) {
13178                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13179                            }
13180                            else {
13181                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13182                            }
13183    
13184                            QueryPos qPos = QueryPos.getInstance(q);
13185    
13186                            qPos.add(groupId);
13187    
13188                            qPos.add(categoryId);
13189    
13190                            qPos.add(status);
13191    
13192                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13193                    }
13194                    catch (Exception e) {
13195                            throw processException(e);
13196                    }
13197                    finally {
13198                            closeSession(session);
13199                    }
13200            }
13201    
13202            /**
13203             * 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;.
13204             *
13205             * @param messageId the primary key of the current message-boards message
13206             * @param groupId the group ID
13207             * @param categoryId the category ID
13208             * @param status the status
13209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13210             * @return the previous, current, and next message-boards message
13211             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13212             * @throws SystemException if a system exception occurred
13213             */
13214            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13215                    long groupId, long categoryId, int status,
13216                    OrderByComparator orderByComparator)
13217                    throws NoSuchMessageException, SystemException {
13218                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13219                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13220                                    status, orderByComparator);
13221                    }
13222    
13223                    MBMessage mbMessage = findByPrimaryKey(messageId);
13224    
13225                    Session session = null;
13226    
13227                    try {
13228                            session = openSession();
13229    
13230                            MBMessage[] array = new MBMessageImpl[3];
13231    
13232                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13233                                            groupId, categoryId, status, orderByComparator, true);
13234    
13235                            array[1] = mbMessage;
13236    
13237                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13238                                            groupId, categoryId, status, orderByComparator, false);
13239    
13240                            return array;
13241                    }
13242                    catch (Exception e) {
13243                            throw processException(e);
13244                    }
13245                    finally {
13246                            closeSession(session);
13247                    }
13248            }
13249    
13250            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13251                    MBMessage mbMessage, long groupId, long categoryId, int status,
13252                    OrderByComparator orderByComparator, boolean previous) {
13253                    StringBundler query = null;
13254    
13255                    if (orderByComparator != null) {
13256                            query = new StringBundler(6 +
13257                                            (orderByComparator.getOrderByFields().length * 6));
13258                    }
13259                    else {
13260                            query = new StringBundler(3);
13261                    }
13262    
13263                    if (getDB().isSupportsInlineDistinct()) {
13264                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13265                    }
13266                    else {
13267                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13268                    }
13269    
13270                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13271    
13272                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13273    
13274                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13275    
13276                    if (!getDB().isSupportsInlineDistinct()) {
13277                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13278                    }
13279    
13280                    if (orderByComparator != null) {
13281                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13282    
13283                            if (orderByConditionFields.length > 0) {
13284                                    query.append(WHERE_AND);
13285                            }
13286    
13287                            for (int i = 0; i < orderByConditionFields.length; i++) {
13288                                    if (getDB().isSupportsInlineDistinct()) {
13289                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13290                                    }
13291                                    else {
13292                                            query.append(_ORDER_BY_ENTITY_TABLE);
13293                                    }
13294    
13295                                    query.append(orderByConditionFields[i]);
13296    
13297                                    if ((i + 1) < orderByConditionFields.length) {
13298                                            if (orderByComparator.isAscending() ^ previous) {
13299                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13300                                            }
13301                                            else {
13302                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13303                                            }
13304                                    }
13305                                    else {
13306                                            if (orderByComparator.isAscending() ^ previous) {
13307                                                    query.append(WHERE_GREATER_THAN);
13308                                            }
13309                                            else {
13310                                                    query.append(WHERE_LESSER_THAN);
13311                                            }
13312                                    }
13313                            }
13314    
13315                            query.append(ORDER_BY_CLAUSE);
13316    
13317                            String[] orderByFields = orderByComparator.getOrderByFields();
13318    
13319                            for (int i = 0; i < orderByFields.length; i++) {
13320                                    if (getDB().isSupportsInlineDistinct()) {
13321                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13322                                    }
13323                                    else {
13324                                            query.append(_ORDER_BY_ENTITY_TABLE);
13325                                    }
13326    
13327                                    query.append(orderByFields[i]);
13328    
13329                                    if ((i + 1) < orderByFields.length) {
13330                                            if (orderByComparator.isAscending() ^ previous) {
13331                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13332                                            }
13333                                            else {
13334                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13335                                            }
13336                                    }
13337                                    else {
13338                                            if (orderByComparator.isAscending() ^ previous) {
13339                                                    query.append(ORDER_BY_ASC);
13340                                            }
13341                                            else {
13342                                                    query.append(ORDER_BY_DESC);
13343                                            }
13344                                    }
13345                            }
13346                    }
13347                    else {
13348                            if (getDB().isSupportsInlineDistinct()) {
13349                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13350                            }
13351                            else {
13352                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13353                            }
13354                    }
13355    
13356                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13357                                    MBMessage.class.getName(),
13358                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13359    
13360                    SQLQuery q = session.createSQLQuery(sql);
13361    
13362                    q.setFirstResult(0);
13363                    q.setMaxResults(2);
13364    
13365                    if (getDB().isSupportsInlineDistinct()) {
13366                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13367                    }
13368                    else {
13369                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13370                    }
13371    
13372                    QueryPos qPos = QueryPos.getInstance(q);
13373    
13374                    qPos.add(groupId);
13375    
13376                    qPos.add(categoryId);
13377    
13378                    qPos.add(status);
13379    
13380                    if (orderByComparator != null) {
13381                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13382    
13383                            for (Object value : values) {
13384                                    qPos.add(value);
13385                            }
13386                    }
13387    
13388                    List<MBMessage> list = q.list();
13389    
13390                    if (list.size() == 2) {
13391                            return list.get(1);
13392                    }
13393                    else {
13394                            return null;
13395                    }
13396            }
13397    
13398            /**
13399             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13400             *
13401             * @param groupId the group ID
13402             * @param categoryId the category ID
13403             * @param status the status
13404             * @throws SystemException if a system exception occurred
13405             */
13406            public void removeByG_C_S(long groupId, long categoryId, int status)
13407                    throws SystemException {
13408                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13409                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13410                            remove(mbMessage);
13411                    }
13412            }
13413    
13414            /**
13415             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13416             *
13417             * @param groupId the group ID
13418             * @param categoryId the category ID
13419             * @param status the status
13420             * @return the number of matching message-boards messages
13421             * @throws SystemException if a system exception occurred
13422             */
13423            public int countByG_C_S(long groupId, long categoryId, int status)
13424                    throws SystemException {
13425                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13426    
13427                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13428    
13429                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13430                                    this);
13431    
13432                    if (count == null) {
13433                            StringBundler query = new StringBundler(4);
13434    
13435                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13436    
13437                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13438    
13439                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13440    
13441                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13442    
13443                            String sql = query.toString();
13444    
13445                            Session session = null;
13446    
13447                            try {
13448                                    session = openSession();
13449    
13450                                    Query q = session.createQuery(sql);
13451    
13452                                    QueryPos qPos = QueryPos.getInstance(q);
13453    
13454                                    qPos.add(groupId);
13455    
13456                                    qPos.add(categoryId);
13457    
13458                                    qPos.add(status);
13459    
13460                                    count = (Long)q.uniqueResult();
13461    
13462                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13463                            }
13464                            catch (Exception e) {
13465                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13466    
13467                                    throw processException(e);
13468                            }
13469                            finally {
13470                                    closeSession(session);
13471                            }
13472                    }
13473    
13474                    return count.intValue();
13475            }
13476    
13477            /**
13478             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13479             *
13480             * @param groupId the group ID
13481             * @param categoryId the category ID
13482             * @param status the status
13483             * @return the number of matching message-boards messages that the user has permission to view
13484             * @throws SystemException if a system exception occurred
13485             */
13486            public int filterCountByG_C_S(long groupId, long categoryId, int status)
13487                    throws SystemException {
13488                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13489                            return countByG_C_S(groupId, categoryId, status);
13490                    }
13491    
13492                    StringBundler query = new StringBundler(4);
13493    
13494                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13495    
13496                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13497    
13498                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13499    
13500                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13501    
13502                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13503                                    MBMessage.class.getName(),
13504                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13505    
13506                    Session session = null;
13507    
13508                    try {
13509                            session = openSession();
13510    
13511                            SQLQuery q = session.createSQLQuery(sql);
13512    
13513                            q.addScalar(COUNT_COLUMN_NAME,
13514                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13515    
13516                            QueryPos qPos = QueryPos.getInstance(q);
13517    
13518                            qPos.add(groupId);
13519    
13520                            qPos.add(categoryId);
13521    
13522                            qPos.add(status);
13523    
13524                            Long count = (Long)q.uniqueResult();
13525    
13526                            return count.intValue();
13527                    }
13528                    catch (Exception e) {
13529                            throw processException(e);
13530                    }
13531                    finally {
13532                            closeSession(session);
13533                    }
13534            }
13535    
13536            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13537            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13538            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13539            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13540                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13541                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13542                            new String[] {
13543                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13544                                    
13545                            Integer.class.getName(), Integer.class.getName(),
13546                                    OrderByComparator.class.getName()
13547                            });
13548            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13549                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13550                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13551                            new String[] {
13552                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13553                            },
13554                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
13555                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13556                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13557                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13558            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13559                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13560                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13561                            new String[] {
13562                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13563                            });
13564    
13565            /**
13566             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13567             *
13568             * @param userId the user ID
13569             * @param classNameId the class name ID
13570             * @param classPK the class p k
13571             * @return the matching message-boards messages
13572             * @throws SystemException if a system exception occurred
13573             */
13574            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13575                    long classPK) throws SystemException {
13576                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13577                            QueryUtil.ALL_POS, null);
13578            }
13579    
13580            /**
13581             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13582             *
13583             * <p>
13584             * 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.
13585             * </p>
13586             *
13587             * @param userId the user ID
13588             * @param classNameId the class name ID
13589             * @param classPK the class p k
13590             * @param start the lower bound of the range of message-boards messages
13591             * @param end the upper bound of the range of message-boards messages (not inclusive)
13592             * @return the range of matching message-boards messages
13593             * @throws SystemException if a system exception occurred
13594             */
13595            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13596                    long classPK, int start, int end) throws SystemException {
13597                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
13598            }
13599    
13600            /**
13601             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13602             *
13603             * <p>
13604             * 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.
13605             * </p>
13606             *
13607             * @param userId the user ID
13608             * @param classNameId the class name ID
13609             * @param classPK the class p k
13610             * @param start the lower bound of the range of message-boards messages
13611             * @param end the upper bound of the range of message-boards messages (not inclusive)
13612             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13613             * @return the ordered range of matching message-boards messages
13614             * @throws SystemException if a system exception occurred
13615             */
13616            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13617                    long classPK, int start, int end, OrderByComparator orderByComparator)
13618                    throws SystemException {
13619                    boolean pagination = true;
13620                    FinderPath finderPath = null;
13621                    Object[] finderArgs = null;
13622    
13623                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13624                                    (orderByComparator == null)) {
13625                            pagination = false;
13626                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13627                            finderArgs = new Object[] { userId, classNameId, classPK };
13628                    }
13629                    else {
13630                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13631                            finderArgs = new Object[] {
13632                                            userId, classNameId, classPK,
13633                                            
13634                                            start, end, orderByComparator
13635                                    };
13636                    }
13637    
13638                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13639                                    finderArgs, this);
13640    
13641                    if ((list != null) && !list.isEmpty()) {
13642                            for (MBMessage mbMessage : list) {
13643                                    if ((userId != mbMessage.getUserId()) ||
13644                                                    (classNameId != mbMessage.getClassNameId()) ||
13645                                                    (classPK != mbMessage.getClassPK())) {
13646                                            list = null;
13647    
13648                                            break;
13649                                    }
13650                            }
13651                    }
13652    
13653                    if (list == null) {
13654                            StringBundler query = null;
13655    
13656                            if (orderByComparator != null) {
13657                                    query = new StringBundler(5 +
13658                                                    (orderByComparator.getOrderByFields().length * 3));
13659                            }
13660                            else {
13661                                    query = new StringBundler(5);
13662                            }
13663    
13664                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13665    
13666                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13667    
13668                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13669    
13670                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13671    
13672                            if (orderByComparator != null) {
13673                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13674                                            orderByComparator);
13675                            }
13676                            else
13677                             if (pagination) {
13678                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13679                            }
13680    
13681                            String sql = query.toString();
13682    
13683                            Session session = null;
13684    
13685                            try {
13686                                    session = openSession();
13687    
13688                                    Query q = session.createQuery(sql);
13689    
13690                                    QueryPos qPos = QueryPos.getInstance(q);
13691    
13692                                    qPos.add(userId);
13693    
13694                                    qPos.add(classNameId);
13695    
13696                                    qPos.add(classPK);
13697    
13698                                    if (!pagination) {
13699                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13700                                                            start, end, false);
13701    
13702                                            Collections.sort(list);
13703    
13704                                            list = new UnmodifiableList<MBMessage>(list);
13705                                    }
13706                                    else {
13707                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13708                                                            start, end);
13709                                    }
13710    
13711                                    cacheResult(list);
13712    
13713                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13714                            }
13715                            catch (Exception e) {
13716                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13717    
13718                                    throw processException(e);
13719                            }
13720                            finally {
13721                                    closeSession(session);
13722                            }
13723                    }
13724    
13725                    return list;
13726            }
13727    
13728            /**
13729             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13730             *
13731             * @param userId the user ID
13732             * @param classNameId the class name ID
13733             * @param classPK the class p k
13734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13735             * @return the first matching message-boards message
13736             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13737             * @throws SystemException if a system exception occurred
13738             */
13739            public MBMessage findByU_C_C_First(long userId, long classNameId,
13740                    long classPK, OrderByComparator orderByComparator)
13741                    throws NoSuchMessageException, SystemException {
13742                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
13743                                    orderByComparator);
13744    
13745                    if (mbMessage != null) {
13746                            return mbMessage;
13747                    }
13748    
13749                    StringBundler msg = new StringBundler(8);
13750    
13751                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13752    
13753                    msg.append("userId=");
13754                    msg.append(userId);
13755    
13756                    msg.append(", classNameId=");
13757                    msg.append(classNameId);
13758    
13759                    msg.append(", classPK=");
13760                    msg.append(classPK);
13761    
13762                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13763    
13764                    throw new NoSuchMessageException(msg.toString());
13765            }
13766    
13767            /**
13768             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13769             *
13770             * @param userId the user ID
13771             * @param classNameId the class name ID
13772             * @param classPK the class p k
13773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13774             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13775             * @throws SystemException if a system exception occurred
13776             */
13777            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
13778                    long classPK, OrderByComparator orderByComparator)
13779                    throws SystemException {
13780                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
13781                                    orderByComparator);
13782    
13783                    if (!list.isEmpty()) {
13784                            return list.get(0);
13785                    }
13786    
13787                    return null;
13788            }
13789    
13790            /**
13791             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13792             *
13793             * @param userId the user ID
13794             * @param classNameId the class name ID
13795             * @param classPK the class p k
13796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13797             * @return the last matching message-boards message
13798             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13799             * @throws SystemException if a system exception occurred
13800             */
13801            public MBMessage findByU_C_C_Last(long userId, long classNameId,
13802                    long classPK, OrderByComparator orderByComparator)
13803                    throws NoSuchMessageException, SystemException {
13804                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
13805                                    orderByComparator);
13806    
13807                    if (mbMessage != null) {
13808                            return mbMessage;
13809                    }
13810    
13811                    StringBundler msg = new StringBundler(8);
13812    
13813                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13814    
13815                    msg.append("userId=");
13816                    msg.append(userId);
13817    
13818                    msg.append(", classNameId=");
13819                    msg.append(classNameId);
13820    
13821                    msg.append(", classPK=");
13822                    msg.append(classPK);
13823    
13824                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13825    
13826                    throw new NoSuchMessageException(msg.toString());
13827            }
13828    
13829            /**
13830             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13831             *
13832             * @param userId the user ID
13833             * @param classNameId the class name ID
13834             * @param classPK the class p k
13835             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13836             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13837             * @throws SystemException if a system exception occurred
13838             */
13839            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
13840                    long classPK, OrderByComparator orderByComparator)
13841                    throws SystemException {
13842                    int count = countByU_C_C(userId, classNameId, classPK);
13843    
13844                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
13845                                    count - 1, count, orderByComparator);
13846    
13847                    if (!list.isEmpty()) {
13848                            return list.get(0);
13849                    }
13850    
13851                    return null;
13852            }
13853    
13854            /**
13855             * 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;.
13856             *
13857             * @param messageId the primary key of the current message-boards message
13858             * @param userId the user ID
13859             * @param classNameId the class name ID
13860             * @param classPK the class p k
13861             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13862             * @return the previous, current, and next message-boards message
13863             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13864             * @throws SystemException if a system exception occurred
13865             */
13866            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
13867                    long classNameId, long classPK, OrderByComparator orderByComparator)
13868                    throws NoSuchMessageException, SystemException {
13869                    MBMessage mbMessage = findByPrimaryKey(messageId);
13870    
13871                    Session session = null;
13872    
13873                    try {
13874                            session = openSession();
13875    
13876                            MBMessage[] array = new MBMessageImpl[3];
13877    
13878                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13879                                            classNameId, classPK, orderByComparator, true);
13880    
13881                            array[1] = mbMessage;
13882    
13883                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13884                                            classNameId, classPK, orderByComparator, false);
13885    
13886                            return array;
13887                    }
13888                    catch (Exception e) {
13889                            throw processException(e);
13890                    }
13891                    finally {
13892                            closeSession(session);
13893                    }
13894            }
13895    
13896            protected MBMessage getByU_C_C_PrevAndNext(Session session,
13897                    MBMessage mbMessage, long userId, long classNameId, long classPK,
13898                    OrderByComparator orderByComparator, boolean previous) {
13899                    StringBundler query = null;
13900    
13901                    if (orderByComparator != null) {
13902                            query = new StringBundler(6 +
13903                                            (orderByComparator.getOrderByFields().length * 6));
13904                    }
13905                    else {
13906                            query = new StringBundler(3);
13907                    }
13908    
13909                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13910    
13911                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13912    
13913                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13914    
13915                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13916    
13917                    if (orderByComparator != null) {
13918                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13919    
13920                            if (orderByConditionFields.length > 0) {
13921                                    query.append(WHERE_AND);
13922                            }
13923    
13924                            for (int i = 0; i < orderByConditionFields.length; i++) {
13925                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13926                                    query.append(orderByConditionFields[i]);
13927    
13928                                    if ((i + 1) < orderByConditionFields.length) {
13929                                            if (orderByComparator.isAscending() ^ previous) {
13930                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13931                                            }
13932                                            else {
13933                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13934                                            }
13935                                    }
13936                                    else {
13937                                            if (orderByComparator.isAscending() ^ previous) {
13938                                                    query.append(WHERE_GREATER_THAN);
13939                                            }
13940                                            else {
13941                                                    query.append(WHERE_LESSER_THAN);
13942                                            }
13943                                    }
13944                            }
13945    
13946                            query.append(ORDER_BY_CLAUSE);
13947    
13948                            String[] orderByFields = orderByComparator.getOrderByFields();
13949    
13950                            for (int i = 0; i < orderByFields.length; i++) {
13951                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13952                                    query.append(orderByFields[i]);
13953    
13954                                    if ((i + 1) < orderByFields.length) {
13955                                            if (orderByComparator.isAscending() ^ previous) {
13956                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13957                                            }
13958                                            else {
13959                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13960                                            }
13961                                    }
13962                                    else {
13963                                            if (orderByComparator.isAscending() ^ previous) {
13964                                                    query.append(ORDER_BY_ASC);
13965                                            }
13966                                            else {
13967                                                    query.append(ORDER_BY_DESC);
13968                                            }
13969                                    }
13970                            }
13971                    }
13972                    else {
13973                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13974                    }
13975    
13976                    String sql = query.toString();
13977    
13978                    Query q = session.createQuery(sql);
13979    
13980                    q.setFirstResult(0);
13981                    q.setMaxResults(2);
13982    
13983                    QueryPos qPos = QueryPos.getInstance(q);
13984    
13985                    qPos.add(userId);
13986    
13987                    qPos.add(classNameId);
13988    
13989                    qPos.add(classPK);
13990    
13991                    if (orderByComparator != null) {
13992                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13993    
13994                            for (Object value : values) {
13995                                    qPos.add(value);
13996                            }
13997                    }
13998    
13999                    List<MBMessage> list = q.list();
14000    
14001                    if (list.size() == 2) {
14002                            return list.get(1);
14003                    }
14004                    else {
14005                            return null;
14006                    }
14007            }
14008    
14009            /**
14010             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14011             *
14012             * @param userId the user ID
14013             * @param classNameId the class name ID
14014             * @param classPK the class p k
14015             * @throws SystemException if a system exception occurred
14016             */
14017            public void removeByU_C_C(long userId, long classNameId, long classPK)
14018                    throws SystemException {
14019                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14020                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14021                            remove(mbMessage);
14022                    }
14023            }
14024    
14025            /**
14026             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14027             *
14028             * @param userId the user ID
14029             * @param classNameId the class name ID
14030             * @param classPK the class p k
14031             * @return the number of matching message-boards messages
14032             * @throws SystemException if a system exception occurred
14033             */
14034            public int countByU_C_C(long userId, long classNameId, long classPK)
14035                    throws SystemException {
14036                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14037    
14038                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14039    
14040                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14041                                    this);
14042    
14043                    if (count == null) {
14044                            StringBundler query = new StringBundler(4);
14045    
14046                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14047    
14048                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14049    
14050                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14051    
14052                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14053    
14054                            String sql = query.toString();
14055    
14056                            Session session = null;
14057    
14058                            try {
14059                                    session = openSession();
14060    
14061                                    Query q = session.createQuery(sql);
14062    
14063                                    QueryPos qPos = QueryPos.getInstance(q);
14064    
14065                                    qPos.add(userId);
14066    
14067                                    qPos.add(classNameId);
14068    
14069                                    qPos.add(classPK);
14070    
14071                                    count = (Long)q.uniqueResult();
14072    
14073                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14074                            }
14075                            catch (Exception e) {
14076                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14077    
14078                                    throw processException(e);
14079                            }
14080                            finally {
14081                                    closeSession(session);
14082                            }
14083                    }
14084    
14085                    return count.intValue();
14086            }
14087    
14088            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14089            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14090            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14092                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14094                            new String[] {
14095                                    Long.class.getName(), Long.class.getName(),
14096                                    Integer.class.getName(),
14097                                    
14098                            Integer.class.getName(), Integer.class.getName(),
14099                                    OrderByComparator.class.getName()
14100                            });
14101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14104                            new String[] {
14105                                    Long.class.getName(), Long.class.getName(),
14106                                    Integer.class.getName()
14107                            },
14108                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14109                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14110                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14111                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14112            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14113                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14115                            new String[] {
14116                                    Long.class.getName(), Long.class.getName(),
14117                                    Integer.class.getName()
14118                            });
14119            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14120                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14121                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14122                            new String[] {
14123                                    Long.class.getName(), Long.class.getName(),
14124                                    Integer.class.getName()
14125                            });
14126    
14127            /**
14128             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14129             *
14130             * @param userId the user ID
14131             * @param classNameId the class name ID
14132             * @param status the status
14133             * @return the matching message-boards messages
14134             * @throws SystemException if a system exception occurred
14135             */
14136            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
14137                    throws SystemException {
14138                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14139                            QueryUtil.ALL_POS, null);
14140            }
14141    
14142            /**
14143             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14144             *
14145             * <p>
14146             * 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.
14147             * </p>
14148             *
14149             * @param userId the user ID
14150             * @param classNameId the class name ID
14151             * @param status the status
14152             * @param start the lower bound of the range of message-boards messages
14153             * @param end the upper bound of the range of message-boards messages (not inclusive)
14154             * @return the range of matching message-boards messages
14155             * @throws SystemException if a system exception occurred
14156             */
14157            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14158                    int status, int start, int end) throws SystemException {
14159                    return findByU_C_S(userId, classNameId, status, start, end, null);
14160            }
14161    
14162            /**
14163             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14164             *
14165             * <p>
14166             * 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.
14167             * </p>
14168             *
14169             * @param userId the user ID
14170             * @param classNameId the class name ID
14171             * @param status the status
14172             * @param start the lower bound of the range of message-boards messages
14173             * @param end the upper bound of the range of message-boards messages (not inclusive)
14174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14175             * @return the ordered range of matching message-boards messages
14176             * @throws SystemException if a system exception occurred
14177             */
14178            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14179                    int status, int start, int end, OrderByComparator orderByComparator)
14180                    throws SystemException {
14181                    boolean pagination = true;
14182                    FinderPath finderPath = null;
14183                    Object[] finderArgs = null;
14184    
14185                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14186                                    (orderByComparator == null)) {
14187                            pagination = false;
14188                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14189                            finderArgs = new Object[] { userId, classNameId, status };
14190                    }
14191                    else {
14192                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14193                            finderArgs = new Object[] {
14194                                            userId, classNameId, status,
14195                                            
14196                                            start, end, orderByComparator
14197                                    };
14198                    }
14199    
14200                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14201                                    finderArgs, this);
14202    
14203                    if ((list != null) && !list.isEmpty()) {
14204                            for (MBMessage mbMessage : list) {
14205                                    if ((userId != mbMessage.getUserId()) ||
14206                                                    (classNameId != mbMessage.getClassNameId()) ||
14207                                                    (status != mbMessage.getStatus())) {
14208                                            list = null;
14209    
14210                                            break;
14211                                    }
14212                            }
14213                    }
14214    
14215                    if (list == null) {
14216                            StringBundler query = null;
14217    
14218                            if (orderByComparator != null) {
14219                                    query = new StringBundler(5 +
14220                                                    (orderByComparator.getOrderByFields().length * 3));
14221                            }
14222                            else {
14223                                    query = new StringBundler(5);
14224                            }
14225    
14226                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14227    
14228                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14229    
14230                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14231    
14232                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14233    
14234                            if (orderByComparator != null) {
14235                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14236                                            orderByComparator);
14237                            }
14238                            else
14239                             if (pagination) {
14240                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14241                            }
14242    
14243                            String sql = query.toString();
14244    
14245                            Session session = null;
14246    
14247                            try {
14248                                    session = openSession();
14249    
14250                                    Query q = session.createQuery(sql);
14251    
14252                                    QueryPos qPos = QueryPos.getInstance(q);
14253    
14254                                    qPos.add(userId);
14255    
14256                                    qPos.add(classNameId);
14257    
14258                                    qPos.add(status);
14259    
14260                                    if (!pagination) {
14261                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14262                                                            start, end, false);
14263    
14264                                            Collections.sort(list);
14265    
14266                                            list = new UnmodifiableList<MBMessage>(list);
14267                                    }
14268                                    else {
14269                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14270                                                            start, end);
14271                                    }
14272    
14273                                    cacheResult(list);
14274    
14275                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14276                            }
14277                            catch (Exception e) {
14278                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14279    
14280                                    throw processException(e);
14281                            }
14282                            finally {
14283                                    closeSession(session);
14284                            }
14285                    }
14286    
14287                    return list;
14288            }
14289    
14290            /**
14291             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14292             *
14293             * @param userId the user ID
14294             * @param classNameId the class name ID
14295             * @param status the status
14296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14297             * @return the first matching message-boards message
14298             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14299             * @throws SystemException if a system exception occurred
14300             */
14301            public MBMessage findByU_C_S_First(long userId, long classNameId,
14302                    int status, OrderByComparator orderByComparator)
14303                    throws NoSuchMessageException, SystemException {
14304                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14305                                    orderByComparator);
14306    
14307                    if (mbMessage != null) {
14308                            return mbMessage;
14309                    }
14310    
14311                    StringBundler msg = new StringBundler(8);
14312    
14313                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14314    
14315                    msg.append("userId=");
14316                    msg.append(userId);
14317    
14318                    msg.append(", classNameId=");
14319                    msg.append(classNameId);
14320    
14321                    msg.append(", status=");
14322                    msg.append(status);
14323    
14324                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14325    
14326                    throw new NoSuchMessageException(msg.toString());
14327            }
14328    
14329            /**
14330             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14331             *
14332             * @param userId the user ID
14333             * @param classNameId the class name ID
14334             * @param status the status
14335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14336             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14337             * @throws SystemException if a system exception occurred
14338             */
14339            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14340                    int status, OrderByComparator orderByComparator)
14341                    throws SystemException {
14342                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14343                                    orderByComparator);
14344    
14345                    if (!list.isEmpty()) {
14346                            return list.get(0);
14347                    }
14348    
14349                    return null;
14350            }
14351    
14352            /**
14353             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14354             *
14355             * @param userId the user ID
14356             * @param classNameId the class name ID
14357             * @param status the status
14358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14359             * @return the last matching message-boards message
14360             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14361             * @throws SystemException if a system exception occurred
14362             */
14363            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14364                    int status, OrderByComparator orderByComparator)
14365                    throws NoSuchMessageException, SystemException {
14366                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14367                                    orderByComparator);
14368    
14369                    if (mbMessage != null) {
14370                            return mbMessage;
14371                    }
14372    
14373                    StringBundler msg = new StringBundler(8);
14374    
14375                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14376    
14377                    msg.append("userId=");
14378                    msg.append(userId);
14379    
14380                    msg.append(", classNameId=");
14381                    msg.append(classNameId);
14382    
14383                    msg.append(", status=");
14384                    msg.append(status);
14385    
14386                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14387    
14388                    throw new NoSuchMessageException(msg.toString());
14389            }
14390    
14391            /**
14392             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14393             *
14394             * @param userId the user ID
14395             * @param classNameId the class name ID
14396             * @param status the status
14397             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14398             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14399             * @throws SystemException if a system exception occurred
14400             */
14401            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14402                    int status, OrderByComparator orderByComparator)
14403                    throws SystemException {
14404                    int count = countByU_C_S(userId, classNameId, status);
14405    
14406                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14407                                    count - 1, count, orderByComparator);
14408    
14409                    if (!list.isEmpty()) {
14410                            return list.get(0);
14411                    }
14412    
14413                    return null;
14414            }
14415    
14416            /**
14417             * 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;.
14418             *
14419             * @param messageId the primary key of the current message-boards message
14420             * @param userId the user ID
14421             * @param classNameId the class name ID
14422             * @param status the status
14423             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14424             * @return the previous, current, and next message-boards message
14425             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14426             * @throws SystemException if a system exception occurred
14427             */
14428            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14429                    long classNameId, int status, OrderByComparator orderByComparator)
14430                    throws NoSuchMessageException, SystemException {
14431                    MBMessage mbMessage = findByPrimaryKey(messageId);
14432    
14433                    Session session = null;
14434    
14435                    try {
14436                            session = openSession();
14437    
14438                            MBMessage[] array = new MBMessageImpl[3];
14439    
14440                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14441                                            classNameId, status, orderByComparator, true);
14442    
14443                            array[1] = mbMessage;
14444    
14445                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14446                                            classNameId, status, orderByComparator, false);
14447    
14448                            return array;
14449                    }
14450                    catch (Exception e) {
14451                            throw processException(e);
14452                    }
14453                    finally {
14454                            closeSession(session);
14455                    }
14456            }
14457    
14458            protected MBMessage getByU_C_S_PrevAndNext(Session session,
14459                    MBMessage mbMessage, long userId, long classNameId, int status,
14460                    OrderByComparator orderByComparator, boolean previous) {
14461                    StringBundler query = null;
14462    
14463                    if (orderByComparator != null) {
14464                            query = new StringBundler(6 +
14465                                            (orderByComparator.getOrderByFields().length * 6));
14466                    }
14467                    else {
14468                            query = new StringBundler(3);
14469                    }
14470    
14471                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14472    
14473                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14474    
14475                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14476    
14477                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14478    
14479                    if (orderByComparator != null) {
14480                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14481    
14482                            if (orderByConditionFields.length > 0) {
14483                                    query.append(WHERE_AND);
14484                            }
14485    
14486                            for (int i = 0; i < orderByConditionFields.length; i++) {
14487                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14488                                    query.append(orderByConditionFields[i]);
14489    
14490                                    if ((i + 1) < orderByConditionFields.length) {
14491                                            if (orderByComparator.isAscending() ^ previous) {
14492                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14493                                            }
14494                                            else {
14495                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14496                                            }
14497                                    }
14498                                    else {
14499                                            if (orderByComparator.isAscending() ^ previous) {
14500                                                    query.append(WHERE_GREATER_THAN);
14501                                            }
14502                                            else {
14503                                                    query.append(WHERE_LESSER_THAN);
14504                                            }
14505                                    }
14506                            }
14507    
14508                            query.append(ORDER_BY_CLAUSE);
14509    
14510                            String[] orderByFields = orderByComparator.getOrderByFields();
14511    
14512                            for (int i = 0; i < orderByFields.length; i++) {
14513                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14514                                    query.append(orderByFields[i]);
14515    
14516                                    if ((i + 1) < orderByFields.length) {
14517                                            if (orderByComparator.isAscending() ^ previous) {
14518                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14519                                            }
14520                                            else {
14521                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14522                                            }
14523                                    }
14524                                    else {
14525                                            if (orderByComparator.isAscending() ^ previous) {
14526                                                    query.append(ORDER_BY_ASC);
14527                                            }
14528                                            else {
14529                                                    query.append(ORDER_BY_DESC);
14530                                            }
14531                                    }
14532                            }
14533                    }
14534                    else {
14535                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14536                    }
14537    
14538                    String sql = query.toString();
14539    
14540                    Query q = session.createQuery(sql);
14541    
14542                    q.setFirstResult(0);
14543                    q.setMaxResults(2);
14544    
14545                    QueryPos qPos = QueryPos.getInstance(q);
14546    
14547                    qPos.add(userId);
14548    
14549                    qPos.add(classNameId);
14550    
14551                    qPos.add(status);
14552    
14553                    if (orderByComparator != null) {
14554                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14555    
14556                            for (Object value : values) {
14557                                    qPos.add(value);
14558                            }
14559                    }
14560    
14561                    List<MBMessage> list = q.list();
14562    
14563                    if (list.size() == 2) {
14564                            return list.get(1);
14565                    }
14566                    else {
14567                            return null;
14568                    }
14569            }
14570    
14571            /**
14572             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14573             *
14574             * <p>
14575             * 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.
14576             * </p>
14577             *
14578             * @param userId the user ID
14579             * @param classNameIds the class name IDs
14580             * @param status the status
14581             * @return the matching message-boards messages
14582             * @throws SystemException if a system exception occurred
14583             */
14584            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14585                    int status) throws SystemException {
14586                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14587                            QueryUtil.ALL_POS, null);
14588            }
14589    
14590            /**
14591             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14592             *
14593             * <p>
14594             * 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.
14595             * </p>
14596             *
14597             * @param userId the user ID
14598             * @param classNameIds the class name IDs
14599             * @param status the status
14600             * @param start the lower bound of the range of message-boards messages
14601             * @param end the upper bound of the range of message-boards messages (not inclusive)
14602             * @return the range of matching message-boards messages
14603             * @throws SystemException if a system exception occurred
14604             */
14605            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14606                    int status, int start, int end) throws SystemException {
14607                    return findByU_C_S(userId, classNameIds, status, start, end, null);
14608            }
14609    
14610            /**
14611             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14612             *
14613             * <p>
14614             * 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.
14615             * </p>
14616             *
14617             * @param userId the user ID
14618             * @param classNameIds the class name IDs
14619             * @param status the status
14620             * @param start the lower bound of the range of message-boards messages
14621             * @param end the upper bound of the range of message-boards messages (not inclusive)
14622             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14623             * @return the ordered range of matching message-boards messages
14624             * @throws SystemException if a system exception occurred
14625             */
14626            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14627                    int status, int start, int end, OrderByComparator orderByComparator)
14628                    throws SystemException {
14629                    if ((classNameIds != null) && (classNameIds.length == 1)) {
14630                            return findByU_C_S(userId, classNameIds[0], status, start, end,
14631                                    orderByComparator);
14632                    }
14633    
14634                    boolean pagination = true;
14635                    Object[] finderArgs = null;
14636    
14637                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14638                                    (orderByComparator == null)) {
14639                            pagination = false;
14640                            finderArgs = new Object[] {
14641                                            userId, StringUtil.merge(classNameIds), status
14642                                    };
14643                    }
14644                    else {
14645                            finderArgs = new Object[] {
14646                                            userId, StringUtil.merge(classNameIds), status,
14647                                            
14648                                            start, end, orderByComparator
14649                                    };
14650                    }
14651    
14652                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14653                                    finderArgs, this);
14654    
14655                    if ((list != null) && !list.isEmpty()) {
14656                            for (MBMessage mbMessage : list) {
14657                                    if ((userId != mbMessage.getUserId()) ||
14658                                                    !ArrayUtil.contains(classNameIds,
14659                                                            mbMessage.getClassNameId()) ||
14660                                                    (status != mbMessage.getStatus())) {
14661                                            list = null;
14662    
14663                                            break;
14664                                    }
14665                            }
14666                    }
14667    
14668                    if (list == null) {
14669                            StringBundler query = new StringBundler();
14670    
14671                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14672    
14673                            boolean conjunctionable = false;
14674    
14675                            if (conjunctionable) {
14676                                    query.append(WHERE_AND);
14677                            }
14678    
14679                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14680    
14681                            conjunctionable = true;
14682    
14683                            if ((classNameIds == null) || (classNameIds.length > 0)) {
14684                                    if (conjunctionable) {
14685                                            query.append(WHERE_AND);
14686                                    }
14687    
14688                                    query.append(StringPool.OPEN_PARENTHESIS);
14689    
14690                                    for (int i = 0; i < classNameIds.length; i++) {
14691                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14692    
14693                                            if ((i + 1) < classNameIds.length) {
14694                                                    query.append(WHERE_OR);
14695                                            }
14696                                    }
14697    
14698                                    query.append(StringPool.CLOSE_PARENTHESIS);
14699    
14700                                    conjunctionable = true;
14701                            }
14702    
14703                            if (conjunctionable) {
14704                                    query.append(WHERE_AND);
14705                            }
14706    
14707                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14708    
14709                            conjunctionable = true;
14710    
14711                            if (orderByComparator != null) {
14712                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14713                                            orderByComparator);
14714                            }
14715                            else
14716                             if (pagination) {
14717                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14718                            }
14719    
14720                            String sql = query.toString();
14721    
14722                            Session session = null;
14723    
14724                            try {
14725                                    session = openSession();
14726    
14727                                    Query q = session.createQuery(sql);
14728    
14729                                    QueryPos qPos = QueryPos.getInstance(q);
14730    
14731                                    qPos.add(userId);
14732    
14733                                    if (classNameIds != null) {
14734                                            qPos.add(classNameIds);
14735                                    }
14736    
14737                                    qPos.add(status);
14738    
14739                                    if (!pagination) {
14740                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14741                                                            start, end, false);
14742    
14743                                            Collections.sort(list);
14744    
14745                                            list = new UnmodifiableList<MBMessage>(list);
14746                                    }
14747                                    else {
14748                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14749                                                            start, end);
14750                                    }
14751    
14752                                    cacheResult(list);
14753    
14754                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14755                                            finderArgs, list);
14756                            }
14757                            catch (Exception e) {
14758                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14759                                            finderArgs);
14760    
14761                                    throw processException(e);
14762                            }
14763                            finally {
14764                                    closeSession(session);
14765                            }
14766                    }
14767    
14768                    return list;
14769            }
14770    
14771            /**
14772             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
14773             *
14774             * @param userId the user ID
14775             * @param classNameId the class name ID
14776             * @param status the status
14777             * @throws SystemException if a system exception occurred
14778             */
14779            public void removeByU_C_S(long userId, long classNameId, int status)
14780                    throws SystemException {
14781                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
14782                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14783                            remove(mbMessage);
14784                    }
14785            }
14786    
14787            /**
14788             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14789             *
14790             * @param userId the user ID
14791             * @param classNameId the class name ID
14792             * @param status the status
14793             * @return the number of matching message-boards messages
14794             * @throws SystemException if a system exception occurred
14795             */
14796            public int countByU_C_S(long userId, long classNameId, int status)
14797                    throws SystemException {
14798                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
14799    
14800                    Object[] finderArgs = new Object[] { userId, classNameId, status };
14801    
14802                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14803                                    this);
14804    
14805                    if (count == null) {
14806                            StringBundler query = new StringBundler(4);
14807    
14808                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14809    
14810                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14811    
14812                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14813    
14814                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14815    
14816                            String sql = query.toString();
14817    
14818                            Session session = null;
14819    
14820                            try {
14821                                    session = openSession();
14822    
14823                                    Query q = session.createQuery(sql);
14824    
14825                                    QueryPos qPos = QueryPos.getInstance(q);
14826    
14827                                    qPos.add(userId);
14828    
14829                                    qPos.add(classNameId);
14830    
14831                                    qPos.add(status);
14832    
14833                                    count = (Long)q.uniqueResult();
14834    
14835                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14836                            }
14837                            catch (Exception e) {
14838                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14839    
14840                                    throw processException(e);
14841                            }
14842                            finally {
14843                                    closeSession(session);
14844                            }
14845                    }
14846    
14847                    return count.intValue();
14848            }
14849    
14850            /**
14851             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14852             *
14853             * @param userId the user ID
14854             * @param classNameIds the class name IDs
14855             * @param status the status
14856             * @return the number of matching message-boards messages
14857             * @throws SystemException if a system exception occurred
14858             */
14859            public int countByU_C_S(long userId, long[] classNameIds, int status)
14860                    throws SystemException {
14861                    Object[] finderArgs = new Object[] {
14862                                    userId, StringUtil.merge(classNameIds), status
14863                            };
14864    
14865                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14866                                    finderArgs, this);
14867    
14868                    if (count == null) {
14869                            StringBundler query = new StringBundler();
14870    
14871                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14872    
14873                            boolean conjunctionable = false;
14874    
14875                            if (conjunctionable) {
14876                                    query.append(WHERE_AND);
14877                            }
14878    
14879                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14880    
14881                            conjunctionable = true;
14882    
14883                            if ((classNameIds == null) || (classNameIds.length > 0)) {
14884                                    if (conjunctionable) {
14885                                            query.append(WHERE_AND);
14886                                    }
14887    
14888                                    query.append(StringPool.OPEN_PARENTHESIS);
14889    
14890                                    for (int i = 0; i < classNameIds.length; i++) {
14891                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14892    
14893                                            if ((i + 1) < classNameIds.length) {
14894                                                    query.append(WHERE_OR);
14895                                            }
14896                                    }
14897    
14898                                    query.append(StringPool.CLOSE_PARENTHESIS);
14899    
14900                                    conjunctionable = true;
14901                            }
14902    
14903                            if (conjunctionable) {
14904                                    query.append(WHERE_AND);
14905                            }
14906    
14907                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14908    
14909                            conjunctionable = true;
14910    
14911                            String sql = query.toString();
14912    
14913                            Session session = null;
14914    
14915                            try {
14916                                    session = openSession();
14917    
14918                                    Query q = session.createQuery(sql);
14919    
14920                                    QueryPos qPos = QueryPos.getInstance(q);
14921    
14922                                    qPos.add(userId);
14923    
14924                                    if (classNameIds != null) {
14925                                            qPos.add(classNameIds);
14926                                    }
14927    
14928                                    qPos.add(status);
14929    
14930                                    count = (Long)q.uniqueResult();
14931    
14932                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14933                                            finderArgs, count);
14934                            }
14935                            catch (Exception e) {
14936                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14937                                            finderArgs);
14938    
14939                                    throw processException(e);
14940                            }
14941                            finally {
14942                                    closeSession(session);
14943                            }
14944                    }
14945    
14946                    return count.intValue();
14947            }
14948    
14949            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
14950            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
14951                    _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
14952            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14953            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
14954                    _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
14955            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
14956            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
14957                    _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
14958            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14959                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14960                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
14961                            new String[] {
14962                                    Long.class.getName(), Long.class.getName(),
14963                                    Integer.class.getName(),
14964                                    
14965                            Integer.class.getName(), Integer.class.getName(),
14966                                    OrderByComparator.class.getName()
14967                            });
14968            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14969                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14970                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
14971                            new String[] {
14972                                    Long.class.getName(), Long.class.getName(),
14973                                    Integer.class.getName()
14974                            },
14975                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14976                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14977                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14978                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14979            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14980                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14981                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
14982                            new String[] {
14983                                    Long.class.getName(), Long.class.getName(),
14984                                    Integer.class.getName()
14985                            });
14986    
14987            /**
14988             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
14989             *
14990             * @param classNameId the class name ID
14991             * @param classPK the class p k
14992             * @param status the status
14993             * @return the matching message-boards messages
14994             * @throws SystemException if a system exception occurred
14995             */
14996            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
14997                    int status) throws SystemException {
14998                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
14999                            QueryUtil.ALL_POS, null);
15000            }
15001    
15002            /**
15003             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15004             *
15005             * <p>
15006             * 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.
15007             * </p>
15008             *
15009             * @param classNameId the class name ID
15010             * @param classPK the class p k
15011             * @param status the status
15012             * @param start the lower bound of the range of message-boards messages
15013             * @param end the upper bound of the range of message-boards messages (not inclusive)
15014             * @return the range of matching message-boards messages
15015             * @throws SystemException if a system exception occurred
15016             */
15017            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15018                    int status, int start, int end) throws SystemException {
15019                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15020            }
15021    
15022            /**
15023             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15024             *
15025             * <p>
15026             * 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.
15027             * </p>
15028             *
15029             * @param classNameId the class name ID
15030             * @param classPK the class p k
15031             * @param status the status
15032             * @param start the lower bound of the range of message-boards messages
15033             * @param end the upper bound of the range of message-boards messages (not inclusive)
15034             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15035             * @return the ordered range of matching message-boards messages
15036             * @throws SystemException if a system exception occurred
15037             */
15038            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15039                    int status, int start, int end, OrderByComparator orderByComparator)
15040                    throws SystemException {
15041                    boolean pagination = true;
15042                    FinderPath finderPath = null;
15043                    Object[] finderArgs = null;
15044    
15045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15046                                    (orderByComparator == null)) {
15047                            pagination = false;
15048                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15049                            finderArgs = new Object[] { classNameId, classPK, status };
15050                    }
15051                    else {
15052                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15053                            finderArgs = new Object[] {
15054                                            classNameId, classPK, status,
15055                                            
15056                                            start, end, orderByComparator
15057                                    };
15058                    }
15059    
15060                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15061                                    finderArgs, this);
15062    
15063                    if ((list != null) && !list.isEmpty()) {
15064                            for (MBMessage mbMessage : list) {
15065                                    if ((classNameId != mbMessage.getClassNameId()) ||
15066                                                    (classPK != mbMessage.getClassPK()) ||
15067                                                    (status != mbMessage.getStatus())) {
15068                                            list = null;
15069    
15070                                            break;
15071                                    }
15072                            }
15073                    }
15074    
15075                    if (list == null) {
15076                            StringBundler query = null;
15077    
15078                            if (orderByComparator != null) {
15079                                    query = new StringBundler(5 +
15080                                                    (orderByComparator.getOrderByFields().length * 3));
15081                            }
15082                            else {
15083                                    query = new StringBundler(5);
15084                            }
15085    
15086                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15087    
15088                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15089    
15090                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15091    
15092                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15093    
15094                            if (orderByComparator != null) {
15095                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15096                                            orderByComparator);
15097                            }
15098                            else
15099                             if (pagination) {
15100                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15101                            }
15102    
15103                            String sql = query.toString();
15104    
15105                            Session session = null;
15106    
15107                            try {
15108                                    session = openSession();
15109    
15110                                    Query q = session.createQuery(sql);
15111    
15112                                    QueryPos qPos = QueryPos.getInstance(q);
15113    
15114                                    qPos.add(classNameId);
15115    
15116                                    qPos.add(classPK);
15117    
15118                                    qPos.add(status);
15119    
15120                                    if (!pagination) {
15121                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15122                                                            start, end, false);
15123    
15124                                            Collections.sort(list);
15125    
15126                                            list = new UnmodifiableList<MBMessage>(list);
15127                                    }
15128                                    else {
15129                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15130                                                            start, end);
15131                                    }
15132    
15133                                    cacheResult(list);
15134    
15135                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15136                            }
15137                            catch (Exception e) {
15138                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15139    
15140                                    throw processException(e);
15141                            }
15142                            finally {
15143                                    closeSession(session);
15144                            }
15145                    }
15146    
15147                    return list;
15148            }
15149    
15150            /**
15151             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15152             *
15153             * @param classNameId the class name ID
15154             * @param classPK the class p k
15155             * @param status the status
15156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15157             * @return the first matching message-boards message
15158             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15159             * @throws SystemException if a system exception occurred
15160             */
15161            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15162                    int status, OrderByComparator orderByComparator)
15163                    throws NoSuchMessageException, SystemException {
15164                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15165                                    orderByComparator);
15166    
15167                    if (mbMessage != null) {
15168                            return mbMessage;
15169                    }
15170    
15171                    StringBundler msg = new StringBundler(8);
15172    
15173                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15174    
15175                    msg.append("classNameId=");
15176                    msg.append(classNameId);
15177    
15178                    msg.append(", classPK=");
15179                    msg.append(classPK);
15180    
15181                    msg.append(", status=");
15182                    msg.append(status);
15183    
15184                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15185    
15186                    throw new NoSuchMessageException(msg.toString());
15187            }
15188    
15189            /**
15190             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15191             *
15192             * @param classNameId the class name ID
15193             * @param classPK the class p k
15194             * @param status the status
15195             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15196             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15197             * @throws SystemException if a system exception occurred
15198             */
15199            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15200                    int status, OrderByComparator orderByComparator)
15201                    throws SystemException {
15202                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15203                                    orderByComparator);
15204    
15205                    if (!list.isEmpty()) {
15206                            return list.get(0);
15207                    }
15208    
15209                    return null;
15210            }
15211    
15212            /**
15213             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15214             *
15215             * @param classNameId the class name ID
15216             * @param classPK the class p k
15217             * @param status the status
15218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15219             * @return the last matching message-boards message
15220             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15221             * @throws SystemException if a system exception occurred
15222             */
15223            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15224                    int status, OrderByComparator orderByComparator)
15225                    throws NoSuchMessageException, SystemException {
15226                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15227                                    orderByComparator);
15228    
15229                    if (mbMessage != null) {
15230                            return mbMessage;
15231                    }
15232    
15233                    StringBundler msg = new StringBundler(8);
15234    
15235                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15236    
15237                    msg.append("classNameId=");
15238                    msg.append(classNameId);
15239    
15240                    msg.append(", classPK=");
15241                    msg.append(classPK);
15242    
15243                    msg.append(", status=");
15244                    msg.append(status);
15245    
15246                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15247    
15248                    throw new NoSuchMessageException(msg.toString());
15249            }
15250    
15251            /**
15252             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15253             *
15254             * @param classNameId the class name ID
15255             * @param classPK the class p k
15256             * @param status the status
15257             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15258             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15259             * @throws SystemException if a system exception occurred
15260             */
15261            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15262                    int status, OrderByComparator orderByComparator)
15263                    throws SystemException {
15264                    int count = countByC_C_S(classNameId, classPK, status);
15265    
15266                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15267                                    count - 1, count, orderByComparator);
15268    
15269                    if (!list.isEmpty()) {
15270                            return list.get(0);
15271                    }
15272    
15273                    return null;
15274            }
15275    
15276            /**
15277             * 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;.
15278             *
15279             * @param messageId the primary key of the current message-boards message
15280             * @param classNameId the class name ID
15281             * @param classPK the class p k
15282             * @param status the status
15283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15284             * @return the previous, current, and next message-boards message
15285             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15286             * @throws SystemException if a system exception occurred
15287             */
15288            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15289                    long classNameId, long classPK, int status,
15290                    OrderByComparator orderByComparator)
15291                    throws NoSuchMessageException, SystemException {
15292                    MBMessage mbMessage = findByPrimaryKey(messageId);
15293    
15294                    Session session = null;
15295    
15296                    try {
15297                            session = openSession();
15298    
15299                            MBMessage[] array = new MBMessageImpl[3];
15300    
15301                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15302                                            classPK, status, orderByComparator, true);
15303    
15304                            array[1] = mbMessage;
15305    
15306                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15307                                            classPK, status, orderByComparator, false);
15308    
15309                            return array;
15310                    }
15311                    catch (Exception e) {
15312                            throw processException(e);
15313                    }
15314                    finally {
15315                            closeSession(session);
15316                    }
15317            }
15318    
15319            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15320                    MBMessage mbMessage, long classNameId, long classPK, int status,
15321                    OrderByComparator orderByComparator, boolean previous) {
15322                    StringBundler query = null;
15323    
15324                    if (orderByComparator != null) {
15325                            query = new StringBundler(6 +
15326                                            (orderByComparator.getOrderByFields().length * 6));
15327                    }
15328                    else {
15329                            query = new StringBundler(3);
15330                    }
15331    
15332                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15333    
15334                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15335    
15336                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15337    
15338                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15339    
15340                    if (orderByComparator != null) {
15341                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15342    
15343                            if (orderByConditionFields.length > 0) {
15344                                    query.append(WHERE_AND);
15345                            }
15346    
15347                            for (int i = 0; i < orderByConditionFields.length; i++) {
15348                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15349                                    query.append(orderByConditionFields[i]);
15350    
15351                                    if ((i + 1) < orderByConditionFields.length) {
15352                                            if (orderByComparator.isAscending() ^ previous) {
15353                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15354                                            }
15355                                            else {
15356                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15357                                            }
15358                                    }
15359                                    else {
15360                                            if (orderByComparator.isAscending() ^ previous) {
15361                                                    query.append(WHERE_GREATER_THAN);
15362                                            }
15363                                            else {
15364                                                    query.append(WHERE_LESSER_THAN);
15365                                            }
15366                                    }
15367                            }
15368    
15369                            query.append(ORDER_BY_CLAUSE);
15370    
15371                            String[] orderByFields = orderByComparator.getOrderByFields();
15372    
15373                            for (int i = 0; i < orderByFields.length; i++) {
15374                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15375                                    query.append(orderByFields[i]);
15376    
15377                                    if ((i + 1) < orderByFields.length) {
15378                                            if (orderByComparator.isAscending() ^ previous) {
15379                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15380                                            }
15381                                            else {
15382                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15383                                            }
15384                                    }
15385                                    else {
15386                                            if (orderByComparator.isAscending() ^ previous) {
15387                                                    query.append(ORDER_BY_ASC);
15388                                            }
15389                                            else {
15390                                                    query.append(ORDER_BY_DESC);
15391                                            }
15392                                    }
15393                            }
15394                    }
15395                    else {
15396                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15397                    }
15398    
15399                    String sql = query.toString();
15400    
15401                    Query q = session.createQuery(sql);
15402    
15403                    q.setFirstResult(0);
15404                    q.setMaxResults(2);
15405    
15406                    QueryPos qPos = QueryPos.getInstance(q);
15407    
15408                    qPos.add(classNameId);
15409    
15410                    qPos.add(classPK);
15411    
15412                    qPos.add(status);
15413    
15414                    if (orderByComparator != null) {
15415                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15416    
15417                            for (Object value : values) {
15418                                    qPos.add(value);
15419                            }
15420                    }
15421    
15422                    List<MBMessage> list = q.list();
15423    
15424                    if (list.size() == 2) {
15425                            return list.get(1);
15426                    }
15427                    else {
15428                            return null;
15429                    }
15430            }
15431    
15432            /**
15433             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15434             *
15435             * @param classNameId the class name ID
15436             * @param classPK the class p k
15437             * @param status the status
15438             * @throws SystemException if a system exception occurred
15439             */
15440            public void removeByC_C_S(long classNameId, long classPK, int status)
15441                    throws SystemException {
15442                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15443                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15444                            remove(mbMessage);
15445                    }
15446            }
15447    
15448            /**
15449             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15450             *
15451             * @param classNameId the class name ID
15452             * @param classPK the class p k
15453             * @param status the status
15454             * @return the number of matching message-boards messages
15455             * @throws SystemException if a system exception occurred
15456             */
15457            public int countByC_C_S(long classNameId, long classPK, int status)
15458                    throws SystemException {
15459                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15460    
15461                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
15462    
15463                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15464                                    this);
15465    
15466                    if (count == null) {
15467                            StringBundler query = new StringBundler(4);
15468    
15469                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15470    
15471                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15472    
15473                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15474    
15475                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15476    
15477                            String sql = query.toString();
15478    
15479                            Session session = null;
15480    
15481                            try {
15482                                    session = openSession();
15483    
15484                                    Query q = session.createQuery(sql);
15485    
15486                                    QueryPos qPos = QueryPos.getInstance(q);
15487    
15488                                    qPos.add(classNameId);
15489    
15490                                    qPos.add(classPK);
15491    
15492                                    qPos.add(status);
15493    
15494                                    count = (Long)q.uniqueResult();
15495    
15496                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15497                            }
15498                            catch (Exception e) {
15499                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15500    
15501                                    throw processException(e);
15502                            }
15503                            finally {
15504                                    closeSession(session);
15505                            }
15506                    }
15507    
15508                    return count.intValue();
15509            }
15510    
15511            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15512            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15513            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15514            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15515                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15516                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
15517                            new String[] {
15518                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15519                                    Boolean.class.getName(),
15520                                    
15521                            Integer.class.getName(), Integer.class.getName(),
15522                                    OrderByComparator.class.getName()
15523                            });
15524            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
15525                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15526                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15527                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
15528                            new String[] {
15529                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15530                                    Boolean.class.getName()
15531                            },
15532                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15533                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15534                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
15535                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
15536                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15537            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15538                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15539                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
15540                            new String[] {
15541                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15542                                    Boolean.class.getName()
15543                            });
15544    
15545            /**
15546             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15547             *
15548             * @param groupId the group ID
15549             * @param categoryId the category ID
15550             * @param threadId the thread ID
15551             * @param answer the answer
15552             * @return the matching message-boards messages
15553             * @throws SystemException if a system exception occurred
15554             */
15555            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15556                    long threadId, boolean answer) throws SystemException {
15557                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
15558                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15559            }
15560    
15561            /**
15562             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15563             *
15564             * <p>
15565             * 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.
15566             * </p>
15567             *
15568             * @param groupId the group ID
15569             * @param categoryId the category ID
15570             * @param threadId the thread ID
15571             * @param answer the answer
15572             * @param start the lower bound of the range of message-boards messages
15573             * @param end the upper bound of the range of message-boards messages (not inclusive)
15574             * @return the range of matching message-boards messages
15575             * @throws SystemException if a system exception occurred
15576             */
15577            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15578                    long threadId, boolean answer, int start, int end)
15579                    throws SystemException {
15580                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
15581                            null);
15582            }
15583    
15584            /**
15585             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15586             *
15587             * <p>
15588             * 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.
15589             * </p>
15590             *
15591             * @param groupId the group ID
15592             * @param categoryId the category ID
15593             * @param threadId the thread ID
15594             * @param answer the answer
15595             * @param start the lower bound of the range of message-boards messages
15596             * @param end the upper bound of the range of message-boards messages (not inclusive)
15597             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15598             * @return the ordered range of matching message-boards messages
15599             * @throws SystemException if a system exception occurred
15600             */
15601            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15602                    long threadId, boolean answer, int start, int end,
15603                    OrderByComparator orderByComparator) throws SystemException {
15604                    boolean pagination = true;
15605                    FinderPath finderPath = null;
15606                    Object[] finderArgs = null;
15607    
15608                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15609                                    (orderByComparator == null)) {
15610                            pagination = false;
15611                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
15612                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
15613                    }
15614                    else {
15615                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
15616                            finderArgs = new Object[] {
15617                                            groupId, categoryId, threadId, answer,
15618                                            
15619                                            start, end, orderByComparator
15620                                    };
15621                    }
15622    
15623                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15624                                    finderArgs, this);
15625    
15626                    if ((list != null) && !list.isEmpty()) {
15627                            for (MBMessage mbMessage : list) {
15628                                    if ((groupId != mbMessage.getGroupId()) ||
15629                                                    (categoryId != mbMessage.getCategoryId()) ||
15630                                                    (threadId != mbMessage.getThreadId()) ||
15631                                                    (answer != mbMessage.getAnswer())) {
15632                                            list = null;
15633    
15634                                            break;
15635                                    }
15636                            }
15637                    }
15638    
15639                    if (list == null) {
15640                            StringBundler query = null;
15641    
15642                            if (orderByComparator != null) {
15643                                    query = new StringBundler(6 +
15644                                                    (orderByComparator.getOrderByFields().length * 3));
15645                            }
15646                            else {
15647                                    query = new StringBundler(6);
15648                            }
15649    
15650                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15651    
15652                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15653    
15654                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15655    
15656                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15657    
15658                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15659    
15660                            if (orderByComparator != null) {
15661                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15662                                            orderByComparator);
15663                            }
15664                            else
15665                             if (pagination) {
15666                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15667                            }
15668    
15669                            String sql = query.toString();
15670    
15671                            Session session = null;
15672    
15673                            try {
15674                                    session = openSession();
15675    
15676                                    Query q = session.createQuery(sql);
15677    
15678                                    QueryPos qPos = QueryPos.getInstance(q);
15679    
15680                                    qPos.add(groupId);
15681    
15682                                    qPos.add(categoryId);
15683    
15684                                    qPos.add(threadId);
15685    
15686                                    qPos.add(answer);
15687    
15688                                    if (!pagination) {
15689                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15690                                                            start, end, false);
15691    
15692                                            Collections.sort(list);
15693    
15694                                            list = new UnmodifiableList<MBMessage>(list);
15695                                    }
15696                                    else {
15697                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15698                                                            start, end);
15699                                    }
15700    
15701                                    cacheResult(list);
15702    
15703                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15704                            }
15705                            catch (Exception e) {
15706                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15707    
15708                                    throw processException(e);
15709                            }
15710                            finally {
15711                                    closeSession(session);
15712                            }
15713                    }
15714    
15715                    return list;
15716            }
15717    
15718            /**
15719             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15720             *
15721             * @param groupId the group ID
15722             * @param categoryId the category ID
15723             * @param threadId the thread ID
15724             * @param answer the answer
15725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15726             * @return the first matching message-boards message
15727             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15728             * @throws SystemException if a system exception occurred
15729             */
15730            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
15731                    long threadId, boolean answer, OrderByComparator orderByComparator)
15732                    throws NoSuchMessageException, SystemException {
15733                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
15734                                    threadId, answer, orderByComparator);
15735    
15736                    if (mbMessage != null) {
15737                            return mbMessage;
15738                    }
15739    
15740                    StringBundler msg = new StringBundler(10);
15741    
15742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15743    
15744                    msg.append("groupId=");
15745                    msg.append(groupId);
15746    
15747                    msg.append(", categoryId=");
15748                    msg.append(categoryId);
15749    
15750                    msg.append(", threadId=");
15751                    msg.append(threadId);
15752    
15753                    msg.append(", answer=");
15754                    msg.append(answer);
15755    
15756                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15757    
15758                    throw new NoSuchMessageException(msg.toString());
15759            }
15760    
15761            /**
15762             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15763             *
15764             * @param groupId the group ID
15765             * @param categoryId the category ID
15766             * @param threadId the thread ID
15767             * @param answer the answer
15768             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15769             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15770             * @throws SystemException if a system exception occurred
15771             */
15772            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
15773                    long threadId, boolean answer, OrderByComparator orderByComparator)
15774                    throws SystemException {
15775                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15776                                    answer, 0, 1, orderByComparator);
15777    
15778                    if (!list.isEmpty()) {
15779                            return list.get(0);
15780                    }
15781    
15782                    return null;
15783            }
15784    
15785            /**
15786             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15787             *
15788             * @param groupId the group ID
15789             * @param categoryId the category ID
15790             * @param threadId the thread ID
15791             * @param answer the answer
15792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15793             * @return the last matching message-boards message
15794             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15795             * @throws SystemException if a system exception occurred
15796             */
15797            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
15798                    long threadId, boolean answer, OrderByComparator orderByComparator)
15799                    throws NoSuchMessageException, SystemException {
15800                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
15801                                    threadId, answer, orderByComparator);
15802    
15803                    if (mbMessage != null) {
15804                            return mbMessage;
15805                    }
15806    
15807                    StringBundler msg = new StringBundler(10);
15808    
15809                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15810    
15811                    msg.append("groupId=");
15812                    msg.append(groupId);
15813    
15814                    msg.append(", categoryId=");
15815                    msg.append(categoryId);
15816    
15817                    msg.append(", threadId=");
15818                    msg.append(threadId);
15819    
15820                    msg.append(", answer=");
15821                    msg.append(answer);
15822    
15823                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15824    
15825                    throw new NoSuchMessageException(msg.toString());
15826            }
15827    
15828            /**
15829             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15830             *
15831             * @param groupId the group ID
15832             * @param categoryId the category ID
15833             * @param threadId the thread ID
15834             * @param answer the answer
15835             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15836             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15837             * @throws SystemException if a system exception occurred
15838             */
15839            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
15840                    long threadId, boolean answer, OrderByComparator orderByComparator)
15841                    throws SystemException {
15842                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
15843    
15844                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15845                                    answer, count - 1, count, orderByComparator);
15846    
15847                    if (!list.isEmpty()) {
15848                            return list.get(0);
15849                    }
15850    
15851                    return null;
15852            }
15853    
15854            /**
15855             * 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;.
15856             *
15857             * @param messageId the primary key of the current message-boards message
15858             * @param groupId the group ID
15859             * @param categoryId the category ID
15860             * @param threadId the thread ID
15861             * @param answer the answer
15862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15863             * @return the previous, current, and next message-boards message
15864             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15865             * @throws SystemException if a system exception occurred
15866             */
15867            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
15868                    long categoryId, long threadId, boolean answer,
15869                    OrderByComparator orderByComparator)
15870                    throws NoSuchMessageException, SystemException {
15871                    MBMessage mbMessage = findByPrimaryKey(messageId);
15872    
15873                    Session session = null;
15874    
15875                    try {
15876                            session = openSession();
15877    
15878                            MBMessage[] array = new MBMessageImpl[3];
15879    
15880                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15881                                            categoryId, threadId, answer, orderByComparator, true);
15882    
15883                            array[1] = mbMessage;
15884    
15885                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15886                                            categoryId, threadId, answer, orderByComparator, false);
15887    
15888                            return array;
15889                    }
15890                    catch (Exception e) {
15891                            throw processException(e);
15892                    }
15893                    finally {
15894                            closeSession(session);
15895                    }
15896            }
15897    
15898            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
15899                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
15900                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
15901                    StringBundler query = null;
15902    
15903                    if (orderByComparator != null) {
15904                            query = new StringBundler(6 +
15905                                            (orderByComparator.getOrderByFields().length * 6));
15906                    }
15907                    else {
15908                            query = new StringBundler(3);
15909                    }
15910    
15911                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15912    
15913                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15914    
15915                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15916    
15917                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15918    
15919                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15920    
15921                    if (orderByComparator != null) {
15922                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15923    
15924                            if (orderByConditionFields.length > 0) {
15925                                    query.append(WHERE_AND);
15926                            }
15927    
15928                            for (int i = 0; i < orderByConditionFields.length; i++) {
15929                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15930                                    query.append(orderByConditionFields[i]);
15931    
15932                                    if ((i + 1) < orderByConditionFields.length) {
15933                                            if (orderByComparator.isAscending() ^ previous) {
15934                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15935                                            }
15936                                            else {
15937                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15938                                            }
15939                                    }
15940                                    else {
15941                                            if (orderByComparator.isAscending() ^ previous) {
15942                                                    query.append(WHERE_GREATER_THAN);
15943                                            }
15944                                            else {
15945                                                    query.append(WHERE_LESSER_THAN);
15946                                            }
15947                                    }
15948                            }
15949    
15950                            query.append(ORDER_BY_CLAUSE);
15951    
15952                            String[] orderByFields = orderByComparator.getOrderByFields();
15953    
15954                            for (int i = 0; i < orderByFields.length; i++) {
15955                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15956                                    query.append(orderByFields[i]);
15957    
15958                                    if ((i + 1) < orderByFields.length) {
15959                                            if (orderByComparator.isAscending() ^ previous) {
15960                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15961                                            }
15962                                            else {
15963                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15964                                            }
15965                                    }
15966                                    else {
15967                                            if (orderByComparator.isAscending() ^ previous) {
15968                                                    query.append(ORDER_BY_ASC);
15969                                            }
15970                                            else {
15971                                                    query.append(ORDER_BY_DESC);
15972                                            }
15973                                    }
15974                            }
15975                    }
15976                    else {
15977                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15978                    }
15979    
15980                    String sql = query.toString();
15981    
15982                    Query q = session.createQuery(sql);
15983    
15984                    q.setFirstResult(0);
15985                    q.setMaxResults(2);
15986    
15987                    QueryPos qPos = QueryPos.getInstance(q);
15988    
15989                    qPos.add(groupId);
15990    
15991                    qPos.add(categoryId);
15992    
15993                    qPos.add(threadId);
15994    
15995                    qPos.add(answer);
15996    
15997                    if (orderByComparator != null) {
15998                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15999    
16000                            for (Object value : values) {
16001                                    qPos.add(value);
16002                            }
16003                    }
16004    
16005                    List<MBMessage> list = q.list();
16006    
16007                    if (list.size() == 2) {
16008                            return list.get(1);
16009                    }
16010                    else {
16011                            return null;
16012                    }
16013            }
16014    
16015            /**
16016             * 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;.
16017             *
16018             * @param groupId the group ID
16019             * @param categoryId the category ID
16020             * @param threadId the thread ID
16021             * @param answer the answer
16022             * @return the matching message-boards messages that the user has permission to view
16023             * @throws SystemException if a system exception occurred
16024             */
16025            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16026                    long threadId, boolean answer) throws SystemException {
16027                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16028                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16029            }
16030    
16031            /**
16032             * 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;.
16033             *
16034             * <p>
16035             * 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.
16036             * </p>
16037             *
16038             * @param groupId the group ID
16039             * @param categoryId the category ID
16040             * @param threadId the thread ID
16041             * @param answer the answer
16042             * @param start the lower bound of the range of message-boards messages
16043             * @param end the upper bound of the range of message-boards messages (not inclusive)
16044             * @return the range of matching message-boards messages that the user has permission to view
16045             * @throws SystemException if a system exception occurred
16046             */
16047            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16048                    long threadId, boolean answer, int start, int end)
16049                    throws SystemException {
16050                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16051                            start, end, null);
16052            }
16053    
16054            /**
16055             * 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;.
16056             *
16057             * <p>
16058             * 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.
16059             * </p>
16060             *
16061             * @param groupId the group ID
16062             * @param categoryId the category ID
16063             * @param threadId the thread ID
16064             * @param answer the answer
16065             * @param start the lower bound of the range of message-boards messages
16066             * @param end the upper bound of the range of message-boards messages (not inclusive)
16067             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16068             * @return the ordered 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_C_T_A(long groupId, long categoryId,
16072                    long threadId, boolean answer, int start, int end,
16073                    OrderByComparator orderByComparator) throws SystemException {
16074                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16075                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16076                                    end, orderByComparator);
16077                    }
16078    
16079                    StringBundler query = null;
16080    
16081                    if (orderByComparator != null) {
16082                            query = new StringBundler(6 +
16083                                            (orderByComparator.getOrderByFields().length * 3));
16084                    }
16085                    else {
16086                            query = new StringBundler(6);
16087                    }
16088    
16089                    if (getDB().isSupportsInlineDistinct()) {
16090                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16091                    }
16092                    else {
16093                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16094                    }
16095    
16096                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16097    
16098                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16099    
16100                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16101    
16102                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16103    
16104                    if (!getDB().isSupportsInlineDistinct()) {
16105                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16106                    }
16107    
16108                    if (orderByComparator != null) {
16109                            if (getDB().isSupportsInlineDistinct()) {
16110                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16111                                            orderByComparator);
16112                            }
16113                            else {
16114                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16115                                            orderByComparator);
16116                            }
16117                    }
16118                    else {
16119                            if (getDB().isSupportsInlineDistinct()) {
16120                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16121                            }
16122                            else {
16123                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16124                            }
16125                    }
16126    
16127                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16128                                    MBMessage.class.getName(),
16129                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16130    
16131                    Session session = null;
16132    
16133                    try {
16134                            session = openSession();
16135    
16136                            SQLQuery q = session.createSQLQuery(sql);
16137    
16138                            if (getDB().isSupportsInlineDistinct()) {
16139                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16140                            }
16141                            else {
16142                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16143                            }
16144    
16145                            QueryPos qPos = QueryPos.getInstance(q);
16146    
16147                            qPos.add(groupId);
16148    
16149                            qPos.add(categoryId);
16150    
16151                            qPos.add(threadId);
16152    
16153                            qPos.add(answer);
16154    
16155                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16156                    }
16157                    catch (Exception e) {
16158                            throw processException(e);
16159                    }
16160                    finally {
16161                            closeSession(session);
16162                    }
16163            }
16164    
16165            /**
16166             * 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;.
16167             *
16168             * @param messageId the primary key of the current message-boards message
16169             * @param groupId the group ID
16170             * @param categoryId the category ID
16171             * @param threadId the thread ID
16172             * @param answer the answer
16173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16174             * @return the previous, current, and next message-boards message
16175             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16176             * @throws SystemException if a system exception occurred
16177             */
16178            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16179                    long groupId, long categoryId, long threadId, boolean answer,
16180                    OrderByComparator orderByComparator)
16181                    throws NoSuchMessageException, SystemException {
16182                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16183                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16184                                    threadId, answer, orderByComparator);
16185                    }
16186    
16187                    MBMessage mbMessage = findByPrimaryKey(messageId);
16188    
16189                    Session session = null;
16190    
16191                    try {
16192                            session = openSession();
16193    
16194                            MBMessage[] array = new MBMessageImpl[3];
16195    
16196                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16197                                            groupId, categoryId, threadId, answer, orderByComparator,
16198                                            true);
16199    
16200                            array[1] = mbMessage;
16201    
16202                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16203                                            groupId, categoryId, threadId, answer, orderByComparator,
16204                                            false);
16205    
16206                            return array;
16207                    }
16208                    catch (Exception e) {
16209                            throw processException(e);
16210                    }
16211                    finally {
16212                            closeSession(session);
16213                    }
16214            }
16215    
16216            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16217                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16218                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
16219                    StringBundler query = null;
16220    
16221                    if (orderByComparator != null) {
16222                            query = new StringBundler(6 +
16223                                            (orderByComparator.getOrderByFields().length * 6));
16224                    }
16225                    else {
16226                            query = new StringBundler(3);
16227                    }
16228    
16229                    if (getDB().isSupportsInlineDistinct()) {
16230                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16231                    }
16232                    else {
16233                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16234                    }
16235    
16236                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16237    
16238                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16239    
16240                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16241    
16242                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16243    
16244                    if (!getDB().isSupportsInlineDistinct()) {
16245                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16246                    }
16247    
16248                    if (orderByComparator != null) {
16249                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16250    
16251                            if (orderByConditionFields.length > 0) {
16252                                    query.append(WHERE_AND);
16253                            }
16254    
16255                            for (int i = 0; i < orderByConditionFields.length; i++) {
16256                                    if (getDB().isSupportsInlineDistinct()) {
16257                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16258                                    }
16259                                    else {
16260                                            query.append(_ORDER_BY_ENTITY_TABLE);
16261                                    }
16262    
16263                                    query.append(orderByConditionFields[i]);
16264    
16265                                    if ((i + 1) < orderByConditionFields.length) {
16266                                            if (orderByComparator.isAscending() ^ previous) {
16267                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16268                                            }
16269                                            else {
16270                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16271                                            }
16272                                    }
16273                                    else {
16274                                            if (orderByComparator.isAscending() ^ previous) {
16275                                                    query.append(WHERE_GREATER_THAN);
16276                                            }
16277                                            else {
16278                                                    query.append(WHERE_LESSER_THAN);
16279                                            }
16280                                    }
16281                            }
16282    
16283                            query.append(ORDER_BY_CLAUSE);
16284    
16285                            String[] orderByFields = orderByComparator.getOrderByFields();
16286    
16287                            for (int i = 0; i < orderByFields.length; i++) {
16288                                    if (getDB().isSupportsInlineDistinct()) {
16289                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16290                                    }
16291                                    else {
16292                                            query.append(_ORDER_BY_ENTITY_TABLE);
16293                                    }
16294    
16295                                    query.append(orderByFields[i]);
16296    
16297                                    if ((i + 1) < orderByFields.length) {
16298                                            if (orderByComparator.isAscending() ^ previous) {
16299                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16300                                            }
16301                                            else {
16302                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16303                                            }
16304                                    }
16305                                    else {
16306                                            if (orderByComparator.isAscending() ^ previous) {
16307                                                    query.append(ORDER_BY_ASC);
16308                                            }
16309                                            else {
16310                                                    query.append(ORDER_BY_DESC);
16311                                            }
16312                                    }
16313                            }
16314                    }
16315                    else {
16316                            if (getDB().isSupportsInlineDistinct()) {
16317                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16318                            }
16319                            else {
16320                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16321                            }
16322                    }
16323    
16324                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16325                                    MBMessage.class.getName(),
16326                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16327    
16328                    SQLQuery q = session.createSQLQuery(sql);
16329    
16330                    q.setFirstResult(0);
16331                    q.setMaxResults(2);
16332    
16333                    if (getDB().isSupportsInlineDistinct()) {
16334                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16335                    }
16336                    else {
16337                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16338                    }
16339    
16340                    QueryPos qPos = QueryPos.getInstance(q);
16341    
16342                    qPos.add(groupId);
16343    
16344                    qPos.add(categoryId);
16345    
16346                    qPos.add(threadId);
16347    
16348                    qPos.add(answer);
16349    
16350                    if (orderByComparator != null) {
16351                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16352    
16353                            for (Object value : values) {
16354                                    qPos.add(value);
16355                            }
16356                    }
16357    
16358                    List<MBMessage> list = q.list();
16359    
16360                    if (list.size() == 2) {
16361                            return list.get(1);
16362                    }
16363                    else {
16364                            return null;
16365                    }
16366            }
16367    
16368            /**
16369             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16370             *
16371             * @param groupId the group ID
16372             * @param categoryId the category ID
16373             * @param threadId the thread ID
16374             * @param answer the answer
16375             * @throws SystemException if a system exception occurred
16376             */
16377            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16378                    boolean answer) throws SystemException {
16379                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16380                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16381                            remove(mbMessage);
16382                    }
16383            }
16384    
16385            /**
16386             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16387             *
16388             * @param groupId the group ID
16389             * @param categoryId the category ID
16390             * @param threadId the thread ID
16391             * @param answer the answer
16392             * @return the number of matching message-boards messages
16393             * @throws SystemException if a system exception occurred
16394             */
16395            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16396                    boolean answer) throws SystemException {
16397                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
16398    
16399                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16400    
16401                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16402                                    this);
16403    
16404                    if (count == null) {
16405                            StringBundler query = new StringBundler(5);
16406    
16407                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16408    
16409                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16410    
16411                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16412    
16413                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16414    
16415                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16416    
16417                            String sql = query.toString();
16418    
16419                            Session session = null;
16420    
16421                            try {
16422                                    session = openSession();
16423    
16424                                    Query q = session.createQuery(sql);
16425    
16426                                    QueryPos qPos = QueryPos.getInstance(q);
16427    
16428                                    qPos.add(groupId);
16429    
16430                                    qPos.add(categoryId);
16431    
16432                                    qPos.add(threadId);
16433    
16434                                    qPos.add(answer);
16435    
16436                                    count = (Long)q.uniqueResult();
16437    
16438                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16439                            }
16440                            catch (Exception e) {
16441                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16442    
16443                                    throw processException(e);
16444                            }
16445                            finally {
16446                                    closeSession(session);
16447                            }
16448                    }
16449    
16450                    return count.intValue();
16451            }
16452    
16453            /**
16454             * 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;.
16455             *
16456             * @param groupId the group ID
16457             * @param categoryId the category ID
16458             * @param threadId the thread ID
16459             * @param answer the answer
16460             * @return the number of matching message-boards messages that the user has permission to view
16461             * @throws SystemException if a system exception occurred
16462             */
16463            public int filterCountByG_C_T_A(long groupId, long categoryId,
16464                    long threadId, boolean answer) throws SystemException {
16465                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16466                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
16467                    }
16468    
16469                    StringBundler query = new StringBundler(5);
16470    
16471                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16472    
16473                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16474    
16475                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16476    
16477                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16478    
16479                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16480    
16481                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16482                                    MBMessage.class.getName(),
16483                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16484    
16485                    Session session = null;
16486    
16487                    try {
16488                            session = openSession();
16489    
16490                            SQLQuery q = session.createSQLQuery(sql);
16491    
16492                            q.addScalar(COUNT_COLUMN_NAME,
16493                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16494    
16495                            QueryPos qPos = QueryPos.getInstance(q);
16496    
16497                            qPos.add(groupId);
16498    
16499                            qPos.add(categoryId);
16500    
16501                            qPos.add(threadId);
16502    
16503                            qPos.add(answer);
16504    
16505                            Long count = (Long)q.uniqueResult();
16506    
16507                            return count.intValue();
16508                    }
16509                    catch (Exception e) {
16510                            throw processException(e);
16511                    }
16512                    finally {
16513                            closeSession(session);
16514                    }
16515            }
16516    
16517            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
16518            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
16519            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
16520            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
16521            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16522                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16523                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
16524                            new String[] {
16525                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16526                                    Integer.class.getName(),
16527                                    
16528                            Integer.class.getName(), Integer.class.getName(),
16529                                    OrderByComparator.class.getName()
16530                            });
16531            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
16532                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16533                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16534                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
16535                            new String[] {
16536                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16537                                    Integer.class.getName()
16538                            },
16539                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16540                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16541                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16542                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
16543                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16544            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16545                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16546                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
16547                            new String[] {
16548                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16549                                    Integer.class.getName()
16550                            });
16551    
16552            /**
16553             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16554             *
16555             * @param groupId the group ID
16556             * @param categoryId the category ID
16557             * @param threadId the thread ID
16558             * @param status the status
16559             * @return the matching message-boards messages
16560             * @throws SystemException if a system exception occurred
16561             */
16562            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16563                    long threadId, int status) throws SystemException {
16564                    return findByG_C_T_S(groupId, categoryId, threadId, status,
16565                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16566            }
16567    
16568            /**
16569             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16570             *
16571             * <p>
16572             * 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.
16573             * </p>
16574             *
16575             * @param groupId the group ID
16576             * @param categoryId the category ID
16577             * @param threadId the thread ID
16578             * @param status the status
16579             * @param start the lower bound of the range of message-boards messages
16580             * @param end the upper bound of the range of message-boards messages (not inclusive)
16581             * @return the range of matching message-boards messages
16582             * @throws SystemException if a system exception occurred
16583             */
16584            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16585                    long threadId, int status, int start, int end)
16586                    throws SystemException {
16587                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
16588                            null);
16589            }
16590    
16591            /**
16592             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16593             *
16594             * <p>
16595             * 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.
16596             * </p>
16597             *
16598             * @param groupId the group ID
16599             * @param categoryId the category ID
16600             * @param threadId the thread ID
16601             * @param status the status
16602             * @param start the lower bound of the range of message-boards messages
16603             * @param end the upper bound of the range of message-boards messages (not inclusive)
16604             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16605             * @return the ordered range of matching message-boards messages
16606             * @throws SystemException if a system exception occurred
16607             */
16608            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16609                    long threadId, int status, int start, int end,
16610                    OrderByComparator orderByComparator) throws SystemException {
16611                    boolean pagination = true;
16612                    FinderPath finderPath = null;
16613                    Object[] finderArgs = null;
16614    
16615                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16616                                    (orderByComparator == null)) {
16617                            pagination = false;
16618                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
16619                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
16620                    }
16621                    else {
16622                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
16623                            finderArgs = new Object[] {
16624                                            groupId, categoryId, threadId, status,
16625                                            
16626                                            start, end, orderByComparator
16627                                    };
16628                    }
16629    
16630                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16631                                    finderArgs, this);
16632    
16633                    if ((list != null) && !list.isEmpty()) {
16634                            for (MBMessage mbMessage : list) {
16635                                    if ((groupId != mbMessage.getGroupId()) ||
16636                                                    (categoryId != mbMessage.getCategoryId()) ||
16637                                                    (threadId != mbMessage.getThreadId()) ||
16638                                                    (status != mbMessage.getStatus())) {
16639                                            list = null;
16640    
16641                                            break;
16642                                    }
16643                            }
16644                    }
16645    
16646                    if (list == null) {
16647                            StringBundler query = null;
16648    
16649                            if (orderByComparator != null) {
16650                                    query = new StringBundler(6 +
16651                                                    (orderByComparator.getOrderByFields().length * 3));
16652                            }
16653                            else {
16654                                    query = new StringBundler(6);
16655                            }
16656    
16657                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16658    
16659                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16660    
16661                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16662    
16663                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16664    
16665                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16666    
16667                            if (orderByComparator != null) {
16668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16669                                            orderByComparator);
16670                            }
16671                            else
16672                             if (pagination) {
16673                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16674                            }
16675    
16676                            String sql = query.toString();
16677    
16678                            Session session = null;
16679    
16680                            try {
16681                                    session = openSession();
16682    
16683                                    Query q = session.createQuery(sql);
16684    
16685                                    QueryPos qPos = QueryPos.getInstance(q);
16686    
16687                                    qPos.add(groupId);
16688    
16689                                    qPos.add(categoryId);
16690    
16691                                    qPos.add(threadId);
16692    
16693                                    qPos.add(status);
16694    
16695                                    if (!pagination) {
16696                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16697                                                            start, end, false);
16698    
16699                                            Collections.sort(list);
16700    
16701                                            list = new UnmodifiableList<MBMessage>(list);
16702                                    }
16703                                    else {
16704                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16705                                                            start, end);
16706                                    }
16707    
16708                                    cacheResult(list);
16709    
16710                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16711                            }
16712                            catch (Exception e) {
16713                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16714    
16715                                    throw processException(e);
16716                            }
16717                            finally {
16718                                    closeSession(session);
16719                            }
16720                    }
16721    
16722                    return list;
16723            }
16724    
16725            /**
16726             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16727             *
16728             * @param groupId the group ID
16729             * @param categoryId the category ID
16730             * @param threadId the thread ID
16731             * @param status the status
16732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16733             * @return the first matching message-boards message
16734             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16735             * @throws SystemException if a system exception occurred
16736             */
16737            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
16738                    long threadId, int status, OrderByComparator orderByComparator)
16739                    throws NoSuchMessageException, SystemException {
16740                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
16741                                    threadId, status, orderByComparator);
16742    
16743                    if (mbMessage != null) {
16744                            return mbMessage;
16745                    }
16746    
16747                    StringBundler msg = new StringBundler(10);
16748    
16749                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16750    
16751                    msg.append("groupId=");
16752                    msg.append(groupId);
16753    
16754                    msg.append(", categoryId=");
16755                    msg.append(categoryId);
16756    
16757                    msg.append(", threadId=");
16758                    msg.append(threadId);
16759    
16760                    msg.append(", status=");
16761                    msg.append(status);
16762    
16763                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16764    
16765                    throw new NoSuchMessageException(msg.toString());
16766            }
16767    
16768            /**
16769             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16770             *
16771             * @param groupId the group ID
16772             * @param categoryId the category ID
16773             * @param threadId the thread ID
16774             * @param status the status
16775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16776             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16777             * @throws SystemException if a system exception occurred
16778             */
16779            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
16780                    long threadId, int status, OrderByComparator orderByComparator)
16781                    throws SystemException {
16782                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16783                                    status, 0, 1, orderByComparator);
16784    
16785                    if (!list.isEmpty()) {
16786                            return list.get(0);
16787                    }
16788    
16789                    return null;
16790            }
16791    
16792            /**
16793             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16794             *
16795             * @param groupId the group ID
16796             * @param categoryId the category ID
16797             * @param threadId the thread ID
16798             * @param status the status
16799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16800             * @return the last matching message-boards message
16801             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16802             * @throws SystemException if a system exception occurred
16803             */
16804            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
16805                    long threadId, int status, OrderByComparator orderByComparator)
16806                    throws NoSuchMessageException, SystemException {
16807                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
16808                                    threadId, status, orderByComparator);
16809    
16810                    if (mbMessage != null) {
16811                            return mbMessage;
16812                    }
16813    
16814                    StringBundler msg = new StringBundler(10);
16815    
16816                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16817    
16818                    msg.append("groupId=");
16819                    msg.append(groupId);
16820    
16821                    msg.append(", categoryId=");
16822                    msg.append(categoryId);
16823    
16824                    msg.append(", threadId=");
16825                    msg.append(threadId);
16826    
16827                    msg.append(", status=");
16828                    msg.append(status);
16829    
16830                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16831    
16832                    throw new NoSuchMessageException(msg.toString());
16833            }
16834    
16835            /**
16836             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16837             *
16838             * @param groupId the group ID
16839             * @param categoryId the category ID
16840             * @param threadId the thread ID
16841             * @param status the status
16842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16843             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16844             * @throws SystemException if a system exception occurred
16845             */
16846            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
16847                    long threadId, int status, OrderByComparator orderByComparator)
16848                    throws SystemException {
16849                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
16850    
16851                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16852                                    status, count - 1, count, orderByComparator);
16853    
16854                    if (!list.isEmpty()) {
16855                            return list.get(0);
16856                    }
16857    
16858                    return null;
16859            }
16860    
16861            /**
16862             * 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;.
16863             *
16864             * @param messageId the primary key of the current message-boards message
16865             * @param groupId the group ID
16866             * @param categoryId the category ID
16867             * @param threadId the thread ID
16868             * @param status the status
16869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16870             * @return the previous, current, and next message-boards message
16871             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16872             * @throws SystemException if a system exception occurred
16873             */
16874            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
16875                    long categoryId, long threadId, int status,
16876                    OrderByComparator orderByComparator)
16877                    throws NoSuchMessageException, SystemException {
16878                    MBMessage mbMessage = findByPrimaryKey(messageId);
16879    
16880                    Session session = null;
16881    
16882                    try {
16883                            session = openSession();
16884    
16885                            MBMessage[] array = new MBMessageImpl[3];
16886    
16887                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16888                                            categoryId, threadId, status, orderByComparator, true);
16889    
16890                            array[1] = mbMessage;
16891    
16892                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16893                                            categoryId, threadId, status, orderByComparator, false);
16894    
16895                            return array;
16896                    }
16897                    catch (Exception e) {
16898                            throw processException(e);
16899                    }
16900                    finally {
16901                            closeSession(session);
16902                    }
16903            }
16904    
16905            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
16906                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16907                    int status, OrderByComparator orderByComparator, boolean previous) {
16908                    StringBundler query = null;
16909    
16910                    if (orderByComparator != null) {
16911                            query = new StringBundler(6 +
16912                                            (orderByComparator.getOrderByFields().length * 6));
16913                    }
16914                    else {
16915                            query = new StringBundler(3);
16916                    }
16917    
16918                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16919    
16920                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16921    
16922                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16923    
16924                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16925    
16926                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16927    
16928                    if (orderByComparator != null) {
16929                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16930    
16931                            if (orderByConditionFields.length > 0) {
16932                                    query.append(WHERE_AND);
16933                            }
16934    
16935                            for (int i = 0; i < orderByConditionFields.length; i++) {
16936                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16937                                    query.append(orderByConditionFields[i]);
16938    
16939                                    if ((i + 1) < orderByConditionFields.length) {
16940                                            if (orderByComparator.isAscending() ^ previous) {
16941                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16942                                            }
16943                                            else {
16944                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16945                                            }
16946                                    }
16947                                    else {
16948                                            if (orderByComparator.isAscending() ^ previous) {
16949                                                    query.append(WHERE_GREATER_THAN);
16950                                            }
16951                                            else {
16952                                                    query.append(WHERE_LESSER_THAN);
16953                                            }
16954                                    }
16955                            }
16956    
16957                            query.append(ORDER_BY_CLAUSE);
16958    
16959                            String[] orderByFields = orderByComparator.getOrderByFields();
16960    
16961                            for (int i = 0; i < orderByFields.length; i++) {
16962                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16963                                    query.append(orderByFields[i]);
16964    
16965                                    if ((i + 1) < orderByFields.length) {
16966                                            if (orderByComparator.isAscending() ^ previous) {
16967                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16968                                            }
16969                                            else {
16970                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16971                                            }
16972                                    }
16973                                    else {
16974                                            if (orderByComparator.isAscending() ^ previous) {
16975                                                    query.append(ORDER_BY_ASC);
16976                                            }
16977                                            else {
16978                                                    query.append(ORDER_BY_DESC);
16979                                            }
16980                                    }
16981                            }
16982                    }
16983                    else {
16984                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16985                    }
16986    
16987                    String sql = query.toString();
16988    
16989                    Query q = session.createQuery(sql);
16990    
16991                    q.setFirstResult(0);
16992                    q.setMaxResults(2);
16993    
16994                    QueryPos qPos = QueryPos.getInstance(q);
16995    
16996                    qPos.add(groupId);
16997    
16998                    qPos.add(categoryId);
16999    
17000                    qPos.add(threadId);
17001    
17002                    qPos.add(status);
17003    
17004                    if (orderByComparator != null) {
17005                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17006    
17007                            for (Object value : values) {
17008                                    qPos.add(value);
17009                            }
17010                    }
17011    
17012                    List<MBMessage> list = q.list();
17013    
17014                    if (list.size() == 2) {
17015                            return list.get(1);
17016                    }
17017                    else {
17018                            return null;
17019                    }
17020            }
17021    
17022            /**
17023             * 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;.
17024             *
17025             * @param groupId the group ID
17026             * @param categoryId the category ID
17027             * @param threadId the thread ID
17028             * @param status the status
17029             * @return the matching message-boards messages that the user has permission to view
17030             * @throws SystemException if a system exception occurred
17031             */
17032            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17033                    long threadId, int status) throws SystemException {
17034                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17035                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17036            }
17037    
17038            /**
17039             * 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;.
17040             *
17041             * <p>
17042             * 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.
17043             * </p>
17044             *
17045             * @param groupId the group ID
17046             * @param categoryId the category ID
17047             * @param threadId the thread ID
17048             * @param status the status
17049             * @param start the lower bound of the range of message-boards messages
17050             * @param end the upper bound of the range of message-boards messages (not inclusive)
17051             * @return the range of matching message-boards messages that the user has permission to view
17052             * @throws SystemException if a system exception occurred
17053             */
17054            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17055                    long threadId, int status, int start, int end)
17056                    throws SystemException {
17057                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17058                            start, end, null);
17059            }
17060    
17061            /**
17062             * 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;.
17063             *
17064             * <p>
17065             * 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.
17066             * </p>
17067             *
17068             * @param groupId the group ID
17069             * @param categoryId the category ID
17070             * @param threadId the thread ID
17071             * @param status the status
17072             * @param start the lower bound of the range of message-boards messages
17073             * @param end the upper bound of the range of message-boards messages (not inclusive)
17074             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17075             * @return the ordered range of matching message-boards messages that the user has permission to view
17076             * @throws SystemException if a system exception occurred
17077             */
17078            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17079                    long threadId, int status, int start, int end,
17080                    OrderByComparator orderByComparator) throws SystemException {
17081                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17082                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17083                                    end, orderByComparator);
17084                    }
17085    
17086                    StringBundler query = null;
17087    
17088                    if (orderByComparator != null) {
17089                            query = new StringBundler(6 +
17090                                            (orderByComparator.getOrderByFields().length * 3));
17091                    }
17092                    else {
17093                            query = new StringBundler(6);
17094                    }
17095    
17096                    if (getDB().isSupportsInlineDistinct()) {
17097                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17098                    }
17099                    else {
17100                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17101                    }
17102    
17103                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17104    
17105                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17106    
17107                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17108    
17109                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17110    
17111                    if (!getDB().isSupportsInlineDistinct()) {
17112                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17113                    }
17114    
17115                    if (orderByComparator != null) {
17116                            if (getDB().isSupportsInlineDistinct()) {
17117                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17118                                            orderByComparator);
17119                            }
17120                            else {
17121                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17122                                            orderByComparator);
17123                            }
17124                    }
17125                    else {
17126                            if (getDB().isSupportsInlineDistinct()) {
17127                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17128                            }
17129                            else {
17130                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17131                            }
17132                    }
17133    
17134                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17135                                    MBMessage.class.getName(),
17136                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17137    
17138                    Session session = null;
17139    
17140                    try {
17141                            session = openSession();
17142    
17143                            SQLQuery q = session.createSQLQuery(sql);
17144    
17145                            if (getDB().isSupportsInlineDistinct()) {
17146                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17147                            }
17148                            else {
17149                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17150                            }
17151    
17152                            QueryPos qPos = QueryPos.getInstance(q);
17153    
17154                            qPos.add(groupId);
17155    
17156                            qPos.add(categoryId);
17157    
17158                            qPos.add(threadId);
17159    
17160                            qPos.add(status);
17161    
17162                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17163                    }
17164                    catch (Exception e) {
17165                            throw processException(e);
17166                    }
17167                    finally {
17168                            closeSession(session);
17169                    }
17170            }
17171    
17172            /**
17173             * 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;.
17174             *
17175             * @param messageId the primary key of the current message-boards message
17176             * @param groupId the group ID
17177             * @param categoryId the category ID
17178             * @param threadId the thread ID
17179             * @param status the status
17180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17181             * @return the previous, current, and next message-boards message
17182             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17183             * @throws SystemException if a system exception occurred
17184             */
17185            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17186                    long groupId, long categoryId, long threadId, int status,
17187                    OrderByComparator orderByComparator)
17188                    throws NoSuchMessageException, SystemException {
17189                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17190                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17191                                    threadId, status, orderByComparator);
17192                    }
17193    
17194                    MBMessage mbMessage = findByPrimaryKey(messageId);
17195    
17196                    Session session = null;
17197    
17198                    try {
17199                            session = openSession();
17200    
17201                            MBMessage[] array = new MBMessageImpl[3];
17202    
17203                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17204                                            groupId, categoryId, threadId, status, orderByComparator,
17205                                            true);
17206    
17207                            array[1] = mbMessage;
17208    
17209                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17210                                            groupId, categoryId, threadId, status, orderByComparator,
17211                                            false);
17212    
17213                            return array;
17214                    }
17215                    catch (Exception e) {
17216                            throw processException(e);
17217                    }
17218                    finally {
17219                            closeSession(session);
17220                    }
17221            }
17222    
17223            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17224                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17225                    int status, OrderByComparator orderByComparator, boolean previous) {
17226                    StringBundler query = null;
17227    
17228                    if (orderByComparator != null) {
17229                            query = new StringBundler(6 +
17230                                            (orderByComparator.getOrderByFields().length * 6));
17231                    }
17232                    else {
17233                            query = new StringBundler(3);
17234                    }
17235    
17236                    if (getDB().isSupportsInlineDistinct()) {
17237                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17238                    }
17239                    else {
17240                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17241                    }
17242    
17243                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17244    
17245                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17246    
17247                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17248    
17249                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17250    
17251                    if (!getDB().isSupportsInlineDistinct()) {
17252                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17253                    }
17254    
17255                    if (orderByComparator != null) {
17256                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17257    
17258                            if (orderByConditionFields.length > 0) {
17259                                    query.append(WHERE_AND);
17260                            }
17261    
17262                            for (int i = 0; i < orderByConditionFields.length; i++) {
17263                                    if (getDB().isSupportsInlineDistinct()) {
17264                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17265                                    }
17266                                    else {
17267                                            query.append(_ORDER_BY_ENTITY_TABLE);
17268                                    }
17269    
17270                                    query.append(orderByConditionFields[i]);
17271    
17272                                    if ((i + 1) < orderByConditionFields.length) {
17273                                            if (orderByComparator.isAscending() ^ previous) {
17274                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17275                                            }
17276                                            else {
17277                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17278                                            }
17279                                    }
17280                                    else {
17281                                            if (orderByComparator.isAscending() ^ previous) {
17282                                                    query.append(WHERE_GREATER_THAN);
17283                                            }
17284                                            else {
17285                                                    query.append(WHERE_LESSER_THAN);
17286                                            }
17287                                    }
17288                            }
17289    
17290                            query.append(ORDER_BY_CLAUSE);
17291    
17292                            String[] orderByFields = orderByComparator.getOrderByFields();
17293    
17294                            for (int i = 0; i < orderByFields.length; i++) {
17295                                    if (getDB().isSupportsInlineDistinct()) {
17296                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17297                                    }
17298                                    else {
17299                                            query.append(_ORDER_BY_ENTITY_TABLE);
17300                                    }
17301    
17302                                    query.append(orderByFields[i]);
17303    
17304                                    if ((i + 1) < orderByFields.length) {
17305                                            if (orderByComparator.isAscending() ^ previous) {
17306                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17307                                            }
17308                                            else {
17309                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17310                                            }
17311                                    }
17312                                    else {
17313                                            if (orderByComparator.isAscending() ^ previous) {
17314                                                    query.append(ORDER_BY_ASC);
17315                                            }
17316                                            else {
17317                                                    query.append(ORDER_BY_DESC);
17318                                            }
17319                                    }
17320                            }
17321                    }
17322                    else {
17323                            if (getDB().isSupportsInlineDistinct()) {
17324                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17325                            }
17326                            else {
17327                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17328                            }
17329                    }
17330    
17331                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17332                                    MBMessage.class.getName(),
17333                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17334    
17335                    SQLQuery q = session.createSQLQuery(sql);
17336    
17337                    q.setFirstResult(0);
17338                    q.setMaxResults(2);
17339    
17340                    if (getDB().isSupportsInlineDistinct()) {
17341                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17342                    }
17343                    else {
17344                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17345                    }
17346    
17347                    QueryPos qPos = QueryPos.getInstance(q);
17348    
17349                    qPos.add(groupId);
17350    
17351                    qPos.add(categoryId);
17352    
17353                    qPos.add(threadId);
17354    
17355                    qPos.add(status);
17356    
17357                    if (orderByComparator != null) {
17358                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17359    
17360                            for (Object value : values) {
17361                                    qPos.add(value);
17362                            }
17363                    }
17364    
17365                    List<MBMessage> list = q.list();
17366    
17367                    if (list.size() == 2) {
17368                            return list.get(1);
17369                    }
17370                    else {
17371                            return null;
17372                    }
17373            }
17374    
17375            /**
17376             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
17377             *
17378             * @param groupId the group ID
17379             * @param categoryId the category ID
17380             * @param threadId the thread ID
17381             * @param status the status
17382             * @throws SystemException if a system exception occurred
17383             */
17384            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
17385                    int status) throws SystemException {
17386                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
17387                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17388                            remove(mbMessage);
17389                    }
17390            }
17391    
17392            /**
17393             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17394             *
17395             * @param groupId the group ID
17396             * @param categoryId the category ID
17397             * @param threadId the thread ID
17398             * @param status the status
17399             * @return the number of matching message-boards messages
17400             * @throws SystemException if a system exception occurred
17401             */
17402            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17403                    int status) throws SystemException {
17404                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
17405    
17406                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17407    
17408                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17409                                    this);
17410    
17411                    if (count == null) {
17412                            StringBundler query = new StringBundler(5);
17413    
17414                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17415    
17416                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17417    
17418                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17419    
17420                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17421    
17422                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17423    
17424                            String sql = query.toString();
17425    
17426                            Session session = null;
17427    
17428                            try {
17429                                    session = openSession();
17430    
17431                                    Query q = session.createQuery(sql);
17432    
17433                                    QueryPos qPos = QueryPos.getInstance(q);
17434    
17435                                    qPos.add(groupId);
17436    
17437                                    qPos.add(categoryId);
17438    
17439                                    qPos.add(threadId);
17440    
17441                                    qPos.add(status);
17442    
17443                                    count = (Long)q.uniqueResult();
17444    
17445                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17446                            }
17447                            catch (Exception e) {
17448                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17449    
17450                                    throw processException(e);
17451                            }
17452                            finally {
17453                                    closeSession(session);
17454                            }
17455                    }
17456    
17457                    return count.intValue();
17458            }
17459    
17460            /**
17461             * 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;.
17462             *
17463             * @param groupId the group ID
17464             * @param categoryId the category ID
17465             * @param threadId the thread ID
17466             * @param status the status
17467             * @return the number of matching message-boards messages that the user has permission to view
17468             * @throws SystemException if a system exception occurred
17469             */
17470            public int filterCountByG_C_T_S(long groupId, long categoryId,
17471                    long threadId, int status) throws SystemException {
17472                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17473                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17474                    }
17475    
17476                    StringBundler query = new StringBundler(5);
17477    
17478                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17479    
17480                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17481    
17482                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17483    
17484                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17485    
17486                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17487    
17488                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17489                                    MBMessage.class.getName(),
17490                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17491    
17492                    Session session = null;
17493    
17494                    try {
17495                            session = openSession();
17496    
17497                            SQLQuery q = session.createSQLQuery(sql);
17498    
17499                            q.addScalar(COUNT_COLUMN_NAME,
17500                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17501    
17502                            QueryPos qPos = QueryPos.getInstance(q);
17503    
17504                            qPos.add(groupId);
17505    
17506                            qPos.add(categoryId);
17507    
17508                            qPos.add(threadId);
17509    
17510                            qPos.add(status);
17511    
17512                            Long count = (Long)q.uniqueResult();
17513    
17514                            return count.intValue();
17515                    }
17516                    catch (Exception e) {
17517                            throw processException(e);
17518                    }
17519                    finally {
17520                            closeSession(session);
17521                    }
17522            }
17523    
17524            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17525            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17526            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17527            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17528            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17529                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17530                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
17531                            new String[] {
17532                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17533                                    Integer.class.getName(),
17534                                    
17535                            Integer.class.getName(), Integer.class.getName(),
17536                                    OrderByComparator.class.getName()
17537                            });
17538            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
17539                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17540                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17541                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
17542                            new String[] {
17543                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17544                                    Integer.class.getName()
17545                            },
17546                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
17547                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17548                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
17549                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17550                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17551            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17552                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17553                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
17554                            new String[] {
17555                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17556                                    Integer.class.getName()
17557                            });
17558    
17559            /**
17560             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17561             *
17562             * @param userId the user ID
17563             * @param classNameId the class name ID
17564             * @param classPK the class p k
17565             * @param status the status
17566             * @return the matching message-boards messages
17567             * @throws SystemException if a system exception occurred
17568             */
17569            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17570                    long classPK, int status) throws SystemException {
17571                    return findByU_C_C_S(userId, classNameId, classPK, status,
17572                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17573            }
17574    
17575            /**
17576             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17577             *
17578             * <p>
17579             * 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.
17580             * </p>
17581             *
17582             * @param userId the user ID
17583             * @param classNameId the class name ID
17584             * @param classPK the class p k
17585             * @param status the status
17586             * @param start the lower bound of the range of message-boards messages
17587             * @param end the upper bound of the range of message-boards messages (not inclusive)
17588             * @return the range of matching message-boards messages
17589             * @throws SystemException if a system exception occurred
17590             */
17591            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17592                    long classPK, int status, int start, int end) throws SystemException {
17593                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
17594                            null);
17595            }
17596    
17597            /**
17598             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17599             *
17600             * <p>
17601             * 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.
17602             * </p>
17603             *
17604             * @param userId the user ID
17605             * @param classNameId the class name ID
17606             * @param classPK the class p k
17607             * @param status the status
17608             * @param start the lower bound of the range of message-boards messages
17609             * @param end the upper bound of the range of message-boards messages (not inclusive)
17610             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17611             * @return the ordered range of matching message-boards messages
17612             * @throws SystemException if a system exception occurred
17613             */
17614            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17615                    long classPK, int status, int start, int end,
17616                    OrderByComparator orderByComparator) throws SystemException {
17617                    boolean pagination = true;
17618                    FinderPath finderPath = null;
17619                    Object[] finderArgs = null;
17620    
17621                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17622                                    (orderByComparator == null)) {
17623                            pagination = false;
17624                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
17625                            finderArgs = new Object[] { userId, classNameId, classPK, status };
17626                    }
17627                    else {
17628                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
17629                            finderArgs = new Object[] {
17630                                            userId, classNameId, classPK, status,
17631                                            
17632                                            start, end, orderByComparator
17633                                    };
17634                    }
17635    
17636                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17637                                    finderArgs, this);
17638    
17639                    if ((list != null) && !list.isEmpty()) {
17640                            for (MBMessage mbMessage : list) {
17641                                    if ((userId != mbMessage.getUserId()) ||
17642                                                    (classNameId != mbMessage.getClassNameId()) ||
17643                                                    (classPK != mbMessage.getClassPK()) ||
17644                                                    (status != mbMessage.getStatus())) {
17645                                            list = null;
17646    
17647                                            break;
17648                                    }
17649                            }
17650                    }
17651    
17652                    if (list == null) {
17653                            StringBundler query = null;
17654    
17655                            if (orderByComparator != null) {
17656                                    query = new StringBundler(6 +
17657                                                    (orderByComparator.getOrderByFields().length * 3));
17658                            }
17659                            else {
17660                                    query = new StringBundler(6);
17661                            }
17662    
17663                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17664    
17665                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17666    
17667                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17668    
17669                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17670    
17671                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17672    
17673                            if (orderByComparator != null) {
17674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17675                                            orderByComparator);
17676                            }
17677                            else
17678                             if (pagination) {
17679                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17680                            }
17681    
17682                            String sql = query.toString();
17683    
17684                            Session session = null;
17685    
17686                            try {
17687                                    session = openSession();
17688    
17689                                    Query q = session.createQuery(sql);
17690    
17691                                    QueryPos qPos = QueryPos.getInstance(q);
17692    
17693                                    qPos.add(userId);
17694    
17695                                    qPos.add(classNameId);
17696    
17697                                    qPos.add(classPK);
17698    
17699                                    qPos.add(status);
17700    
17701                                    if (!pagination) {
17702                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17703                                                            start, end, false);
17704    
17705                                            Collections.sort(list);
17706    
17707                                            list = new UnmodifiableList<MBMessage>(list);
17708                                    }
17709                                    else {
17710                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17711                                                            start, end);
17712                                    }
17713    
17714                                    cacheResult(list);
17715    
17716                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17717                            }
17718                            catch (Exception e) {
17719                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17720    
17721                                    throw processException(e);
17722                            }
17723                            finally {
17724                                    closeSession(session);
17725                            }
17726                    }
17727    
17728                    return list;
17729            }
17730    
17731            /**
17732             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17733             *
17734             * @param userId the user ID
17735             * @param classNameId the class name ID
17736             * @param classPK the class p k
17737             * @param status the status
17738             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17739             * @return the first matching message-boards message
17740             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17741             * @throws SystemException if a system exception occurred
17742             */
17743            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
17744                    long classPK, int status, OrderByComparator orderByComparator)
17745                    throws NoSuchMessageException, SystemException {
17746                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
17747                                    classPK, status, orderByComparator);
17748    
17749                    if (mbMessage != null) {
17750                            return mbMessage;
17751                    }
17752    
17753                    StringBundler msg = new StringBundler(10);
17754    
17755                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17756    
17757                    msg.append("userId=");
17758                    msg.append(userId);
17759    
17760                    msg.append(", classNameId=");
17761                    msg.append(classNameId);
17762    
17763                    msg.append(", classPK=");
17764                    msg.append(classPK);
17765    
17766                    msg.append(", status=");
17767                    msg.append(status);
17768    
17769                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17770    
17771                    throw new NoSuchMessageException(msg.toString());
17772            }
17773    
17774            /**
17775             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17776             *
17777             * @param userId the user ID
17778             * @param classNameId the class name ID
17779             * @param classPK the class p k
17780             * @param status the status
17781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17782             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17783             * @throws SystemException if a system exception occurred
17784             */
17785            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
17786                    long classPK, int status, OrderByComparator orderByComparator)
17787                    throws SystemException {
17788                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17789                                    status, 0, 1, orderByComparator);
17790    
17791                    if (!list.isEmpty()) {
17792                            return list.get(0);
17793                    }
17794    
17795                    return null;
17796            }
17797    
17798            /**
17799             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17800             *
17801             * @param userId the user ID
17802             * @param classNameId the class name ID
17803             * @param classPK the class p k
17804             * @param status the status
17805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17806             * @return the last matching message-boards message
17807             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17808             * @throws SystemException if a system exception occurred
17809             */
17810            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
17811                    long classPK, int status, OrderByComparator orderByComparator)
17812                    throws NoSuchMessageException, SystemException {
17813                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
17814                                    status, orderByComparator);
17815    
17816                    if (mbMessage != null) {
17817                            return mbMessage;
17818                    }
17819    
17820                    StringBundler msg = new StringBundler(10);
17821    
17822                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17823    
17824                    msg.append("userId=");
17825                    msg.append(userId);
17826    
17827                    msg.append(", classNameId=");
17828                    msg.append(classNameId);
17829    
17830                    msg.append(", classPK=");
17831                    msg.append(classPK);
17832    
17833                    msg.append(", status=");
17834                    msg.append(status);
17835    
17836                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17837    
17838                    throw new NoSuchMessageException(msg.toString());
17839            }
17840    
17841            /**
17842             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17843             *
17844             * @param userId the user ID
17845             * @param classNameId the class name ID
17846             * @param classPK the class p k
17847             * @param status the status
17848             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17849             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17850             * @throws SystemException if a system exception occurred
17851             */
17852            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
17853                    long classPK, int status, OrderByComparator orderByComparator)
17854                    throws SystemException {
17855                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
17856    
17857                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17858                                    status, count - 1, count, orderByComparator);
17859    
17860                    if (!list.isEmpty()) {
17861                            return list.get(0);
17862                    }
17863    
17864                    return null;
17865            }
17866    
17867            /**
17868             * 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;.
17869             *
17870             * @param messageId the primary key of the current message-boards message
17871             * @param userId the user ID
17872             * @param classNameId the class name ID
17873             * @param classPK the class p k
17874             * @param status the status
17875             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17876             * @return the previous, current, and next message-boards message
17877             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17878             * @throws SystemException if a system exception occurred
17879             */
17880            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
17881                    long classNameId, long classPK, int status,
17882                    OrderByComparator orderByComparator)
17883                    throws NoSuchMessageException, SystemException {
17884                    MBMessage mbMessage = findByPrimaryKey(messageId);
17885    
17886                    Session session = null;
17887    
17888                    try {
17889                            session = openSession();
17890    
17891                            MBMessage[] array = new MBMessageImpl[3];
17892    
17893                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17894                                            classNameId, classPK, status, orderByComparator, true);
17895    
17896                            array[1] = mbMessage;
17897    
17898                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17899                                            classNameId, classPK, status, orderByComparator, false);
17900    
17901                            return array;
17902                    }
17903                    catch (Exception e) {
17904                            throw processException(e);
17905                    }
17906                    finally {
17907                            closeSession(session);
17908                    }
17909            }
17910    
17911            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
17912                    MBMessage mbMessage, long userId, long classNameId, long classPK,
17913                    int status, OrderByComparator orderByComparator, boolean previous) {
17914                    StringBundler query = null;
17915    
17916                    if (orderByComparator != null) {
17917                            query = new StringBundler(6 +
17918                                            (orderByComparator.getOrderByFields().length * 6));
17919                    }
17920                    else {
17921                            query = new StringBundler(3);
17922                    }
17923    
17924                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17925    
17926                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17927    
17928                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17929    
17930                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17931    
17932                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17933    
17934                    if (orderByComparator != null) {
17935                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17936    
17937                            if (orderByConditionFields.length > 0) {
17938                                    query.append(WHERE_AND);
17939                            }
17940    
17941                            for (int i = 0; i < orderByConditionFields.length; i++) {
17942                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17943                                    query.append(orderByConditionFields[i]);
17944    
17945                                    if ((i + 1) < orderByConditionFields.length) {
17946                                            if (orderByComparator.isAscending() ^ previous) {
17947                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17948                                            }
17949                                            else {
17950                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17951                                            }
17952                                    }
17953                                    else {
17954                                            if (orderByComparator.isAscending() ^ previous) {
17955                                                    query.append(WHERE_GREATER_THAN);
17956                                            }
17957                                            else {
17958                                                    query.append(WHERE_LESSER_THAN);
17959                                            }
17960                                    }
17961                            }
17962    
17963                            query.append(ORDER_BY_CLAUSE);
17964    
17965                            String[] orderByFields = orderByComparator.getOrderByFields();
17966    
17967                            for (int i = 0; i < orderByFields.length; i++) {
17968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17969                                    query.append(orderByFields[i]);
17970    
17971                                    if ((i + 1) < orderByFields.length) {
17972                                            if (orderByComparator.isAscending() ^ previous) {
17973                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17974                                            }
17975                                            else {
17976                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17977                                            }
17978                                    }
17979                                    else {
17980                                            if (orderByComparator.isAscending() ^ previous) {
17981                                                    query.append(ORDER_BY_ASC);
17982                                            }
17983                                            else {
17984                                                    query.append(ORDER_BY_DESC);
17985                                            }
17986                                    }
17987                            }
17988                    }
17989                    else {
17990                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17991                    }
17992    
17993                    String sql = query.toString();
17994    
17995                    Query q = session.createQuery(sql);
17996    
17997                    q.setFirstResult(0);
17998                    q.setMaxResults(2);
17999    
18000                    QueryPos qPos = QueryPos.getInstance(q);
18001    
18002                    qPos.add(userId);
18003    
18004                    qPos.add(classNameId);
18005    
18006                    qPos.add(classPK);
18007    
18008                    qPos.add(status);
18009    
18010                    if (orderByComparator != null) {
18011                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18012    
18013                            for (Object value : values) {
18014                                    qPos.add(value);
18015                            }
18016                    }
18017    
18018                    List<MBMessage> list = q.list();
18019    
18020                    if (list.size() == 2) {
18021                            return list.get(1);
18022                    }
18023                    else {
18024                            return null;
18025                    }
18026            }
18027    
18028            /**
18029             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18030             *
18031             * @param userId the user ID
18032             * @param classNameId the class name ID
18033             * @param classPK the class p k
18034             * @param status the status
18035             * @throws SystemException if a system exception occurred
18036             */
18037            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18038                    int status) throws SystemException {
18039                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18040                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18041                            remove(mbMessage);
18042                    }
18043            }
18044    
18045            /**
18046             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18047             *
18048             * @param userId the user ID
18049             * @param classNameId the class name ID
18050             * @param classPK the class p k
18051             * @param status the status
18052             * @return the number of matching message-boards messages
18053             * @throws SystemException if a system exception occurred
18054             */
18055            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18056                    int status) throws SystemException {
18057                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18058    
18059                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18060    
18061                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18062                                    this);
18063    
18064                    if (count == null) {
18065                            StringBundler query = new StringBundler(5);
18066    
18067                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18068    
18069                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18070    
18071                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18072    
18073                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18074    
18075                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18076    
18077                            String sql = query.toString();
18078    
18079                            Session session = null;
18080    
18081                            try {
18082                                    session = openSession();
18083    
18084                                    Query q = session.createQuery(sql);
18085    
18086                                    QueryPos qPos = QueryPos.getInstance(q);
18087    
18088                                    qPos.add(userId);
18089    
18090                                    qPos.add(classNameId);
18091    
18092                                    qPos.add(classPK);
18093    
18094                                    qPos.add(status);
18095    
18096                                    count = (Long)q.uniqueResult();
18097    
18098                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18099                            }
18100                            catch (Exception e) {
18101                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18102    
18103                                    throw processException(e);
18104                            }
18105                            finally {
18106                                    closeSession(session);
18107                            }
18108                    }
18109    
18110                    return count.intValue();
18111            }
18112    
18113            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18114            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18115            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18116            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18117    
18118            /**
18119             * Caches the message-boards message in the entity cache if it is enabled.
18120             *
18121             * @param mbMessage the message-boards message
18122             */
18123            public void cacheResult(MBMessage mbMessage) {
18124                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18125                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18126    
18127                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18128                            new Object[] {
18129                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
18130                            }, mbMessage);
18131    
18132                    mbMessage.resetOriginalValues();
18133            }
18134    
18135            /**
18136             * Caches the message-boards messages in the entity cache if it is enabled.
18137             *
18138             * @param mbMessages the message-boards messages
18139             */
18140            public void cacheResult(List<MBMessage> mbMessages) {
18141                    for (MBMessage mbMessage : mbMessages) {
18142                            if (EntityCacheUtil.getResult(
18143                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18144                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18145                                    cacheResult(mbMessage);
18146                            }
18147                            else {
18148                                    mbMessage.resetOriginalValues();
18149                            }
18150                    }
18151            }
18152    
18153            /**
18154             * Clears the cache for all message-boards messages.
18155             *
18156             * <p>
18157             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18158             * </p>
18159             */
18160            @Override
18161            public void clearCache() {
18162                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
18163                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
18164                    }
18165    
18166                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
18167    
18168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18169                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18171            }
18172    
18173            /**
18174             * Clears the cache for the message-boards message.
18175             *
18176             * <p>
18177             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18178             * </p>
18179             */
18180            @Override
18181            public void clearCache(MBMessage mbMessage) {
18182                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18183                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18184    
18185                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18187    
18188                    clearUniqueFindersCache(mbMessage);
18189            }
18190    
18191            @Override
18192            public void clearCache(List<MBMessage> mbMessages) {
18193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18195    
18196                    for (MBMessage mbMessage : mbMessages) {
18197                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18198                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18199    
18200                            clearUniqueFindersCache(mbMessage);
18201                    }
18202            }
18203    
18204            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
18205                    if (mbMessage.isNew()) {
18206                            Object[] args = new Object[] {
18207                                            mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
18208                                    };
18209    
18210                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18211                                    Long.valueOf(1));
18212                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18213                                    mbMessage);
18214                    }
18215                    else {
18216                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18217    
18218                            if ((mbMessageModelImpl.getColumnBitmask() &
18219                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18220                                    Object[] args = new Object[] {
18221                                                    mbMessage.getUuid(),
18222                                                    Long.valueOf(mbMessage.getGroupId())
18223                                            };
18224    
18225                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18226                                            Long.valueOf(1));
18227                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18228                                            mbMessage);
18229                            }
18230                    }
18231            }
18232    
18233            protected void clearUniqueFindersCache(MBMessage mbMessage) {
18234                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18235    
18236                    Object[] args = new Object[] {
18237                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
18238                            };
18239    
18240                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18241                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18242    
18243                    if ((mbMessageModelImpl.getColumnBitmask() &
18244                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18245                            args = new Object[] {
18246                                            mbMessageModelImpl.getOriginalUuid(),
18247                                            Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
18248                                    };
18249    
18250                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18251                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18252                    }
18253            }
18254    
18255            /**
18256             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18257             *
18258             * @param messageId the primary key for the new message-boards message
18259             * @return the new message-boards message
18260             */
18261            public MBMessage create(long messageId) {
18262                    MBMessage mbMessage = new MBMessageImpl();
18263    
18264                    mbMessage.setNew(true);
18265                    mbMessage.setPrimaryKey(messageId);
18266    
18267                    String uuid = PortalUUIDUtil.generate();
18268    
18269                    mbMessage.setUuid(uuid);
18270    
18271                    return mbMessage;
18272            }
18273    
18274            /**
18275             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18276             *
18277             * @param messageId the primary key of the message-boards message
18278             * @return the message-boards message that was removed
18279             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18280             * @throws SystemException if a system exception occurred
18281             */
18282            public MBMessage remove(long messageId)
18283                    throws NoSuchMessageException, SystemException {
18284                    return remove(Long.valueOf(messageId));
18285            }
18286    
18287            /**
18288             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18289             *
18290             * @param primaryKey the primary key of the message-boards message
18291             * @return the message-boards message that was removed
18292             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18293             * @throws SystemException if a system exception occurred
18294             */
18295            @Override
18296            public MBMessage remove(Serializable primaryKey)
18297                    throws NoSuchMessageException, SystemException {
18298                    Session session = null;
18299    
18300                    try {
18301                            session = openSession();
18302    
18303                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18304                                            primaryKey);
18305    
18306                            if (mbMessage == null) {
18307                                    if (_log.isWarnEnabled()) {
18308                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18309                                    }
18310    
18311                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18312                                            primaryKey);
18313                            }
18314    
18315                            return remove(mbMessage);
18316                    }
18317                    catch (NoSuchMessageException nsee) {
18318                            throw nsee;
18319                    }
18320                    catch (Exception e) {
18321                            throw processException(e);
18322                    }
18323                    finally {
18324                            closeSession(session);
18325                    }
18326            }
18327    
18328            @Override
18329            protected MBMessage removeImpl(MBMessage mbMessage)
18330                    throws SystemException {
18331                    mbMessage = toUnwrappedModel(mbMessage);
18332    
18333                    Session session = null;
18334    
18335                    try {
18336                            session = openSession();
18337    
18338                            if (!session.contains(mbMessage)) {
18339                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18340                                                    mbMessage.getPrimaryKeyObj());
18341                            }
18342    
18343                            if (mbMessage != null) {
18344                                    session.delete(mbMessage);
18345                            }
18346                    }
18347                    catch (Exception e) {
18348                            throw processException(e);
18349                    }
18350                    finally {
18351                            closeSession(session);
18352                    }
18353    
18354                    if (mbMessage != null) {
18355                            clearCache(mbMessage);
18356                    }
18357    
18358                    return mbMessage;
18359            }
18360    
18361            @Override
18362            public MBMessage updateImpl(
18363                    com.liferay.portlet.messageboards.model.MBMessage mbMessage)
18364                    throws SystemException {
18365                    mbMessage = toUnwrappedModel(mbMessage);
18366    
18367                    boolean isNew = mbMessage.isNew();
18368    
18369                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18370    
18371                    if (Validator.isNull(mbMessage.getUuid())) {
18372                            String uuid = PortalUUIDUtil.generate();
18373    
18374                            mbMessage.setUuid(uuid);
18375                    }
18376    
18377                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18378    
18379                    if (userId > 0) {
18380                            long companyId = mbMessage.getCompanyId();
18381    
18382                            long groupId = mbMessage.getGroupId();
18383    
18384                            long messageId = 0;
18385    
18386                            if (!isNew) {
18387                                    messageId = mbMessage.getPrimaryKey();
18388                            }
18389    
18390                            try {
18391                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
18392                                                    userId,
18393                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
18394                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18395                                                    mbMessage.getSubject(), null));
18396                            }
18397                            catch (SanitizerException se) {
18398                                    throw new SystemException(se);
18399                            }
18400                    }
18401    
18402                    Session session = null;
18403    
18404                    try {
18405                            session = openSession();
18406    
18407                            if (mbMessage.isNew()) {
18408                                    session.save(mbMessage);
18409    
18410                                    mbMessage.setNew(false);
18411                            }
18412                            else {
18413                                    session.merge(mbMessage);
18414                            }
18415                    }
18416                    catch (Exception e) {
18417                            throw processException(e);
18418                    }
18419                    finally {
18420                            closeSession(session);
18421                    }
18422    
18423                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18424    
18425                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
18426                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18427                    }
18428    
18429                    else {
18430                            if ((mbMessageModelImpl.getColumnBitmask() &
18431                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18432                                    Object[] args = new Object[] {
18433                                                    mbMessageModelImpl.getOriginalUuid()
18434                                            };
18435    
18436                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18437                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18438                                            args);
18439    
18440                                    args = new Object[] { mbMessageModelImpl.getUuid() };
18441    
18442                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18443                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18444                                            args);
18445                            }
18446    
18447                            if ((mbMessageModelImpl.getColumnBitmask() &
18448                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18449                                    Object[] args = new Object[] {
18450                                                    mbMessageModelImpl.getOriginalUuid(),
18451                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
18452                                            };
18453    
18454                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18455                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18456                                            args);
18457    
18458                                    args = new Object[] {
18459                                                    mbMessageModelImpl.getUuid(),
18460                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
18461                                            };
18462    
18463                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18464                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18465                                            args);
18466                            }
18467    
18468                            if ((mbMessageModelImpl.getColumnBitmask() &
18469                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
18470                                    Object[] args = new Object[] {
18471                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
18472                                            };
18473    
18474                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18475                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18476                                            args);
18477    
18478                                    args = new Object[] {
18479                                                    Long.valueOf(mbMessageModelImpl.getGroupId())
18480                                            };
18481    
18482                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18483                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18484                                            args);
18485                            }
18486    
18487                            if ((mbMessageModelImpl.getColumnBitmask() &
18488                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
18489                                    Object[] args = new Object[] {
18490                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
18491                                            };
18492    
18493                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18494                                            args);
18495                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18496                                            args);
18497    
18498                                    args = new Object[] {
18499                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
18500                                            };
18501    
18502                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18503                                            args);
18504                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18505                                            args);
18506                            }
18507    
18508                            if ((mbMessageModelImpl.getColumnBitmask() &
18509                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
18510                                    Object[] args = new Object[] {
18511                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
18512                                            };
18513    
18514                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18515                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18516                                            args);
18517    
18518                                    args = new Object[] {
18519                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
18520                                            };
18521    
18522                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18523                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18524                                            args);
18525                            }
18526    
18527                            if ((mbMessageModelImpl.getColumnBitmask() &
18528                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
18529                                    Object[] args = new Object[] {
18530                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
18531                                            };
18532    
18533                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18534                                            args);
18535                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18536                                            args);
18537    
18538                                    args = new Object[] {
18539                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
18540                                            };
18541    
18542                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18543                                            args);
18544                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18545                                            args);
18546                            }
18547    
18548                            if ((mbMessageModelImpl.getColumnBitmask() &
18549                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
18550                                    Object[] args = new Object[] {
18551                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
18552                                            };
18553    
18554                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18555                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18556                                            args);
18557    
18558                                    args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
18559    
18560                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18561                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18562                                            args);
18563                            }
18564    
18565                            if ((mbMessageModelImpl.getColumnBitmask() &
18566                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
18567                                    Object[] args = new Object[] {
18568                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18569                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
18570                                            };
18571    
18572                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18573                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18574                                            args);
18575    
18576                                    args = new Object[] {
18577                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18578                                                    Long.valueOf(mbMessageModelImpl.getUserId())
18579                                            };
18580    
18581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18583                                            args);
18584                            }
18585    
18586                            if ((mbMessageModelImpl.getColumnBitmask() &
18587                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
18588                                    Object[] args = new Object[] {
18589                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18590                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
18591                                            };
18592    
18593                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18594                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18595                                            args);
18596    
18597                                    args = new Object[] {
18598                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18599                                                    Long.valueOf(mbMessageModelImpl.getCategoryId())
18600                                            };
18601    
18602                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18603                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18604                                            args);
18605                            }
18606    
18607                            if ((mbMessageModelImpl.getColumnBitmask() &
18608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
18609                                    Object[] args = new Object[] {
18610                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18611                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18612                                            };
18613    
18614                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18615                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18616                                            args);
18617    
18618                                    args = new Object[] {
18619                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18620                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18621                                            };
18622    
18623                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18624                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18625                                            args);
18626                            }
18627    
18628                            if ((mbMessageModelImpl.getColumnBitmask() &
18629                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
18630                                    Object[] args = new Object[] {
18631                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
18632                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18633                                            };
18634    
18635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18636                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18637                                            args);
18638    
18639                                    args = new Object[] {
18640                                                    Long.valueOf(mbMessageModelImpl.getCompanyId()),
18641                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18642                                            };
18643    
18644                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18645                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18646                                            args);
18647                            }
18648    
18649                            if ((mbMessageModelImpl.getColumnBitmask() &
18650                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
18651                                    Object[] args = new Object[] {
18652                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18653                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
18654                                            };
18655    
18656                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18657                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18658                                            args);
18659    
18660                                    args = new Object[] {
18661                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
18662                                                    Long.valueOf(mbMessageModelImpl.getClassNameId())
18663                                            };
18664    
18665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18666                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18667                                            args);
18668                            }
18669    
18670                            if ((mbMessageModelImpl.getColumnBitmask() &
18671                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
18672                                    Object[] args = new Object[] {
18673                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18674                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
18675                                            };
18676    
18677                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18678                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18679                                            args);
18680    
18681                                    args = new Object[] {
18682                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
18683                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
18684                                            };
18685    
18686                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18687                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18688                                            args);
18689                            }
18690    
18691                            if ((mbMessageModelImpl.getColumnBitmask() &
18692                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
18693                                    Object[] args = new Object[] {
18694                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18695                                                    Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
18696                                            };
18697    
18698                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18699                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18700                                            args);
18701    
18702                                    args = new Object[] {
18703                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
18704                                                    Long.valueOf(mbMessageModelImpl.getParentMessageId())
18705                                            };
18706    
18707                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18708                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18709                                            args);
18710                            }
18711    
18712                            if ((mbMessageModelImpl.getColumnBitmask() &
18713                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
18714                                    Object[] args = new Object[] {
18715                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18716                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
18717                                            };
18718    
18719                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18720                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18721                                            args);
18722    
18723                                    args = new Object[] {
18724                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
18725                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
18726                                            };
18727    
18728                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18729                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18730                                            args);
18731                            }
18732    
18733                            if ((mbMessageModelImpl.getColumnBitmask() &
18734                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
18735                                    Object[] args = new Object[] {
18736                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18737                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18738                                            };
18739    
18740                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18741                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18742                                            args);
18743    
18744                                    args = new Object[] {
18745                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
18746                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18747                                            };
18748    
18749                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18750                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18751                                            args);
18752                            }
18753    
18754                            if ((mbMessageModelImpl.getColumnBitmask() &
18755                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
18756                                    Object[] args = new Object[] {
18757                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18758                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18759                                            };
18760    
18761                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18762                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18763                                            args);
18764    
18765                                    args = new Object[] {
18766                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
18767                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18768                                            };
18769    
18770                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18771                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18772                                            args);
18773                            }
18774    
18775                            if ((mbMessageModelImpl.getColumnBitmask() &
18776                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
18777                                    Object[] args = new Object[] {
18778                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18779                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18780                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18781                                            };
18782    
18783                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18784                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18785                                            args);
18786    
18787                                    args = new Object[] {
18788                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18789                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
18790                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18791                                            };
18792    
18793                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18794                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18795                                            args);
18796                            }
18797    
18798                            if ((mbMessageModelImpl.getColumnBitmask() &
18799                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
18800                                    Object[] args = new Object[] {
18801                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18802                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18803                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
18804                                            };
18805    
18806                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18807                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18808                                            args);
18809    
18810                                    args = new Object[] {
18811                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18812                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
18813                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
18814                                            };
18815    
18816                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18817                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18818                                            args);
18819                            }
18820    
18821                            if ((mbMessageModelImpl.getColumnBitmask() &
18822                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
18823                                    Object[] args = new Object[] {
18824                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18825                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18826                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18827                                            };
18828    
18829                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18830                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18831                                            args);
18832    
18833                                    args = new Object[] {
18834                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18835                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
18836                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18837                                            };
18838    
18839                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18840                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18841                                            args);
18842                            }
18843    
18844                            if ((mbMessageModelImpl.getColumnBitmask() &
18845                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
18846                                    Object[] args = new Object[] {
18847                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18848                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18849                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
18850                                            };
18851    
18852                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18853                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18854                                            args);
18855    
18856                                    args = new Object[] {
18857                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
18858                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
18859                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
18860                                            };
18861    
18862                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18863                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18864                                            args);
18865                            }
18866    
18867                            if ((mbMessageModelImpl.getColumnBitmask() &
18868                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
18869                                    Object[] args = new Object[] {
18870                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18871                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18872                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18873                                            };
18874    
18875                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18876                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18877                                            args);
18878    
18879                                    args = new Object[] {
18880                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
18881                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
18882                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18883                                            };
18884    
18885                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18886                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18887                                            args);
18888                            }
18889    
18890                            if ((mbMessageModelImpl.getColumnBitmask() &
18891                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
18892                                    Object[] args = new Object[] {
18893                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18894                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
18895                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18896                                            };
18897    
18898                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18899                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18900                                            args);
18901    
18902                                    args = new Object[] {
18903                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
18904                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
18905                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18906                                            };
18907    
18908                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18909                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18910                                            args);
18911                            }
18912    
18913                            if ((mbMessageModelImpl.getColumnBitmask() &
18914                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
18915                                    Object[] args = new Object[] {
18916                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18917                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18918                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18919                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
18920                                            };
18921    
18922                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18923                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18924                                            args);
18925    
18926                                    args = new Object[] {
18927                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18928                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
18929                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
18930                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
18931                                            };
18932    
18933                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18934                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18935                                            args);
18936                            }
18937    
18938                            if ((mbMessageModelImpl.getColumnBitmask() &
18939                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
18940                                    Object[] args = new Object[] {
18941                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18942                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18943                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18944                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18945                                            };
18946    
18947                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18948                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18949                                            args);
18950    
18951                                    args = new Object[] {
18952                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
18953                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
18954                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
18955                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18956                                            };
18957    
18958                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18959                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18960                                            args);
18961                            }
18962    
18963                            if ((mbMessageModelImpl.getColumnBitmask() &
18964                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
18965                                    Object[] args = new Object[] {
18966                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18967                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18968                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
18969                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18970                                            };
18971    
18972                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18973                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18974                                            args);
18975    
18976                                    args = new Object[] {
18977                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
18978                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
18979                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
18980                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
18981                                            };
18982    
18983                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18984                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18985                                            args);
18986                            }
18987                    }
18988    
18989                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18990                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18991    
18992                    clearUniqueFindersCache(mbMessage);
18993                    cacheUniqueFindersCache(mbMessage);
18994    
18995                    return mbMessage;
18996            }
18997    
18998            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
18999                    if (mbMessage instanceof MBMessageImpl) {
19000                            return mbMessage;
19001                    }
19002    
19003                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19004    
19005                    mbMessageImpl.setNew(mbMessage.isNew());
19006                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19007    
19008                    mbMessageImpl.setUuid(mbMessage.getUuid());
19009                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19010                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19011                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19012                    mbMessageImpl.setUserId(mbMessage.getUserId());
19013                    mbMessageImpl.setUserName(mbMessage.getUserName());
19014                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19015                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19016                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19017                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19018                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19019                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19020                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19021                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19022                    mbMessageImpl.setSubject(mbMessage.getSubject());
19023                    mbMessageImpl.setBody(mbMessage.getBody());
19024                    mbMessageImpl.setFormat(mbMessage.getFormat());
19025                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19026                    mbMessageImpl.setPriority(mbMessage.getPriority());
19027                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19028                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19029                    mbMessageImpl.setStatus(mbMessage.getStatus());
19030                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19031                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19032                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19033    
19034                    return mbMessageImpl;
19035            }
19036    
19037            /**
19038             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19039             *
19040             * @param primaryKey the primary key of the message-boards message
19041             * @return the message-boards message
19042             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
19043             * @throws SystemException if a system exception occurred
19044             */
19045            @Override
19046            public MBMessage findByPrimaryKey(Serializable primaryKey)
19047                    throws NoSuchModelException, SystemException {
19048                    return findByPrimaryKey(((Long)primaryKey).longValue());
19049            }
19050    
19051            /**
19052             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
19053             *
19054             * @param messageId the primary key of the message-boards message
19055             * @return the message-boards message
19056             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19057             * @throws SystemException if a system exception occurred
19058             */
19059            public MBMessage findByPrimaryKey(long messageId)
19060                    throws NoSuchMessageException, SystemException {
19061                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
19062    
19063                    if (mbMessage == null) {
19064                            if (_log.isWarnEnabled()) {
19065                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
19066                            }
19067    
19068                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19069                                    messageId);
19070                    }
19071    
19072                    return mbMessage;
19073            }
19074    
19075            /**
19076             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19077             *
19078             * @param primaryKey the primary key of the message-boards message
19079             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19080             * @throws SystemException if a system exception occurred
19081             */
19082            @Override
19083            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
19084                    throws SystemException {
19085                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
19086            }
19087    
19088            /**
19089             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19090             *
19091             * @param messageId the primary key of the message-boards message
19092             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19093             * @throws SystemException if a system exception occurred
19094             */
19095            public MBMessage fetchByPrimaryKey(long messageId)
19096                    throws SystemException {
19097                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19098                                    MBMessageImpl.class, messageId);
19099    
19100                    if (mbMessage == _nullMBMessage) {
19101                            return null;
19102                    }
19103    
19104                    if (mbMessage == null) {
19105                            Session session = null;
19106    
19107                            try {
19108                                    session = openSession();
19109    
19110                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19111                                                    Long.valueOf(messageId));
19112    
19113                                    if (mbMessage != null) {
19114                                            cacheResult(mbMessage);
19115                                    }
19116                                    else {
19117                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19118                                                    MBMessageImpl.class, messageId, _nullMBMessage);
19119                                    }
19120                            }
19121                            catch (Exception e) {
19122                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19123                                            MBMessageImpl.class, messageId);
19124    
19125                                    throw processException(e);
19126                            }
19127                            finally {
19128                                    closeSession(session);
19129                            }
19130                    }
19131    
19132                    return mbMessage;
19133            }
19134    
19135            /**
19136             * Returns all the message-boards messages.
19137             *
19138             * @return the message-boards messages
19139             * @throws SystemException if a system exception occurred
19140             */
19141            public List<MBMessage> findAll() throws SystemException {
19142                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19143            }
19144    
19145            /**
19146             * Returns a range of all the message-boards messages.
19147             *
19148             * <p>
19149             * 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.
19150             * </p>
19151             *
19152             * @param start the lower bound of the range of message-boards messages
19153             * @param end the upper bound of the range of message-boards messages (not inclusive)
19154             * @return the range of message-boards messages
19155             * @throws SystemException if a system exception occurred
19156             */
19157            public List<MBMessage> findAll(int start, int end)
19158                    throws SystemException {
19159                    return findAll(start, end, null);
19160            }
19161    
19162            /**
19163             * Returns an ordered range of all the message-boards messages.
19164             *
19165             * <p>
19166             * 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.
19167             * </p>
19168             *
19169             * @param start the lower bound of the range of message-boards messages
19170             * @param end the upper bound of the range of message-boards messages (not inclusive)
19171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19172             * @return the ordered range of message-boards messages
19173             * @throws SystemException if a system exception occurred
19174             */
19175            public List<MBMessage> findAll(int start, int end,
19176                    OrderByComparator orderByComparator) throws SystemException {
19177                    boolean pagination = true;
19178                    FinderPath finderPath = null;
19179                    Object[] finderArgs = null;
19180    
19181                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19182                                    (orderByComparator == null)) {
19183                            pagination = false;
19184                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19185                            finderArgs = FINDER_ARGS_EMPTY;
19186                    }
19187                    else {
19188                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19189                            finderArgs = new Object[] { start, end, orderByComparator };
19190                    }
19191    
19192                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19193                                    finderArgs, this);
19194    
19195                    if (list == null) {
19196                            StringBundler query = null;
19197                            String sql = null;
19198    
19199                            if (orderByComparator != null) {
19200                                    query = new StringBundler(2 +
19201                                                    (orderByComparator.getOrderByFields().length * 3));
19202    
19203                                    query.append(_SQL_SELECT_MBMESSAGE);
19204    
19205                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19206                                            orderByComparator);
19207    
19208                                    sql = query.toString();
19209                            }
19210                            else {
19211                                    sql = _SQL_SELECT_MBMESSAGE;
19212    
19213                                    if (pagination) {
19214                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
19215                                    }
19216                            }
19217    
19218                            Session session = null;
19219    
19220                            try {
19221                                    session = openSession();
19222    
19223                                    Query q = session.createQuery(sql);
19224    
19225                                    if (!pagination) {
19226                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19227                                                            start, end, false);
19228    
19229                                            Collections.sort(list);
19230    
19231                                            list = new UnmodifiableList<MBMessage>(list);
19232                                    }
19233                                    else {
19234                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19235                                                            start, end);
19236                                    }
19237    
19238                                    cacheResult(list);
19239    
19240                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19241                            }
19242                            catch (Exception e) {
19243                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19244    
19245                                    throw processException(e);
19246                            }
19247                            finally {
19248                                    closeSession(session);
19249                            }
19250                    }
19251    
19252                    return list;
19253            }
19254    
19255            /**
19256             * Removes all the message-boards messages from the database.
19257             *
19258             * @throws SystemException if a system exception occurred
19259             */
19260            public void removeAll() throws SystemException {
19261                    for (MBMessage mbMessage : findAll()) {
19262                            remove(mbMessage);
19263                    }
19264            }
19265    
19266            /**
19267             * Returns the number of message-boards messages.
19268             *
19269             * @return the number of message-boards messages
19270             * @throws SystemException if a system exception occurred
19271             */
19272            public int countAll() throws SystemException {
19273                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19274                                    FINDER_ARGS_EMPTY, this);
19275    
19276                    if (count == null) {
19277                            Session session = null;
19278    
19279                            try {
19280                                    session = openSession();
19281    
19282                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
19283    
19284                                    count = (Long)q.uniqueResult();
19285    
19286                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19287                                            FINDER_ARGS_EMPTY, count);
19288                            }
19289                            catch (Exception e) {
19290                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19291                                            FINDER_ARGS_EMPTY);
19292    
19293                                    throw processException(e);
19294                            }
19295                            finally {
19296                                    closeSession(session);
19297                            }
19298                    }
19299    
19300                    return count.intValue();
19301            }
19302    
19303            /**
19304             * Initializes the message-boards message persistence.
19305             */
19306            public void afterPropertiesSet() {
19307                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
19308                                            com.liferay.portal.util.PropsUtil.get(
19309                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
19310    
19311                    if (listenerClassNames.length > 0) {
19312                            try {
19313                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
19314    
19315                                    for (String listenerClassName : listenerClassNames) {
19316                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
19317                                                            listenerClassName));
19318                                    }
19319    
19320                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
19321                            }
19322                            catch (Exception e) {
19323                                    _log.error(e);
19324                            }
19325                    }
19326            }
19327    
19328            public void destroy() {
19329                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
19330                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19331                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19332                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19333            }
19334    
19335            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19336            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19337            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19338            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19339    
19340            private static String _removeConjunction(String sql) {
19341                    int pos = sql.indexOf(" AND ");
19342    
19343                    if (pos != -1) {
19344                            sql = sql.substring(0, pos);
19345                    }
19346    
19347                    return sql;
19348            }
19349    
19350            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19351            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19352            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19353                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19354            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19355                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19356            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19357            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19358            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19359            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19360            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19361            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19362            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19363            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19364            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19365            private static MBMessage _nullMBMessage = new MBMessageImpl() {
19366                            @Override
19367                            public Object clone() {
19368                                    return this;
19369                            }
19370    
19371                            @Override
19372                            public CacheModel<MBMessage> toCacheModel() {
19373                                    return _nullMBMessageCacheModel;
19374                            }
19375                    };
19376    
19377            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19378                            public MBMessage toEntityModel() {
19379                                    return _nullMBMessage;
19380                            }
19381                    };
19382    }