001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.sanitizer.Sanitizer;
030    import com.liferay.portal.kernel.sanitizer.SanitizerException;
031    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
032    import com.liferay.portal.kernel.util.ArrayUtil;
033    import com.liferay.portal.kernel.util.ContentTypes;
034    import com.liferay.portal.kernel.util.GetterUtil;
035    import com.liferay.portal.kernel.util.InstanceFactory;
036    import com.liferay.portal.kernel.util.OrderByComparator;
037    import com.liferay.portal.kernel.util.SetUtil;
038    import com.liferay.portal.kernel.util.StringBundler;
039    import com.liferay.portal.kernel.util.StringPool;
040    import com.liferay.portal.kernel.util.StringUtil;
041    import com.liferay.portal.kernel.util.UnmodifiableList;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049    
050    import com.liferay.portlet.messageboards.NoSuchMessageException;
051    import com.liferay.portlet.messageboards.model.MBMessage;
052    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
053    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
054    
055    import java.io.Serializable;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.List;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the message-boards message service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see MBMessagePersistence
071     * @see MBMessageUtil
072     * @generated
073     */
074    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
075            implements MBMessagePersistence {
076            /*
077             * NOTE FOR DEVELOPERS:
078             *
079             * Never modify or reference this class directly. Always use {@link MBMessageUtil} to access the message-boards message persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
080             */
081            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List1";
084            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List2";
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
087                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
090                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
093                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
105                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
107                            new String[] { String.class.getName() },
108                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
109                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
111                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
113                            new String[] { String.class.getName() });
114    
115            /**
116             * Returns all the message-boards messages where uuid = &#63;.
117             *
118             * @param uuid the uuid
119             * @return the matching message-boards messages
120             * @throws SystemException if a system exception occurred
121             */
122            @Override
123            public List<MBMessage> findByUuid(String uuid) throws SystemException {
124                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the message-boards messages where uuid = &#63;.
129             *
130             * <p>
131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
132             * </p>
133             *
134             * @param uuid the uuid
135             * @param start the lower bound of the range of message-boards messages
136             * @param end the upper bound of the range of message-boards messages (not inclusive)
137             * @return the range of matching message-boards messages
138             * @throws SystemException if a system exception occurred
139             */
140            @Override
141            public List<MBMessage> findByUuid(String uuid, int start, int end)
142                    throws SystemException {
143                    return findByUuid(uuid, start, end, null);
144            }
145    
146            /**
147             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
148             *
149             * <p>
150             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
151             * </p>
152             *
153             * @param uuid the uuid
154             * @param start the lower bound of the range of message-boards messages
155             * @param end the upper bound of the range of message-boards messages (not inclusive)
156             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
157             * @return the ordered range of matching message-boards messages
158             * @throws SystemException if a system exception occurred
159             */
160            @Override
161            public List<MBMessage> findByUuid(String uuid, int start, int end,
162                    OrderByComparator orderByComparator) throws SystemException {
163                    boolean pagination = true;
164                    FinderPath finderPath = null;
165                    Object[] finderArgs = null;
166    
167                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
168                                    (orderByComparator == null)) {
169                            pagination = false;
170                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
171                            finderArgs = new Object[] { uuid };
172                    }
173                    else {
174                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
175                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
176                    }
177    
178                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
179                                    finderArgs, this);
180    
181                    if ((list != null) && !list.isEmpty()) {
182                            for (MBMessage mbMessage : list) {
183                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
184                                            list = null;
185    
186                                            break;
187                                    }
188                            }
189                    }
190    
191                    if (list == null) {
192                            StringBundler query = null;
193    
194                            if (orderByComparator != null) {
195                                    query = new StringBundler(3 +
196                                                    (orderByComparator.getOrderByFields().length * 3));
197                            }
198                            else {
199                                    query = new StringBundler(3);
200                            }
201    
202                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
203    
204                            boolean bindUuid = false;
205    
206                            if (uuid == null) {
207                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
208                            }
209                            else if (uuid.equals(StringPool.BLANK)) {
210                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
211                            }
212                            else {
213                                    bindUuid = true;
214    
215                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
216                            }
217    
218                            if (orderByComparator != null) {
219                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
220                                            orderByComparator);
221                            }
222                            else
223                             if (pagination) {
224                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
225                            }
226    
227                            String sql = query.toString();
228    
229                            Session session = null;
230    
231                            try {
232                                    session = openSession();
233    
234                                    Query q = session.createQuery(sql);
235    
236                                    QueryPos qPos = QueryPos.getInstance(q);
237    
238                                    if (bindUuid) {
239                                            qPos.add(uuid);
240                                    }
241    
242                                    if (!pagination) {
243                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
244                                                            start, end, false);
245    
246                                            Collections.sort(list);
247    
248                                            list = new UnmodifiableList<MBMessage>(list);
249                                    }
250                                    else {
251                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
252                                                            start, end);
253                                    }
254    
255                                    cacheResult(list);
256    
257                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
258                            }
259                            catch (Exception e) {
260                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
261    
262                                    throw processException(e);
263                            }
264                            finally {
265                                    closeSession(session);
266                            }
267                    }
268    
269                    return list;
270            }
271    
272            /**
273             * Returns the first message-boards message in the ordered set where uuid = &#63;.
274             *
275             * @param uuid the uuid
276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
277             * @return the first matching message-boards message
278             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
279             * @throws SystemException if a system exception occurred
280             */
281            @Override
282            public MBMessage findByUuid_First(String uuid,
283                    OrderByComparator orderByComparator)
284                    throws NoSuchMessageException, SystemException {
285                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
286    
287                    if (mbMessage != null) {
288                            return mbMessage;
289                    }
290    
291                    StringBundler msg = new StringBundler(4);
292    
293                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
294    
295                    msg.append("uuid=");
296                    msg.append(uuid);
297    
298                    msg.append(StringPool.CLOSE_CURLY_BRACE);
299    
300                    throw new NoSuchMessageException(msg.toString());
301            }
302    
303            /**
304             * Returns the first message-boards message in the ordered set where uuid = &#63;.
305             *
306             * @param uuid the uuid
307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
308             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
309             * @throws SystemException if a system exception occurred
310             */
311            @Override
312            public MBMessage fetchByUuid_First(String uuid,
313                    OrderByComparator orderByComparator) throws SystemException {
314                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
315    
316                    if (!list.isEmpty()) {
317                            return list.get(0);
318                    }
319    
320                    return null;
321            }
322    
323            /**
324             * Returns the last message-boards message in the ordered set where uuid = &#63;.
325             *
326             * @param uuid the uuid
327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
328             * @return the last matching message-boards message
329             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
330             * @throws SystemException if a system exception occurred
331             */
332            @Override
333            public MBMessage findByUuid_Last(String uuid,
334                    OrderByComparator orderByComparator)
335                    throws NoSuchMessageException, SystemException {
336                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
337    
338                    if (mbMessage != null) {
339                            return mbMessage;
340                    }
341    
342                    StringBundler msg = new StringBundler(4);
343    
344                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
345    
346                    msg.append("uuid=");
347                    msg.append(uuid);
348    
349                    msg.append(StringPool.CLOSE_CURLY_BRACE);
350    
351                    throw new NoSuchMessageException(msg.toString());
352            }
353    
354            /**
355             * Returns the last message-boards message in the ordered set where uuid = &#63;.
356             *
357             * @param uuid the uuid
358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
359             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
360             * @throws SystemException if a system exception occurred
361             */
362            @Override
363            public MBMessage fetchByUuid_Last(String uuid,
364                    OrderByComparator orderByComparator) throws SystemException {
365                    int count = countByUuid(uuid);
366    
367                    if (count == 0) {
368                            return null;
369                    }
370    
371                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
372                                    orderByComparator);
373    
374                    if (!list.isEmpty()) {
375                            return list.get(0);
376                    }
377    
378                    return null;
379            }
380    
381            /**
382             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
383             *
384             * @param messageId the primary key of the current message-boards message
385             * @param uuid the uuid
386             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
387             * @return the previous, current, and next message-boards message
388             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
389             * @throws SystemException if a system exception occurred
390             */
391            @Override
392            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
393                    OrderByComparator orderByComparator)
394                    throws NoSuchMessageException, SystemException {
395                    MBMessage mbMessage = findByPrimaryKey(messageId);
396    
397                    Session session = null;
398    
399                    try {
400                            session = openSession();
401    
402                            MBMessage[] array = new MBMessageImpl[3];
403    
404                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
405                                            orderByComparator, true);
406    
407                            array[1] = mbMessage;
408    
409                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
410                                            orderByComparator, false);
411    
412                            return array;
413                    }
414                    catch (Exception e) {
415                            throw processException(e);
416                    }
417                    finally {
418                            closeSession(session);
419                    }
420            }
421    
422            protected MBMessage getByUuid_PrevAndNext(Session session,
423                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
424                    boolean previous) {
425                    StringBundler query = null;
426    
427                    if (orderByComparator != null) {
428                            query = new StringBundler(6 +
429                                            (orderByComparator.getOrderByFields().length * 6));
430                    }
431                    else {
432                            query = new StringBundler(3);
433                    }
434    
435                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
436    
437                    boolean bindUuid = false;
438    
439                    if (uuid == null) {
440                            query.append(_FINDER_COLUMN_UUID_UUID_1);
441                    }
442                    else if (uuid.equals(StringPool.BLANK)) {
443                            query.append(_FINDER_COLUMN_UUID_UUID_3);
444                    }
445                    else {
446                            bindUuid = true;
447    
448                            query.append(_FINDER_COLUMN_UUID_UUID_2);
449                    }
450    
451                    if (orderByComparator != null) {
452                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
453    
454                            if (orderByConditionFields.length > 0) {
455                                    query.append(WHERE_AND);
456                            }
457    
458                            for (int i = 0; i < orderByConditionFields.length; i++) {
459                                    query.append(_ORDER_BY_ENTITY_ALIAS);
460                                    query.append(orderByConditionFields[i]);
461    
462                                    if ((i + 1) < orderByConditionFields.length) {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
468                                            }
469                                    }
470                                    else {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(WHERE_GREATER_THAN);
473                                            }
474                                            else {
475                                                    query.append(WHERE_LESSER_THAN);
476                                            }
477                                    }
478                            }
479    
480                            query.append(ORDER_BY_CLAUSE);
481    
482                            String[] orderByFields = orderByComparator.getOrderByFields();
483    
484                            for (int i = 0; i < orderByFields.length; i++) {
485                                    query.append(_ORDER_BY_ENTITY_ALIAS);
486                                    query.append(orderByFields[i]);
487    
488                                    if ((i + 1) < orderByFields.length) {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
494                                            }
495                                    }
496                                    else {
497                                            if (orderByComparator.isAscending() ^ previous) {
498                                                    query.append(ORDER_BY_ASC);
499                                            }
500                                            else {
501                                                    query.append(ORDER_BY_DESC);
502                                            }
503                                    }
504                            }
505                    }
506                    else {
507                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
508                    }
509    
510                    String sql = query.toString();
511    
512                    Query q = session.createQuery(sql);
513    
514                    q.setFirstResult(0);
515                    q.setMaxResults(2);
516    
517                    QueryPos qPos = QueryPos.getInstance(q);
518    
519                    if (bindUuid) {
520                            qPos.add(uuid);
521                    }
522    
523                    if (orderByComparator != null) {
524                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
525    
526                            for (Object value : values) {
527                                    qPos.add(value);
528                            }
529                    }
530    
531                    List<MBMessage> list = q.list();
532    
533                    if (list.size() == 2) {
534                            return list.get(1);
535                    }
536                    else {
537                            return null;
538                    }
539            }
540    
541            /**
542             * Removes all the message-boards messages where uuid = &#63; from the database.
543             *
544             * @param uuid the uuid
545             * @throws SystemException if a system exception occurred
546             */
547            @Override
548            public void removeByUuid(String uuid) throws SystemException {
549                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
550                                    QueryUtil.ALL_POS, null)) {
551                            remove(mbMessage);
552                    }
553            }
554    
555            /**
556             * Returns the number of message-boards messages where uuid = &#63;.
557             *
558             * @param uuid the uuid
559             * @return the number of matching message-boards messages
560             * @throws SystemException if a system exception occurred
561             */
562            @Override
563            public int countByUuid(String uuid) throws SystemException {
564                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
565    
566                    Object[] finderArgs = new Object[] { uuid };
567    
568                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
569                                    this);
570    
571                    if (count == null) {
572                            StringBundler query = new StringBundler(2);
573    
574                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
575    
576                            boolean bindUuid = false;
577    
578                            if (uuid == null) {
579                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
580                            }
581                            else if (uuid.equals(StringPool.BLANK)) {
582                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
583                            }
584                            else {
585                                    bindUuid = true;
586    
587                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
588                            }
589    
590                            String sql = query.toString();
591    
592                            Session session = null;
593    
594                            try {
595                                    session = openSession();
596    
597                                    Query q = session.createQuery(sql);
598    
599                                    QueryPos qPos = QueryPos.getInstance(q);
600    
601                                    if (bindUuid) {
602                                            qPos.add(uuid);
603                                    }
604    
605                                    count = (Long)q.uniqueResult();
606    
607                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
608                            }
609                            catch (Exception e) {
610                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
611    
612                                    throw processException(e);
613                            }
614                            finally {
615                                    closeSession(session);
616                            }
617                    }
618    
619                    return count.intValue();
620            }
621    
622            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
623            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
624            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
625            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
626                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
627                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
628                            new String[] { String.class.getName(), Long.class.getName() },
629                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
630                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
631            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
632                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
633                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
634                            new String[] { String.class.getName(), Long.class.getName() });
635    
636            /**
637             * 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.
638             *
639             * @param uuid the uuid
640             * @param groupId the group ID
641             * @return the matching message-boards message
642             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
643             * @throws SystemException if a system exception occurred
644             */
645            @Override
646            public MBMessage findByUUID_G(String uuid, long groupId)
647                    throws NoSuchMessageException, SystemException {
648                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
649    
650                    if (mbMessage == null) {
651                            StringBundler msg = new StringBundler(6);
652    
653                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
654    
655                            msg.append("uuid=");
656                            msg.append(uuid);
657    
658                            msg.append(", groupId=");
659                            msg.append(groupId);
660    
661                            msg.append(StringPool.CLOSE_CURLY_BRACE);
662    
663                            if (_log.isWarnEnabled()) {
664                                    _log.warn(msg.toString());
665                            }
666    
667                            throw new NoSuchMessageException(msg.toString());
668                    }
669    
670                    return mbMessage;
671            }
672    
673            /**
674             * 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.
675             *
676             * @param uuid the uuid
677             * @param groupId the group ID
678             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            @Override
682            public MBMessage fetchByUUID_G(String uuid, long groupId)
683                    throws SystemException {
684                    return fetchByUUID_G(uuid, groupId, true);
685            }
686    
687            /**
688             * 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.
689             *
690             * @param uuid the uuid
691             * @param groupId the group ID
692             * @param retrieveFromCache whether to use the finder cache
693             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
694             * @throws SystemException if a system exception occurred
695             */
696            @Override
697            public MBMessage fetchByUUID_G(String uuid, long groupId,
698                    boolean retrieveFromCache) throws SystemException {
699                    Object[] finderArgs = new Object[] { uuid, groupId };
700    
701                    Object result = null;
702    
703                    if (retrieveFromCache) {
704                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
705                                            finderArgs, this);
706                    }
707    
708                    if (result instanceof MBMessage) {
709                            MBMessage mbMessage = (MBMessage)result;
710    
711                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
712                                            (groupId != mbMessage.getGroupId())) {
713                                    result = null;
714                            }
715                    }
716    
717                    if (result == null) {
718                            StringBundler query = new StringBundler(4);
719    
720                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
721    
722                            boolean bindUuid = false;
723    
724                            if (uuid == null) {
725                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
726                            }
727                            else if (uuid.equals(StringPool.BLANK)) {
728                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
729                            }
730                            else {
731                                    bindUuid = true;
732    
733                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
734                            }
735    
736                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
737    
738                            String sql = query.toString();
739    
740                            Session session = null;
741    
742                            try {
743                                    session = openSession();
744    
745                                    Query q = session.createQuery(sql);
746    
747                                    QueryPos qPos = QueryPos.getInstance(q);
748    
749                                    if (bindUuid) {
750                                            qPos.add(uuid);
751                                    }
752    
753                                    qPos.add(groupId);
754    
755                                    List<MBMessage> list = q.list();
756    
757                                    if (list.isEmpty()) {
758                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
759                                                    finderArgs, list);
760                                    }
761                                    else {
762                                            MBMessage mbMessage = list.get(0);
763    
764                                            result = mbMessage;
765    
766                                            cacheResult(mbMessage);
767    
768                                            if ((mbMessage.getUuid() == null) ||
769                                                            !mbMessage.getUuid().equals(uuid) ||
770                                                            (mbMessage.getGroupId() != groupId)) {
771                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
772                                                            finderArgs, mbMessage);
773                                            }
774                                    }
775                            }
776                            catch (Exception e) {
777                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
778                                            finderArgs);
779    
780                                    throw processException(e);
781                            }
782                            finally {
783                                    closeSession(session);
784                            }
785                    }
786    
787                    if (result instanceof List<?>) {
788                            return null;
789                    }
790                    else {
791                            return (MBMessage)result;
792                    }
793            }
794    
795            /**
796             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
797             *
798             * @param uuid the uuid
799             * @param groupId the group ID
800             * @return the message-boards message that was removed
801             * @throws SystemException if a system exception occurred
802             */
803            @Override
804            public MBMessage removeByUUID_G(String uuid, long groupId)
805                    throws NoSuchMessageException, SystemException {
806                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
807    
808                    return remove(mbMessage);
809            }
810    
811            /**
812             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
813             *
814             * @param uuid the uuid
815             * @param groupId the group ID
816             * @return the number of matching message-boards messages
817             * @throws SystemException if a system exception occurred
818             */
819            @Override
820            public int countByUUID_G(String uuid, long groupId)
821                    throws SystemException {
822                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
823    
824                    Object[] finderArgs = new Object[] { uuid, groupId };
825    
826                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
827                                    this);
828    
829                    if (count == null) {
830                            StringBundler query = new StringBundler(3);
831    
832                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
833    
834                            boolean bindUuid = false;
835    
836                            if (uuid == null) {
837                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
838                            }
839                            else if (uuid.equals(StringPool.BLANK)) {
840                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
841                            }
842                            else {
843                                    bindUuid = true;
844    
845                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
846                            }
847    
848                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
849    
850                            String sql = query.toString();
851    
852                            Session session = null;
853    
854                            try {
855                                    session = openSession();
856    
857                                    Query q = session.createQuery(sql);
858    
859                                    QueryPos qPos = QueryPos.getInstance(q);
860    
861                                    if (bindUuid) {
862                                            qPos.add(uuid);
863                                    }
864    
865                                    qPos.add(groupId);
866    
867                                    count = (Long)q.uniqueResult();
868    
869                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
870                            }
871                            catch (Exception e) {
872                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
873    
874                                    throw processException(e);
875                            }
876                            finally {
877                                    closeSession(session);
878                            }
879                    }
880    
881                    return count.intValue();
882            }
883    
884            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
885            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
886            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
887            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
888            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
889                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
890                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
891                            new String[] {
892                                    String.class.getName(), Long.class.getName(),
893                                    
894                            Integer.class.getName(), Integer.class.getName(),
895                                    OrderByComparator.class.getName()
896                            });
897            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
898                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
899                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
900                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
901                            new String[] { String.class.getName(), Long.class.getName() },
902                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
903                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
904                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
905            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
906                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
907                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
908                            new String[] { String.class.getName(), Long.class.getName() });
909    
910            /**
911             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
912             *
913             * @param uuid the uuid
914             * @param companyId the company ID
915             * @return the matching message-boards messages
916             * @throws SystemException if a system exception occurred
917             */
918            @Override
919            public List<MBMessage> findByUuid_C(String uuid, long companyId)
920                    throws SystemException {
921                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
922                            QueryUtil.ALL_POS, null);
923            }
924    
925            /**
926             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
927             *
928             * <p>
929             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
930             * </p>
931             *
932             * @param uuid the uuid
933             * @param companyId the company ID
934             * @param start the lower bound of the range of message-boards messages
935             * @param end the upper bound of the range of message-boards messages (not inclusive)
936             * @return the range of matching message-boards messages
937             * @throws SystemException if a system exception occurred
938             */
939            @Override
940            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
941                    int end) throws SystemException {
942                    return findByUuid_C(uuid, companyId, start, end, null);
943            }
944    
945            /**
946             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
947             *
948             * <p>
949             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
950             * </p>
951             *
952             * @param uuid the uuid
953             * @param companyId the company ID
954             * @param start the lower bound of the range of message-boards messages
955             * @param end the upper bound of the range of message-boards messages (not inclusive)
956             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
957             * @return the ordered range of matching message-boards messages
958             * @throws SystemException if a system exception occurred
959             */
960            @Override
961            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
962                    int end, OrderByComparator orderByComparator) throws SystemException {
963                    boolean pagination = true;
964                    FinderPath finderPath = null;
965                    Object[] finderArgs = null;
966    
967                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
968                                    (orderByComparator == null)) {
969                            pagination = false;
970                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
971                            finderArgs = new Object[] { uuid, companyId };
972                    }
973                    else {
974                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
975                            finderArgs = new Object[] {
976                                            uuid, companyId,
977                                            
978                                            start, end, orderByComparator
979                                    };
980                    }
981    
982                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
983                                    finderArgs, this);
984    
985                    if ((list != null) && !list.isEmpty()) {
986                            for (MBMessage mbMessage : list) {
987                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
988                                                    (companyId != mbMessage.getCompanyId())) {
989                                            list = null;
990    
991                                            break;
992                                    }
993                            }
994                    }
995    
996                    if (list == null) {
997                            StringBundler query = null;
998    
999                            if (orderByComparator != null) {
1000                                    query = new StringBundler(4 +
1001                                                    (orderByComparator.getOrderByFields().length * 3));
1002                            }
1003                            else {
1004                                    query = new StringBundler(4);
1005                            }
1006    
1007                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1008    
1009                            boolean bindUuid = false;
1010    
1011                            if (uuid == null) {
1012                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1013                            }
1014                            else if (uuid.equals(StringPool.BLANK)) {
1015                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1016                            }
1017                            else {
1018                                    bindUuid = true;
1019    
1020                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1021                            }
1022    
1023                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1024    
1025                            if (orderByComparator != null) {
1026                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1027                                            orderByComparator);
1028                            }
1029                            else
1030                             if (pagination) {
1031                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1032                            }
1033    
1034                            String sql = query.toString();
1035    
1036                            Session session = null;
1037    
1038                            try {
1039                                    session = openSession();
1040    
1041                                    Query q = session.createQuery(sql);
1042    
1043                                    QueryPos qPos = QueryPos.getInstance(q);
1044    
1045                                    if (bindUuid) {
1046                                            qPos.add(uuid);
1047                                    }
1048    
1049                                    qPos.add(companyId);
1050    
1051                                    if (!pagination) {
1052                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1053                                                            start, end, false);
1054    
1055                                            Collections.sort(list);
1056    
1057                                            list = new UnmodifiableList<MBMessage>(list);
1058                                    }
1059                                    else {
1060                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1061                                                            start, end);
1062                                    }
1063    
1064                                    cacheResult(list);
1065    
1066                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1067                            }
1068                            catch (Exception e) {
1069                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1070    
1071                                    throw processException(e);
1072                            }
1073                            finally {
1074                                    closeSession(session);
1075                            }
1076                    }
1077    
1078                    return list;
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
1088             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1089             * @throws SystemException if a system exception occurred
1090             */
1091            @Override
1092            public MBMessage findByUuid_C_First(String uuid, long companyId,
1093                    OrderByComparator orderByComparator)
1094                    throws NoSuchMessageException, SystemException {
1095                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1096                                    orderByComparator);
1097    
1098                    if (mbMessage != null) {
1099                            return mbMessage;
1100                    }
1101    
1102                    StringBundler msg = new StringBundler(6);
1103    
1104                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1105    
1106                    msg.append("uuid=");
1107                    msg.append(uuid);
1108    
1109                    msg.append(", companyId=");
1110                    msg.append(companyId);
1111    
1112                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1113    
1114                    throw new NoSuchMessageException(msg.toString());
1115            }
1116    
1117            /**
1118             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1119             *
1120             * @param uuid the uuid
1121             * @param companyId the company ID
1122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1123             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1124             * @throws SystemException if a system exception occurred
1125             */
1126            @Override
1127            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1128                    OrderByComparator orderByComparator) throws SystemException {
1129                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1130                                    orderByComparator);
1131    
1132                    if (!list.isEmpty()) {
1133                            return list.get(0);
1134                    }
1135    
1136                    return null;
1137            }
1138    
1139            /**
1140             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1141             *
1142             * @param uuid the uuid
1143             * @param companyId the company ID
1144             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1145             * @return the last matching message-boards message
1146             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1147             * @throws SystemException if a system exception occurred
1148             */
1149            @Override
1150            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1151                    OrderByComparator orderByComparator)
1152                    throws NoSuchMessageException, SystemException {
1153                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1154                                    orderByComparator);
1155    
1156                    if (mbMessage != null) {
1157                            return mbMessage;
1158                    }
1159    
1160                    StringBundler msg = new StringBundler(6);
1161    
1162                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1163    
1164                    msg.append("uuid=");
1165                    msg.append(uuid);
1166    
1167                    msg.append(", companyId=");
1168                    msg.append(companyId);
1169    
1170                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1171    
1172                    throw new NoSuchMessageException(msg.toString());
1173            }
1174    
1175            /**
1176             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1177             *
1178             * @param uuid the uuid
1179             * @param companyId the company ID
1180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1181             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1182             * @throws SystemException if a system exception occurred
1183             */
1184            @Override
1185            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1186                    OrderByComparator orderByComparator) throws SystemException {
1187                    int count = countByUuid_C(uuid, companyId);
1188    
1189                    if (count == 0) {
1190                            return null;
1191                    }
1192    
1193                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1194                                    orderByComparator);
1195    
1196                    if (!list.isEmpty()) {
1197                            return list.get(0);
1198                    }
1199    
1200                    return null;
1201            }
1202    
1203            /**
1204             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1205             *
1206             * @param messageId the primary key of the current message-boards message
1207             * @param uuid the uuid
1208             * @param companyId the company ID
1209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1210             * @return the previous, current, and next message-boards message
1211             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1212             * @throws SystemException if a system exception occurred
1213             */
1214            @Override
1215            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1216                    long companyId, OrderByComparator orderByComparator)
1217                    throws NoSuchMessageException, SystemException {
1218                    MBMessage mbMessage = findByPrimaryKey(messageId);
1219    
1220                    Session session = null;
1221    
1222                    try {
1223                            session = openSession();
1224    
1225                            MBMessage[] array = new MBMessageImpl[3];
1226    
1227                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1228                                            companyId, orderByComparator, true);
1229    
1230                            array[1] = mbMessage;
1231    
1232                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1233                                            companyId, orderByComparator, false);
1234    
1235                            return array;
1236                    }
1237                    catch (Exception e) {
1238                            throw processException(e);
1239                    }
1240                    finally {
1241                            closeSession(session);
1242                    }
1243            }
1244    
1245            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1246                    MBMessage mbMessage, String uuid, long companyId,
1247                    OrderByComparator orderByComparator, boolean previous) {
1248                    StringBundler query = null;
1249    
1250                    if (orderByComparator != null) {
1251                            query = new StringBundler(6 +
1252                                            (orderByComparator.getOrderByFields().length * 6));
1253                    }
1254                    else {
1255                            query = new StringBundler(3);
1256                    }
1257    
1258                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1259    
1260                    boolean bindUuid = false;
1261    
1262                    if (uuid == null) {
1263                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1264                    }
1265                    else if (uuid.equals(StringPool.BLANK)) {
1266                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1267                    }
1268                    else {
1269                            bindUuid = true;
1270    
1271                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1272                    }
1273    
1274                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1275    
1276                    if (orderByComparator != null) {
1277                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1278    
1279                            if (orderByConditionFields.length > 0) {
1280                                    query.append(WHERE_AND);
1281                            }
1282    
1283                            for (int i = 0; i < orderByConditionFields.length; i++) {
1284                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1285                                    query.append(orderByConditionFields[i]);
1286    
1287                                    if ((i + 1) < orderByConditionFields.length) {
1288                                            if (orderByComparator.isAscending() ^ previous) {
1289                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1290                                            }
1291                                            else {
1292                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1293                                            }
1294                                    }
1295                                    else {
1296                                            if (orderByComparator.isAscending() ^ previous) {
1297                                                    query.append(WHERE_GREATER_THAN);
1298                                            }
1299                                            else {
1300                                                    query.append(WHERE_LESSER_THAN);
1301                                            }
1302                                    }
1303                            }
1304    
1305                            query.append(ORDER_BY_CLAUSE);
1306    
1307                            String[] orderByFields = orderByComparator.getOrderByFields();
1308    
1309                            for (int i = 0; i < orderByFields.length; i++) {
1310                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1311                                    query.append(orderByFields[i]);
1312    
1313                                    if ((i + 1) < orderByFields.length) {
1314                                            if (orderByComparator.isAscending() ^ previous) {
1315                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1316                                            }
1317                                            else {
1318                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1319                                            }
1320                                    }
1321                                    else {
1322                                            if (orderByComparator.isAscending() ^ previous) {
1323                                                    query.append(ORDER_BY_ASC);
1324                                            }
1325                                            else {
1326                                                    query.append(ORDER_BY_DESC);
1327                                            }
1328                                    }
1329                            }
1330                    }
1331                    else {
1332                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1333                    }
1334    
1335                    String sql = query.toString();
1336    
1337                    Query q = session.createQuery(sql);
1338    
1339                    q.setFirstResult(0);
1340                    q.setMaxResults(2);
1341    
1342                    QueryPos qPos = QueryPos.getInstance(q);
1343    
1344                    if (bindUuid) {
1345                            qPos.add(uuid);
1346                    }
1347    
1348                    qPos.add(companyId);
1349    
1350                    if (orderByComparator != null) {
1351                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1352    
1353                            for (Object value : values) {
1354                                    qPos.add(value);
1355                            }
1356                    }
1357    
1358                    List<MBMessage> list = q.list();
1359    
1360                    if (list.size() == 2) {
1361                            return list.get(1);
1362                    }
1363                    else {
1364                            return null;
1365                    }
1366            }
1367    
1368            /**
1369             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1370             *
1371             * @param uuid the uuid
1372             * @param companyId the company ID
1373             * @throws SystemException if a system exception occurred
1374             */
1375            @Override
1376            public void removeByUuid_C(String uuid, long companyId)
1377                    throws SystemException {
1378                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1379                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1380                            remove(mbMessage);
1381                    }
1382            }
1383    
1384            /**
1385             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1386             *
1387             * @param uuid the uuid
1388             * @param companyId the company ID
1389             * @return the number of matching message-boards messages
1390             * @throws SystemException if a system exception occurred
1391             */
1392            @Override
1393            public int countByUuid_C(String uuid, long companyId)
1394                    throws SystemException {
1395                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1396    
1397                    Object[] finderArgs = new Object[] { uuid, companyId };
1398    
1399                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1400                                    this);
1401    
1402                    if (count == null) {
1403                            StringBundler query = new StringBundler(3);
1404    
1405                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1406    
1407                            boolean bindUuid = false;
1408    
1409                            if (uuid == null) {
1410                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1411                            }
1412                            else if (uuid.equals(StringPool.BLANK)) {
1413                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1414                            }
1415                            else {
1416                                    bindUuid = true;
1417    
1418                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1419                            }
1420    
1421                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1422    
1423                            String sql = query.toString();
1424    
1425                            Session session = null;
1426    
1427                            try {
1428                                    session = openSession();
1429    
1430                                    Query q = session.createQuery(sql);
1431    
1432                                    QueryPos qPos = QueryPos.getInstance(q);
1433    
1434                                    if (bindUuid) {
1435                                            qPos.add(uuid);
1436                                    }
1437    
1438                                    qPos.add(companyId);
1439    
1440                                    count = (Long)q.uniqueResult();
1441    
1442                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1443                            }
1444                            catch (Exception e) {
1445                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1446    
1447                                    throw processException(e);
1448                            }
1449                            finally {
1450                                    closeSession(session);
1451                            }
1452                    }
1453    
1454                    return count.intValue();
1455            }
1456    
1457            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1458            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1459            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1460            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1461            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1462                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1463                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1464                            new String[] {
1465                                    Long.class.getName(),
1466                                    
1467                            Integer.class.getName(), Integer.class.getName(),
1468                                    OrderByComparator.class.getName()
1469                            });
1470            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1471                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1472                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1473                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1474                            new String[] { Long.class.getName() },
1475                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1476                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1477            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1478                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1479                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1480                            new String[] { Long.class.getName() });
1481    
1482            /**
1483             * Returns all the message-boards messages where groupId = &#63;.
1484             *
1485             * @param groupId the group ID
1486             * @return the matching message-boards messages
1487             * @throws SystemException if a system exception occurred
1488             */
1489            @Override
1490            public List<MBMessage> findByGroupId(long groupId)
1491                    throws SystemException {
1492                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1493            }
1494    
1495            /**
1496             * Returns a range of all the message-boards messages where groupId = &#63;.
1497             *
1498             * <p>
1499             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
1500             * </p>
1501             *
1502             * @param groupId the group ID
1503             * @param start the lower bound of the range of message-boards messages
1504             * @param end the upper bound of the range of message-boards messages (not inclusive)
1505             * @return the range of matching message-boards messages
1506             * @throws SystemException if a system exception occurred
1507             */
1508            @Override
1509            public List<MBMessage> findByGroupId(long groupId, int start, int end)
1510                    throws SystemException {
1511                    return findByGroupId(groupId, start, end, null);
1512            }
1513    
1514            /**
1515             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1516             *
1517             * <p>
1518             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
1519             * </p>
1520             *
1521             * @param groupId the group ID
1522             * @param start the lower bound of the range of message-boards messages
1523             * @param end the upper bound of the range of message-boards messages (not inclusive)
1524             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1525             * @return the ordered range of matching message-boards messages
1526             * @throws SystemException if a system exception occurred
1527             */
1528            @Override
1529            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1530                    OrderByComparator orderByComparator) throws SystemException {
1531                    boolean pagination = true;
1532                    FinderPath finderPath = null;
1533                    Object[] finderArgs = null;
1534    
1535                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1536                                    (orderByComparator == null)) {
1537                            pagination = false;
1538                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1539                            finderArgs = new Object[] { groupId };
1540                    }
1541                    else {
1542                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1543                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1544                    }
1545    
1546                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1547                                    finderArgs, this);
1548    
1549                    if ((list != null) && !list.isEmpty()) {
1550                            for (MBMessage mbMessage : list) {
1551                                    if ((groupId != mbMessage.getGroupId())) {
1552                                            list = null;
1553    
1554                                            break;
1555                                    }
1556                            }
1557                    }
1558    
1559                    if (list == null) {
1560                            StringBundler query = null;
1561    
1562                            if (orderByComparator != null) {
1563                                    query = new StringBundler(3 +
1564                                                    (orderByComparator.getOrderByFields().length * 3));
1565                            }
1566                            else {
1567                                    query = new StringBundler(3);
1568                            }
1569    
1570                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1571    
1572                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1573    
1574                            if (orderByComparator != null) {
1575                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1576                                            orderByComparator);
1577                            }
1578                            else
1579                             if (pagination) {
1580                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1581                            }
1582    
1583                            String sql = query.toString();
1584    
1585                            Session session = null;
1586    
1587                            try {
1588                                    session = openSession();
1589    
1590                                    Query q = session.createQuery(sql);
1591    
1592                                    QueryPos qPos = QueryPos.getInstance(q);
1593    
1594                                    qPos.add(groupId);
1595    
1596                                    if (!pagination) {
1597                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1598                                                            start, end, false);
1599    
1600                                            Collections.sort(list);
1601    
1602                                            list = new UnmodifiableList<MBMessage>(list);
1603                                    }
1604                                    else {
1605                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1606                                                            start, end);
1607                                    }
1608    
1609                                    cacheResult(list);
1610    
1611                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1612                            }
1613                            catch (Exception e) {
1614                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1615    
1616                                    throw processException(e);
1617                            }
1618                            finally {
1619                                    closeSession(session);
1620                            }
1621                    }
1622    
1623                    return list;
1624            }
1625    
1626            /**
1627             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1628             *
1629             * @param groupId the group ID
1630             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1631             * @return the first matching message-boards message
1632             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1633             * @throws SystemException if a system exception occurred
1634             */
1635            @Override
1636            public MBMessage findByGroupId_First(long groupId,
1637                    OrderByComparator orderByComparator)
1638                    throws NoSuchMessageException, SystemException {
1639                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1640    
1641                    if (mbMessage != null) {
1642                            return mbMessage;
1643                    }
1644    
1645                    StringBundler msg = new StringBundler(4);
1646    
1647                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1648    
1649                    msg.append("groupId=");
1650                    msg.append(groupId);
1651    
1652                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1653    
1654                    throw new NoSuchMessageException(msg.toString());
1655            }
1656    
1657            /**
1658             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1659             *
1660             * @param groupId the group ID
1661             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1662             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1663             * @throws SystemException if a system exception occurred
1664             */
1665            @Override
1666            public MBMessage fetchByGroupId_First(long groupId,
1667                    OrderByComparator orderByComparator) throws SystemException {
1668                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1669    
1670                    if (!list.isEmpty()) {
1671                            return list.get(0);
1672                    }
1673    
1674                    return null;
1675            }
1676    
1677            /**
1678             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1679             *
1680             * @param groupId the group ID
1681             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1682             * @return the last matching message-boards message
1683             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1684             * @throws SystemException if a system exception occurred
1685             */
1686            @Override
1687            public MBMessage findByGroupId_Last(long groupId,
1688                    OrderByComparator orderByComparator)
1689                    throws NoSuchMessageException, SystemException {
1690                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1691    
1692                    if (mbMessage != null) {
1693                            return mbMessage;
1694                    }
1695    
1696                    StringBundler msg = new StringBundler(4);
1697    
1698                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1699    
1700                    msg.append("groupId=");
1701                    msg.append(groupId);
1702    
1703                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1704    
1705                    throw new NoSuchMessageException(msg.toString());
1706            }
1707    
1708            /**
1709             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1710             *
1711             * @param groupId the group ID
1712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1713             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1714             * @throws SystemException if a system exception occurred
1715             */
1716            @Override
1717            public MBMessage fetchByGroupId_Last(long groupId,
1718                    OrderByComparator orderByComparator) throws SystemException {
1719                    int count = countByGroupId(groupId);
1720    
1721                    if (count == 0) {
1722                            return null;
1723                    }
1724    
1725                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1726                                    orderByComparator);
1727    
1728                    if (!list.isEmpty()) {
1729                            return list.get(0);
1730                    }
1731    
1732                    return null;
1733            }
1734    
1735            /**
1736             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1737             *
1738             * @param messageId the primary key of the current message-boards message
1739             * @param groupId the group ID
1740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1741             * @return the previous, current, and next message-boards message
1742             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1743             * @throws SystemException if a system exception occurred
1744             */
1745            @Override
1746            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1747                    OrderByComparator orderByComparator)
1748                    throws NoSuchMessageException, SystemException {
1749                    MBMessage mbMessage = findByPrimaryKey(messageId);
1750    
1751                    Session session = null;
1752    
1753                    try {
1754                            session = openSession();
1755    
1756                            MBMessage[] array = new MBMessageImpl[3];
1757    
1758                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1759                                            orderByComparator, true);
1760    
1761                            array[1] = mbMessage;
1762    
1763                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1764                                            orderByComparator, false);
1765    
1766                            return array;
1767                    }
1768                    catch (Exception e) {
1769                            throw processException(e);
1770                    }
1771                    finally {
1772                            closeSession(session);
1773                    }
1774            }
1775    
1776            protected MBMessage getByGroupId_PrevAndNext(Session session,
1777                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1778                    boolean previous) {
1779                    StringBundler query = null;
1780    
1781                    if (orderByComparator != null) {
1782                            query = new StringBundler(6 +
1783                                            (orderByComparator.getOrderByFields().length * 6));
1784                    }
1785                    else {
1786                            query = new StringBundler(3);
1787                    }
1788    
1789                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1790    
1791                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1792    
1793                    if (orderByComparator != null) {
1794                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1795    
1796                            if (orderByConditionFields.length > 0) {
1797                                    query.append(WHERE_AND);
1798                            }
1799    
1800                            for (int i = 0; i < orderByConditionFields.length; i++) {
1801                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1802                                    query.append(orderByConditionFields[i]);
1803    
1804                                    if ((i + 1) < orderByConditionFields.length) {
1805                                            if (orderByComparator.isAscending() ^ previous) {
1806                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1807                                            }
1808                                            else {
1809                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1810                                            }
1811                                    }
1812                                    else {
1813                                            if (orderByComparator.isAscending() ^ previous) {
1814                                                    query.append(WHERE_GREATER_THAN);
1815                                            }
1816                                            else {
1817                                                    query.append(WHERE_LESSER_THAN);
1818                                            }
1819                                    }
1820                            }
1821    
1822                            query.append(ORDER_BY_CLAUSE);
1823    
1824                            String[] orderByFields = orderByComparator.getOrderByFields();
1825    
1826                            for (int i = 0; i < orderByFields.length; i++) {
1827                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1828                                    query.append(orderByFields[i]);
1829    
1830                                    if ((i + 1) < orderByFields.length) {
1831                                            if (orderByComparator.isAscending() ^ previous) {
1832                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1833                                            }
1834                                            else {
1835                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1836                                            }
1837                                    }
1838                                    else {
1839                                            if (orderByComparator.isAscending() ^ previous) {
1840                                                    query.append(ORDER_BY_ASC);
1841                                            }
1842                                            else {
1843                                                    query.append(ORDER_BY_DESC);
1844                                            }
1845                                    }
1846                            }
1847                    }
1848                    else {
1849                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1850                    }
1851    
1852                    String sql = query.toString();
1853    
1854                    Query q = session.createQuery(sql);
1855    
1856                    q.setFirstResult(0);
1857                    q.setMaxResults(2);
1858    
1859                    QueryPos qPos = QueryPos.getInstance(q);
1860    
1861                    qPos.add(groupId);
1862    
1863                    if (orderByComparator != null) {
1864                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1865    
1866                            for (Object value : values) {
1867                                    qPos.add(value);
1868                            }
1869                    }
1870    
1871                    List<MBMessage> list = q.list();
1872    
1873                    if (list.size() == 2) {
1874                            return list.get(1);
1875                    }
1876                    else {
1877                            return null;
1878                    }
1879            }
1880    
1881            /**
1882             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1883             *
1884             * @param groupId the group ID
1885             * @return the matching message-boards messages that the user has permission to view
1886             * @throws SystemException if a system exception occurred
1887             */
1888            @Override
1889            public List<MBMessage> filterFindByGroupId(long groupId)
1890                    throws SystemException {
1891                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1892                            QueryUtil.ALL_POS, null);
1893            }
1894    
1895            /**
1896             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1897             *
1898             * <p>
1899             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
1900             * </p>
1901             *
1902             * @param groupId the group ID
1903             * @param start the lower bound of the range of message-boards messages
1904             * @param end the upper bound of the range of message-boards messages (not inclusive)
1905             * @return the range of matching message-boards messages that the user has permission to view
1906             * @throws SystemException if a system exception occurred
1907             */
1908            @Override
1909            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1910                    throws SystemException {
1911                    return filterFindByGroupId(groupId, start, end, null);
1912            }
1913    
1914            /**
1915             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1916             *
1917             * <p>
1918             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
1919             * </p>
1920             *
1921             * @param groupId the group ID
1922             * @param start the lower bound of the range of message-boards messages
1923             * @param end the upper bound of the range of message-boards messages (not inclusive)
1924             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1925             * @return the ordered range of matching message-boards messages that the user has permission to view
1926             * @throws SystemException if a system exception occurred
1927             */
1928            @Override
1929            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1930                    int end, OrderByComparator orderByComparator) throws SystemException {
1931                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1932                            return findByGroupId(groupId, start, end, orderByComparator);
1933                    }
1934    
1935                    StringBundler query = null;
1936    
1937                    if (orderByComparator != null) {
1938                            query = new StringBundler(3 +
1939                                            (orderByComparator.getOrderByFields().length * 3));
1940                    }
1941                    else {
1942                            query = new StringBundler(3);
1943                    }
1944    
1945                    if (getDB().isSupportsInlineDistinct()) {
1946                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1947                    }
1948                    else {
1949                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1950                    }
1951    
1952                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1953    
1954                    if (!getDB().isSupportsInlineDistinct()) {
1955                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1956                    }
1957    
1958                    if (orderByComparator != null) {
1959                            if (getDB().isSupportsInlineDistinct()) {
1960                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1961                                            orderByComparator, true);
1962                            }
1963                            else {
1964                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1965                                            orderByComparator, true);
1966                            }
1967                    }
1968                    else {
1969                            if (getDB().isSupportsInlineDistinct()) {
1970                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1971                            }
1972                            else {
1973                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
1974                            }
1975                    }
1976    
1977                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1978                                    MBMessage.class.getName(),
1979                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1980    
1981                    Session session = null;
1982    
1983                    try {
1984                            session = openSession();
1985    
1986                            SQLQuery q = session.createSQLQuery(sql);
1987    
1988                            if (getDB().isSupportsInlineDistinct()) {
1989                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1990                            }
1991                            else {
1992                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1993                            }
1994    
1995                            QueryPos qPos = QueryPos.getInstance(q);
1996    
1997                            qPos.add(groupId);
1998    
1999                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2000                    }
2001                    catch (Exception e) {
2002                            throw processException(e);
2003                    }
2004                    finally {
2005                            closeSession(session);
2006                    }
2007            }
2008    
2009            /**
2010             * 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;.
2011             *
2012             * @param messageId the primary key of the current message-boards message
2013             * @param groupId the group ID
2014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2015             * @return the previous, current, and next message-boards message
2016             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2017             * @throws SystemException if a system exception occurred
2018             */
2019            @Override
2020            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2021                    long groupId, OrderByComparator orderByComparator)
2022                    throws NoSuchMessageException, SystemException {
2023                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2024                            return findByGroupId_PrevAndNext(messageId, groupId,
2025                                    orderByComparator);
2026                    }
2027    
2028                    MBMessage mbMessage = findByPrimaryKey(messageId);
2029    
2030                    Session session = null;
2031    
2032                    try {
2033                            session = openSession();
2034    
2035                            MBMessage[] array = new MBMessageImpl[3];
2036    
2037                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2038                                            groupId, orderByComparator, true);
2039    
2040                            array[1] = mbMessage;
2041    
2042                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2043                                            groupId, orderByComparator, false);
2044    
2045                            return array;
2046                    }
2047                    catch (Exception e) {
2048                            throw processException(e);
2049                    }
2050                    finally {
2051                            closeSession(session);
2052                    }
2053            }
2054    
2055            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2056                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2057                    boolean previous) {
2058                    StringBundler query = null;
2059    
2060                    if (orderByComparator != null) {
2061                            query = new StringBundler(6 +
2062                                            (orderByComparator.getOrderByFields().length * 6));
2063                    }
2064                    else {
2065                            query = new StringBundler(3);
2066                    }
2067    
2068                    if (getDB().isSupportsInlineDistinct()) {
2069                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2070                    }
2071                    else {
2072                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2073                    }
2074    
2075                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2076    
2077                    if (!getDB().isSupportsInlineDistinct()) {
2078                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2079                    }
2080    
2081                    if (orderByComparator != null) {
2082                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2083    
2084                            if (orderByConditionFields.length > 0) {
2085                                    query.append(WHERE_AND);
2086                            }
2087    
2088                            for (int i = 0; i < orderByConditionFields.length; i++) {
2089                                    if (getDB().isSupportsInlineDistinct()) {
2090                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2091                                    }
2092                                    else {
2093                                            query.append(_ORDER_BY_ENTITY_TABLE);
2094                                    }
2095    
2096                                    query.append(orderByConditionFields[i]);
2097    
2098                                    if ((i + 1) < orderByConditionFields.length) {
2099                                            if (orderByComparator.isAscending() ^ previous) {
2100                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2101                                            }
2102                                            else {
2103                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2104                                            }
2105                                    }
2106                                    else {
2107                                            if (orderByComparator.isAscending() ^ previous) {
2108                                                    query.append(WHERE_GREATER_THAN);
2109                                            }
2110                                            else {
2111                                                    query.append(WHERE_LESSER_THAN);
2112                                            }
2113                                    }
2114                            }
2115    
2116                            query.append(ORDER_BY_CLAUSE);
2117    
2118                            String[] orderByFields = orderByComparator.getOrderByFields();
2119    
2120                            for (int i = 0; i < orderByFields.length; i++) {
2121                                    if (getDB().isSupportsInlineDistinct()) {
2122                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2123                                    }
2124                                    else {
2125                                            query.append(_ORDER_BY_ENTITY_TABLE);
2126                                    }
2127    
2128                                    query.append(orderByFields[i]);
2129    
2130                                    if ((i + 1) < orderByFields.length) {
2131                                            if (orderByComparator.isAscending() ^ previous) {
2132                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2133                                            }
2134                                            else {
2135                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2136                                            }
2137                                    }
2138                                    else {
2139                                            if (orderByComparator.isAscending() ^ previous) {
2140                                                    query.append(ORDER_BY_ASC);
2141                                            }
2142                                            else {
2143                                                    query.append(ORDER_BY_DESC);
2144                                            }
2145                                    }
2146                            }
2147                    }
2148                    else {
2149                            if (getDB().isSupportsInlineDistinct()) {
2150                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2151                            }
2152                            else {
2153                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2154                            }
2155                    }
2156    
2157                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2158                                    MBMessage.class.getName(),
2159                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2160    
2161                    SQLQuery q = session.createSQLQuery(sql);
2162    
2163                    q.setFirstResult(0);
2164                    q.setMaxResults(2);
2165    
2166                    if (getDB().isSupportsInlineDistinct()) {
2167                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2168                    }
2169                    else {
2170                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2171                    }
2172    
2173                    QueryPos qPos = QueryPos.getInstance(q);
2174    
2175                    qPos.add(groupId);
2176    
2177                    if (orderByComparator != null) {
2178                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2179    
2180                            for (Object value : values) {
2181                                    qPos.add(value);
2182                            }
2183                    }
2184    
2185                    List<MBMessage> list = q.list();
2186    
2187                    if (list.size() == 2) {
2188                            return list.get(1);
2189                    }
2190                    else {
2191                            return null;
2192                    }
2193            }
2194    
2195            /**
2196             * Removes all the message-boards messages where groupId = &#63; from the database.
2197             *
2198             * @param groupId the group ID
2199             * @throws SystemException if a system exception occurred
2200             */
2201            @Override
2202            public void removeByGroupId(long groupId) throws SystemException {
2203                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2204                                    QueryUtil.ALL_POS, null)) {
2205                            remove(mbMessage);
2206                    }
2207            }
2208    
2209            /**
2210             * Returns the number of message-boards messages where groupId = &#63;.
2211             *
2212             * @param groupId the group ID
2213             * @return the number of matching message-boards messages
2214             * @throws SystemException if a system exception occurred
2215             */
2216            @Override
2217            public int countByGroupId(long groupId) throws SystemException {
2218                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2219    
2220                    Object[] finderArgs = new Object[] { groupId };
2221    
2222                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2223                                    this);
2224    
2225                    if (count == null) {
2226                            StringBundler query = new StringBundler(2);
2227    
2228                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2229    
2230                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2231    
2232                            String sql = query.toString();
2233    
2234                            Session session = null;
2235    
2236                            try {
2237                                    session = openSession();
2238    
2239                                    Query q = session.createQuery(sql);
2240    
2241                                    QueryPos qPos = QueryPos.getInstance(q);
2242    
2243                                    qPos.add(groupId);
2244    
2245                                    count = (Long)q.uniqueResult();
2246    
2247                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2248                            }
2249                            catch (Exception e) {
2250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2251    
2252                                    throw processException(e);
2253                            }
2254                            finally {
2255                                    closeSession(session);
2256                            }
2257                    }
2258    
2259                    return count.intValue();
2260            }
2261    
2262            /**
2263             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2264             *
2265             * @param groupId the group ID
2266             * @return the number of matching message-boards messages that the user has permission to view
2267             * @throws SystemException if a system exception occurred
2268             */
2269            @Override
2270            public int filterCountByGroupId(long groupId) throws SystemException {
2271                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2272                            return countByGroupId(groupId);
2273                    }
2274    
2275                    StringBundler query = new StringBundler(2);
2276    
2277                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2278    
2279                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2280    
2281                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2282                                    MBMessage.class.getName(),
2283                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2284    
2285                    Session session = null;
2286    
2287                    try {
2288                            session = openSession();
2289    
2290                            SQLQuery q = session.createSQLQuery(sql);
2291    
2292                            q.addScalar(COUNT_COLUMN_NAME,
2293                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2294    
2295                            QueryPos qPos = QueryPos.getInstance(q);
2296    
2297                            qPos.add(groupId);
2298    
2299                            Long count = (Long)q.uniqueResult();
2300    
2301                            return count.intValue();
2302                    }
2303                    catch (Exception e) {
2304                            throw processException(e);
2305                    }
2306                    finally {
2307                            closeSession(session);
2308                    }
2309            }
2310    
2311            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2312            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2313                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2314                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2315                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2316                            new String[] {
2317                                    Long.class.getName(),
2318                                    
2319                            Integer.class.getName(), Integer.class.getName(),
2320                                    OrderByComparator.class.getName()
2321                            });
2322            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2323                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2324                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2325                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2326                            new String[] { Long.class.getName() },
2327                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2328                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2329            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2330                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2331                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2332                            new String[] { Long.class.getName() });
2333    
2334            /**
2335             * Returns all the message-boards messages where companyId = &#63;.
2336             *
2337             * @param companyId the company ID
2338             * @return the matching message-boards messages
2339             * @throws SystemException if a system exception occurred
2340             */
2341            @Override
2342            public List<MBMessage> findByCompanyId(long companyId)
2343                    throws SystemException {
2344                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2345                            null);
2346            }
2347    
2348            /**
2349             * Returns a range of all the message-boards messages where companyId = &#63;.
2350             *
2351             * <p>
2352             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
2353             * </p>
2354             *
2355             * @param companyId the company ID
2356             * @param start the lower bound of the range of message-boards messages
2357             * @param end the upper bound of the range of message-boards messages (not inclusive)
2358             * @return the range of matching message-boards messages
2359             * @throws SystemException if a system exception occurred
2360             */
2361            @Override
2362            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2363                    throws SystemException {
2364                    return findByCompanyId(companyId, start, end, null);
2365            }
2366    
2367            /**
2368             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2369             *
2370             * <p>
2371             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
2372             * </p>
2373             *
2374             * @param companyId the company ID
2375             * @param start the lower bound of the range of message-boards messages
2376             * @param end the upper bound of the range of message-boards messages (not inclusive)
2377             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2378             * @return the ordered range of matching message-boards messages
2379             * @throws SystemException if a system exception occurred
2380             */
2381            @Override
2382            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2383                    OrderByComparator orderByComparator) throws SystemException {
2384                    boolean pagination = true;
2385                    FinderPath finderPath = null;
2386                    Object[] finderArgs = null;
2387    
2388                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2389                                    (orderByComparator == null)) {
2390                            pagination = false;
2391                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2392                            finderArgs = new Object[] { companyId };
2393                    }
2394                    else {
2395                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2396                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2397                    }
2398    
2399                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2400                                    finderArgs, this);
2401    
2402                    if ((list != null) && !list.isEmpty()) {
2403                            for (MBMessage mbMessage : list) {
2404                                    if ((companyId != mbMessage.getCompanyId())) {
2405                                            list = null;
2406    
2407                                            break;
2408                                    }
2409                            }
2410                    }
2411    
2412                    if (list == null) {
2413                            StringBundler query = null;
2414    
2415                            if (orderByComparator != null) {
2416                                    query = new StringBundler(3 +
2417                                                    (orderByComparator.getOrderByFields().length * 3));
2418                            }
2419                            else {
2420                                    query = new StringBundler(3);
2421                            }
2422    
2423                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2424    
2425                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2426    
2427                            if (orderByComparator != null) {
2428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2429                                            orderByComparator);
2430                            }
2431                            else
2432                             if (pagination) {
2433                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2434                            }
2435    
2436                            String sql = query.toString();
2437    
2438                            Session session = null;
2439    
2440                            try {
2441                                    session = openSession();
2442    
2443                                    Query q = session.createQuery(sql);
2444    
2445                                    QueryPos qPos = QueryPos.getInstance(q);
2446    
2447                                    qPos.add(companyId);
2448    
2449                                    if (!pagination) {
2450                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2451                                                            start, end, false);
2452    
2453                                            Collections.sort(list);
2454    
2455                                            list = new UnmodifiableList<MBMessage>(list);
2456                                    }
2457                                    else {
2458                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2459                                                            start, end);
2460                                    }
2461    
2462                                    cacheResult(list);
2463    
2464                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2465                            }
2466                            catch (Exception e) {
2467                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2468    
2469                                    throw processException(e);
2470                            }
2471                            finally {
2472                                    closeSession(session);
2473                            }
2474                    }
2475    
2476                    return list;
2477            }
2478    
2479            /**
2480             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2481             *
2482             * @param companyId the company ID
2483             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2484             * @return the first matching message-boards message
2485             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2486             * @throws SystemException if a system exception occurred
2487             */
2488            @Override
2489            public MBMessage findByCompanyId_First(long companyId,
2490                    OrderByComparator orderByComparator)
2491                    throws NoSuchMessageException, SystemException {
2492                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2493                                    orderByComparator);
2494    
2495                    if (mbMessage != null) {
2496                            return mbMessage;
2497                    }
2498    
2499                    StringBundler msg = new StringBundler(4);
2500    
2501                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2502    
2503                    msg.append("companyId=");
2504                    msg.append(companyId);
2505    
2506                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2507    
2508                    throw new NoSuchMessageException(msg.toString());
2509            }
2510    
2511            /**
2512             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2513             *
2514             * @param companyId the company ID
2515             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2516             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2517             * @throws SystemException if a system exception occurred
2518             */
2519            @Override
2520            public MBMessage fetchByCompanyId_First(long companyId,
2521                    OrderByComparator orderByComparator) throws SystemException {
2522                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2523                                    orderByComparator);
2524    
2525                    if (!list.isEmpty()) {
2526                            return list.get(0);
2527                    }
2528    
2529                    return null;
2530            }
2531    
2532            /**
2533             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2534             *
2535             * @param companyId the company ID
2536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2537             * @return the last matching message-boards message
2538             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2539             * @throws SystemException if a system exception occurred
2540             */
2541            @Override
2542            public MBMessage findByCompanyId_Last(long companyId,
2543                    OrderByComparator orderByComparator)
2544                    throws NoSuchMessageException, SystemException {
2545                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2546    
2547                    if (mbMessage != null) {
2548                            return mbMessage;
2549                    }
2550    
2551                    StringBundler msg = new StringBundler(4);
2552    
2553                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2554    
2555                    msg.append("companyId=");
2556                    msg.append(companyId);
2557    
2558                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2559    
2560                    throw new NoSuchMessageException(msg.toString());
2561            }
2562    
2563            /**
2564             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2565             *
2566             * @param companyId the company ID
2567             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2568             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2569             * @throws SystemException if a system exception occurred
2570             */
2571            @Override
2572            public MBMessage fetchByCompanyId_Last(long companyId,
2573                    OrderByComparator orderByComparator) throws SystemException {
2574                    int count = countByCompanyId(companyId);
2575    
2576                    if (count == 0) {
2577                            return null;
2578                    }
2579    
2580                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2581                                    orderByComparator);
2582    
2583                    if (!list.isEmpty()) {
2584                            return list.get(0);
2585                    }
2586    
2587                    return null;
2588            }
2589    
2590            /**
2591             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2592             *
2593             * @param messageId the primary key of the current message-boards message
2594             * @param companyId the company ID
2595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2596             * @return the previous, current, and next message-boards message
2597             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2598             * @throws SystemException if a system exception occurred
2599             */
2600            @Override
2601            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2602                    long companyId, OrderByComparator orderByComparator)
2603                    throws NoSuchMessageException, SystemException {
2604                    MBMessage mbMessage = findByPrimaryKey(messageId);
2605    
2606                    Session session = null;
2607    
2608                    try {
2609                            session = openSession();
2610    
2611                            MBMessage[] array = new MBMessageImpl[3];
2612    
2613                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2614                                            companyId, orderByComparator, true);
2615    
2616                            array[1] = mbMessage;
2617    
2618                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2619                                            companyId, orderByComparator, false);
2620    
2621                            return array;
2622                    }
2623                    catch (Exception e) {
2624                            throw processException(e);
2625                    }
2626                    finally {
2627                            closeSession(session);
2628                    }
2629            }
2630    
2631            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2632                    MBMessage mbMessage, long companyId,
2633                    OrderByComparator orderByComparator, boolean previous) {
2634                    StringBundler query = null;
2635    
2636                    if (orderByComparator != null) {
2637                            query = new StringBundler(6 +
2638                                            (orderByComparator.getOrderByFields().length * 6));
2639                    }
2640                    else {
2641                            query = new StringBundler(3);
2642                    }
2643    
2644                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2645    
2646                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2647    
2648                    if (orderByComparator != null) {
2649                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2650    
2651                            if (orderByConditionFields.length > 0) {
2652                                    query.append(WHERE_AND);
2653                            }
2654    
2655                            for (int i = 0; i < orderByConditionFields.length; i++) {
2656                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2657                                    query.append(orderByConditionFields[i]);
2658    
2659                                    if ((i + 1) < orderByConditionFields.length) {
2660                                            if (orderByComparator.isAscending() ^ previous) {
2661                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2662                                            }
2663                                            else {
2664                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2665                                            }
2666                                    }
2667                                    else {
2668                                            if (orderByComparator.isAscending() ^ previous) {
2669                                                    query.append(WHERE_GREATER_THAN);
2670                                            }
2671                                            else {
2672                                                    query.append(WHERE_LESSER_THAN);
2673                                            }
2674                                    }
2675                            }
2676    
2677                            query.append(ORDER_BY_CLAUSE);
2678    
2679                            String[] orderByFields = orderByComparator.getOrderByFields();
2680    
2681                            for (int i = 0; i < orderByFields.length; i++) {
2682                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2683                                    query.append(orderByFields[i]);
2684    
2685                                    if ((i + 1) < orderByFields.length) {
2686                                            if (orderByComparator.isAscending() ^ previous) {
2687                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2688                                            }
2689                                            else {
2690                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2691                                            }
2692                                    }
2693                                    else {
2694                                            if (orderByComparator.isAscending() ^ previous) {
2695                                                    query.append(ORDER_BY_ASC);
2696                                            }
2697                                            else {
2698                                                    query.append(ORDER_BY_DESC);
2699                                            }
2700                                    }
2701                            }
2702                    }
2703                    else {
2704                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2705                    }
2706    
2707                    String sql = query.toString();
2708    
2709                    Query q = session.createQuery(sql);
2710    
2711                    q.setFirstResult(0);
2712                    q.setMaxResults(2);
2713    
2714                    QueryPos qPos = QueryPos.getInstance(q);
2715    
2716                    qPos.add(companyId);
2717    
2718                    if (orderByComparator != null) {
2719                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2720    
2721                            for (Object value : values) {
2722                                    qPos.add(value);
2723                            }
2724                    }
2725    
2726                    List<MBMessage> list = q.list();
2727    
2728                    if (list.size() == 2) {
2729                            return list.get(1);
2730                    }
2731                    else {
2732                            return null;
2733                    }
2734            }
2735    
2736            /**
2737             * Removes all the message-boards messages where companyId = &#63; from the database.
2738             *
2739             * @param companyId the company ID
2740             * @throws SystemException if a system exception occurred
2741             */
2742            @Override
2743            public void removeByCompanyId(long companyId) throws SystemException {
2744                    for (MBMessage mbMessage : findByCompanyId(companyId,
2745                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2746                            remove(mbMessage);
2747                    }
2748            }
2749    
2750            /**
2751             * Returns the number of message-boards messages where companyId = &#63;.
2752             *
2753             * @param companyId the company ID
2754             * @return the number of matching message-boards messages
2755             * @throws SystemException if a system exception occurred
2756             */
2757            @Override
2758            public int countByCompanyId(long companyId) throws SystemException {
2759                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2760    
2761                    Object[] finderArgs = new Object[] { companyId };
2762    
2763                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2764                                    this);
2765    
2766                    if (count == null) {
2767                            StringBundler query = new StringBundler(2);
2768    
2769                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2770    
2771                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2772    
2773                            String sql = query.toString();
2774    
2775                            Session session = null;
2776    
2777                            try {
2778                                    session = openSession();
2779    
2780                                    Query q = session.createQuery(sql);
2781    
2782                                    QueryPos qPos = QueryPos.getInstance(q);
2783    
2784                                    qPos.add(companyId);
2785    
2786                                    count = (Long)q.uniqueResult();
2787    
2788                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2789                            }
2790                            catch (Exception e) {
2791                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2792    
2793                                    throw processException(e);
2794                            }
2795                            finally {
2796                                    closeSession(session);
2797                            }
2798                    }
2799    
2800                    return count.intValue();
2801            }
2802    
2803            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2804            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2805                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2806                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
2807                            new String[] {
2808                                    Long.class.getName(),
2809                                    
2810                            Integer.class.getName(), Integer.class.getName(),
2811                                    OrderByComparator.class.getName()
2812                            });
2813            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
2814                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2815                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2816                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
2817                            new String[] { Long.class.getName() },
2818                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
2819                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2820            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2821                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2822                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
2823                            new String[] { Long.class.getName() });
2824    
2825            /**
2826             * Returns all the message-boards messages where threadId = &#63;.
2827             *
2828             * @param threadId the thread ID
2829             * @return the matching message-boards messages
2830             * @throws SystemException if a system exception occurred
2831             */
2832            @Override
2833            public List<MBMessage> findByThreadId(long threadId)
2834                    throws SystemException {
2835                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2836                            null);
2837            }
2838    
2839            /**
2840             * Returns a range of all the message-boards messages where threadId = &#63;.
2841             *
2842             * <p>
2843             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
2844             * </p>
2845             *
2846             * @param threadId the thread ID
2847             * @param start the lower bound of the range of message-boards messages
2848             * @param end the upper bound of the range of message-boards messages (not inclusive)
2849             * @return the range of matching message-boards messages
2850             * @throws SystemException if a system exception occurred
2851             */
2852            @Override
2853            public List<MBMessage> findByThreadId(long threadId, int start, int end)
2854                    throws SystemException {
2855                    return findByThreadId(threadId, start, end, null);
2856            }
2857    
2858            /**
2859             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
2860             *
2861             * <p>
2862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
2863             * </p>
2864             *
2865             * @param threadId the thread ID
2866             * @param start the lower bound of the range of message-boards messages
2867             * @param end the upper bound of the range of message-boards messages (not inclusive)
2868             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2869             * @return the ordered range of matching message-boards messages
2870             * @throws SystemException if a system exception occurred
2871             */
2872            @Override
2873            public List<MBMessage> findByThreadId(long threadId, int start, int end,
2874                    OrderByComparator orderByComparator) throws SystemException {
2875                    boolean pagination = true;
2876                    FinderPath finderPath = null;
2877                    Object[] finderArgs = null;
2878    
2879                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2880                                    (orderByComparator == null)) {
2881                            pagination = false;
2882                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
2883                            finderArgs = new Object[] { threadId };
2884                    }
2885                    else {
2886                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
2887                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
2888                    }
2889    
2890                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2891                                    finderArgs, this);
2892    
2893                    if ((list != null) && !list.isEmpty()) {
2894                            for (MBMessage mbMessage : list) {
2895                                    if ((threadId != mbMessage.getThreadId())) {
2896                                            list = null;
2897    
2898                                            break;
2899                                    }
2900                            }
2901                    }
2902    
2903                    if (list == null) {
2904                            StringBundler query = null;
2905    
2906                            if (orderByComparator != null) {
2907                                    query = new StringBundler(3 +
2908                                                    (orderByComparator.getOrderByFields().length * 3));
2909                            }
2910                            else {
2911                                    query = new StringBundler(3);
2912                            }
2913    
2914                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2915    
2916                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2917    
2918                            if (orderByComparator != null) {
2919                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2920                                            orderByComparator);
2921                            }
2922                            else
2923                             if (pagination) {
2924                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2925                            }
2926    
2927                            String sql = query.toString();
2928    
2929                            Session session = null;
2930    
2931                            try {
2932                                    session = openSession();
2933    
2934                                    Query q = session.createQuery(sql);
2935    
2936                                    QueryPos qPos = QueryPos.getInstance(q);
2937    
2938                                    qPos.add(threadId);
2939    
2940                                    if (!pagination) {
2941                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2942                                                            start, end, false);
2943    
2944                                            Collections.sort(list);
2945    
2946                                            list = new UnmodifiableList<MBMessage>(list);
2947                                    }
2948                                    else {
2949                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2950                                                            start, end);
2951                                    }
2952    
2953                                    cacheResult(list);
2954    
2955                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2956                            }
2957                            catch (Exception e) {
2958                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2959    
2960                                    throw processException(e);
2961                            }
2962                            finally {
2963                                    closeSession(session);
2964                            }
2965                    }
2966    
2967                    return list;
2968            }
2969    
2970            /**
2971             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2972             *
2973             * @param threadId the thread ID
2974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2975             * @return the first matching message-boards message
2976             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2977             * @throws SystemException if a system exception occurred
2978             */
2979            @Override
2980            public MBMessage findByThreadId_First(long threadId,
2981                    OrderByComparator orderByComparator)
2982                    throws NoSuchMessageException, SystemException {
2983                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
2984    
2985                    if (mbMessage != null) {
2986                            return mbMessage;
2987                    }
2988    
2989                    StringBundler msg = new StringBundler(4);
2990    
2991                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2992    
2993                    msg.append("threadId=");
2994                    msg.append(threadId);
2995    
2996                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2997    
2998                    throw new NoSuchMessageException(msg.toString());
2999            }
3000    
3001            /**
3002             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3003             *
3004             * @param threadId the thread ID
3005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3006             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3007             * @throws SystemException if a system exception occurred
3008             */
3009            @Override
3010            public MBMessage fetchByThreadId_First(long threadId,
3011                    OrderByComparator orderByComparator) throws SystemException {
3012                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3013    
3014                    if (!list.isEmpty()) {
3015                            return list.get(0);
3016                    }
3017    
3018                    return null;
3019            }
3020    
3021            /**
3022             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3023             *
3024             * @param threadId the thread ID
3025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3026             * @return the last matching message-boards message
3027             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3028             * @throws SystemException if a system exception occurred
3029             */
3030            @Override
3031            public MBMessage findByThreadId_Last(long threadId,
3032                    OrderByComparator orderByComparator)
3033                    throws NoSuchMessageException, SystemException {
3034                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3035    
3036                    if (mbMessage != null) {
3037                            return mbMessage;
3038                    }
3039    
3040                    StringBundler msg = new StringBundler(4);
3041    
3042                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3043    
3044                    msg.append("threadId=");
3045                    msg.append(threadId);
3046    
3047                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3048    
3049                    throw new NoSuchMessageException(msg.toString());
3050            }
3051    
3052            /**
3053             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3054             *
3055             * @param threadId the thread ID
3056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3057             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3058             * @throws SystemException if a system exception occurred
3059             */
3060            @Override
3061            public MBMessage fetchByThreadId_Last(long threadId,
3062                    OrderByComparator orderByComparator) throws SystemException {
3063                    int count = countByThreadId(threadId);
3064    
3065                    if (count == 0) {
3066                            return null;
3067                    }
3068    
3069                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3070                                    orderByComparator);
3071    
3072                    if (!list.isEmpty()) {
3073                            return list.get(0);
3074                    }
3075    
3076                    return null;
3077            }
3078    
3079            /**
3080             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3081             *
3082             * @param messageId the primary key of the current message-boards message
3083             * @param threadId the thread ID
3084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3085             * @return the previous, current, and next message-boards message
3086             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3087             * @throws SystemException if a system exception occurred
3088             */
3089            @Override
3090            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3091                    long threadId, OrderByComparator orderByComparator)
3092                    throws NoSuchMessageException, SystemException {
3093                    MBMessage mbMessage = findByPrimaryKey(messageId);
3094    
3095                    Session session = null;
3096    
3097                    try {
3098                            session = openSession();
3099    
3100                            MBMessage[] array = new MBMessageImpl[3];
3101    
3102                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3103                                            orderByComparator, true);
3104    
3105                            array[1] = mbMessage;
3106    
3107                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3108                                            orderByComparator, false);
3109    
3110                            return array;
3111                    }
3112                    catch (Exception e) {
3113                            throw processException(e);
3114                    }
3115                    finally {
3116                            closeSession(session);
3117                    }
3118            }
3119    
3120            protected MBMessage getByThreadId_PrevAndNext(Session session,
3121                    MBMessage mbMessage, long threadId,
3122                    OrderByComparator orderByComparator, boolean previous) {
3123                    StringBundler query = null;
3124    
3125                    if (orderByComparator != null) {
3126                            query = new StringBundler(6 +
3127                                            (orderByComparator.getOrderByFields().length * 6));
3128                    }
3129                    else {
3130                            query = new StringBundler(3);
3131                    }
3132    
3133                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3134    
3135                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3136    
3137                    if (orderByComparator != null) {
3138                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3139    
3140                            if (orderByConditionFields.length > 0) {
3141                                    query.append(WHERE_AND);
3142                            }
3143    
3144                            for (int i = 0; i < orderByConditionFields.length; i++) {
3145                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3146                                    query.append(orderByConditionFields[i]);
3147    
3148                                    if ((i + 1) < orderByConditionFields.length) {
3149                                            if (orderByComparator.isAscending() ^ previous) {
3150                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3151                                            }
3152                                            else {
3153                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3154                                            }
3155                                    }
3156                                    else {
3157                                            if (orderByComparator.isAscending() ^ previous) {
3158                                                    query.append(WHERE_GREATER_THAN);
3159                                            }
3160                                            else {
3161                                                    query.append(WHERE_LESSER_THAN);
3162                                            }
3163                                    }
3164                            }
3165    
3166                            query.append(ORDER_BY_CLAUSE);
3167    
3168                            String[] orderByFields = orderByComparator.getOrderByFields();
3169    
3170                            for (int i = 0; i < orderByFields.length; i++) {
3171                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3172                                    query.append(orderByFields[i]);
3173    
3174                                    if ((i + 1) < orderByFields.length) {
3175                                            if (orderByComparator.isAscending() ^ previous) {
3176                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3177                                            }
3178                                            else {
3179                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3180                                            }
3181                                    }
3182                                    else {
3183                                            if (orderByComparator.isAscending() ^ previous) {
3184                                                    query.append(ORDER_BY_ASC);
3185                                            }
3186                                            else {
3187                                                    query.append(ORDER_BY_DESC);
3188                                            }
3189                                    }
3190                            }
3191                    }
3192                    else {
3193                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3194                    }
3195    
3196                    String sql = query.toString();
3197    
3198                    Query q = session.createQuery(sql);
3199    
3200                    q.setFirstResult(0);
3201                    q.setMaxResults(2);
3202    
3203                    QueryPos qPos = QueryPos.getInstance(q);
3204    
3205                    qPos.add(threadId);
3206    
3207                    if (orderByComparator != null) {
3208                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3209    
3210                            for (Object value : values) {
3211                                    qPos.add(value);
3212                            }
3213                    }
3214    
3215                    List<MBMessage> list = q.list();
3216    
3217                    if (list.size() == 2) {
3218                            return list.get(1);
3219                    }
3220                    else {
3221                            return null;
3222                    }
3223            }
3224    
3225            /**
3226             * Removes all the message-boards messages where threadId = &#63; from the database.
3227             *
3228             * @param threadId the thread ID
3229             * @throws SystemException if a system exception occurred
3230             */
3231            @Override
3232            public void removeByThreadId(long threadId) throws SystemException {
3233                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3234                                    QueryUtil.ALL_POS, null)) {
3235                            remove(mbMessage);
3236                    }
3237            }
3238    
3239            /**
3240             * Returns the number of message-boards messages where threadId = &#63;.
3241             *
3242             * @param threadId the thread ID
3243             * @return the number of matching message-boards messages
3244             * @throws SystemException if a system exception occurred
3245             */
3246            @Override
3247            public int countByThreadId(long threadId) throws SystemException {
3248                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3249    
3250                    Object[] finderArgs = new Object[] { threadId };
3251    
3252                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3253                                    this);
3254    
3255                    if (count == null) {
3256                            StringBundler query = new StringBundler(2);
3257    
3258                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3259    
3260                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3261    
3262                            String sql = query.toString();
3263    
3264                            Session session = null;
3265    
3266                            try {
3267                                    session = openSession();
3268    
3269                                    Query q = session.createQuery(sql);
3270    
3271                                    QueryPos qPos = QueryPos.getInstance(q);
3272    
3273                                    qPos.add(threadId);
3274    
3275                                    count = (Long)q.uniqueResult();
3276    
3277                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3278                            }
3279                            catch (Exception e) {
3280                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3281    
3282                                    throw processException(e);
3283                            }
3284                            finally {
3285                                    closeSession(session);
3286                            }
3287                    }
3288    
3289                    return count.intValue();
3290            }
3291    
3292            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3293            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3294                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3295                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3296                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3297                            new String[] {
3298                                    Long.class.getName(),
3299                                    
3300                            Integer.class.getName(), Integer.class.getName(),
3301                                    OrderByComparator.class.getName()
3302                            });
3303            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3304                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3305                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3306                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3307                            new String[] { Long.class.getName() },
3308                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3309                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3310            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3311                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3312                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3313                            new String[] { Long.class.getName() });
3314    
3315            /**
3316             * Returns all the message-boards messages where threadId = &#63;.
3317             *
3318             * @param threadId the thread ID
3319             * @return the matching message-boards messages
3320             * @throws SystemException if a system exception occurred
3321             */
3322            @Override
3323            public List<MBMessage> findByThreadReplies(long threadId)
3324                    throws SystemException {
3325                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3326                            QueryUtil.ALL_POS, null);
3327            }
3328    
3329            /**
3330             * Returns a range of all the message-boards messages where threadId = &#63;.
3331             *
3332             * <p>
3333             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
3334             * </p>
3335             *
3336             * @param threadId the thread ID
3337             * @param start the lower bound of the range of message-boards messages
3338             * @param end the upper bound of the range of message-boards messages (not inclusive)
3339             * @return the range of matching message-boards messages
3340             * @throws SystemException if a system exception occurred
3341             */
3342            @Override
3343            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3344                    throws SystemException {
3345                    return findByThreadReplies(threadId, start, end, null);
3346            }
3347    
3348            /**
3349             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3350             *
3351             * <p>
3352             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
3353             * </p>
3354             *
3355             * @param threadId the thread ID
3356             * @param start the lower bound of the range of message-boards messages
3357             * @param end the upper bound of the range of message-boards messages (not inclusive)
3358             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3359             * @return the ordered range of matching message-boards messages
3360             * @throws SystemException if a system exception occurred
3361             */
3362            @Override
3363            public List<MBMessage> findByThreadReplies(long threadId, int start,
3364                    int end, OrderByComparator orderByComparator) throws SystemException {
3365                    boolean pagination = true;
3366                    FinderPath finderPath = null;
3367                    Object[] finderArgs = null;
3368    
3369                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3370                                    (orderByComparator == null)) {
3371                            pagination = false;
3372                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3373                            finderArgs = new Object[] { threadId };
3374                    }
3375                    else {
3376                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3377                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3378                    }
3379    
3380                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3381                                    finderArgs, this);
3382    
3383                    if ((list != null) && !list.isEmpty()) {
3384                            for (MBMessage mbMessage : list) {
3385                                    if ((threadId != mbMessage.getThreadId())) {
3386                                            list = null;
3387    
3388                                            break;
3389                                    }
3390                            }
3391                    }
3392    
3393                    if (list == null) {
3394                            StringBundler query = null;
3395    
3396                            if (orderByComparator != null) {
3397                                    query = new StringBundler(3 +
3398                                                    (orderByComparator.getOrderByFields().length * 3));
3399                            }
3400                            else {
3401                                    query = new StringBundler(3);
3402                            }
3403    
3404                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3405    
3406                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3407    
3408                            if (orderByComparator != null) {
3409                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3410                                            orderByComparator);
3411                            }
3412                            else
3413                             if (pagination) {
3414                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3415                            }
3416    
3417                            String sql = query.toString();
3418    
3419                            Session session = null;
3420    
3421                            try {
3422                                    session = openSession();
3423    
3424                                    Query q = session.createQuery(sql);
3425    
3426                                    QueryPos qPos = QueryPos.getInstance(q);
3427    
3428                                    qPos.add(threadId);
3429    
3430                                    if (!pagination) {
3431                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3432                                                            start, end, false);
3433    
3434                                            Collections.sort(list);
3435    
3436                                            list = new UnmodifiableList<MBMessage>(list);
3437                                    }
3438                                    else {
3439                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3440                                                            start, end);
3441                                    }
3442    
3443                                    cacheResult(list);
3444    
3445                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3446                            }
3447                            catch (Exception e) {
3448                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3449    
3450                                    throw processException(e);
3451                            }
3452                            finally {
3453                                    closeSession(session);
3454                            }
3455                    }
3456    
3457                    return list;
3458            }
3459    
3460            /**
3461             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3462             *
3463             * @param threadId the thread ID
3464             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3465             * @return the first matching message-boards message
3466             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3467             * @throws SystemException if a system exception occurred
3468             */
3469            @Override
3470            public MBMessage findByThreadReplies_First(long threadId,
3471                    OrderByComparator orderByComparator)
3472                    throws NoSuchMessageException, SystemException {
3473                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3474                                    orderByComparator);
3475    
3476                    if (mbMessage != null) {
3477                            return mbMessage;
3478                    }
3479    
3480                    StringBundler msg = new StringBundler(4);
3481    
3482                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3483    
3484                    msg.append("threadId=");
3485                    msg.append(threadId);
3486    
3487                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3488    
3489                    throw new NoSuchMessageException(msg.toString());
3490            }
3491    
3492            /**
3493             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3494             *
3495             * @param threadId the thread ID
3496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3497             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3498             * @throws SystemException if a system exception occurred
3499             */
3500            @Override
3501            public MBMessage fetchByThreadReplies_First(long threadId,
3502                    OrderByComparator orderByComparator) throws SystemException {
3503                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3504                                    orderByComparator);
3505    
3506                    if (!list.isEmpty()) {
3507                            return list.get(0);
3508                    }
3509    
3510                    return null;
3511            }
3512    
3513            /**
3514             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3515             *
3516             * @param threadId the thread ID
3517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3518             * @return the last matching message-boards message
3519             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3520             * @throws SystemException if a system exception occurred
3521             */
3522            @Override
3523            public MBMessage findByThreadReplies_Last(long threadId,
3524                    OrderByComparator orderByComparator)
3525                    throws NoSuchMessageException, SystemException {
3526                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3527                                    orderByComparator);
3528    
3529                    if (mbMessage != null) {
3530                            return mbMessage;
3531                    }
3532    
3533                    StringBundler msg = new StringBundler(4);
3534    
3535                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3536    
3537                    msg.append("threadId=");
3538                    msg.append(threadId);
3539    
3540                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3541    
3542                    throw new NoSuchMessageException(msg.toString());
3543            }
3544    
3545            /**
3546             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3547             *
3548             * @param threadId the thread ID
3549             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3550             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3551             * @throws SystemException if a system exception occurred
3552             */
3553            @Override
3554            public MBMessage fetchByThreadReplies_Last(long threadId,
3555                    OrderByComparator orderByComparator) throws SystemException {
3556                    int count = countByThreadReplies(threadId);
3557    
3558                    if (count == 0) {
3559                            return null;
3560                    }
3561    
3562                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3563                                    orderByComparator);
3564    
3565                    if (!list.isEmpty()) {
3566                            return list.get(0);
3567                    }
3568    
3569                    return null;
3570            }
3571    
3572            /**
3573             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3574             *
3575             * @param messageId the primary key of the current message-boards message
3576             * @param threadId the thread ID
3577             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3578             * @return the previous, current, and next message-boards message
3579             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3580             * @throws SystemException if a system exception occurred
3581             */
3582            @Override
3583            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3584                    long threadId, OrderByComparator orderByComparator)
3585                    throws NoSuchMessageException, SystemException {
3586                    MBMessage mbMessage = findByPrimaryKey(messageId);
3587    
3588                    Session session = null;
3589    
3590                    try {
3591                            session = openSession();
3592    
3593                            MBMessage[] array = new MBMessageImpl[3];
3594    
3595                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3596                                            threadId, orderByComparator, true);
3597    
3598                            array[1] = mbMessage;
3599    
3600                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3601                                            threadId, orderByComparator, false);
3602    
3603                            return array;
3604                    }
3605                    catch (Exception e) {
3606                            throw processException(e);
3607                    }
3608                    finally {
3609                            closeSession(session);
3610                    }
3611            }
3612    
3613            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3614                    MBMessage mbMessage, long threadId,
3615                    OrderByComparator orderByComparator, boolean previous) {
3616                    StringBundler query = null;
3617    
3618                    if (orderByComparator != null) {
3619                            query = new StringBundler(6 +
3620                                            (orderByComparator.getOrderByFields().length * 6));
3621                    }
3622                    else {
3623                            query = new StringBundler(3);
3624                    }
3625    
3626                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3627    
3628                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3629    
3630                    if (orderByComparator != null) {
3631                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3632    
3633                            if (orderByConditionFields.length > 0) {
3634                                    query.append(WHERE_AND);
3635                            }
3636    
3637                            for (int i = 0; i < orderByConditionFields.length; i++) {
3638                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3639                                    query.append(orderByConditionFields[i]);
3640    
3641                                    if ((i + 1) < orderByConditionFields.length) {
3642                                            if (orderByComparator.isAscending() ^ previous) {
3643                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3644                                            }
3645                                            else {
3646                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3647                                            }
3648                                    }
3649                                    else {
3650                                            if (orderByComparator.isAscending() ^ previous) {
3651                                                    query.append(WHERE_GREATER_THAN);
3652                                            }
3653                                            else {
3654                                                    query.append(WHERE_LESSER_THAN);
3655                                            }
3656                                    }
3657                            }
3658    
3659                            query.append(ORDER_BY_CLAUSE);
3660    
3661                            String[] orderByFields = orderByComparator.getOrderByFields();
3662    
3663                            for (int i = 0; i < orderByFields.length; i++) {
3664                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3665                                    query.append(orderByFields[i]);
3666    
3667                                    if ((i + 1) < orderByFields.length) {
3668                                            if (orderByComparator.isAscending() ^ previous) {
3669                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3670                                            }
3671                                            else {
3672                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3673                                            }
3674                                    }
3675                                    else {
3676                                            if (orderByComparator.isAscending() ^ previous) {
3677                                                    query.append(ORDER_BY_ASC);
3678                                            }
3679                                            else {
3680                                                    query.append(ORDER_BY_DESC);
3681                                            }
3682                                    }
3683                            }
3684                    }
3685                    else {
3686                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3687                    }
3688    
3689                    String sql = query.toString();
3690    
3691                    Query q = session.createQuery(sql);
3692    
3693                    q.setFirstResult(0);
3694                    q.setMaxResults(2);
3695    
3696                    QueryPos qPos = QueryPos.getInstance(q);
3697    
3698                    qPos.add(threadId);
3699    
3700                    if (orderByComparator != null) {
3701                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3702    
3703                            for (Object value : values) {
3704                                    qPos.add(value);
3705                            }
3706                    }
3707    
3708                    List<MBMessage> list = q.list();
3709    
3710                    if (list.size() == 2) {
3711                            return list.get(1);
3712                    }
3713                    else {
3714                            return null;
3715                    }
3716            }
3717    
3718            /**
3719             * Removes all the message-boards messages where threadId = &#63; from the database.
3720             *
3721             * @param threadId the thread ID
3722             * @throws SystemException if a system exception occurred
3723             */
3724            @Override
3725            public void removeByThreadReplies(long threadId) throws SystemException {
3726                    for (MBMessage mbMessage : findByThreadReplies(threadId,
3727                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3728                            remove(mbMessage);
3729                    }
3730            }
3731    
3732            /**
3733             * Returns the number of message-boards messages where threadId = &#63;.
3734             *
3735             * @param threadId the thread ID
3736             * @return the number of matching message-boards messages
3737             * @throws SystemException if a system exception occurred
3738             */
3739            @Override
3740            public int countByThreadReplies(long threadId) throws SystemException {
3741                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
3742    
3743                    Object[] finderArgs = new Object[] { threadId };
3744    
3745                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3746                                    this);
3747    
3748                    if (count == null) {
3749                            StringBundler query = new StringBundler(2);
3750    
3751                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3752    
3753                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3754    
3755                            String sql = query.toString();
3756    
3757                            Session session = null;
3758    
3759                            try {
3760                                    session = openSession();
3761    
3762                                    Query q = session.createQuery(sql);
3763    
3764                                    QueryPos qPos = QueryPos.getInstance(q);
3765    
3766                                    qPos.add(threadId);
3767    
3768                                    count = (Long)q.uniqueResult();
3769    
3770                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3771                            }
3772                            catch (Exception e) {
3773                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3774    
3775                                    throw processException(e);
3776                            }
3777                            finally {
3778                                    closeSession(session);
3779                            }
3780                    }
3781    
3782                    return count.intValue();
3783            }
3784    
3785            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
3786            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3787                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3788                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
3789                            new String[] {
3790                                    Long.class.getName(),
3791                                    
3792                            Integer.class.getName(), Integer.class.getName(),
3793                                    OrderByComparator.class.getName()
3794                            });
3795            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
3796                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3797                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3798                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
3799                            new String[] { Long.class.getName() },
3800                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
3801                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3802            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3803                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3804                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
3805                            new String[] { Long.class.getName() });
3806    
3807            /**
3808             * Returns all the message-boards messages where userId = &#63;.
3809             *
3810             * @param userId the user ID
3811             * @return the matching message-boards messages
3812             * @throws SystemException if a system exception occurred
3813             */
3814            @Override
3815            public List<MBMessage> findByUserId(long userId) throws SystemException {
3816                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3817            }
3818    
3819            /**
3820             * Returns a range of all the message-boards messages where userId = &#63;.
3821             *
3822             * <p>
3823             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
3824             * </p>
3825             *
3826             * @param userId the user ID
3827             * @param start the lower bound of the range of message-boards messages
3828             * @param end the upper bound of the range of message-boards messages (not inclusive)
3829             * @return the range of matching message-boards messages
3830             * @throws SystemException if a system exception occurred
3831             */
3832            @Override
3833            public List<MBMessage> findByUserId(long userId, int start, int end)
3834                    throws SystemException {
3835                    return findByUserId(userId, start, end, null);
3836            }
3837    
3838            /**
3839             * Returns an ordered range of all the message-boards messages where userId = &#63;.
3840             *
3841             * <p>
3842             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
3843             * </p>
3844             *
3845             * @param userId the user ID
3846             * @param start the lower bound of the range of message-boards messages
3847             * @param end the upper bound of the range of message-boards messages (not inclusive)
3848             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3849             * @return the ordered range of matching message-boards messages
3850             * @throws SystemException if a system exception occurred
3851             */
3852            @Override
3853            public List<MBMessage> findByUserId(long userId, int start, int end,
3854                    OrderByComparator orderByComparator) throws SystemException {
3855                    boolean pagination = true;
3856                    FinderPath finderPath = null;
3857                    Object[] finderArgs = null;
3858    
3859                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3860                                    (orderByComparator == null)) {
3861                            pagination = false;
3862                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3863                            finderArgs = new Object[] { userId };
3864                    }
3865                    else {
3866                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3867                            finderArgs = new Object[] { userId, start, end, orderByComparator };
3868                    }
3869    
3870                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3871                                    finderArgs, this);
3872    
3873                    if ((list != null) && !list.isEmpty()) {
3874                            for (MBMessage mbMessage : list) {
3875                                    if ((userId != mbMessage.getUserId())) {
3876                                            list = null;
3877    
3878                                            break;
3879                                    }
3880                            }
3881                    }
3882    
3883                    if (list == null) {
3884                            StringBundler query = null;
3885    
3886                            if (orderByComparator != null) {
3887                                    query = new StringBundler(3 +
3888                                                    (orderByComparator.getOrderByFields().length * 3));
3889                            }
3890                            else {
3891                                    query = new StringBundler(3);
3892                            }
3893    
3894                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3895    
3896                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3897    
3898                            if (orderByComparator != null) {
3899                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3900                                            orderByComparator);
3901                            }
3902                            else
3903                             if (pagination) {
3904                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3905                            }
3906    
3907                            String sql = query.toString();
3908    
3909                            Session session = null;
3910    
3911                            try {
3912                                    session = openSession();
3913    
3914                                    Query q = session.createQuery(sql);
3915    
3916                                    QueryPos qPos = QueryPos.getInstance(q);
3917    
3918                                    qPos.add(userId);
3919    
3920                                    if (!pagination) {
3921                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3922                                                            start, end, false);
3923    
3924                                            Collections.sort(list);
3925    
3926                                            list = new UnmodifiableList<MBMessage>(list);
3927                                    }
3928                                    else {
3929                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3930                                                            start, end);
3931                                    }
3932    
3933                                    cacheResult(list);
3934    
3935                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3936                            }
3937                            catch (Exception e) {
3938                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3939    
3940                                    throw processException(e);
3941                            }
3942                            finally {
3943                                    closeSession(session);
3944                            }
3945                    }
3946    
3947                    return list;
3948            }
3949    
3950            /**
3951             * Returns the first message-boards message in the ordered set where userId = &#63;.
3952             *
3953             * @param userId the user ID
3954             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3955             * @return the first matching message-boards message
3956             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3957             * @throws SystemException if a system exception occurred
3958             */
3959            @Override
3960            public MBMessage findByUserId_First(long userId,
3961                    OrderByComparator orderByComparator)
3962                    throws NoSuchMessageException, SystemException {
3963                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3964    
3965                    if (mbMessage != null) {
3966                            return mbMessage;
3967                    }
3968    
3969                    StringBundler msg = new StringBundler(4);
3970    
3971                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3972    
3973                    msg.append("userId=");
3974                    msg.append(userId);
3975    
3976                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3977    
3978                    throw new NoSuchMessageException(msg.toString());
3979            }
3980    
3981            /**
3982             * Returns the first message-boards message in the ordered set where userId = &#63;.
3983             *
3984             * @param userId the user ID
3985             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3986             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3987             * @throws SystemException if a system exception occurred
3988             */
3989            @Override
3990            public MBMessage fetchByUserId_First(long userId,
3991                    OrderByComparator orderByComparator) throws SystemException {
3992                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3993    
3994                    if (!list.isEmpty()) {
3995                            return list.get(0);
3996                    }
3997    
3998                    return null;
3999            }
4000    
4001            /**
4002             * Returns the last message-boards message in the ordered set where userId = &#63;.
4003             *
4004             * @param userId the user ID
4005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4006             * @return the last matching message-boards message
4007             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4008             * @throws SystemException if a system exception occurred
4009             */
4010            @Override
4011            public MBMessage findByUserId_Last(long userId,
4012                    OrderByComparator orderByComparator)
4013                    throws NoSuchMessageException, SystemException {
4014                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
4015    
4016                    if (mbMessage != null) {
4017                            return mbMessage;
4018                    }
4019    
4020                    StringBundler msg = new StringBundler(4);
4021    
4022                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4023    
4024                    msg.append("userId=");
4025                    msg.append(userId);
4026    
4027                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4028    
4029                    throw new NoSuchMessageException(msg.toString());
4030            }
4031    
4032            /**
4033             * Returns the last message-boards message in the ordered set where userId = &#63;.
4034             *
4035             * @param userId the user ID
4036             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4037             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4038             * @throws SystemException if a system exception occurred
4039             */
4040            @Override
4041            public MBMessage fetchByUserId_Last(long userId,
4042                    OrderByComparator orderByComparator) throws SystemException {
4043                    int count = countByUserId(userId);
4044    
4045                    if (count == 0) {
4046                            return null;
4047                    }
4048    
4049                    List<MBMessage> list = findByUserId(userId, count - 1, count,
4050                                    orderByComparator);
4051    
4052                    if (!list.isEmpty()) {
4053                            return list.get(0);
4054                    }
4055    
4056                    return null;
4057            }
4058    
4059            /**
4060             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
4061             *
4062             * @param messageId the primary key of the current message-boards message
4063             * @param userId the user ID
4064             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4065             * @return the previous, current, and next message-boards message
4066             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4067             * @throws SystemException if a system exception occurred
4068             */
4069            @Override
4070            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
4071                    OrderByComparator orderByComparator)
4072                    throws NoSuchMessageException, SystemException {
4073                    MBMessage mbMessage = findByPrimaryKey(messageId);
4074    
4075                    Session session = null;
4076    
4077                    try {
4078                            session = openSession();
4079    
4080                            MBMessage[] array = new MBMessageImpl[3];
4081    
4082                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
4083                                            orderByComparator, true);
4084    
4085                            array[1] = mbMessage;
4086    
4087                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
4088                                            orderByComparator, false);
4089    
4090                            return array;
4091                    }
4092                    catch (Exception e) {
4093                            throw processException(e);
4094                    }
4095                    finally {
4096                            closeSession(session);
4097                    }
4098            }
4099    
4100            protected MBMessage getByUserId_PrevAndNext(Session session,
4101                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
4102                    boolean previous) {
4103                    StringBundler query = null;
4104    
4105                    if (orderByComparator != null) {
4106                            query = new StringBundler(6 +
4107                                            (orderByComparator.getOrderByFields().length * 6));
4108                    }
4109                    else {
4110                            query = new StringBundler(3);
4111                    }
4112    
4113                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4114    
4115                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4116    
4117                    if (orderByComparator != null) {
4118                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4119    
4120                            if (orderByConditionFields.length > 0) {
4121                                    query.append(WHERE_AND);
4122                            }
4123    
4124                            for (int i = 0; i < orderByConditionFields.length; i++) {
4125                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4126                                    query.append(orderByConditionFields[i]);
4127    
4128                                    if ((i + 1) < orderByConditionFields.length) {
4129                                            if (orderByComparator.isAscending() ^ previous) {
4130                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4131                                            }
4132                                            else {
4133                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4134                                            }
4135                                    }
4136                                    else {
4137                                            if (orderByComparator.isAscending() ^ previous) {
4138                                                    query.append(WHERE_GREATER_THAN);
4139                                            }
4140                                            else {
4141                                                    query.append(WHERE_LESSER_THAN);
4142                                            }
4143                                    }
4144                            }
4145    
4146                            query.append(ORDER_BY_CLAUSE);
4147    
4148                            String[] orderByFields = orderByComparator.getOrderByFields();
4149    
4150                            for (int i = 0; i < orderByFields.length; i++) {
4151                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4152                                    query.append(orderByFields[i]);
4153    
4154                                    if ((i + 1) < orderByFields.length) {
4155                                            if (orderByComparator.isAscending() ^ previous) {
4156                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4157                                            }
4158                                            else {
4159                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4160                                            }
4161                                    }
4162                                    else {
4163                                            if (orderByComparator.isAscending() ^ previous) {
4164                                                    query.append(ORDER_BY_ASC);
4165                                            }
4166                                            else {
4167                                                    query.append(ORDER_BY_DESC);
4168                                            }
4169                                    }
4170                            }
4171                    }
4172                    else {
4173                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4174                    }
4175    
4176                    String sql = query.toString();
4177    
4178                    Query q = session.createQuery(sql);
4179    
4180                    q.setFirstResult(0);
4181                    q.setMaxResults(2);
4182    
4183                    QueryPos qPos = QueryPos.getInstance(q);
4184    
4185                    qPos.add(userId);
4186    
4187                    if (orderByComparator != null) {
4188                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4189    
4190                            for (Object value : values) {
4191                                    qPos.add(value);
4192                            }
4193                    }
4194    
4195                    List<MBMessage> list = q.list();
4196    
4197                    if (list.size() == 2) {
4198                            return list.get(1);
4199                    }
4200                    else {
4201                            return null;
4202                    }
4203            }
4204    
4205            /**
4206             * Removes all the message-boards messages where userId = &#63; from the database.
4207             *
4208             * @param userId the user ID
4209             * @throws SystemException if a system exception occurred
4210             */
4211            @Override
4212            public void removeByUserId(long userId) throws SystemException {
4213                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
4214                                    QueryUtil.ALL_POS, null)) {
4215                            remove(mbMessage);
4216                    }
4217            }
4218    
4219            /**
4220             * Returns the number of message-boards messages where userId = &#63;.
4221             *
4222             * @param userId the user ID
4223             * @return the number of matching message-boards messages
4224             * @throws SystemException if a system exception occurred
4225             */
4226            @Override
4227            public int countByUserId(long userId) throws SystemException {
4228                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
4229    
4230                    Object[] finderArgs = new Object[] { userId };
4231    
4232                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4233                                    this);
4234    
4235                    if (count == null) {
4236                            StringBundler query = new StringBundler(2);
4237    
4238                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4239    
4240                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4241    
4242                            String sql = query.toString();
4243    
4244                            Session session = null;
4245    
4246                            try {
4247                                    session = openSession();
4248    
4249                                    Query q = session.createQuery(sql);
4250    
4251                                    QueryPos qPos = QueryPos.getInstance(q);
4252    
4253                                    qPos.add(userId);
4254    
4255                                    count = (Long)q.uniqueResult();
4256    
4257                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4258                            }
4259                            catch (Exception e) {
4260                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4261    
4262                                    throw processException(e);
4263                            }
4264                            finally {
4265                                    closeSession(session);
4266                            }
4267                    }
4268    
4269                    return count.intValue();
4270            }
4271    
4272            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
4273            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4274                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4275                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4276                            new String[] {
4277                                    Long.class.getName(), Long.class.getName(),
4278                                    
4279                            Integer.class.getName(), Integer.class.getName(),
4280                                    OrderByComparator.class.getName()
4281                            });
4282            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4283                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4284                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4285                            new String[] { Long.class.getName(), Long.class.getName() },
4286                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4287                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4288                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4289            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4290                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4291                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4292                            new String[] { Long.class.getName(), Long.class.getName() });
4293    
4294            /**
4295             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4296             *
4297             * @param groupId the group ID
4298             * @param userId the user ID
4299             * @return the matching message-boards messages
4300             * @throws SystemException if a system exception occurred
4301             */
4302            @Override
4303            public List<MBMessage> findByG_U(long groupId, long userId)
4304                    throws SystemException {
4305                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4306                            null);
4307            }
4308    
4309            /**
4310             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4311             *
4312             * <p>
4313             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
4314             * </p>
4315             *
4316             * @param groupId the group ID
4317             * @param userId the user ID
4318             * @param start the lower bound of the range of message-boards messages
4319             * @param end the upper bound of the range of message-boards messages (not inclusive)
4320             * @return the range of matching message-boards messages
4321             * @throws SystemException if a system exception occurred
4322             */
4323            @Override
4324            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4325                    int end) throws SystemException {
4326                    return findByG_U(groupId, userId, start, end, null);
4327            }
4328    
4329            /**
4330             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4331             *
4332             * <p>
4333             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
4334             * </p>
4335             *
4336             * @param groupId the group ID
4337             * @param userId the user ID
4338             * @param start the lower bound of the range of message-boards messages
4339             * @param end the upper bound of the range of message-boards messages (not inclusive)
4340             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4341             * @return the ordered range of matching message-boards messages
4342             * @throws SystemException if a system exception occurred
4343             */
4344            @Override
4345            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4346                    int end, OrderByComparator orderByComparator) throws SystemException {
4347                    boolean pagination = true;
4348                    FinderPath finderPath = null;
4349                    Object[] finderArgs = null;
4350    
4351                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4352                                    (orderByComparator == null)) {
4353                            pagination = false;
4354                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4355                            finderArgs = new Object[] { groupId, userId };
4356                    }
4357                    else {
4358                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4359                            finderArgs = new Object[] {
4360                                            groupId, userId,
4361                                            
4362                                            start, end, orderByComparator
4363                                    };
4364                    }
4365    
4366                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4367                                    finderArgs, this);
4368    
4369                    if ((list != null) && !list.isEmpty()) {
4370                            for (MBMessage mbMessage : list) {
4371                                    if ((groupId != mbMessage.getGroupId()) ||
4372                                                    (userId != mbMessage.getUserId())) {
4373                                            list = null;
4374    
4375                                            break;
4376                                    }
4377                            }
4378                    }
4379    
4380                    if (list == null) {
4381                            StringBundler query = null;
4382    
4383                            if (orderByComparator != null) {
4384                                    query = new StringBundler(4 +
4385                                                    (orderByComparator.getOrderByFields().length * 3));
4386                            }
4387                            else {
4388                                    query = new StringBundler(4);
4389                            }
4390    
4391                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4392    
4393                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4394    
4395                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4396    
4397                            if (orderByComparator != null) {
4398                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4399                                            orderByComparator);
4400                            }
4401                            else
4402                             if (pagination) {
4403                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4404                            }
4405    
4406                            String sql = query.toString();
4407    
4408                            Session session = null;
4409    
4410                            try {
4411                                    session = openSession();
4412    
4413                                    Query q = session.createQuery(sql);
4414    
4415                                    QueryPos qPos = QueryPos.getInstance(q);
4416    
4417                                    qPos.add(groupId);
4418    
4419                                    qPos.add(userId);
4420    
4421                                    if (!pagination) {
4422                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4423                                                            start, end, false);
4424    
4425                                            Collections.sort(list);
4426    
4427                                            list = new UnmodifiableList<MBMessage>(list);
4428                                    }
4429                                    else {
4430                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4431                                                            start, end);
4432                                    }
4433    
4434                                    cacheResult(list);
4435    
4436                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4437                            }
4438                            catch (Exception e) {
4439                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4440    
4441                                    throw processException(e);
4442                            }
4443                            finally {
4444                                    closeSession(session);
4445                            }
4446                    }
4447    
4448                    return list;
4449            }
4450    
4451            /**
4452             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4453             *
4454             * @param groupId the group ID
4455             * @param userId the user ID
4456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4457             * @return the first matching message-boards message
4458             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4459             * @throws SystemException if a system exception occurred
4460             */
4461            @Override
4462            public MBMessage findByG_U_First(long groupId, long userId,
4463                    OrderByComparator orderByComparator)
4464                    throws NoSuchMessageException, SystemException {
4465                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4466                                    orderByComparator);
4467    
4468                    if (mbMessage != null) {
4469                            return mbMessage;
4470                    }
4471    
4472                    StringBundler msg = new StringBundler(6);
4473    
4474                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4475    
4476                    msg.append("groupId=");
4477                    msg.append(groupId);
4478    
4479                    msg.append(", userId=");
4480                    msg.append(userId);
4481    
4482                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4483    
4484                    throw new NoSuchMessageException(msg.toString());
4485            }
4486    
4487            /**
4488             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4489             *
4490             * @param groupId the group ID
4491             * @param userId the user ID
4492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4493             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4494             * @throws SystemException if a system exception occurred
4495             */
4496            @Override
4497            public MBMessage fetchByG_U_First(long groupId, long userId,
4498                    OrderByComparator orderByComparator) throws SystemException {
4499                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4500                                    orderByComparator);
4501    
4502                    if (!list.isEmpty()) {
4503                            return list.get(0);
4504                    }
4505    
4506                    return null;
4507            }
4508    
4509            /**
4510             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4511             *
4512             * @param groupId the group ID
4513             * @param userId the user ID
4514             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4515             * @return the last matching message-boards message
4516             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4517             * @throws SystemException if a system exception occurred
4518             */
4519            @Override
4520            public MBMessage findByG_U_Last(long groupId, long userId,
4521                    OrderByComparator orderByComparator)
4522                    throws NoSuchMessageException, SystemException {
4523                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4524    
4525                    if (mbMessage != null) {
4526                            return mbMessage;
4527                    }
4528    
4529                    StringBundler msg = new StringBundler(6);
4530    
4531                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4532    
4533                    msg.append("groupId=");
4534                    msg.append(groupId);
4535    
4536                    msg.append(", userId=");
4537                    msg.append(userId);
4538    
4539                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4540    
4541                    throw new NoSuchMessageException(msg.toString());
4542            }
4543    
4544            /**
4545             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4546             *
4547             * @param groupId the group ID
4548             * @param userId the user ID
4549             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4550             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4551             * @throws SystemException if a system exception occurred
4552             */
4553            @Override
4554            public MBMessage fetchByG_U_Last(long groupId, long userId,
4555                    OrderByComparator orderByComparator) throws SystemException {
4556                    int count = countByG_U(groupId, userId);
4557    
4558                    if (count == 0) {
4559                            return null;
4560                    }
4561    
4562                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4563                                    orderByComparator);
4564    
4565                    if (!list.isEmpty()) {
4566                            return list.get(0);
4567                    }
4568    
4569                    return null;
4570            }
4571    
4572            /**
4573             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4574             *
4575             * @param messageId the primary key of the current message-boards message
4576             * @param groupId the group ID
4577             * @param userId the user ID
4578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4579             * @return the previous, current, and next message-boards message
4580             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4581             * @throws SystemException if a system exception occurred
4582             */
4583            @Override
4584            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4585                    long userId, OrderByComparator orderByComparator)
4586                    throws NoSuchMessageException, SystemException {
4587                    MBMessage mbMessage = findByPrimaryKey(messageId);
4588    
4589                    Session session = null;
4590    
4591                    try {
4592                            session = openSession();
4593    
4594                            MBMessage[] array = new MBMessageImpl[3];
4595    
4596                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4597                                            userId, orderByComparator, true);
4598    
4599                            array[1] = mbMessage;
4600    
4601                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4602                                            userId, orderByComparator, false);
4603    
4604                            return array;
4605                    }
4606                    catch (Exception e) {
4607                            throw processException(e);
4608                    }
4609                    finally {
4610                            closeSession(session);
4611                    }
4612            }
4613    
4614            protected MBMessage getByG_U_PrevAndNext(Session session,
4615                    MBMessage mbMessage, long groupId, long userId,
4616                    OrderByComparator orderByComparator, boolean previous) {
4617                    StringBundler query = null;
4618    
4619                    if (orderByComparator != null) {
4620                            query = new StringBundler(6 +
4621                                            (orderByComparator.getOrderByFields().length * 6));
4622                    }
4623                    else {
4624                            query = new StringBundler(3);
4625                    }
4626    
4627                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4628    
4629                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4630    
4631                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4632    
4633                    if (orderByComparator != null) {
4634                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4635    
4636                            if (orderByConditionFields.length > 0) {
4637                                    query.append(WHERE_AND);
4638                            }
4639    
4640                            for (int i = 0; i < orderByConditionFields.length; i++) {
4641                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4642                                    query.append(orderByConditionFields[i]);
4643    
4644                                    if ((i + 1) < orderByConditionFields.length) {
4645                                            if (orderByComparator.isAscending() ^ previous) {
4646                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4647                                            }
4648                                            else {
4649                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4650                                            }
4651                                    }
4652                                    else {
4653                                            if (orderByComparator.isAscending() ^ previous) {
4654                                                    query.append(WHERE_GREATER_THAN);
4655                                            }
4656                                            else {
4657                                                    query.append(WHERE_LESSER_THAN);
4658                                            }
4659                                    }
4660                            }
4661    
4662                            query.append(ORDER_BY_CLAUSE);
4663    
4664                            String[] orderByFields = orderByComparator.getOrderByFields();
4665    
4666                            for (int i = 0; i < orderByFields.length; i++) {
4667                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4668                                    query.append(orderByFields[i]);
4669    
4670                                    if ((i + 1) < orderByFields.length) {
4671                                            if (orderByComparator.isAscending() ^ previous) {
4672                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4673                                            }
4674                                            else {
4675                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4676                                            }
4677                                    }
4678                                    else {
4679                                            if (orderByComparator.isAscending() ^ previous) {
4680                                                    query.append(ORDER_BY_ASC);
4681                                            }
4682                                            else {
4683                                                    query.append(ORDER_BY_DESC);
4684                                            }
4685                                    }
4686                            }
4687                    }
4688                    else {
4689                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4690                    }
4691    
4692                    String sql = query.toString();
4693    
4694                    Query q = session.createQuery(sql);
4695    
4696                    q.setFirstResult(0);
4697                    q.setMaxResults(2);
4698    
4699                    QueryPos qPos = QueryPos.getInstance(q);
4700    
4701                    qPos.add(groupId);
4702    
4703                    qPos.add(userId);
4704    
4705                    if (orderByComparator != null) {
4706                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4707    
4708                            for (Object value : values) {
4709                                    qPos.add(value);
4710                            }
4711                    }
4712    
4713                    List<MBMessage> list = q.list();
4714    
4715                    if (list.size() == 2) {
4716                            return list.get(1);
4717                    }
4718                    else {
4719                            return null;
4720                    }
4721            }
4722    
4723            /**
4724             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4725             *
4726             * @param groupId the group ID
4727             * @param userId the user ID
4728             * @return the matching message-boards messages that the user has permission to view
4729             * @throws SystemException if a system exception occurred
4730             */
4731            @Override
4732            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4733                    throws SystemException {
4734                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4735                            QueryUtil.ALL_POS, null);
4736            }
4737    
4738            /**
4739             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4740             *
4741             * <p>
4742             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
4743             * </p>
4744             *
4745             * @param groupId the group ID
4746             * @param userId the user ID
4747             * @param start the lower bound of the range of message-boards messages
4748             * @param end the upper bound of the range of message-boards messages (not inclusive)
4749             * @return the range of matching message-boards messages that the user has permission to view
4750             * @throws SystemException if a system exception occurred
4751             */
4752            @Override
4753            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4754                    int start, int end) throws SystemException {
4755                    return filterFindByG_U(groupId, userId, start, end, null);
4756            }
4757    
4758            /**
4759             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4760             *
4761             * <p>
4762             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
4763             * </p>
4764             *
4765             * @param groupId the group ID
4766             * @param userId the user ID
4767             * @param start the lower bound of the range of message-boards messages
4768             * @param end the upper bound of the range of message-boards messages (not inclusive)
4769             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4770             * @return the ordered range of matching message-boards messages that the user has permission to view
4771             * @throws SystemException if a system exception occurred
4772             */
4773            @Override
4774            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4775                    int start, int end, OrderByComparator orderByComparator)
4776                    throws SystemException {
4777                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4778                            return findByG_U(groupId, userId, start, end, orderByComparator);
4779                    }
4780    
4781                    StringBundler query = null;
4782    
4783                    if (orderByComparator != null) {
4784                            query = new StringBundler(4 +
4785                                            (orderByComparator.getOrderByFields().length * 3));
4786                    }
4787                    else {
4788                            query = new StringBundler(4);
4789                    }
4790    
4791                    if (getDB().isSupportsInlineDistinct()) {
4792                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4793                    }
4794                    else {
4795                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4796                    }
4797    
4798                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4799    
4800                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4801    
4802                    if (!getDB().isSupportsInlineDistinct()) {
4803                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4804                    }
4805    
4806                    if (orderByComparator != null) {
4807                            if (getDB().isSupportsInlineDistinct()) {
4808                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4809                                            orderByComparator, true);
4810                            }
4811                            else {
4812                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4813                                            orderByComparator, true);
4814                            }
4815                    }
4816                    else {
4817                            if (getDB().isSupportsInlineDistinct()) {
4818                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4819                            }
4820                            else {
4821                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4822                            }
4823                    }
4824    
4825                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4826                                    MBMessage.class.getName(),
4827                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4828    
4829                    Session session = null;
4830    
4831                    try {
4832                            session = openSession();
4833    
4834                            SQLQuery q = session.createSQLQuery(sql);
4835    
4836                            if (getDB().isSupportsInlineDistinct()) {
4837                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4838                            }
4839                            else {
4840                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4841                            }
4842    
4843                            QueryPos qPos = QueryPos.getInstance(q);
4844    
4845                            qPos.add(groupId);
4846    
4847                            qPos.add(userId);
4848    
4849                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4850                    }
4851                    catch (Exception e) {
4852                            throw processException(e);
4853                    }
4854                    finally {
4855                            closeSession(session);
4856                    }
4857            }
4858    
4859            /**
4860             * 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;.
4861             *
4862             * @param messageId the primary key of the current message-boards message
4863             * @param groupId the group ID
4864             * @param userId the user ID
4865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4866             * @return the previous, current, and next message-boards message
4867             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4868             * @throws SystemException if a system exception occurred
4869             */
4870            @Override
4871            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4872                    long groupId, long userId, OrderByComparator orderByComparator)
4873                    throws NoSuchMessageException, SystemException {
4874                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4875                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4876                                    orderByComparator);
4877                    }
4878    
4879                    MBMessage mbMessage = findByPrimaryKey(messageId);
4880    
4881                    Session session = null;
4882    
4883                    try {
4884                            session = openSession();
4885    
4886                            MBMessage[] array = new MBMessageImpl[3];
4887    
4888                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4889                                            userId, orderByComparator, true);
4890    
4891                            array[1] = mbMessage;
4892    
4893                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4894                                            userId, orderByComparator, false);
4895    
4896                            return array;
4897                    }
4898                    catch (Exception e) {
4899                            throw processException(e);
4900                    }
4901                    finally {
4902                            closeSession(session);
4903                    }
4904            }
4905    
4906            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4907                    MBMessage mbMessage, long groupId, long userId,
4908                    OrderByComparator orderByComparator, boolean previous) {
4909                    StringBundler query = null;
4910    
4911                    if (orderByComparator != null) {
4912                            query = new StringBundler(6 +
4913                                            (orderByComparator.getOrderByFields().length * 6));
4914                    }
4915                    else {
4916                            query = new StringBundler(3);
4917                    }
4918    
4919                    if (getDB().isSupportsInlineDistinct()) {
4920                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4921                    }
4922                    else {
4923                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4924                    }
4925    
4926                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4927    
4928                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4929    
4930                    if (!getDB().isSupportsInlineDistinct()) {
4931                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4932                    }
4933    
4934                    if (orderByComparator != null) {
4935                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4936    
4937                            if (orderByConditionFields.length > 0) {
4938                                    query.append(WHERE_AND);
4939                            }
4940    
4941                            for (int i = 0; i < orderByConditionFields.length; i++) {
4942                                    if (getDB().isSupportsInlineDistinct()) {
4943                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4944                                    }
4945                                    else {
4946                                            query.append(_ORDER_BY_ENTITY_TABLE);
4947                                    }
4948    
4949                                    query.append(orderByConditionFields[i]);
4950    
4951                                    if ((i + 1) < orderByConditionFields.length) {
4952                                            if (orderByComparator.isAscending() ^ previous) {
4953                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4954                                            }
4955                                            else {
4956                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4957                                            }
4958                                    }
4959                                    else {
4960                                            if (orderByComparator.isAscending() ^ previous) {
4961                                                    query.append(WHERE_GREATER_THAN);
4962                                            }
4963                                            else {
4964                                                    query.append(WHERE_LESSER_THAN);
4965                                            }
4966                                    }
4967                            }
4968    
4969                            query.append(ORDER_BY_CLAUSE);
4970    
4971                            String[] orderByFields = orderByComparator.getOrderByFields();
4972    
4973                            for (int i = 0; i < orderByFields.length; i++) {
4974                                    if (getDB().isSupportsInlineDistinct()) {
4975                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4976                                    }
4977                                    else {
4978                                            query.append(_ORDER_BY_ENTITY_TABLE);
4979                                    }
4980    
4981                                    query.append(orderByFields[i]);
4982    
4983                                    if ((i + 1) < orderByFields.length) {
4984                                            if (orderByComparator.isAscending() ^ previous) {
4985                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4986                                            }
4987                                            else {
4988                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4989                                            }
4990                                    }
4991                                    else {
4992                                            if (orderByComparator.isAscending() ^ previous) {
4993                                                    query.append(ORDER_BY_ASC);
4994                                            }
4995                                            else {
4996                                                    query.append(ORDER_BY_DESC);
4997                                            }
4998                                    }
4999                            }
5000                    }
5001                    else {
5002                            if (getDB().isSupportsInlineDistinct()) {
5003                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5004                            }
5005                            else {
5006                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5007                            }
5008                    }
5009    
5010                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5011                                    MBMessage.class.getName(),
5012                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5013    
5014                    SQLQuery q = session.createSQLQuery(sql);
5015    
5016                    q.setFirstResult(0);
5017                    q.setMaxResults(2);
5018    
5019                    if (getDB().isSupportsInlineDistinct()) {
5020                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5021                    }
5022                    else {
5023                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5024                    }
5025    
5026                    QueryPos qPos = QueryPos.getInstance(q);
5027    
5028                    qPos.add(groupId);
5029    
5030                    qPos.add(userId);
5031    
5032                    if (orderByComparator != null) {
5033                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5034    
5035                            for (Object value : values) {
5036                                    qPos.add(value);
5037                            }
5038                    }
5039    
5040                    List<MBMessage> list = q.list();
5041    
5042                    if (list.size() == 2) {
5043                            return list.get(1);
5044                    }
5045                    else {
5046                            return null;
5047                    }
5048            }
5049    
5050            /**
5051             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5052             *
5053             * @param groupId the group ID
5054             * @param userId the user ID
5055             * @throws SystemException if a system exception occurred
5056             */
5057            @Override
5058            public void removeByG_U(long groupId, long userId)
5059                    throws SystemException {
5060                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5061                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5062                            remove(mbMessage);
5063                    }
5064            }
5065    
5066            /**
5067             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5068             *
5069             * @param groupId the group ID
5070             * @param userId the user ID
5071             * @return the number of matching message-boards messages
5072             * @throws SystemException if a system exception occurred
5073             */
5074            @Override
5075            public int countByG_U(long groupId, long userId) throws SystemException {
5076                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5077    
5078                    Object[] finderArgs = new Object[] { groupId, userId };
5079    
5080                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5081                                    this);
5082    
5083                    if (count == null) {
5084                            StringBundler query = new StringBundler(3);
5085    
5086                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5087    
5088                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5089    
5090                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5091    
5092                            String sql = query.toString();
5093    
5094                            Session session = null;
5095    
5096                            try {
5097                                    session = openSession();
5098    
5099                                    Query q = session.createQuery(sql);
5100    
5101                                    QueryPos qPos = QueryPos.getInstance(q);
5102    
5103                                    qPos.add(groupId);
5104    
5105                                    qPos.add(userId);
5106    
5107                                    count = (Long)q.uniqueResult();
5108    
5109                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5110                            }
5111                            catch (Exception e) {
5112                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5113    
5114                                    throw processException(e);
5115                            }
5116                            finally {
5117                                    closeSession(session);
5118                            }
5119                    }
5120    
5121                    return count.intValue();
5122            }
5123    
5124            /**
5125             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5126             *
5127             * @param groupId the group ID
5128             * @param userId the user ID
5129             * @return the number of matching message-boards messages that the user has permission to view
5130             * @throws SystemException if a system exception occurred
5131             */
5132            @Override
5133            public int filterCountByG_U(long groupId, long userId)
5134                    throws SystemException {
5135                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5136                            return countByG_U(groupId, userId);
5137                    }
5138    
5139                    StringBundler query = new StringBundler(3);
5140    
5141                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5142    
5143                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5144    
5145                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5146    
5147                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5148                                    MBMessage.class.getName(),
5149                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5150    
5151                    Session session = null;
5152    
5153                    try {
5154                            session = openSession();
5155    
5156                            SQLQuery q = session.createSQLQuery(sql);
5157    
5158                            q.addScalar(COUNT_COLUMN_NAME,
5159                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5160    
5161                            QueryPos qPos = QueryPos.getInstance(q);
5162    
5163                            qPos.add(groupId);
5164    
5165                            qPos.add(userId);
5166    
5167                            Long count = (Long)q.uniqueResult();
5168    
5169                            return count.intValue();
5170                    }
5171                    catch (Exception e) {
5172                            throw processException(e);
5173                    }
5174                    finally {
5175                            closeSession(session);
5176                    }
5177            }
5178    
5179            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5180            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5181            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5182                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5183                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5184                            new String[] {
5185                                    Long.class.getName(), Long.class.getName(),
5186                                    
5187                            Integer.class.getName(), Integer.class.getName(),
5188                                    OrderByComparator.class.getName()
5189                            });
5190            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5191                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5192                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5193                            new String[] { Long.class.getName(), Long.class.getName() },
5194                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5195                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5196                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5197            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5199                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5200                            new String[] { Long.class.getName(), Long.class.getName() });
5201    
5202            /**
5203             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5204             *
5205             * @param groupId the group ID
5206             * @param categoryId the category ID
5207             * @return the matching message-boards messages
5208             * @throws SystemException if a system exception occurred
5209             */
5210            @Override
5211            public List<MBMessage> findByG_C(long groupId, long categoryId)
5212                    throws SystemException {
5213                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5214                            QueryUtil.ALL_POS, null);
5215            }
5216    
5217            /**
5218             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5219             *
5220             * <p>
5221             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
5222             * </p>
5223             *
5224             * @param groupId the group ID
5225             * @param categoryId the category ID
5226             * @param start the lower bound of the range of message-boards messages
5227             * @param end the upper bound of the range of message-boards messages (not inclusive)
5228             * @return the range of matching message-boards messages
5229             * @throws SystemException if a system exception occurred
5230             */
5231            @Override
5232            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5233                    int end) throws SystemException {
5234                    return findByG_C(groupId, categoryId, start, end, null);
5235            }
5236    
5237            /**
5238             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5239             *
5240             * <p>
5241             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
5242             * </p>
5243             *
5244             * @param groupId the group ID
5245             * @param categoryId the category ID
5246             * @param start the lower bound of the range of message-boards messages
5247             * @param end the upper bound of the range of message-boards messages (not inclusive)
5248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5249             * @return the ordered range of matching message-boards messages
5250             * @throws SystemException if a system exception occurred
5251             */
5252            @Override
5253            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5254                    int end, OrderByComparator orderByComparator) throws SystemException {
5255                    boolean pagination = true;
5256                    FinderPath finderPath = null;
5257                    Object[] finderArgs = null;
5258    
5259                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5260                                    (orderByComparator == null)) {
5261                            pagination = false;
5262                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5263                            finderArgs = new Object[] { groupId, categoryId };
5264                    }
5265                    else {
5266                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5267                            finderArgs = new Object[] {
5268                                            groupId, categoryId,
5269                                            
5270                                            start, end, orderByComparator
5271                                    };
5272                    }
5273    
5274                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5275                                    finderArgs, this);
5276    
5277                    if ((list != null) && !list.isEmpty()) {
5278                            for (MBMessage mbMessage : list) {
5279                                    if ((groupId != mbMessage.getGroupId()) ||
5280                                                    (categoryId != mbMessage.getCategoryId())) {
5281                                            list = null;
5282    
5283                                            break;
5284                                    }
5285                            }
5286                    }
5287    
5288                    if (list == null) {
5289                            StringBundler query = null;
5290    
5291                            if (orderByComparator != null) {
5292                                    query = new StringBundler(4 +
5293                                                    (orderByComparator.getOrderByFields().length * 3));
5294                            }
5295                            else {
5296                                    query = new StringBundler(4);
5297                            }
5298    
5299                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5300    
5301                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5302    
5303                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5304    
5305                            if (orderByComparator != null) {
5306                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5307                                            orderByComparator);
5308                            }
5309                            else
5310                             if (pagination) {
5311                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5312                            }
5313    
5314                            String sql = query.toString();
5315    
5316                            Session session = null;
5317    
5318                            try {
5319                                    session = openSession();
5320    
5321                                    Query q = session.createQuery(sql);
5322    
5323                                    QueryPos qPos = QueryPos.getInstance(q);
5324    
5325                                    qPos.add(groupId);
5326    
5327                                    qPos.add(categoryId);
5328    
5329                                    if (!pagination) {
5330                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5331                                                            start, end, false);
5332    
5333                                            Collections.sort(list);
5334    
5335                                            list = new UnmodifiableList<MBMessage>(list);
5336                                    }
5337                                    else {
5338                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5339                                                            start, end);
5340                                    }
5341    
5342                                    cacheResult(list);
5343    
5344                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5345                            }
5346                            catch (Exception e) {
5347                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5348    
5349                                    throw processException(e);
5350                            }
5351                            finally {
5352                                    closeSession(session);
5353                            }
5354                    }
5355    
5356                    return list;
5357            }
5358    
5359            /**
5360             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5361             *
5362             * @param groupId the group ID
5363             * @param categoryId the category ID
5364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5365             * @return the first matching message-boards message
5366             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5367             * @throws SystemException if a system exception occurred
5368             */
5369            @Override
5370            public MBMessage findByG_C_First(long groupId, long categoryId,
5371                    OrderByComparator orderByComparator)
5372                    throws NoSuchMessageException, SystemException {
5373                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5374                                    orderByComparator);
5375    
5376                    if (mbMessage != null) {
5377                            return mbMessage;
5378                    }
5379    
5380                    StringBundler msg = new StringBundler(6);
5381    
5382                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5383    
5384                    msg.append("groupId=");
5385                    msg.append(groupId);
5386    
5387                    msg.append(", categoryId=");
5388                    msg.append(categoryId);
5389    
5390                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5391    
5392                    throw new NoSuchMessageException(msg.toString());
5393            }
5394    
5395            /**
5396             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5397             *
5398             * @param groupId the group ID
5399             * @param categoryId the category ID
5400             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5401             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5402             * @throws SystemException if a system exception occurred
5403             */
5404            @Override
5405            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5406                    OrderByComparator orderByComparator) throws SystemException {
5407                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5408                                    orderByComparator);
5409    
5410                    if (!list.isEmpty()) {
5411                            return list.get(0);
5412                    }
5413    
5414                    return null;
5415            }
5416    
5417            /**
5418             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5419             *
5420             * @param groupId the group ID
5421             * @param categoryId the category ID
5422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5423             * @return the last matching message-boards message
5424             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5425             * @throws SystemException if a system exception occurred
5426             */
5427            @Override
5428            public MBMessage findByG_C_Last(long groupId, long categoryId,
5429                    OrderByComparator orderByComparator)
5430                    throws NoSuchMessageException, SystemException {
5431                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5432                                    orderByComparator);
5433    
5434                    if (mbMessage != null) {
5435                            return mbMessage;
5436                    }
5437    
5438                    StringBundler msg = new StringBundler(6);
5439    
5440                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5441    
5442                    msg.append("groupId=");
5443                    msg.append(groupId);
5444    
5445                    msg.append(", categoryId=");
5446                    msg.append(categoryId);
5447    
5448                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5449    
5450                    throw new NoSuchMessageException(msg.toString());
5451            }
5452    
5453            /**
5454             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5455             *
5456             * @param groupId the group ID
5457             * @param categoryId the category ID
5458             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5459             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5460             * @throws SystemException if a system exception occurred
5461             */
5462            @Override
5463            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5464                    OrderByComparator orderByComparator) throws SystemException {
5465                    int count = countByG_C(groupId, categoryId);
5466    
5467                    if (count == 0) {
5468                            return null;
5469                    }
5470    
5471                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5472                                    orderByComparator);
5473    
5474                    if (!list.isEmpty()) {
5475                            return list.get(0);
5476                    }
5477    
5478                    return null;
5479            }
5480    
5481            /**
5482             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5483             *
5484             * @param messageId the primary key of the current message-boards message
5485             * @param groupId the group ID
5486             * @param categoryId the category ID
5487             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5488             * @return the previous, current, and next message-boards message
5489             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5490             * @throws SystemException if a system exception occurred
5491             */
5492            @Override
5493            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5494                    long categoryId, OrderByComparator orderByComparator)
5495                    throws NoSuchMessageException, SystemException {
5496                    MBMessage mbMessage = findByPrimaryKey(messageId);
5497    
5498                    Session session = null;
5499    
5500                    try {
5501                            session = openSession();
5502    
5503                            MBMessage[] array = new MBMessageImpl[3];
5504    
5505                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5506                                            categoryId, orderByComparator, true);
5507    
5508                            array[1] = mbMessage;
5509    
5510                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5511                                            categoryId, orderByComparator, false);
5512    
5513                            return array;
5514                    }
5515                    catch (Exception e) {
5516                            throw processException(e);
5517                    }
5518                    finally {
5519                            closeSession(session);
5520                    }
5521            }
5522    
5523            protected MBMessage getByG_C_PrevAndNext(Session session,
5524                    MBMessage mbMessage, long groupId, long categoryId,
5525                    OrderByComparator orderByComparator, boolean previous) {
5526                    StringBundler query = null;
5527    
5528                    if (orderByComparator != null) {
5529                            query = new StringBundler(6 +
5530                                            (orderByComparator.getOrderByFields().length * 6));
5531                    }
5532                    else {
5533                            query = new StringBundler(3);
5534                    }
5535    
5536                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5537    
5538                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5539    
5540                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5541    
5542                    if (orderByComparator != null) {
5543                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5544    
5545                            if (orderByConditionFields.length > 0) {
5546                                    query.append(WHERE_AND);
5547                            }
5548    
5549                            for (int i = 0; i < orderByConditionFields.length; i++) {
5550                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5551                                    query.append(orderByConditionFields[i]);
5552    
5553                                    if ((i + 1) < orderByConditionFields.length) {
5554                                            if (orderByComparator.isAscending() ^ previous) {
5555                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5556                                            }
5557                                            else {
5558                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5559                                            }
5560                                    }
5561                                    else {
5562                                            if (orderByComparator.isAscending() ^ previous) {
5563                                                    query.append(WHERE_GREATER_THAN);
5564                                            }
5565                                            else {
5566                                                    query.append(WHERE_LESSER_THAN);
5567                                            }
5568                                    }
5569                            }
5570    
5571                            query.append(ORDER_BY_CLAUSE);
5572    
5573                            String[] orderByFields = orderByComparator.getOrderByFields();
5574    
5575                            for (int i = 0; i < orderByFields.length; i++) {
5576                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5577                                    query.append(orderByFields[i]);
5578    
5579                                    if ((i + 1) < orderByFields.length) {
5580                                            if (orderByComparator.isAscending() ^ previous) {
5581                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5582                                            }
5583                                            else {
5584                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5585                                            }
5586                                    }
5587                                    else {
5588                                            if (orderByComparator.isAscending() ^ previous) {
5589                                                    query.append(ORDER_BY_ASC);
5590                                            }
5591                                            else {
5592                                                    query.append(ORDER_BY_DESC);
5593                                            }
5594                                    }
5595                            }
5596                    }
5597                    else {
5598                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5599                    }
5600    
5601                    String sql = query.toString();
5602    
5603                    Query q = session.createQuery(sql);
5604    
5605                    q.setFirstResult(0);
5606                    q.setMaxResults(2);
5607    
5608                    QueryPos qPos = QueryPos.getInstance(q);
5609    
5610                    qPos.add(groupId);
5611    
5612                    qPos.add(categoryId);
5613    
5614                    if (orderByComparator != null) {
5615                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5616    
5617                            for (Object value : values) {
5618                                    qPos.add(value);
5619                            }
5620                    }
5621    
5622                    List<MBMessage> list = q.list();
5623    
5624                    if (list.size() == 2) {
5625                            return list.get(1);
5626                    }
5627                    else {
5628                            return null;
5629                    }
5630            }
5631    
5632            /**
5633             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5634             *
5635             * @param groupId the group ID
5636             * @param categoryId the category ID
5637             * @return the matching message-boards messages that the user has permission to view
5638             * @throws SystemException if a system exception occurred
5639             */
5640            @Override
5641            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5642                    throws SystemException {
5643                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5644                            QueryUtil.ALL_POS, null);
5645            }
5646    
5647            /**
5648             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5649             *
5650             * <p>
5651             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
5652             * </p>
5653             *
5654             * @param groupId the group ID
5655             * @param categoryId the category ID
5656             * @param start the lower bound of the range of message-boards messages
5657             * @param end the upper bound of the range of message-boards messages (not inclusive)
5658             * @return the range of matching message-boards messages that the user has permission to view
5659             * @throws SystemException if a system exception occurred
5660             */
5661            @Override
5662            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5663                    int start, int end) throws SystemException {
5664                    return filterFindByG_C(groupId, categoryId, start, end, null);
5665            }
5666    
5667            /**
5668             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5669             *
5670             * <p>
5671             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
5672             * </p>
5673             *
5674             * @param groupId the group ID
5675             * @param categoryId the category ID
5676             * @param start the lower bound of the range of message-boards messages
5677             * @param end the upper bound of the range of message-boards messages (not inclusive)
5678             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5679             * @return the ordered range of matching message-boards messages that the user has permission to view
5680             * @throws SystemException if a system exception occurred
5681             */
5682            @Override
5683            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5684                    int start, int end, OrderByComparator orderByComparator)
5685                    throws SystemException {
5686                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5687                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5688                    }
5689    
5690                    StringBundler query = null;
5691    
5692                    if (orderByComparator != null) {
5693                            query = new StringBundler(4 +
5694                                            (orderByComparator.getOrderByFields().length * 3));
5695                    }
5696                    else {
5697                            query = new StringBundler(4);
5698                    }
5699    
5700                    if (getDB().isSupportsInlineDistinct()) {
5701                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5702                    }
5703                    else {
5704                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5705                    }
5706    
5707                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5708    
5709                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5710    
5711                    if (!getDB().isSupportsInlineDistinct()) {
5712                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5713                    }
5714    
5715                    if (orderByComparator != null) {
5716                            if (getDB().isSupportsInlineDistinct()) {
5717                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5718                                            orderByComparator, true);
5719                            }
5720                            else {
5721                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5722                                            orderByComparator, true);
5723                            }
5724                    }
5725                    else {
5726                            if (getDB().isSupportsInlineDistinct()) {
5727                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5728                            }
5729                            else {
5730                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5731                            }
5732                    }
5733    
5734                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5735                                    MBMessage.class.getName(),
5736                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5737    
5738                    Session session = null;
5739    
5740                    try {
5741                            session = openSession();
5742    
5743                            SQLQuery q = session.createSQLQuery(sql);
5744    
5745                            if (getDB().isSupportsInlineDistinct()) {
5746                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5747                            }
5748                            else {
5749                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5750                            }
5751    
5752                            QueryPos qPos = QueryPos.getInstance(q);
5753    
5754                            qPos.add(groupId);
5755    
5756                            qPos.add(categoryId);
5757    
5758                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5759                    }
5760                    catch (Exception e) {
5761                            throw processException(e);
5762                    }
5763                    finally {
5764                            closeSession(session);
5765                    }
5766            }
5767    
5768            /**
5769             * 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;.
5770             *
5771             * @param messageId the primary key of the current message-boards message
5772             * @param groupId the group ID
5773             * @param categoryId the category ID
5774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5775             * @return the previous, current, and next message-boards message
5776             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5777             * @throws SystemException if a system exception occurred
5778             */
5779            @Override
5780            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5781                    long groupId, long categoryId, OrderByComparator orderByComparator)
5782                    throws NoSuchMessageException, SystemException {
5783                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5784                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5785                                    orderByComparator);
5786                    }
5787    
5788                    MBMessage mbMessage = findByPrimaryKey(messageId);
5789    
5790                    Session session = null;
5791    
5792                    try {
5793                            session = openSession();
5794    
5795                            MBMessage[] array = new MBMessageImpl[3];
5796    
5797                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5798                                            categoryId, orderByComparator, true);
5799    
5800                            array[1] = mbMessage;
5801    
5802                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5803                                            categoryId, orderByComparator, false);
5804    
5805                            return array;
5806                    }
5807                    catch (Exception e) {
5808                            throw processException(e);
5809                    }
5810                    finally {
5811                            closeSession(session);
5812                    }
5813            }
5814    
5815            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5816                    MBMessage mbMessage, long groupId, long categoryId,
5817                    OrderByComparator orderByComparator, boolean previous) {
5818                    StringBundler query = null;
5819    
5820                    if (orderByComparator != null) {
5821                            query = new StringBundler(6 +
5822                                            (orderByComparator.getOrderByFields().length * 6));
5823                    }
5824                    else {
5825                            query = new StringBundler(3);
5826                    }
5827    
5828                    if (getDB().isSupportsInlineDistinct()) {
5829                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5830                    }
5831                    else {
5832                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5833                    }
5834    
5835                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5836    
5837                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5838    
5839                    if (!getDB().isSupportsInlineDistinct()) {
5840                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5841                    }
5842    
5843                    if (orderByComparator != null) {
5844                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5845    
5846                            if (orderByConditionFields.length > 0) {
5847                                    query.append(WHERE_AND);
5848                            }
5849    
5850                            for (int i = 0; i < orderByConditionFields.length; i++) {
5851                                    if (getDB().isSupportsInlineDistinct()) {
5852                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5853                                    }
5854                                    else {
5855                                            query.append(_ORDER_BY_ENTITY_TABLE);
5856                                    }
5857    
5858                                    query.append(orderByConditionFields[i]);
5859    
5860                                    if ((i + 1) < orderByConditionFields.length) {
5861                                            if (orderByComparator.isAscending() ^ previous) {
5862                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5863                                            }
5864                                            else {
5865                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5866                                            }
5867                                    }
5868                                    else {
5869                                            if (orderByComparator.isAscending() ^ previous) {
5870                                                    query.append(WHERE_GREATER_THAN);
5871                                            }
5872                                            else {
5873                                                    query.append(WHERE_LESSER_THAN);
5874                                            }
5875                                    }
5876                            }
5877    
5878                            query.append(ORDER_BY_CLAUSE);
5879    
5880                            String[] orderByFields = orderByComparator.getOrderByFields();
5881    
5882                            for (int i = 0; i < orderByFields.length; i++) {
5883                                    if (getDB().isSupportsInlineDistinct()) {
5884                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5885                                    }
5886                                    else {
5887                                            query.append(_ORDER_BY_ENTITY_TABLE);
5888                                    }
5889    
5890                                    query.append(orderByFields[i]);
5891    
5892                                    if ((i + 1) < orderByFields.length) {
5893                                            if (orderByComparator.isAscending() ^ previous) {
5894                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5895                                            }
5896                                            else {
5897                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5898                                            }
5899                                    }
5900                                    else {
5901                                            if (orderByComparator.isAscending() ^ previous) {
5902                                                    query.append(ORDER_BY_ASC);
5903                                            }
5904                                            else {
5905                                                    query.append(ORDER_BY_DESC);
5906                                            }
5907                                    }
5908                            }
5909                    }
5910                    else {
5911                            if (getDB().isSupportsInlineDistinct()) {
5912                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5913                            }
5914                            else {
5915                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5916                            }
5917                    }
5918    
5919                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5920                                    MBMessage.class.getName(),
5921                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5922    
5923                    SQLQuery q = session.createSQLQuery(sql);
5924    
5925                    q.setFirstResult(0);
5926                    q.setMaxResults(2);
5927    
5928                    if (getDB().isSupportsInlineDistinct()) {
5929                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5930                    }
5931                    else {
5932                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5933                    }
5934    
5935                    QueryPos qPos = QueryPos.getInstance(q);
5936    
5937                    qPos.add(groupId);
5938    
5939                    qPos.add(categoryId);
5940    
5941                    if (orderByComparator != null) {
5942                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5943    
5944                            for (Object value : values) {
5945                                    qPos.add(value);
5946                            }
5947                    }
5948    
5949                    List<MBMessage> list = q.list();
5950    
5951                    if (list.size() == 2) {
5952                            return list.get(1);
5953                    }
5954                    else {
5955                            return null;
5956                    }
5957            }
5958    
5959            /**
5960             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
5961             *
5962             * @param groupId the group ID
5963             * @param categoryId the category ID
5964             * @throws SystemException if a system exception occurred
5965             */
5966            @Override
5967            public void removeByG_C(long groupId, long categoryId)
5968                    throws SystemException {
5969                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5970                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5971                            remove(mbMessage);
5972                    }
5973            }
5974    
5975            /**
5976             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
5977             *
5978             * @param groupId the group ID
5979             * @param categoryId the category ID
5980             * @return the number of matching message-boards messages
5981             * @throws SystemException if a system exception occurred
5982             */
5983            @Override
5984            public int countByG_C(long groupId, long categoryId)
5985                    throws SystemException {
5986                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5987    
5988                    Object[] finderArgs = new Object[] { groupId, categoryId };
5989    
5990                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5991                                    this);
5992    
5993                    if (count == null) {
5994                            StringBundler query = new StringBundler(3);
5995    
5996                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5997    
5998                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5999    
6000                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6001    
6002                            String sql = query.toString();
6003    
6004                            Session session = null;
6005    
6006                            try {
6007                                    session = openSession();
6008    
6009                                    Query q = session.createQuery(sql);
6010    
6011                                    QueryPos qPos = QueryPos.getInstance(q);
6012    
6013                                    qPos.add(groupId);
6014    
6015                                    qPos.add(categoryId);
6016    
6017                                    count = (Long)q.uniqueResult();
6018    
6019                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6020                            }
6021                            catch (Exception e) {
6022                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6023    
6024                                    throw processException(e);
6025                            }
6026                            finally {
6027                                    closeSession(session);
6028                            }
6029                    }
6030    
6031                    return count.intValue();
6032            }
6033    
6034            /**
6035             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6036             *
6037             * @param groupId the group ID
6038             * @param categoryId the category ID
6039             * @return the number of matching message-boards messages that the user has permission to view
6040             * @throws SystemException if a system exception occurred
6041             */
6042            @Override
6043            public int filterCountByG_C(long groupId, long categoryId)
6044                    throws SystemException {
6045                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6046                            return countByG_C(groupId, categoryId);
6047                    }
6048    
6049                    StringBundler query = new StringBundler(3);
6050    
6051                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6052    
6053                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6054    
6055                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6056    
6057                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6058                                    MBMessage.class.getName(),
6059                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6060    
6061                    Session session = null;
6062    
6063                    try {
6064                            session = openSession();
6065    
6066                            SQLQuery q = session.createSQLQuery(sql);
6067    
6068                            q.addScalar(COUNT_COLUMN_NAME,
6069                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6070    
6071                            QueryPos qPos = QueryPos.getInstance(q);
6072    
6073                            qPos.add(groupId);
6074    
6075                            qPos.add(categoryId);
6076    
6077                            Long count = (Long)q.uniqueResult();
6078    
6079                            return count.intValue();
6080                    }
6081                    catch (Exception e) {
6082                            throw processException(e);
6083                    }
6084                    finally {
6085                            closeSession(session);
6086                    }
6087            }
6088    
6089            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6090            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6092                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6094                            new String[] {
6095                                    Long.class.getName(), Integer.class.getName(),
6096                                    
6097                            Integer.class.getName(), Integer.class.getName(),
6098                                    OrderByComparator.class.getName()
6099                            });
6100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6101                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6103                            new String[] { Long.class.getName(), Integer.class.getName() },
6104                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6105                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6106                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6107            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6108                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6110                            new String[] { Long.class.getName(), Integer.class.getName() });
6111    
6112            /**
6113             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6114             *
6115             * @param groupId the group ID
6116             * @param status the status
6117             * @return the matching message-boards messages
6118             * @throws SystemException if a system exception occurred
6119             */
6120            @Override
6121            public List<MBMessage> findByG_S(long groupId, int status)
6122                    throws SystemException {
6123                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6124                            null);
6125            }
6126    
6127            /**
6128             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6129             *
6130             * <p>
6131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
6132             * </p>
6133             *
6134             * @param groupId the group ID
6135             * @param status the status
6136             * @param start the lower bound of the range of message-boards messages
6137             * @param end the upper bound of the range of message-boards messages (not inclusive)
6138             * @return the range of matching message-boards messages
6139             * @throws SystemException if a system exception occurred
6140             */
6141            @Override
6142            public List<MBMessage> findByG_S(long groupId, int status, int start,
6143                    int end) throws SystemException {
6144                    return findByG_S(groupId, status, start, end, null);
6145            }
6146    
6147            /**
6148             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6149             *
6150             * <p>
6151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
6152             * </p>
6153             *
6154             * @param groupId the group ID
6155             * @param status the status
6156             * @param start the lower bound of the range of message-boards messages
6157             * @param end the upper bound of the range of message-boards messages (not inclusive)
6158             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6159             * @return the ordered range of matching message-boards messages
6160             * @throws SystemException if a system exception occurred
6161             */
6162            @Override
6163            public List<MBMessage> findByG_S(long groupId, int status, int start,
6164                    int end, OrderByComparator orderByComparator) throws SystemException {
6165                    boolean pagination = true;
6166                    FinderPath finderPath = null;
6167                    Object[] finderArgs = null;
6168    
6169                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6170                                    (orderByComparator == null)) {
6171                            pagination = false;
6172                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6173                            finderArgs = new Object[] { groupId, status };
6174                    }
6175                    else {
6176                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6177                            finderArgs = new Object[] {
6178                                            groupId, status,
6179                                            
6180                                            start, end, orderByComparator
6181                                    };
6182                    }
6183    
6184                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6185                                    finderArgs, this);
6186    
6187                    if ((list != null) && !list.isEmpty()) {
6188                            for (MBMessage mbMessage : list) {
6189                                    if ((groupId != mbMessage.getGroupId()) ||
6190                                                    (status != mbMessage.getStatus())) {
6191                                            list = null;
6192    
6193                                            break;
6194                                    }
6195                            }
6196                    }
6197    
6198                    if (list == null) {
6199                            StringBundler query = null;
6200    
6201                            if (orderByComparator != null) {
6202                                    query = new StringBundler(4 +
6203                                                    (orderByComparator.getOrderByFields().length * 3));
6204                            }
6205                            else {
6206                                    query = new StringBundler(4);
6207                            }
6208    
6209                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6210    
6211                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6212    
6213                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6214    
6215                            if (orderByComparator != null) {
6216                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6217                                            orderByComparator);
6218                            }
6219                            else
6220                             if (pagination) {
6221                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6222                            }
6223    
6224                            String sql = query.toString();
6225    
6226                            Session session = null;
6227    
6228                            try {
6229                                    session = openSession();
6230    
6231                                    Query q = session.createQuery(sql);
6232    
6233                                    QueryPos qPos = QueryPos.getInstance(q);
6234    
6235                                    qPos.add(groupId);
6236    
6237                                    qPos.add(status);
6238    
6239                                    if (!pagination) {
6240                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6241                                                            start, end, false);
6242    
6243                                            Collections.sort(list);
6244    
6245                                            list = new UnmodifiableList<MBMessage>(list);
6246                                    }
6247                                    else {
6248                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6249                                                            start, end);
6250                                    }
6251    
6252                                    cacheResult(list);
6253    
6254                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6255                            }
6256                            catch (Exception e) {
6257                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6258    
6259                                    throw processException(e);
6260                            }
6261                            finally {
6262                                    closeSession(session);
6263                            }
6264                    }
6265    
6266                    return list;
6267            }
6268    
6269            /**
6270             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6271             *
6272             * @param groupId the group ID
6273             * @param status the status
6274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6275             * @return the first matching message-boards message
6276             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6277             * @throws SystemException if a system exception occurred
6278             */
6279            @Override
6280            public MBMessage findByG_S_First(long groupId, int status,
6281                    OrderByComparator orderByComparator)
6282                    throws NoSuchMessageException, SystemException {
6283                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6284                                    orderByComparator);
6285    
6286                    if (mbMessage != null) {
6287                            return mbMessage;
6288                    }
6289    
6290                    StringBundler msg = new StringBundler(6);
6291    
6292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6293    
6294                    msg.append("groupId=");
6295                    msg.append(groupId);
6296    
6297                    msg.append(", status=");
6298                    msg.append(status);
6299    
6300                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6301    
6302                    throw new NoSuchMessageException(msg.toString());
6303            }
6304    
6305            /**
6306             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6307             *
6308             * @param groupId the group ID
6309             * @param status the status
6310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6311             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6312             * @throws SystemException if a system exception occurred
6313             */
6314            @Override
6315            public MBMessage fetchByG_S_First(long groupId, int status,
6316                    OrderByComparator orderByComparator) throws SystemException {
6317                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6318                                    orderByComparator);
6319    
6320                    if (!list.isEmpty()) {
6321                            return list.get(0);
6322                    }
6323    
6324                    return null;
6325            }
6326    
6327            /**
6328             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6329             *
6330             * @param groupId the group ID
6331             * @param status the status
6332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6333             * @return the last matching message-boards message
6334             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6335             * @throws SystemException if a system exception occurred
6336             */
6337            @Override
6338            public MBMessage findByG_S_Last(long groupId, int status,
6339                    OrderByComparator orderByComparator)
6340                    throws NoSuchMessageException, SystemException {
6341                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6342    
6343                    if (mbMessage != null) {
6344                            return mbMessage;
6345                    }
6346    
6347                    StringBundler msg = new StringBundler(6);
6348    
6349                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6350    
6351                    msg.append("groupId=");
6352                    msg.append(groupId);
6353    
6354                    msg.append(", status=");
6355                    msg.append(status);
6356    
6357                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6358    
6359                    throw new NoSuchMessageException(msg.toString());
6360            }
6361    
6362            /**
6363             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6364             *
6365             * @param groupId the group ID
6366             * @param status the status
6367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6368             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6369             * @throws SystemException if a system exception occurred
6370             */
6371            @Override
6372            public MBMessage fetchByG_S_Last(long groupId, int status,
6373                    OrderByComparator orderByComparator) throws SystemException {
6374                    int count = countByG_S(groupId, status);
6375    
6376                    if (count == 0) {
6377                            return null;
6378                    }
6379    
6380                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6381                                    orderByComparator);
6382    
6383                    if (!list.isEmpty()) {
6384                            return list.get(0);
6385                    }
6386    
6387                    return null;
6388            }
6389    
6390            /**
6391             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6392             *
6393             * @param messageId the primary key of the current message-boards message
6394             * @param groupId the group ID
6395             * @param status the status
6396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6397             * @return the previous, current, and next message-boards message
6398             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6399             * @throws SystemException if a system exception occurred
6400             */
6401            @Override
6402            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6403                    int status, OrderByComparator orderByComparator)
6404                    throws NoSuchMessageException, SystemException {
6405                    MBMessage mbMessage = findByPrimaryKey(messageId);
6406    
6407                    Session session = null;
6408    
6409                    try {
6410                            session = openSession();
6411    
6412                            MBMessage[] array = new MBMessageImpl[3];
6413    
6414                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6415                                            status, orderByComparator, true);
6416    
6417                            array[1] = mbMessage;
6418    
6419                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6420                                            status, orderByComparator, false);
6421    
6422                            return array;
6423                    }
6424                    catch (Exception e) {
6425                            throw processException(e);
6426                    }
6427                    finally {
6428                            closeSession(session);
6429                    }
6430            }
6431    
6432            protected MBMessage getByG_S_PrevAndNext(Session session,
6433                    MBMessage mbMessage, long groupId, int status,
6434                    OrderByComparator orderByComparator, boolean previous) {
6435                    StringBundler query = null;
6436    
6437                    if (orderByComparator != null) {
6438                            query = new StringBundler(6 +
6439                                            (orderByComparator.getOrderByFields().length * 6));
6440                    }
6441                    else {
6442                            query = new StringBundler(3);
6443                    }
6444    
6445                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6446    
6447                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6448    
6449                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6450    
6451                    if (orderByComparator != null) {
6452                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6453    
6454                            if (orderByConditionFields.length > 0) {
6455                                    query.append(WHERE_AND);
6456                            }
6457    
6458                            for (int i = 0; i < orderByConditionFields.length; i++) {
6459                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6460                                    query.append(orderByConditionFields[i]);
6461    
6462                                    if ((i + 1) < orderByConditionFields.length) {
6463                                            if (orderByComparator.isAscending() ^ previous) {
6464                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6465                                            }
6466                                            else {
6467                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6468                                            }
6469                                    }
6470                                    else {
6471                                            if (orderByComparator.isAscending() ^ previous) {
6472                                                    query.append(WHERE_GREATER_THAN);
6473                                            }
6474                                            else {
6475                                                    query.append(WHERE_LESSER_THAN);
6476                                            }
6477                                    }
6478                            }
6479    
6480                            query.append(ORDER_BY_CLAUSE);
6481    
6482                            String[] orderByFields = orderByComparator.getOrderByFields();
6483    
6484                            for (int i = 0; i < orderByFields.length; i++) {
6485                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6486                                    query.append(orderByFields[i]);
6487    
6488                                    if ((i + 1) < orderByFields.length) {
6489                                            if (orderByComparator.isAscending() ^ previous) {
6490                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6491                                            }
6492                                            else {
6493                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6494                                            }
6495                                    }
6496                                    else {
6497                                            if (orderByComparator.isAscending() ^ previous) {
6498                                                    query.append(ORDER_BY_ASC);
6499                                            }
6500                                            else {
6501                                                    query.append(ORDER_BY_DESC);
6502                                            }
6503                                    }
6504                            }
6505                    }
6506                    else {
6507                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6508                    }
6509    
6510                    String sql = query.toString();
6511    
6512                    Query q = session.createQuery(sql);
6513    
6514                    q.setFirstResult(0);
6515                    q.setMaxResults(2);
6516    
6517                    QueryPos qPos = QueryPos.getInstance(q);
6518    
6519                    qPos.add(groupId);
6520    
6521                    qPos.add(status);
6522    
6523                    if (orderByComparator != null) {
6524                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6525    
6526                            for (Object value : values) {
6527                                    qPos.add(value);
6528                            }
6529                    }
6530    
6531                    List<MBMessage> list = q.list();
6532    
6533                    if (list.size() == 2) {
6534                            return list.get(1);
6535                    }
6536                    else {
6537                            return null;
6538                    }
6539            }
6540    
6541            /**
6542             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6543             *
6544             * @param groupId the group ID
6545             * @param status the status
6546             * @return the matching message-boards messages that the user has permission to view
6547             * @throws SystemException if a system exception occurred
6548             */
6549            @Override
6550            public List<MBMessage> filterFindByG_S(long groupId, int status)
6551                    throws SystemException {
6552                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6553                            QueryUtil.ALL_POS, null);
6554            }
6555    
6556            /**
6557             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6558             *
6559             * <p>
6560             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
6561             * </p>
6562             *
6563             * @param groupId the group ID
6564             * @param status the status
6565             * @param start the lower bound of the range of message-boards messages
6566             * @param end the upper bound of the range of message-boards messages (not inclusive)
6567             * @return the range of matching message-boards messages that the user has permission to view
6568             * @throws SystemException if a system exception occurred
6569             */
6570            @Override
6571            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6572                    int end) throws SystemException {
6573                    return filterFindByG_S(groupId, status, start, end, null);
6574            }
6575    
6576            /**
6577             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6578             *
6579             * <p>
6580             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
6581             * </p>
6582             *
6583             * @param groupId the group ID
6584             * @param status the status
6585             * @param start the lower bound of the range of message-boards messages
6586             * @param end the upper bound of the range of message-boards messages (not inclusive)
6587             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6588             * @return the ordered range of matching message-boards messages that the user has permission to view
6589             * @throws SystemException if a system exception occurred
6590             */
6591            @Override
6592            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6593                    int end, OrderByComparator orderByComparator) throws SystemException {
6594                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6595                            return findByG_S(groupId, status, start, end, orderByComparator);
6596                    }
6597    
6598                    StringBundler query = null;
6599    
6600                    if (orderByComparator != null) {
6601                            query = new StringBundler(4 +
6602                                            (orderByComparator.getOrderByFields().length * 3));
6603                    }
6604                    else {
6605                            query = new StringBundler(4);
6606                    }
6607    
6608                    if (getDB().isSupportsInlineDistinct()) {
6609                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6610                    }
6611                    else {
6612                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6613                    }
6614    
6615                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6616    
6617                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6618    
6619                    if (!getDB().isSupportsInlineDistinct()) {
6620                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6621                    }
6622    
6623                    if (orderByComparator != null) {
6624                            if (getDB().isSupportsInlineDistinct()) {
6625                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6626                                            orderByComparator, true);
6627                            }
6628                            else {
6629                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6630                                            orderByComparator, true);
6631                            }
6632                    }
6633                    else {
6634                            if (getDB().isSupportsInlineDistinct()) {
6635                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6636                            }
6637                            else {
6638                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6639                            }
6640                    }
6641    
6642                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6643                                    MBMessage.class.getName(),
6644                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6645    
6646                    Session session = null;
6647    
6648                    try {
6649                            session = openSession();
6650    
6651                            SQLQuery q = session.createSQLQuery(sql);
6652    
6653                            if (getDB().isSupportsInlineDistinct()) {
6654                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6655                            }
6656                            else {
6657                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6658                            }
6659    
6660                            QueryPos qPos = QueryPos.getInstance(q);
6661    
6662                            qPos.add(groupId);
6663    
6664                            qPos.add(status);
6665    
6666                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6667                    }
6668                    catch (Exception e) {
6669                            throw processException(e);
6670                    }
6671                    finally {
6672                            closeSession(session);
6673                    }
6674            }
6675    
6676            /**
6677             * 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;.
6678             *
6679             * @param messageId the primary key of the current message-boards message
6680             * @param groupId the group ID
6681             * @param status the status
6682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6683             * @return the previous, current, and next message-boards message
6684             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6685             * @throws SystemException if a system exception occurred
6686             */
6687            @Override
6688            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6689                    long groupId, int status, OrderByComparator orderByComparator)
6690                    throws NoSuchMessageException, SystemException {
6691                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6692                            return findByG_S_PrevAndNext(messageId, groupId, status,
6693                                    orderByComparator);
6694                    }
6695    
6696                    MBMessage mbMessage = findByPrimaryKey(messageId);
6697    
6698                    Session session = null;
6699    
6700                    try {
6701                            session = openSession();
6702    
6703                            MBMessage[] array = new MBMessageImpl[3];
6704    
6705                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6706                                            status, orderByComparator, true);
6707    
6708                            array[1] = mbMessage;
6709    
6710                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6711                                            status, orderByComparator, false);
6712    
6713                            return array;
6714                    }
6715                    catch (Exception e) {
6716                            throw processException(e);
6717                    }
6718                    finally {
6719                            closeSession(session);
6720                    }
6721            }
6722    
6723            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6724                    MBMessage mbMessage, long groupId, int status,
6725                    OrderByComparator orderByComparator, boolean previous) {
6726                    StringBundler query = null;
6727    
6728                    if (orderByComparator != null) {
6729                            query = new StringBundler(6 +
6730                                            (orderByComparator.getOrderByFields().length * 6));
6731                    }
6732                    else {
6733                            query = new StringBundler(3);
6734                    }
6735    
6736                    if (getDB().isSupportsInlineDistinct()) {
6737                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6738                    }
6739                    else {
6740                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6741                    }
6742    
6743                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6744    
6745                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6746    
6747                    if (!getDB().isSupportsInlineDistinct()) {
6748                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6749                    }
6750    
6751                    if (orderByComparator != null) {
6752                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6753    
6754                            if (orderByConditionFields.length > 0) {
6755                                    query.append(WHERE_AND);
6756                            }
6757    
6758                            for (int i = 0; i < orderByConditionFields.length; i++) {
6759                                    if (getDB().isSupportsInlineDistinct()) {
6760                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6761                                    }
6762                                    else {
6763                                            query.append(_ORDER_BY_ENTITY_TABLE);
6764                                    }
6765    
6766                                    query.append(orderByConditionFields[i]);
6767    
6768                                    if ((i + 1) < orderByConditionFields.length) {
6769                                            if (orderByComparator.isAscending() ^ previous) {
6770                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6771                                            }
6772                                            else {
6773                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6774                                            }
6775                                    }
6776                                    else {
6777                                            if (orderByComparator.isAscending() ^ previous) {
6778                                                    query.append(WHERE_GREATER_THAN);
6779                                            }
6780                                            else {
6781                                                    query.append(WHERE_LESSER_THAN);
6782                                            }
6783                                    }
6784                            }
6785    
6786                            query.append(ORDER_BY_CLAUSE);
6787    
6788                            String[] orderByFields = orderByComparator.getOrderByFields();
6789    
6790                            for (int i = 0; i < orderByFields.length; i++) {
6791                                    if (getDB().isSupportsInlineDistinct()) {
6792                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6793                                    }
6794                                    else {
6795                                            query.append(_ORDER_BY_ENTITY_TABLE);
6796                                    }
6797    
6798                                    query.append(orderByFields[i]);
6799    
6800                                    if ((i + 1) < orderByFields.length) {
6801                                            if (orderByComparator.isAscending() ^ previous) {
6802                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6803                                            }
6804                                            else {
6805                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6806                                            }
6807                                    }
6808                                    else {
6809                                            if (orderByComparator.isAscending() ^ previous) {
6810                                                    query.append(ORDER_BY_ASC);
6811                                            }
6812                                            else {
6813                                                    query.append(ORDER_BY_DESC);
6814                                            }
6815                                    }
6816                            }
6817                    }
6818                    else {
6819                            if (getDB().isSupportsInlineDistinct()) {
6820                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6821                            }
6822                            else {
6823                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6824                            }
6825                    }
6826    
6827                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6828                                    MBMessage.class.getName(),
6829                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6830    
6831                    SQLQuery q = session.createSQLQuery(sql);
6832    
6833                    q.setFirstResult(0);
6834                    q.setMaxResults(2);
6835    
6836                    if (getDB().isSupportsInlineDistinct()) {
6837                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6838                    }
6839                    else {
6840                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6841                    }
6842    
6843                    QueryPos qPos = QueryPos.getInstance(q);
6844    
6845                    qPos.add(groupId);
6846    
6847                    qPos.add(status);
6848    
6849                    if (orderByComparator != null) {
6850                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6851    
6852                            for (Object value : values) {
6853                                    qPos.add(value);
6854                            }
6855                    }
6856    
6857                    List<MBMessage> list = q.list();
6858    
6859                    if (list.size() == 2) {
6860                            return list.get(1);
6861                    }
6862                    else {
6863                            return null;
6864                    }
6865            }
6866    
6867            /**
6868             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6869             *
6870             * @param groupId the group ID
6871             * @param status the status
6872             * @throws SystemException if a system exception occurred
6873             */
6874            @Override
6875            public void removeByG_S(long groupId, int status) throws SystemException {
6876                    for (MBMessage mbMessage : findByG_S(groupId, status,
6877                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6878                            remove(mbMessage);
6879                    }
6880            }
6881    
6882            /**
6883             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6884             *
6885             * @param groupId the group ID
6886             * @param status the status
6887             * @return the number of matching message-boards messages
6888             * @throws SystemException if a system exception occurred
6889             */
6890            @Override
6891            public int countByG_S(long groupId, int status) throws SystemException {
6892                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6893    
6894                    Object[] finderArgs = new Object[] { groupId, status };
6895    
6896                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6897                                    this);
6898    
6899                    if (count == null) {
6900                            StringBundler query = new StringBundler(3);
6901    
6902                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6903    
6904                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6905    
6906                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6907    
6908                            String sql = query.toString();
6909    
6910                            Session session = null;
6911    
6912                            try {
6913                                    session = openSession();
6914    
6915                                    Query q = session.createQuery(sql);
6916    
6917                                    QueryPos qPos = QueryPos.getInstance(q);
6918    
6919                                    qPos.add(groupId);
6920    
6921                                    qPos.add(status);
6922    
6923                                    count = (Long)q.uniqueResult();
6924    
6925                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6926                            }
6927                            catch (Exception e) {
6928                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6929    
6930                                    throw processException(e);
6931                            }
6932                            finally {
6933                                    closeSession(session);
6934                            }
6935                    }
6936    
6937                    return count.intValue();
6938            }
6939    
6940            /**
6941             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6942             *
6943             * @param groupId the group ID
6944             * @param status the status
6945             * @return the number of matching message-boards messages that the user has permission to view
6946             * @throws SystemException if a system exception occurred
6947             */
6948            @Override
6949            public int filterCountByG_S(long groupId, int status)
6950                    throws SystemException {
6951                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6952                            return countByG_S(groupId, status);
6953                    }
6954    
6955                    StringBundler query = new StringBundler(3);
6956    
6957                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6958    
6959                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6960    
6961                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6962    
6963                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6964                                    MBMessage.class.getName(),
6965                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6966    
6967                    Session session = null;
6968    
6969                    try {
6970                            session = openSession();
6971    
6972                            SQLQuery q = session.createSQLQuery(sql);
6973    
6974                            q.addScalar(COUNT_COLUMN_NAME,
6975                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6976    
6977                            QueryPos qPos = QueryPos.getInstance(q);
6978    
6979                            qPos.add(groupId);
6980    
6981                            qPos.add(status);
6982    
6983                            Long count = (Long)q.uniqueResult();
6984    
6985                            return count.intValue();
6986                    }
6987                    catch (Exception e) {
6988                            throw processException(e);
6989                    }
6990                    finally {
6991                            closeSession(session);
6992                    }
6993            }
6994    
6995            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6996            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6997            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6998                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6999                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7000                            new String[] {
7001                                    Long.class.getName(), Integer.class.getName(),
7002                                    
7003                            Integer.class.getName(), Integer.class.getName(),
7004                                    OrderByComparator.class.getName()
7005                            });
7006            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7007                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7008                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7009                            new String[] { Long.class.getName(), Integer.class.getName() },
7010                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7011                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7012                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7013            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7014                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7015                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7016                            new String[] { Long.class.getName(), Integer.class.getName() });
7017    
7018            /**
7019             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7020             *
7021             * @param companyId the company ID
7022             * @param status the status
7023             * @return the matching message-boards messages
7024             * @throws SystemException if a system exception occurred
7025             */
7026            @Override
7027            public List<MBMessage> findByC_S(long companyId, int status)
7028                    throws SystemException {
7029                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7030                            QueryUtil.ALL_POS, null);
7031            }
7032    
7033            /**
7034             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7035             *
7036             * <p>
7037             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
7038             * </p>
7039             *
7040             * @param companyId the company ID
7041             * @param status the status
7042             * @param start the lower bound of the range of message-boards messages
7043             * @param end the upper bound of the range of message-boards messages (not inclusive)
7044             * @return the range of matching message-boards messages
7045             * @throws SystemException if a system exception occurred
7046             */
7047            @Override
7048            public List<MBMessage> findByC_S(long companyId, int status, int start,
7049                    int end) throws SystemException {
7050                    return findByC_S(companyId, status, start, end, null);
7051            }
7052    
7053            /**
7054             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7055             *
7056             * <p>
7057             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
7058             * </p>
7059             *
7060             * @param companyId the company ID
7061             * @param status the status
7062             * @param start the lower bound of the range of message-boards messages
7063             * @param end the upper bound of the range of message-boards messages (not inclusive)
7064             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7065             * @return the ordered range of matching message-boards messages
7066             * @throws SystemException if a system exception occurred
7067             */
7068            @Override
7069            public List<MBMessage> findByC_S(long companyId, int status, int start,
7070                    int end, OrderByComparator orderByComparator) throws SystemException {
7071                    boolean pagination = true;
7072                    FinderPath finderPath = null;
7073                    Object[] finderArgs = null;
7074    
7075                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7076                                    (orderByComparator == null)) {
7077                            pagination = false;
7078                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7079                            finderArgs = new Object[] { companyId, status };
7080                    }
7081                    else {
7082                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7083                            finderArgs = new Object[] {
7084                                            companyId, status,
7085                                            
7086                                            start, end, orderByComparator
7087                                    };
7088                    }
7089    
7090                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7091                                    finderArgs, this);
7092    
7093                    if ((list != null) && !list.isEmpty()) {
7094                            for (MBMessage mbMessage : list) {
7095                                    if ((companyId != mbMessage.getCompanyId()) ||
7096                                                    (status != mbMessage.getStatus())) {
7097                                            list = null;
7098    
7099                                            break;
7100                                    }
7101                            }
7102                    }
7103    
7104                    if (list == null) {
7105                            StringBundler query = null;
7106    
7107                            if (orderByComparator != null) {
7108                                    query = new StringBundler(4 +
7109                                                    (orderByComparator.getOrderByFields().length * 3));
7110                            }
7111                            else {
7112                                    query = new StringBundler(4);
7113                            }
7114    
7115                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7116    
7117                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7118    
7119                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7120    
7121                            if (orderByComparator != null) {
7122                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7123                                            orderByComparator);
7124                            }
7125                            else
7126                             if (pagination) {
7127                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7128                            }
7129    
7130                            String sql = query.toString();
7131    
7132                            Session session = null;
7133    
7134                            try {
7135                                    session = openSession();
7136    
7137                                    Query q = session.createQuery(sql);
7138    
7139                                    QueryPos qPos = QueryPos.getInstance(q);
7140    
7141                                    qPos.add(companyId);
7142    
7143                                    qPos.add(status);
7144    
7145                                    if (!pagination) {
7146                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7147                                                            start, end, false);
7148    
7149                                            Collections.sort(list);
7150    
7151                                            list = new UnmodifiableList<MBMessage>(list);
7152                                    }
7153                                    else {
7154                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7155                                                            start, end);
7156                                    }
7157    
7158                                    cacheResult(list);
7159    
7160                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7161                            }
7162                            catch (Exception e) {
7163                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7164    
7165                                    throw processException(e);
7166                            }
7167                            finally {
7168                                    closeSession(session);
7169                            }
7170                    }
7171    
7172                    return list;
7173            }
7174    
7175            /**
7176             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7177             *
7178             * @param companyId the company ID
7179             * @param status the status
7180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7181             * @return the first matching message-boards message
7182             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7183             * @throws SystemException if a system exception occurred
7184             */
7185            @Override
7186            public MBMessage findByC_S_First(long companyId, int status,
7187                    OrderByComparator orderByComparator)
7188                    throws NoSuchMessageException, SystemException {
7189                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7190                                    orderByComparator);
7191    
7192                    if (mbMessage != null) {
7193                            return mbMessage;
7194                    }
7195    
7196                    StringBundler msg = new StringBundler(6);
7197    
7198                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7199    
7200                    msg.append("companyId=");
7201                    msg.append(companyId);
7202    
7203                    msg.append(", status=");
7204                    msg.append(status);
7205    
7206                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7207    
7208                    throw new NoSuchMessageException(msg.toString());
7209            }
7210    
7211            /**
7212             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7213             *
7214             * @param companyId the company ID
7215             * @param status the status
7216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7217             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7218             * @throws SystemException if a system exception occurred
7219             */
7220            @Override
7221            public MBMessage fetchByC_S_First(long companyId, int status,
7222                    OrderByComparator orderByComparator) throws SystemException {
7223                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7224                                    orderByComparator);
7225    
7226                    if (!list.isEmpty()) {
7227                            return list.get(0);
7228                    }
7229    
7230                    return null;
7231            }
7232    
7233            /**
7234             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7235             *
7236             * @param companyId the company ID
7237             * @param status the status
7238             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7239             * @return the last matching message-boards message
7240             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7241             * @throws SystemException if a system exception occurred
7242             */
7243            @Override
7244            public MBMessage findByC_S_Last(long companyId, int status,
7245                    OrderByComparator orderByComparator)
7246                    throws NoSuchMessageException, SystemException {
7247                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7248                                    orderByComparator);
7249    
7250                    if (mbMessage != null) {
7251                            return mbMessage;
7252                    }
7253    
7254                    StringBundler msg = new StringBundler(6);
7255    
7256                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7257    
7258                    msg.append("companyId=");
7259                    msg.append(companyId);
7260    
7261                    msg.append(", status=");
7262                    msg.append(status);
7263    
7264                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7265    
7266                    throw new NoSuchMessageException(msg.toString());
7267            }
7268    
7269            /**
7270             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7271             *
7272             * @param companyId the company ID
7273             * @param status the status
7274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7275             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7276             * @throws SystemException if a system exception occurred
7277             */
7278            @Override
7279            public MBMessage fetchByC_S_Last(long companyId, int status,
7280                    OrderByComparator orderByComparator) throws SystemException {
7281                    int count = countByC_S(companyId, status);
7282    
7283                    if (count == 0) {
7284                            return null;
7285                    }
7286    
7287                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7288                                    orderByComparator);
7289    
7290                    if (!list.isEmpty()) {
7291                            return list.get(0);
7292                    }
7293    
7294                    return null;
7295            }
7296    
7297            /**
7298             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7299             *
7300             * @param messageId the primary key of the current message-boards message
7301             * @param companyId the company ID
7302             * @param status the status
7303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7304             * @return the previous, current, and next message-boards message
7305             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7306             * @throws SystemException if a system exception occurred
7307             */
7308            @Override
7309            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7310                    int status, OrderByComparator orderByComparator)
7311                    throws NoSuchMessageException, SystemException {
7312                    MBMessage mbMessage = findByPrimaryKey(messageId);
7313    
7314                    Session session = null;
7315    
7316                    try {
7317                            session = openSession();
7318    
7319                            MBMessage[] array = new MBMessageImpl[3];
7320    
7321                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7322                                            status, orderByComparator, true);
7323    
7324                            array[1] = mbMessage;
7325    
7326                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7327                                            status, orderByComparator, false);
7328    
7329                            return array;
7330                    }
7331                    catch (Exception e) {
7332                            throw processException(e);
7333                    }
7334                    finally {
7335                            closeSession(session);
7336                    }
7337            }
7338    
7339            protected MBMessage getByC_S_PrevAndNext(Session session,
7340                    MBMessage mbMessage, long companyId, int status,
7341                    OrderByComparator orderByComparator, boolean previous) {
7342                    StringBundler query = null;
7343    
7344                    if (orderByComparator != null) {
7345                            query = new StringBundler(6 +
7346                                            (orderByComparator.getOrderByFields().length * 6));
7347                    }
7348                    else {
7349                            query = new StringBundler(3);
7350                    }
7351    
7352                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7353    
7354                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7355    
7356                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7357    
7358                    if (orderByComparator != null) {
7359                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7360    
7361                            if (orderByConditionFields.length > 0) {
7362                                    query.append(WHERE_AND);
7363                            }
7364    
7365                            for (int i = 0; i < orderByConditionFields.length; i++) {
7366                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7367                                    query.append(orderByConditionFields[i]);
7368    
7369                                    if ((i + 1) < orderByConditionFields.length) {
7370                                            if (orderByComparator.isAscending() ^ previous) {
7371                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7372                                            }
7373                                            else {
7374                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7375                                            }
7376                                    }
7377                                    else {
7378                                            if (orderByComparator.isAscending() ^ previous) {
7379                                                    query.append(WHERE_GREATER_THAN);
7380                                            }
7381                                            else {
7382                                                    query.append(WHERE_LESSER_THAN);
7383                                            }
7384                                    }
7385                            }
7386    
7387                            query.append(ORDER_BY_CLAUSE);
7388    
7389                            String[] orderByFields = orderByComparator.getOrderByFields();
7390    
7391                            for (int i = 0; i < orderByFields.length; i++) {
7392                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7393                                    query.append(orderByFields[i]);
7394    
7395                                    if ((i + 1) < orderByFields.length) {
7396                                            if (orderByComparator.isAscending() ^ previous) {
7397                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7398                                            }
7399                                            else {
7400                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7401                                            }
7402                                    }
7403                                    else {
7404                                            if (orderByComparator.isAscending() ^ previous) {
7405                                                    query.append(ORDER_BY_ASC);
7406                                            }
7407                                            else {
7408                                                    query.append(ORDER_BY_DESC);
7409                                            }
7410                                    }
7411                            }
7412                    }
7413                    else {
7414                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7415                    }
7416    
7417                    String sql = query.toString();
7418    
7419                    Query q = session.createQuery(sql);
7420    
7421                    q.setFirstResult(0);
7422                    q.setMaxResults(2);
7423    
7424                    QueryPos qPos = QueryPos.getInstance(q);
7425    
7426                    qPos.add(companyId);
7427    
7428                    qPos.add(status);
7429    
7430                    if (orderByComparator != null) {
7431                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7432    
7433                            for (Object value : values) {
7434                                    qPos.add(value);
7435                            }
7436                    }
7437    
7438                    List<MBMessage> list = q.list();
7439    
7440                    if (list.size() == 2) {
7441                            return list.get(1);
7442                    }
7443                    else {
7444                            return null;
7445                    }
7446            }
7447    
7448            /**
7449             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7450             *
7451             * @param companyId the company ID
7452             * @param status the status
7453             * @throws SystemException if a system exception occurred
7454             */
7455            @Override
7456            public void removeByC_S(long companyId, int status)
7457                    throws SystemException {
7458                    for (MBMessage mbMessage : findByC_S(companyId, status,
7459                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7460                            remove(mbMessage);
7461                    }
7462            }
7463    
7464            /**
7465             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7466             *
7467             * @param companyId the company ID
7468             * @param status the status
7469             * @return the number of matching message-boards messages
7470             * @throws SystemException if a system exception occurred
7471             */
7472            @Override
7473            public int countByC_S(long companyId, int status) throws SystemException {
7474                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7475    
7476                    Object[] finderArgs = new Object[] { companyId, status };
7477    
7478                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7479                                    this);
7480    
7481                    if (count == null) {
7482                            StringBundler query = new StringBundler(3);
7483    
7484                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7485    
7486                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7487    
7488                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7489    
7490                            String sql = query.toString();
7491    
7492                            Session session = null;
7493    
7494                            try {
7495                                    session = openSession();
7496    
7497                                    Query q = session.createQuery(sql);
7498    
7499                                    QueryPos qPos = QueryPos.getInstance(q);
7500    
7501                                    qPos.add(companyId);
7502    
7503                                    qPos.add(status);
7504    
7505                                    count = (Long)q.uniqueResult();
7506    
7507                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7508                            }
7509                            catch (Exception e) {
7510                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7511    
7512                                    throw processException(e);
7513                            }
7514                            finally {
7515                                    closeSession(session);
7516                            }
7517                    }
7518    
7519                    return count.intValue();
7520            }
7521    
7522            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7523            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7524            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7525                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7526                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7527                            new String[] {
7528                                    Long.class.getName(), Long.class.getName(),
7529                                    
7530                            Integer.class.getName(), Integer.class.getName(),
7531                                    OrderByComparator.class.getName()
7532                            });
7533            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7534                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7535                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7536                            new String[] { Long.class.getName(), Long.class.getName() },
7537                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7538                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7539                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7540            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7541                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7542                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7543                            new String[] { Long.class.getName(), Long.class.getName() });
7544            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7545                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7546                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7547                            new String[] { Long.class.getName(), Long.class.getName() });
7548    
7549            /**
7550             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7551             *
7552             * @param userId the user ID
7553             * @param classNameId the class name ID
7554             * @return the matching message-boards messages
7555             * @throws SystemException if a system exception occurred
7556             */
7557            @Override
7558            public List<MBMessage> findByU_C(long userId, long classNameId)
7559                    throws SystemException {
7560                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7561                            QueryUtil.ALL_POS, null);
7562            }
7563    
7564            /**
7565             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7566             *
7567             * <p>
7568             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
7569             * </p>
7570             *
7571             * @param userId the user ID
7572             * @param classNameId the class name ID
7573             * @param start the lower bound of the range of message-boards messages
7574             * @param end the upper bound of the range of message-boards messages (not inclusive)
7575             * @return the range of matching message-boards messages
7576             * @throws SystemException if a system exception occurred
7577             */
7578            @Override
7579            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7580                    int end) throws SystemException {
7581                    return findByU_C(userId, classNameId, start, end, null);
7582            }
7583    
7584            /**
7585             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7586             *
7587             * <p>
7588             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
7589             * </p>
7590             *
7591             * @param userId the user ID
7592             * @param classNameId the class name ID
7593             * @param start the lower bound of the range of message-boards messages
7594             * @param end the upper bound of the range of message-boards messages (not inclusive)
7595             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7596             * @return the ordered range of matching message-boards messages
7597             * @throws SystemException if a system exception occurred
7598             */
7599            @Override
7600            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7601                    int end, OrderByComparator orderByComparator) throws SystemException {
7602                    boolean pagination = true;
7603                    FinderPath finderPath = null;
7604                    Object[] finderArgs = null;
7605    
7606                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7607                                    (orderByComparator == null)) {
7608                            pagination = false;
7609                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7610                            finderArgs = new Object[] { userId, classNameId };
7611                    }
7612                    else {
7613                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7614                            finderArgs = new Object[] {
7615                                            userId, classNameId,
7616                                            
7617                                            start, end, orderByComparator
7618                                    };
7619                    }
7620    
7621                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7622                                    finderArgs, this);
7623    
7624                    if ((list != null) && !list.isEmpty()) {
7625                            for (MBMessage mbMessage : list) {
7626                                    if ((userId != mbMessage.getUserId()) ||
7627                                                    (classNameId != mbMessage.getClassNameId())) {
7628                                            list = null;
7629    
7630                                            break;
7631                                    }
7632                            }
7633                    }
7634    
7635                    if (list == null) {
7636                            StringBundler query = null;
7637    
7638                            if (orderByComparator != null) {
7639                                    query = new StringBundler(4 +
7640                                                    (orderByComparator.getOrderByFields().length * 3));
7641                            }
7642                            else {
7643                                    query = new StringBundler(4);
7644                            }
7645    
7646                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7647    
7648                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7649    
7650                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7651    
7652                            if (orderByComparator != null) {
7653                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7654                                            orderByComparator);
7655                            }
7656                            else
7657                             if (pagination) {
7658                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7659                            }
7660    
7661                            String sql = query.toString();
7662    
7663                            Session session = null;
7664    
7665                            try {
7666                                    session = openSession();
7667    
7668                                    Query q = session.createQuery(sql);
7669    
7670                                    QueryPos qPos = QueryPos.getInstance(q);
7671    
7672                                    qPos.add(userId);
7673    
7674                                    qPos.add(classNameId);
7675    
7676                                    if (!pagination) {
7677                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7678                                                            start, end, false);
7679    
7680                                            Collections.sort(list);
7681    
7682                                            list = new UnmodifiableList<MBMessage>(list);
7683                                    }
7684                                    else {
7685                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7686                                                            start, end);
7687                                    }
7688    
7689                                    cacheResult(list);
7690    
7691                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7692                            }
7693                            catch (Exception e) {
7694                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7695    
7696                                    throw processException(e);
7697                            }
7698                            finally {
7699                                    closeSession(session);
7700                            }
7701                    }
7702    
7703                    return list;
7704            }
7705    
7706            /**
7707             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7708             *
7709             * @param userId the user ID
7710             * @param classNameId the class name ID
7711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7712             * @return the first matching message-boards message
7713             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7714             * @throws SystemException if a system exception occurred
7715             */
7716            @Override
7717            public MBMessage findByU_C_First(long userId, long classNameId,
7718                    OrderByComparator orderByComparator)
7719                    throws NoSuchMessageException, SystemException {
7720                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7721                                    orderByComparator);
7722    
7723                    if (mbMessage != null) {
7724                            return mbMessage;
7725                    }
7726    
7727                    StringBundler msg = new StringBundler(6);
7728    
7729                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7730    
7731                    msg.append("userId=");
7732                    msg.append(userId);
7733    
7734                    msg.append(", classNameId=");
7735                    msg.append(classNameId);
7736    
7737                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7738    
7739                    throw new NoSuchMessageException(msg.toString());
7740            }
7741    
7742            /**
7743             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7744             *
7745             * @param userId the user ID
7746             * @param classNameId the class name ID
7747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7748             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7749             * @throws SystemException if a system exception occurred
7750             */
7751            @Override
7752            public MBMessage fetchByU_C_First(long userId, long classNameId,
7753                    OrderByComparator orderByComparator) throws SystemException {
7754                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7755                                    orderByComparator);
7756    
7757                    if (!list.isEmpty()) {
7758                            return list.get(0);
7759                    }
7760    
7761                    return null;
7762            }
7763    
7764            /**
7765             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7766             *
7767             * @param userId the user ID
7768             * @param classNameId the class name ID
7769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7770             * @return the last matching message-boards message
7771             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7772             * @throws SystemException if a system exception occurred
7773             */
7774            @Override
7775            public MBMessage findByU_C_Last(long userId, long classNameId,
7776                    OrderByComparator orderByComparator)
7777                    throws NoSuchMessageException, SystemException {
7778                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7779                                    orderByComparator);
7780    
7781                    if (mbMessage != null) {
7782                            return mbMessage;
7783                    }
7784    
7785                    StringBundler msg = new StringBundler(6);
7786    
7787                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7788    
7789                    msg.append("userId=");
7790                    msg.append(userId);
7791    
7792                    msg.append(", classNameId=");
7793                    msg.append(classNameId);
7794    
7795                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7796    
7797                    throw new NoSuchMessageException(msg.toString());
7798            }
7799    
7800            /**
7801             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7802             *
7803             * @param userId the user ID
7804             * @param classNameId the class name ID
7805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7806             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7807             * @throws SystemException if a system exception occurred
7808             */
7809            @Override
7810            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7811                    OrderByComparator orderByComparator) throws SystemException {
7812                    int count = countByU_C(userId, classNameId);
7813    
7814                    if (count == 0) {
7815                            return null;
7816                    }
7817    
7818                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7819                                    orderByComparator);
7820    
7821                    if (!list.isEmpty()) {
7822                            return list.get(0);
7823                    }
7824    
7825                    return null;
7826            }
7827    
7828            /**
7829             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7830             *
7831             * @param messageId the primary key of the current message-boards message
7832             * @param userId the user ID
7833             * @param classNameId the class name ID
7834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7835             * @return the previous, current, and next message-boards message
7836             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7837             * @throws SystemException if a system exception occurred
7838             */
7839            @Override
7840            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7841                    long classNameId, OrderByComparator orderByComparator)
7842                    throws NoSuchMessageException, SystemException {
7843                    MBMessage mbMessage = findByPrimaryKey(messageId);
7844    
7845                    Session session = null;
7846    
7847                    try {
7848                            session = openSession();
7849    
7850                            MBMessage[] array = new MBMessageImpl[3];
7851    
7852                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7853                                            classNameId, orderByComparator, true);
7854    
7855                            array[1] = mbMessage;
7856    
7857                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7858                                            classNameId, orderByComparator, false);
7859    
7860                            return array;
7861                    }
7862                    catch (Exception e) {
7863                            throw processException(e);
7864                    }
7865                    finally {
7866                            closeSession(session);
7867                    }
7868            }
7869    
7870            protected MBMessage getByU_C_PrevAndNext(Session session,
7871                    MBMessage mbMessage, long userId, long classNameId,
7872                    OrderByComparator orderByComparator, boolean previous) {
7873                    StringBundler query = null;
7874    
7875                    if (orderByComparator != null) {
7876                            query = new StringBundler(6 +
7877                                            (orderByComparator.getOrderByFields().length * 6));
7878                    }
7879                    else {
7880                            query = new StringBundler(3);
7881                    }
7882    
7883                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7884    
7885                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7886    
7887                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7888    
7889                    if (orderByComparator != null) {
7890                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7891    
7892                            if (orderByConditionFields.length > 0) {
7893                                    query.append(WHERE_AND);
7894                            }
7895    
7896                            for (int i = 0; i < orderByConditionFields.length; i++) {
7897                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7898                                    query.append(orderByConditionFields[i]);
7899    
7900                                    if ((i + 1) < orderByConditionFields.length) {
7901                                            if (orderByComparator.isAscending() ^ previous) {
7902                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7903                                            }
7904                                            else {
7905                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7906                                            }
7907                                    }
7908                                    else {
7909                                            if (orderByComparator.isAscending() ^ previous) {
7910                                                    query.append(WHERE_GREATER_THAN);
7911                                            }
7912                                            else {
7913                                                    query.append(WHERE_LESSER_THAN);
7914                                            }
7915                                    }
7916                            }
7917    
7918                            query.append(ORDER_BY_CLAUSE);
7919    
7920                            String[] orderByFields = orderByComparator.getOrderByFields();
7921    
7922                            for (int i = 0; i < orderByFields.length; i++) {
7923                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7924                                    query.append(orderByFields[i]);
7925    
7926                                    if ((i + 1) < orderByFields.length) {
7927                                            if (orderByComparator.isAscending() ^ previous) {
7928                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7929                                            }
7930                                            else {
7931                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7932                                            }
7933                                    }
7934                                    else {
7935                                            if (orderByComparator.isAscending() ^ previous) {
7936                                                    query.append(ORDER_BY_ASC);
7937                                            }
7938                                            else {
7939                                                    query.append(ORDER_BY_DESC);
7940                                            }
7941                                    }
7942                            }
7943                    }
7944                    else {
7945                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7946                    }
7947    
7948                    String sql = query.toString();
7949    
7950                    Query q = session.createQuery(sql);
7951    
7952                    q.setFirstResult(0);
7953                    q.setMaxResults(2);
7954    
7955                    QueryPos qPos = QueryPos.getInstance(q);
7956    
7957                    qPos.add(userId);
7958    
7959                    qPos.add(classNameId);
7960    
7961                    if (orderByComparator != null) {
7962                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7963    
7964                            for (Object value : values) {
7965                                    qPos.add(value);
7966                            }
7967                    }
7968    
7969                    List<MBMessage> list = q.list();
7970    
7971                    if (list.size() == 2) {
7972                            return list.get(1);
7973                    }
7974                    else {
7975                            return null;
7976                    }
7977            }
7978    
7979            /**
7980             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7981             *
7982             * <p>
7983             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
7984             * </p>
7985             *
7986             * @param userId the user ID
7987             * @param classNameIds the class name IDs
7988             * @return the matching message-boards messages
7989             * @throws SystemException if a system exception occurred
7990             */
7991            @Override
7992            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7993                    throws SystemException {
7994                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7995                            QueryUtil.ALL_POS, null);
7996            }
7997    
7998            /**
7999             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8000             *
8001             * <p>
8002             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
8003             * </p>
8004             *
8005             * @param userId the user ID
8006             * @param classNameIds the class name IDs
8007             * @param start the lower bound of the range of message-boards messages
8008             * @param end the upper bound of the range of message-boards messages (not inclusive)
8009             * @return the range of matching message-boards messages
8010             * @throws SystemException if a system exception occurred
8011             */
8012            @Override
8013            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8014                    int start, int end) throws SystemException {
8015                    return findByU_C(userId, classNameIds, start, end, null);
8016            }
8017    
8018            /**
8019             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8020             *
8021             * <p>
8022             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
8023             * </p>
8024             *
8025             * @param userId the user ID
8026             * @param classNameIds the class name IDs
8027             * @param start the lower bound of the range of message-boards messages
8028             * @param end the upper bound of the range of message-boards messages (not inclusive)
8029             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8030             * @return the ordered range of matching message-boards messages
8031             * @throws SystemException if a system exception occurred
8032             */
8033            @Override
8034            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8035                    int start, int end, OrderByComparator orderByComparator)
8036                    throws SystemException {
8037                    if ((classNameIds != null) && (classNameIds.length == 1)) {
8038                            return findByU_C(userId, classNameIds[0], start, end,
8039                                    orderByComparator);
8040                    }
8041    
8042                    boolean pagination = true;
8043                    Object[] finderArgs = null;
8044    
8045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8046                                    (orderByComparator == null)) {
8047                            pagination = false;
8048                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8049                    }
8050                    else {
8051                            finderArgs = new Object[] {
8052                                            userId, StringUtil.merge(classNameIds),
8053                                            
8054                                            start, end, orderByComparator
8055                                    };
8056                    }
8057    
8058                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8059                                    finderArgs, this);
8060    
8061                    if ((list != null) && !list.isEmpty()) {
8062                            for (MBMessage mbMessage : list) {
8063                                    if ((userId != mbMessage.getUserId()) ||
8064                                                    !ArrayUtil.contains(classNameIds,
8065                                                            mbMessage.getClassNameId())) {
8066                                            list = null;
8067    
8068                                            break;
8069                                    }
8070                            }
8071                    }
8072    
8073                    if (list == null) {
8074                            StringBundler query = new StringBundler();
8075    
8076                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8077    
8078                            boolean conjunctionable = false;
8079    
8080                            if (conjunctionable) {
8081                                    query.append(WHERE_AND);
8082                            }
8083    
8084                            query.append(_FINDER_COLUMN_U_C_USERID_5);
8085    
8086                            conjunctionable = true;
8087    
8088                            if ((classNameIds == null) || (classNameIds.length > 0)) {
8089                                    if (conjunctionable) {
8090                                            query.append(WHERE_AND);
8091                                    }
8092    
8093                                    query.append(StringPool.OPEN_PARENTHESIS);
8094    
8095                                    for (int i = 0; i < classNameIds.length; i++) {
8096                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8097    
8098                                            if ((i + 1) < classNameIds.length) {
8099                                                    query.append(WHERE_OR);
8100                                            }
8101                                    }
8102    
8103                                    query.append(StringPool.CLOSE_PARENTHESIS);
8104    
8105                                    conjunctionable = true;
8106                            }
8107    
8108                            if (orderByComparator != null) {
8109                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8110                                            orderByComparator);
8111                            }
8112                            else
8113                             if (pagination) {
8114                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8115                            }
8116    
8117                            String sql = query.toString();
8118    
8119                            Session session = null;
8120    
8121                            try {
8122                                    session = openSession();
8123    
8124                                    Query q = session.createQuery(sql);
8125    
8126                                    QueryPos qPos = QueryPos.getInstance(q);
8127    
8128                                    qPos.add(userId);
8129    
8130                                    if (classNameIds != null) {
8131                                            qPos.add(classNameIds);
8132                                    }
8133    
8134                                    if (!pagination) {
8135                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8136                                                            start, end, false);
8137    
8138                                            Collections.sort(list);
8139    
8140                                            list = new UnmodifiableList<MBMessage>(list);
8141                                    }
8142                                    else {
8143                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8144                                                            start, end);
8145                                    }
8146    
8147                                    cacheResult(list);
8148    
8149                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8150                                            finderArgs, list);
8151                            }
8152                            catch (Exception e) {
8153                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8154                                            finderArgs);
8155    
8156                                    throw processException(e);
8157                            }
8158                            finally {
8159                                    closeSession(session);
8160                            }
8161                    }
8162    
8163                    return list;
8164            }
8165    
8166            /**
8167             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8168             *
8169             * @param userId the user ID
8170             * @param classNameId the class name ID
8171             * @throws SystemException if a system exception occurred
8172             */
8173            @Override
8174            public void removeByU_C(long userId, long classNameId)
8175                    throws SystemException {
8176                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8177                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8178                            remove(mbMessage);
8179                    }
8180            }
8181    
8182            /**
8183             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8184             *
8185             * @param userId the user ID
8186             * @param classNameId the class name ID
8187             * @return the number of matching message-boards messages
8188             * @throws SystemException if a system exception occurred
8189             */
8190            @Override
8191            public int countByU_C(long userId, long classNameId)
8192                    throws SystemException {
8193                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8194    
8195                    Object[] finderArgs = new Object[] { userId, classNameId };
8196    
8197                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8198                                    this);
8199    
8200                    if (count == null) {
8201                            StringBundler query = new StringBundler(3);
8202    
8203                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8204    
8205                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8206    
8207                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8208    
8209                            String sql = query.toString();
8210    
8211                            Session session = null;
8212    
8213                            try {
8214                                    session = openSession();
8215    
8216                                    Query q = session.createQuery(sql);
8217    
8218                                    QueryPos qPos = QueryPos.getInstance(q);
8219    
8220                                    qPos.add(userId);
8221    
8222                                    qPos.add(classNameId);
8223    
8224                                    count = (Long)q.uniqueResult();
8225    
8226                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8227                            }
8228                            catch (Exception e) {
8229                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8230    
8231                                    throw processException(e);
8232                            }
8233                            finally {
8234                                    closeSession(session);
8235                            }
8236                    }
8237    
8238                    return count.intValue();
8239            }
8240    
8241            /**
8242             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8243             *
8244             * @param userId the user ID
8245             * @param classNameIds the class name IDs
8246             * @return the number of matching message-boards messages
8247             * @throws SystemException if a system exception occurred
8248             */
8249            @Override
8250            public int countByU_C(long userId, long[] classNameIds)
8251                    throws SystemException {
8252                    Object[] finderArgs = new Object[] {
8253                                    userId, StringUtil.merge(classNameIds)
8254                            };
8255    
8256                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8257                                    finderArgs, this);
8258    
8259                    if (count == null) {
8260                            StringBundler query = new StringBundler();
8261    
8262                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8263    
8264                            boolean conjunctionable = false;
8265    
8266                            if (conjunctionable) {
8267                                    query.append(WHERE_AND);
8268                            }
8269    
8270                            query.append(_FINDER_COLUMN_U_C_USERID_5);
8271    
8272                            conjunctionable = true;
8273    
8274                            if ((classNameIds == null) || (classNameIds.length > 0)) {
8275                                    if (conjunctionable) {
8276                                            query.append(WHERE_AND);
8277                                    }
8278    
8279                                    query.append(StringPool.OPEN_PARENTHESIS);
8280    
8281                                    for (int i = 0; i < classNameIds.length; i++) {
8282                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8283    
8284                                            if ((i + 1) < classNameIds.length) {
8285                                                    query.append(WHERE_OR);
8286                                            }
8287                                    }
8288    
8289                                    query.append(StringPool.CLOSE_PARENTHESIS);
8290    
8291                                    conjunctionable = true;
8292                            }
8293    
8294                            String sql = query.toString();
8295    
8296                            Session session = null;
8297    
8298                            try {
8299                                    session = openSession();
8300    
8301                                    Query q = session.createQuery(sql);
8302    
8303                                    QueryPos qPos = QueryPos.getInstance(q);
8304    
8305                                    qPos.add(userId);
8306    
8307                                    if (classNameIds != null) {
8308                                            qPos.add(classNameIds);
8309                                    }
8310    
8311                                    count = (Long)q.uniqueResult();
8312    
8313                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8314                                            finderArgs, count);
8315                            }
8316                            catch (Exception e) {
8317                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8318                                            finderArgs);
8319    
8320                                    throw processException(e);
8321                            }
8322                            finally {
8323                                    closeSession(session);
8324                            }
8325                    }
8326    
8327                    return count.intValue();
8328            }
8329    
8330            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8331            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
8332                    removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
8333            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8334            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
8335                    removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
8336            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8337                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8338                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8339                            new String[] {
8340                                    Long.class.getName(), Long.class.getName(),
8341                                    
8342                            Integer.class.getName(), Integer.class.getName(),
8343                                    OrderByComparator.class.getName()
8344                            });
8345            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8346                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8347                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8348                            new String[] { Long.class.getName(), Long.class.getName() },
8349                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8350                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8351                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8352            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8353                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8354                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8355                            new String[] { Long.class.getName(), Long.class.getName() });
8356    
8357            /**
8358             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8359             *
8360             * @param classNameId the class name ID
8361             * @param classPK the class p k
8362             * @return the matching message-boards messages
8363             * @throws SystemException if a system exception occurred
8364             */
8365            @Override
8366            public List<MBMessage> findByC_C(long classNameId, long classPK)
8367                    throws SystemException {
8368                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8369                            QueryUtil.ALL_POS, null);
8370            }
8371    
8372            /**
8373             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8374             *
8375             * <p>
8376             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
8377             * </p>
8378             *
8379             * @param classNameId the class name ID
8380             * @param classPK the class p k
8381             * @param start the lower bound of the range of message-boards messages
8382             * @param end the upper bound of the range of message-boards messages (not inclusive)
8383             * @return the range of matching message-boards messages
8384             * @throws SystemException if a system exception occurred
8385             */
8386            @Override
8387            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8388                    int end) throws SystemException {
8389                    return findByC_C(classNameId, classPK, start, end, null);
8390            }
8391    
8392            /**
8393             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8394             *
8395             * <p>
8396             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
8397             * </p>
8398             *
8399             * @param classNameId the class name ID
8400             * @param classPK the class p k
8401             * @param start the lower bound of the range of message-boards messages
8402             * @param end the upper bound of the range of message-boards messages (not inclusive)
8403             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8404             * @return the ordered range of matching message-boards messages
8405             * @throws SystemException if a system exception occurred
8406             */
8407            @Override
8408            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8409                    int end, OrderByComparator orderByComparator) throws SystemException {
8410                    boolean pagination = true;
8411                    FinderPath finderPath = null;
8412                    Object[] finderArgs = null;
8413    
8414                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8415                                    (orderByComparator == null)) {
8416                            pagination = false;
8417                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8418                            finderArgs = new Object[] { classNameId, classPK };
8419                    }
8420                    else {
8421                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8422                            finderArgs = new Object[] {
8423                                            classNameId, classPK,
8424                                            
8425                                            start, end, orderByComparator
8426                                    };
8427                    }
8428    
8429                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8430                                    finderArgs, this);
8431    
8432                    if ((list != null) && !list.isEmpty()) {
8433                            for (MBMessage mbMessage : list) {
8434                                    if ((classNameId != mbMessage.getClassNameId()) ||
8435                                                    (classPK != mbMessage.getClassPK())) {
8436                                            list = null;
8437    
8438                                            break;
8439                                    }
8440                            }
8441                    }
8442    
8443                    if (list == null) {
8444                            StringBundler query = null;
8445    
8446                            if (orderByComparator != null) {
8447                                    query = new StringBundler(4 +
8448                                                    (orderByComparator.getOrderByFields().length * 3));
8449                            }
8450                            else {
8451                                    query = new StringBundler(4);
8452                            }
8453    
8454                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8455    
8456                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8457    
8458                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8459    
8460                            if (orderByComparator != null) {
8461                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8462                                            orderByComparator);
8463                            }
8464                            else
8465                             if (pagination) {
8466                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8467                            }
8468    
8469                            String sql = query.toString();
8470    
8471                            Session session = null;
8472    
8473                            try {
8474                                    session = openSession();
8475    
8476                                    Query q = session.createQuery(sql);
8477    
8478                                    QueryPos qPos = QueryPos.getInstance(q);
8479    
8480                                    qPos.add(classNameId);
8481    
8482                                    qPos.add(classPK);
8483    
8484                                    if (!pagination) {
8485                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8486                                                            start, end, false);
8487    
8488                                            Collections.sort(list);
8489    
8490                                            list = new UnmodifiableList<MBMessage>(list);
8491                                    }
8492                                    else {
8493                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8494                                                            start, end);
8495                                    }
8496    
8497                                    cacheResult(list);
8498    
8499                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8500                            }
8501                            catch (Exception e) {
8502                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8503    
8504                                    throw processException(e);
8505                            }
8506                            finally {
8507                                    closeSession(session);
8508                            }
8509                    }
8510    
8511                    return list;
8512            }
8513    
8514            /**
8515             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8516             *
8517             * @param classNameId the class name ID
8518             * @param classPK the class p k
8519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8520             * @return the first matching message-boards message
8521             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8522             * @throws SystemException if a system exception occurred
8523             */
8524            @Override
8525            public MBMessage findByC_C_First(long classNameId, long classPK,
8526                    OrderByComparator orderByComparator)
8527                    throws NoSuchMessageException, SystemException {
8528                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8529                                    orderByComparator);
8530    
8531                    if (mbMessage != null) {
8532                            return mbMessage;
8533                    }
8534    
8535                    StringBundler msg = new StringBundler(6);
8536    
8537                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8538    
8539                    msg.append("classNameId=");
8540                    msg.append(classNameId);
8541    
8542                    msg.append(", classPK=");
8543                    msg.append(classPK);
8544    
8545                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8546    
8547                    throw new NoSuchMessageException(msg.toString());
8548            }
8549    
8550            /**
8551             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8552             *
8553             * @param classNameId the class name ID
8554             * @param classPK the class p k
8555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8556             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8557             * @throws SystemException if a system exception occurred
8558             */
8559            @Override
8560            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8561                    OrderByComparator orderByComparator) throws SystemException {
8562                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8563                                    orderByComparator);
8564    
8565                    if (!list.isEmpty()) {
8566                            return list.get(0);
8567                    }
8568    
8569                    return null;
8570            }
8571    
8572            /**
8573             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8574             *
8575             * @param classNameId the class name ID
8576             * @param classPK the class p k
8577             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8578             * @return the last matching message-boards message
8579             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8580             * @throws SystemException if a system exception occurred
8581             */
8582            @Override
8583            public MBMessage findByC_C_Last(long classNameId, long classPK,
8584                    OrderByComparator orderByComparator)
8585                    throws NoSuchMessageException, SystemException {
8586                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8587                                    orderByComparator);
8588    
8589                    if (mbMessage != null) {
8590                            return mbMessage;
8591                    }
8592    
8593                    StringBundler msg = new StringBundler(6);
8594    
8595                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8596    
8597                    msg.append("classNameId=");
8598                    msg.append(classNameId);
8599    
8600                    msg.append(", classPK=");
8601                    msg.append(classPK);
8602    
8603                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8604    
8605                    throw new NoSuchMessageException(msg.toString());
8606            }
8607    
8608            /**
8609             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8610             *
8611             * @param classNameId the class name ID
8612             * @param classPK the class p k
8613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8614             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8615             * @throws SystemException if a system exception occurred
8616             */
8617            @Override
8618            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8619                    OrderByComparator orderByComparator) throws SystemException {
8620                    int count = countByC_C(classNameId, classPK);
8621    
8622                    if (count == 0) {
8623                            return null;
8624                    }
8625    
8626                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8627                                    count, orderByComparator);
8628    
8629                    if (!list.isEmpty()) {
8630                            return list.get(0);
8631                    }
8632    
8633                    return null;
8634            }
8635    
8636            /**
8637             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8638             *
8639             * @param messageId the primary key of the current message-boards message
8640             * @param classNameId the class name ID
8641             * @param classPK the class p k
8642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8643             * @return the previous, current, and next message-boards message
8644             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8645             * @throws SystemException if a system exception occurred
8646             */
8647            @Override
8648            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8649                    long classPK, OrderByComparator orderByComparator)
8650                    throws NoSuchMessageException, SystemException {
8651                    MBMessage mbMessage = findByPrimaryKey(messageId);
8652    
8653                    Session session = null;
8654    
8655                    try {
8656                            session = openSession();
8657    
8658                            MBMessage[] array = new MBMessageImpl[3];
8659    
8660                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8661                                            classPK, orderByComparator, true);
8662    
8663                            array[1] = mbMessage;
8664    
8665                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8666                                            classPK, orderByComparator, false);
8667    
8668                            return array;
8669                    }
8670                    catch (Exception e) {
8671                            throw processException(e);
8672                    }
8673                    finally {
8674                            closeSession(session);
8675                    }
8676            }
8677    
8678            protected MBMessage getByC_C_PrevAndNext(Session session,
8679                    MBMessage mbMessage, long classNameId, long classPK,
8680                    OrderByComparator orderByComparator, boolean previous) {
8681                    StringBundler query = null;
8682    
8683                    if (orderByComparator != null) {
8684                            query = new StringBundler(6 +
8685                                            (orderByComparator.getOrderByFields().length * 6));
8686                    }
8687                    else {
8688                            query = new StringBundler(3);
8689                    }
8690    
8691                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8692    
8693                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8694    
8695                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8696    
8697                    if (orderByComparator != null) {
8698                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8699    
8700                            if (orderByConditionFields.length > 0) {
8701                                    query.append(WHERE_AND);
8702                            }
8703    
8704                            for (int i = 0; i < orderByConditionFields.length; i++) {
8705                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8706                                    query.append(orderByConditionFields[i]);
8707    
8708                                    if ((i + 1) < orderByConditionFields.length) {
8709                                            if (orderByComparator.isAscending() ^ previous) {
8710                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8711                                            }
8712                                            else {
8713                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8714                                            }
8715                                    }
8716                                    else {
8717                                            if (orderByComparator.isAscending() ^ previous) {
8718                                                    query.append(WHERE_GREATER_THAN);
8719                                            }
8720                                            else {
8721                                                    query.append(WHERE_LESSER_THAN);
8722                                            }
8723                                    }
8724                            }
8725    
8726                            query.append(ORDER_BY_CLAUSE);
8727    
8728                            String[] orderByFields = orderByComparator.getOrderByFields();
8729    
8730                            for (int i = 0; i < orderByFields.length; i++) {
8731                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8732                                    query.append(orderByFields[i]);
8733    
8734                                    if ((i + 1) < orderByFields.length) {
8735                                            if (orderByComparator.isAscending() ^ previous) {
8736                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8737                                            }
8738                                            else {
8739                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8740                                            }
8741                                    }
8742                                    else {
8743                                            if (orderByComparator.isAscending() ^ previous) {
8744                                                    query.append(ORDER_BY_ASC);
8745                                            }
8746                                            else {
8747                                                    query.append(ORDER_BY_DESC);
8748                                            }
8749                                    }
8750                            }
8751                    }
8752                    else {
8753                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8754                    }
8755    
8756                    String sql = query.toString();
8757    
8758                    Query q = session.createQuery(sql);
8759    
8760                    q.setFirstResult(0);
8761                    q.setMaxResults(2);
8762    
8763                    QueryPos qPos = QueryPos.getInstance(q);
8764    
8765                    qPos.add(classNameId);
8766    
8767                    qPos.add(classPK);
8768    
8769                    if (orderByComparator != null) {
8770                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8771    
8772                            for (Object value : values) {
8773                                    qPos.add(value);
8774                            }
8775                    }
8776    
8777                    List<MBMessage> list = q.list();
8778    
8779                    if (list.size() == 2) {
8780                            return list.get(1);
8781                    }
8782                    else {
8783                            return null;
8784                    }
8785            }
8786    
8787            /**
8788             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8789             *
8790             * @param classNameId the class name ID
8791             * @param classPK the class p k
8792             * @throws SystemException if a system exception occurred
8793             */
8794            @Override
8795            public void removeByC_C(long classNameId, long classPK)
8796                    throws SystemException {
8797                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8798                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8799                            remove(mbMessage);
8800                    }
8801            }
8802    
8803            /**
8804             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8805             *
8806             * @param classNameId the class name ID
8807             * @param classPK the class p k
8808             * @return the number of matching message-boards messages
8809             * @throws SystemException if a system exception occurred
8810             */
8811            @Override
8812            public int countByC_C(long classNameId, long classPK)
8813                    throws SystemException {
8814                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8815    
8816                    Object[] finderArgs = new Object[] { classNameId, classPK };
8817    
8818                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8819                                    this);
8820    
8821                    if (count == null) {
8822                            StringBundler query = new StringBundler(3);
8823    
8824                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8825    
8826                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8827    
8828                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8829    
8830                            String sql = query.toString();
8831    
8832                            Session session = null;
8833    
8834                            try {
8835                                    session = openSession();
8836    
8837                                    Query q = session.createQuery(sql);
8838    
8839                                    QueryPos qPos = QueryPos.getInstance(q);
8840    
8841                                    qPos.add(classNameId);
8842    
8843                                    qPos.add(classPK);
8844    
8845                                    count = (Long)q.uniqueResult();
8846    
8847                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8848                            }
8849                            catch (Exception e) {
8850                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8851    
8852                                    throw processException(e);
8853                            }
8854                            finally {
8855                                    closeSession(session);
8856                            }
8857                    }
8858    
8859                    return count.intValue();
8860            }
8861    
8862            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8863            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8864            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8865                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8866                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8867                            new String[] {
8868                                    Long.class.getName(), Long.class.getName(),
8869                                    
8870                            Integer.class.getName(), Integer.class.getName(),
8871                                    OrderByComparator.class.getName()
8872                            });
8873            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8874                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8875                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8876                            new String[] { Long.class.getName(), Long.class.getName() },
8877                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8878                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8879                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8880            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8881                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8882                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8883                            new String[] { Long.class.getName(), Long.class.getName() });
8884    
8885            /**
8886             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8887             *
8888             * @param threadId the thread ID
8889             * @param parentMessageId the parent message ID
8890             * @return the matching message-boards messages
8891             * @throws SystemException if a system exception occurred
8892             */
8893            @Override
8894            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8895                    throws SystemException {
8896                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8897                            QueryUtil.ALL_POS, null);
8898            }
8899    
8900            /**
8901             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8902             *
8903             * <p>
8904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
8905             * </p>
8906             *
8907             * @param threadId the thread ID
8908             * @param parentMessageId the parent message ID
8909             * @param start the lower bound of the range of message-boards messages
8910             * @param end the upper bound of the range of message-boards messages (not inclusive)
8911             * @return the range of matching message-boards messages
8912             * @throws SystemException if a system exception occurred
8913             */
8914            @Override
8915            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8916                    int start, int end) throws SystemException {
8917                    return findByT_P(threadId, parentMessageId, start, end, null);
8918            }
8919    
8920            /**
8921             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8922             *
8923             * <p>
8924             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
8925             * </p>
8926             *
8927             * @param threadId the thread ID
8928             * @param parentMessageId the parent message ID
8929             * @param start the lower bound of the range of message-boards messages
8930             * @param end the upper bound of the range of message-boards messages (not inclusive)
8931             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8932             * @return the ordered range of matching message-boards messages
8933             * @throws SystemException if a system exception occurred
8934             */
8935            @Override
8936            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8937                    int start, int end, OrderByComparator orderByComparator)
8938                    throws SystemException {
8939                    boolean pagination = true;
8940                    FinderPath finderPath = null;
8941                    Object[] finderArgs = null;
8942    
8943                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8944                                    (orderByComparator == null)) {
8945                            pagination = false;
8946                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8947                            finderArgs = new Object[] { threadId, parentMessageId };
8948                    }
8949                    else {
8950                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8951                            finderArgs = new Object[] {
8952                                            threadId, parentMessageId,
8953                                            
8954                                            start, end, orderByComparator
8955                                    };
8956                    }
8957    
8958                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8959                                    finderArgs, this);
8960    
8961                    if ((list != null) && !list.isEmpty()) {
8962                            for (MBMessage mbMessage : list) {
8963                                    if ((threadId != mbMessage.getThreadId()) ||
8964                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8965                                            list = null;
8966    
8967                                            break;
8968                                    }
8969                            }
8970                    }
8971    
8972                    if (list == null) {
8973                            StringBundler query = null;
8974    
8975                            if (orderByComparator != null) {
8976                                    query = new StringBundler(4 +
8977                                                    (orderByComparator.getOrderByFields().length * 3));
8978                            }
8979                            else {
8980                                    query = new StringBundler(4);
8981                            }
8982    
8983                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8984    
8985                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8986    
8987                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8988    
8989                            if (orderByComparator != null) {
8990                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8991                                            orderByComparator);
8992                            }
8993                            else
8994                             if (pagination) {
8995                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8996                            }
8997    
8998                            String sql = query.toString();
8999    
9000                            Session session = null;
9001    
9002                            try {
9003                                    session = openSession();
9004    
9005                                    Query q = session.createQuery(sql);
9006    
9007                                    QueryPos qPos = QueryPos.getInstance(q);
9008    
9009                                    qPos.add(threadId);
9010    
9011                                    qPos.add(parentMessageId);
9012    
9013                                    if (!pagination) {
9014                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9015                                                            start, end, false);
9016    
9017                                            Collections.sort(list);
9018    
9019                                            list = new UnmodifiableList<MBMessage>(list);
9020                                    }
9021                                    else {
9022                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9023                                                            start, end);
9024                                    }
9025    
9026                                    cacheResult(list);
9027    
9028                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9029                            }
9030                            catch (Exception e) {
9031                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9032    
9033                                    throw processException(e);
9034                            }
9035                            finally {
9036                                    closeSession(session);
9037                            }
9038                    }
9039    
9040                    return list;
9041            }
9042    
9043            /**
9044             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9045             *
9046             * @param threadId the thread ID
9047             * @param parentMessageId the parent message ID
9048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9049             * @return the first matching message-boards message
9050             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9051             * @throws SystemException if a system exception occurred
9052             */
9053            @Override
9054            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9055                    OrderByComparator orderByComparator)
9056                    throws NoSuchMessageException, SystemException {
9057                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9058                                    orderByComparator);
9059    
9060                    if (mbMessage != null) {
9061                            return mbMessage;
9062                    }
9063    
9064                    StringBundler msg = new StringBundler(6);
9065    
9066                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9067    
9068                    msg.append("threadId=");
9069                    msg.append(threadId);
9070    
9071                    msg.append(", parentMessageId=");
9072                    msg.append(parentMessageId);
9073    
9074                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9075    
9076                    throw new NoSuchMessageException(msg.toString());
9077            }
9078    
9079            /**
9080             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9081             *
9082             * @param threadId the thread ID
9083             * @param parentMessageId the parent message ID
9084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9085             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9086             * @throws SystemException if a system exception occurred
9087             */
9088            @Override
9089            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9090                    OrderByComparator orderByComparator) throws SystemException {
9091                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9092                                    orderByComparator);
9093    
9094                    if (!list.isEmpty()) {
9095                            return list.get(0);
9096                    }
9097    
9098                    return null;
9099            }
9100    
9101            /**
9102             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9103             *
9104             * @param threadId the thread ID
9105             * @param parentMessageId the parent message ID
9106             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9107             * @return the last matching message-boards message
9108             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9109             * @throws SystemException if a system exception occurred
9110             */
9111            @Override
9112            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9113                    OrderByComparator orderByComparator)
9114                    throws NoSuchMessageException, SystemException {
9115                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9116                                    orderByComparator);
9117    
9118                    if (mbMessage != null) {
9119                            return mbMessage;
9120                    }
9121    
9122                    StringBundler msg = new StringBundler(6);
9123    
9124                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9125    
9126                    msg.append("threadId=");
9127                    msg.append(threadId);
9128    
9129                    msg.append(", parentMessageId=");
9130                    msg.append(parentMessageId);
9131    
9132                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9133    
9134                    throw new NoSuchMessageException(msg.toString());
9135            }
9136    
9137            /**
9138             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9139             *
9140             * @param threadId the thread ID
9141             * @param parentMessageId the parent message ID
9142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9143             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9144             * @throws SystemException if a system exception occurred
9145             */
9146            @Override
9147            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9148                    OrderByComparator orderByComparator) throws SystemException {
9149                    int count = countByT_P(threadId, parentMessageId);
9150    
9151                    if (count == 0) {
9152                            return null;
9153                    }
9154    
9155                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9156                                    count, orderByComparator);
9157    
9158                    if (!list.isEmpty()) {
9159                            return list.get(0);
9160                    }
9161    
9162                    return null;
9163            }
9164    
9165            /**
9166             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9167             *
9168             * @param messageId the primary key of the current message-boards message
9169             * @param threadId the thread ID
9170             * @param parentMessageId the parent message ID
9171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9172             * @return the previous, current, and next message-boards message
9173             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9174             * @throws SystemException if a system exception occurred
9175             */
9176            @Override
9177            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9178                    long parentMessageId, OrderByComparator orderByComparator)
9179                    throws NoSuchMessageException, SystemException {
9180                    MBMessage mbMessage = findByPrimaryKey(messageId);
9181    
9182                    Session session = null;
9183    
9184                    try {
9185                            session = openSession();
9186    
9187                            MBMessage[] array = new MBMessageImpl[3];
9188    
9189                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9190                                            parentMessageId, orderByComparator, true);
9191    
9192                            array[1] = mbMessage;
9193    
9194                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9195                                            parentMessageId, orderByComparator, false);
9196    
9197                            return array;
9198                    }
9199                    catch (Exception e) {
9200                            throw processException(e);
9201                    }
9202                    finally {
9203                            closeSession(session);
9204                    }
9205            }
9206    
9207            protected MBMessage getByT_P_PrevAndNext(Session session,
9208                    MBMessage mbMessage, long threadId, long parentMessageId,
9209                    OrderByComparator orderByComparator, boolean previous) {
9210                    StringBundler query = null;
9211    
9212                    if (orderByComparator != null) {
9213                            query = new StringBundler(6 +
9214                                            (orderByComparator.getOrderByFields().length * 6));
9215                    }
9216                    else {
9217                            query = new StringBundler(3);
9218                    }
9219    
9220                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9221    
9222                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9223    
9224                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9225    
9226                    if (orderByComparator != null) {
9227                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9228    
9229                            if (orderByConditionFields.length > 0) {
9230                                    query.append(WHERE_AND);
9231                            }
9232    
9233                            for (int i = 0; i < orderByConditionFields.length; i++) {
9234                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9235                                    query.append(orderByConditionFields[i]);
9236    
9237                                    if ((i + 1) < orderByConditionFields.length) {
9238                                            if (orderByComparator.isAscending() ^ previous) {
9239                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9240                                            }
9241                                            else {
9242                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9243                                            }
9244                                    }
9245                                    else {
9246                                            if (orderByComparator.isAscending() ^ previous) {
9247                                                    query.append(WHERE_GREATER_THAN);
9248                                            }
9249                                            else {
9250                                                    query.append(WHERE_LESSER_THAN);
9251                                            }
9252                                    }
9253                            }
9254    
9255                            query.append(ORDER_BY_CLAUSE);
9256    
9257                            String[] orderByFields = orderByComparator.getOrderByFields();
9258    
9259                            for (int i = 0; i < orderByFields.length; i++) {
9260                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9261                                    query.append(orderByFields[i]);
9262    
9263                                    if ((i + 1) < orderByFields.length) {
9264                                            if (orderByComparator.isAscending() ^ previous) {
9265                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9266                                            }
9267                                            else {
9268                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9269                                            }
9270                                    }
9271                                    else {
9272                                            if (orderByComparator.isAscending() ^ previous) {
9273                                                    query.append(ORDER_BY_ASC);
9274                                            }
9275                                            else {
9276                                                    query.append(ORDER_BY_DESC);
9277                                            }
9278                                    }
9279                            }
9280                    }
9281                    else {
9282                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9283                    }
9284    
9285                    String sql = query.toString();
9286    
9287                    Query q = session.createQuery(sql);
9288    
9289                    q.setFirstResult(0);
9290                    q.setMaxResults(2);
9291    
9292                    QueryPos qPos = QueryPos.getInstance(q);
9293    
9294                    qPos.add(threadId);
9295    
9296                    qPos.add(parentMessageId);
9297    
9298                    if (orderByComparator != null) {
9299                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9300    
9301                            for (Object value : values) {
9302                                    qPos.add(value);
9303                            }
9304                    }
9305    
9306                    List<MBMessage> list = q.list();
9307    
9308                    if (list.size() == 2) {
9309                            return list.get(1);
9310                    }
9311                    else {
9312                            return null;
9313                    }
9314            }
9315    
9316            /**
9317             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9318             *
9319             * @param threadId the thread ID
9320             * @param parentMessageId the parent message ID
9321             * @throws SystemException if a system exception occurred
9322             */
9323            @Override
9324            public void removeByT_P(long threadId, long parentMessageId)
9325                    throws SystemException {
9326                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9327                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9328                            remove(mbMessage);
9329                    }
9330            }
9331    
9332            /**
9333             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9334             *
9335             * @param threadId the thread ID
9336             * @param parentMessageId the parent message ID
9337             * @return the number of matching message-boards messages
9338             * @throws SystemException if a system exception occurred
9339             */
9340            @Override
9341            public int countByT_P(long threadId, long parentMessageId)
9342                    throws SystemException {
9343                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9344    
9345                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9346    
9347                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9348                                    this);
9349    
9350                    if (count == null) {
9351                            StringBundler query = new StringBundler(3);
9352    
9353                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9354    
9355                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9356    
9357                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9358    
9359                            String sql = query.toString();
9360    
9361                            Session session = null;
9362    
9363                            try {
9364                                    session = openSession();
9365    
9366                                    Query q = session.createQuery(sql);
9367    
9368                                    QueryPos qPos = QueryPos.getInstance(q);
9369    
9370                                    qPos.add(threadId);
9371    
9372                                    qPos.add(parentMessageId);
9373    
9374                                    count = (Long)q.uniqueResult();
9375    
9376                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9377                            }
9378                            catch (Exception e) {
9379                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9380    
9381                                    throw processException(e);
9382                            }
9383                            finally {
9384                                    closeSession(session);
9385                            }
9386                    }
9387    
9388                    return count.intValue();
9389            }
9390    
9391            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9392            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9393            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9394                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9395                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9396                            new String[] {
9397                                    Long.class.getName(), Boolean.class.getName(),
9398                                    
9399                            Integer.class.getName(), Integer.class.getName(),
9400                                    OrderByComparator.class.getName()
9401                            });
9402            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9403                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9404                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9405                            new String[] { Long.class.getName(), Boolean.class.getName() },
9406                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9407                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9408                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9409            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9410                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9411                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9412                            new String[] { Long.class.getName(), Boolean.class.getName() });
9413    
9414            /**
9415             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9416             *
9417             * @param threadId the thread ID
9418             * @param answer the answer
9419             * @return the matching message-boards messages
9420             * @throws SystemException if a system exception occurred
9421             */
9422            @Override
9423            public List<MBMessage> findByT_A(long threadId, boolean answer)
9424                    throws SystemException {
9425                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9426                            QueryUtil.ALL_POS, null);
9427            }
9428    
9429            /**
9430             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9431             *
9432             * <p>
9433             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
9434             * </p>
9435             *
9436             * @param threadId the thread ID
9437             * @param answer the answer
9438             * @param start the lower bound of the range of message-boards messages
9439             * @param end the upper bound of the range of message-boards messages (not inclusive)
9440             * @return the range of matching message-boards messages
9441             * @throws SystemException if a system exception occurred
9442             */
9443            @Override
9444            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9445                    int end) throws SystemException {
9446                    return findByT_A(threadId, answer, start, end, null);
9447            }
9448    
9449            /**
9450             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9451             *
9452             * <p>
9453             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
9454             * </p>
9455             *
9456             * @param threadId the thread ID
9457             * @param answer the answer
9458             * @param start the lower bound of the range of message-boards messages
9459             * @param end the upper bound of the range of message-boards messages (not inclusive)
9460             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9461             * @return the ordered range of matching message-boards messages
9462             * @throws SystemException if a system exception occurred
9463             */
9464            @Override
9465            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9466                    int end, OrderByComparator orderByComparator) throws SystemException {
9467                    boolean pagination = true;
9468                    FinderPath finderPath = null;
9469                    Object[] finderArgs = null;
9470    
9471                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9472                                    (orderByComparator == null)) {
9473                            pagination = false;
9474                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9475                            finderArgs = new Object[] { threadId, answer };
9476                    }
9477                    else {
9478                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9479                            finderArgs = new Object[] {
9480                                            threadId, answer,
9481                                            
9482                                            start, end, orderByComparator
9483                                    };
9484                    }
9485    
9486                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9487                                    finderArgs, this);
9488    
9489                    if ((list != null) && !list.isEmpty()) {
9490                            for (MBMessage mbMessage : list) {
9491                                    if ((threadId != mbMessage.getThreadId()) ||
9492                                                    (answer != mbMessage.getAnswer())) {
9493                                            list = null;
9494    
9495                                            break;
9496                                    }
9497                            }
9498                    }
9499    
9500                    if (list == null) {
9501                            StringBundler query = null;
9502    
9503                            if (orderByComparator != null) {
9504                                    query = new StringBundler(4 +
9505                                                    (orderByComparator.getOrderByFields().length * 3));
9506                            }
9507                            else {
9508                                    query = new StringBundler(4);
9509                            }
9510    
9511                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9512    
9513                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9514    
9515                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9516    
9517                            if (orderByComparator != null) {
9518                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9519                                            orderByComparator);
9520                            }
9521                            else
9522                             if (pagination) {
9523                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9524                            }
9525    
9526                            String sql = query.toString();
9527    
9528                            Session session = null;
9529    
9530                            try {
9531                                    session = openSession();
9532    
9533                                    Query q = session.createQuery(sql);
9534    
9535                                    QueryPos qPos = QueryPos.getInstance(q);
9536    
9537                                    qPos.add(threadId);
9538    
9539                                    qPos.add(answer);
9540    
9541                                    if (!pagination) {
9542                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9543                                                            start, end, false);
9544    
9545                                            Collections.sort(list);
9546    
9547                                            list = new UnmodifiableList<MBMessage>(list);
9548                                    }
9549                                    else {
9550                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9551                                                            start, end);
9552                                    }
9553    
9554                                    cacheResult(list);
9555    
9556                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9557                            }
9558                            catch (Exception e) {
9559                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9560    
9561                                    throw processException(e);
9562                            }
9563                            finally {
9564                                    closeSession(session);
9565                            }
9566                    }
9567    
9568                    return list;
9569            }
9570    
9571            /**
9572             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9573             *
9574             * @param threadId the thread ID
9575             * @param answer the answer
9576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9577             * @return the first matching message-boards message
9578             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9579             * @throws SystemException if a system exception occurred
9580             */
9581            @Override
9582            public MBMessage findByT_A_First(long threadId, boolean answer,
9583                    OrderByComparator orderByComparator)
9584                    throws NoSuchMessageException, SystemException {
9585                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9586                                    orderByComparator);
9587    
9588                    if (mbMessage != null) {
9589                            return mbMessage;
9590                    }
9591    
9592                    StringBundler msg = new StringBundler(6);
9593    
9594                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9595    
9596                    msg.append("threadId=");
9597                    msg.append(threadId);
9598    
9599                    msg.append(", answer=");
9600                    msg.append(answer);
9601    
9602                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9603    
9604                    throw new NoSuchMessageException(msg.toString());
9605            }
9606    
9607            /**
9608             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9609             *
9610             * @param threadId the thread ID
9611             * @param answer the answer
9612             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9613             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9614             * @throws SystemException if a system exception occurred
9615             */
9616            @Override
9617            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9618                    OrderByComparator orderByComparator) throws SystemException {
9619                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9620                                    orderByComparator);
9621    
9622                    if (!list.isEmpty()) {
9623                            return list.get(0);
9624                    }
9625    
9626                    return null;
9627            }
9628    
9629            /**
9630             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9631             *
9632             * @param threadId the thread ID
9633             * @param answer the answer
9634             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9635             * @return the last matching message-boards message
9636             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9637             * @throws SystemException if a system exception occurred
9638             */
9639            @Override
9640            public MBMessage findByT_A_Last(long threadId, boolean answer,
9641                    OrderByComparator orderByComparator)
9642                    throws NoSuchMessageException, SystemException {
9643                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9644                                    orderByComparator);
9645    
9646                    if (mbMessage != null) {
9647                            return mbMessage;
9648                    }
9649    
9650                    StringBundler msg = new StringBundler(6);
9651    
9652                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9653    
9654                    msg.append("threadId=");
9655                    msg.append(threadId);
9656    
9657                    msg.append(", answer=");
9658                    msg.append(answer);
9659    
9660                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9661    
9662                    throw new NoSuchMessageException(msg.toString());
9663            }
9664    
9665            /**
9666             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9667             *
9668             * @param threadId the thread ID
9669             * @param answer the answer
9670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9671             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9672             * @throws SystemException if a system exception occurred
9673             */
9674            @Override
9675            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9676                    OrderByComparator orderByComparator) throws SystemException {
9677                    int count = countByT_A(threadId, answer);
9678    
9679                    if (count == 0) {
9680                            return null;
9681                    }
9682    
9683                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9684                                    orderByComparator);
9685    
9686                    if (!list.isEmpty()) {
9687                            return list.get(0);
9688                    }
9689    
9690                    return null;
9691            }
9692    
9693            /**
9694             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9695             *
9696             * @param messageId the primary key of the current message-boards message
9697             * @param threadId the thread ID
9698             * @param answer the answer
9699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9700             * @return the previous, current, and next message-boards message
9701             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9702             * @throws SystemException if a system exception occurred
9703             */
9704            @Override
9705            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9706                    boolean answer, OrderByComparator orderByComparator)
9707                    throws NoSuchMessageException, SystemException {
9708                    MBMessage mbMessage = findByPrimaryKey(messageId);
9709    
9710                    Session session = null;
9711    
9712                    try {
9713                            session = openSession();
9714    
9715                            MBMessage[] array = new MBMessageImpl[3];
9716    
9717                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9718                                            answer, orderByComparator, true);
9719    
9720                            array[1] = mbMessage;
9721    
9722                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9723                                            answer, orderByComparator, false);
9724    
9725                            return array;
9726                    }
9727                    catch (Exception e) {
9728                            throw processException(e);
9729                    }
9730                    finally {
9731                            closeSession(session);
9732                    }
9733            }
9734    
9735            protected MBMessage getByT_A_PrevAndNext(Session session,
9736                    MBMessage mbMessage, long threadId, boolean answer,
9737                    OrderByComparator orderByComparator, boolean previous) {
9738                    StringBundler query = null;
9739    
9740                    if (orderByComparator != null) {
9741                            query = new StringBundler(6 +
9742                                            (orderByComparator.getOrderByFields().length * 6));
9743                    }
9744                    else {
9745                            query = new StringBundler(3);
9746                    }
9747    
9748                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9749    
9750                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9751    
9752                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9753    
9754                    if (orderByComparator != null) {
9755                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9756    
9757                            if (orderByConditionFields.length > 0) {
9758                                    query.append(WHERE_AND);
9759                            }
9760    
9761                            for (int i = 0; i < orderByConditionFields.length; i++) {
9762                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9763                                    query.append(orderByConditionFields[i]);
9764    
9765                                    if ((i + 1) < orderByConditionFields.length) {
9766                                            if (orderByComparator.isAscending() ^ previous) {
9767                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9768                                            }
9769                                            else {
9770                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9771                                            }
9772                                    }
9773                                    else {
9774                                            if (orderByComparator.isAscending() ^ previous) {
9775                                                    query.append(WHERE_GREATER_THAN);
9776                                            }
9777                                            else {
9778                                                    query.append(WHERE_LESSER_THAN);
9779                                            }
9780                                    }
9781                            }
9782    
9783                            query.append(ORDER_BY_CLAUSE);
9784    
9785                            String[] orderByFields = orderByComparator.getOrderByFields();
9786    
9787                            for (int i = 0; i < orderByFields.length; i++) {
9788                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9789                                    query.append(orderByFields[i]);
9790    
9791                                    if ((i + 1) < orderByFields.length) {
9792                                            if (orderByComparator.isAscending() ^ previous) {
9793                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9794                                            }
9795                                            else {
9796                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9797                                            }
9798                                    }
9799                                    else {
9800                                            if (orderByComparator.isAscending() ^ previous) {
9801                                                    query.append(ORDER_BY_ASC);
9802                                            }
9803                                            else {
9804                                                    query.append(ORDER_BY_DESC);
9805                                            }
9806                                    }
9807                            }
9808                    }
9809                    else {
9810                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9811                    }
9812    
9813                    String sql = query.toString();
9814    
9815                    Query q = session.createQuery(sql);
9816    
9817                    q.setFirstResult(0);
9818                    q.setMaxResults(2);
9819    
9820                    QueryPos qPos = QueryPos.getInstance(q);
9821    
9822                    qPos.add(threadId);
9823    
9824                    qPos.add(answer);
9825    
9826                    if (orderByComparator != null) {
9827                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9828    
9829                            for (Object value : values) {
9830                                    qPos.add(value);
9831                            }
9832                    }
9833    
9834                    List<MBMessage> list = q.list();
9835    
9836                    if (list.size() == 2) {
9837                            return list.get(1);
9838                    }
9839                    else {
9840                            return null;
9841                    }
9842            }
9843    
9844            /**
9845             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
9846             *
9847             * @param threadId the thread ID
9848             * @param answer the answer
9849             * @throws SystemException if a system exception occurred
9850             */
9851            @Override
9852            public void removeByT_A(long threadId, boolean answer)
9853                    throws SystemException {
9854                    for (MBMessage mbMessage : findByT_A(threadId, answer,
9855                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9856                            remove(mbMessage);
9857                    }
9858            }
9859    
9860            /**
9861             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
9862             *
9863             * @param threadId the thread ID
9864             * @param answer the answer
9865             * @return the number of matching message-boards messages
9866             * @throws SystemException if a system exception occurred
9867             */
9868            @Override
9869            public int countByT_A(long threadId, boolean answer)
9870                    throws SystemException {
9871                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9872    
9873                    Object[] finderArgs = new Object[] { threadId, answer };
9874    
9875                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9876                                    this);
9877    
9878                    if (count == null) {
9879                            StringBundler query = new StringBundler(3);
9880    
9881                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9882    
9883                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9884    
9885                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9886    
9887                            String sql = query.toString();
9888    
9889                            Session session = null;
9890    
9891                            try {
9892                                    session = openSession();
9893    
9894                                    Query q = session.createQuery(sql);
9895    
9896                                    QueryPos qPos = QueryPos.getInstance(q);
9897    
9898                                    qPos.add(threadId);
9899    
9900                                    qPos.add(answer);
9901    
9902                                    count = (Long)q.uniqueResult();
9903    
9904                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9905                            }
9906                            catch (Exception e) {
9907                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9908    
9909                                    throw processException(e);
9910                            }
9911                            finally {
9912                                    closeSession(session);
9913                            }
9914                    }
9915    
9916                    return count.intValue();
9917            }
9918    
9919            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9920            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9921            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9922                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9923                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9924                            new String[] {
9925                                    Long.class.getName(), Integer.class.getName(),
9926                                    
9927                            Integer.class.getName(), Integer.class.getName(),
9928                                    OrderByComparator.class.getName()
9929                            });
9930            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9931                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9932                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9933                            new String[] { Long.class.getName(), Integer.class.getName() },
9934                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9935                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9936                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9937            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9938                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9939                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9940                            new String[] { Long.class.getName(), Integer.class.getName() });
9941    
9942            /**
9943             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9944             *
9945             * @param threadId the thread ID
9946             * @param status the status
9947             * @return the matching message-boards messages
9948             * @throws SystemException if a system exception occurred
9949             */
9950            @Override
9951            public List<MBMessage> findByT_S(long threadId, int status)
9952                    throws SystemException {
9953                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9954                            QueryUtil.ALL_POS, null);
9955            }
9956    
9957            /**
9958             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9959             *
9960             * <p>
9961             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
9962             * </p>
9963             *
9964             * @param threadId the thread ID
9965             * @param status the status
9966             * @param start the lower bound of the range of message-boards messages
9967             * @param end the upper bound of the range of message-boards messages (not inclusive)
9968             * @return the range of matching message-boards messages
9969             * @throws SystemException if a system exception occurred
9970             */
9971            @Override
9972            public List<MBMessage> findByT_S(long threadId, int status, int start,
9973                    int end) throws SystemException {
9974                    return findByT_S(threadId, status, start, end, null);
9975            }
9976    
9977            /**
9978             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9979             *
9980             * <p>
9981             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
9982             * </p>
9983             *
9984             * @param threadId the thread ID
9985             * @param status the status
9986             * @param start the lower bound of the range of message-boards messages
9987             * @param end the upper bound of the range of message-boards messages (not inclusive)
9988             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9989             * @return the ordered range of matching message-boards messages
9990             * @throws SystemException if a system exception occurred
9991             */
9992            @Override
9993            public List<MBMessage> findByT_S(long threadId, int status, int start,
9994                    int end, OrderByComparator orderByComparator) throws SystemException {
9995                    boolean pagination = true;
9996                    FinderPath finderPath = null;
9997                    Object[] finderArgs = null;
9998    
9999                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10000                                    (orderByComparator == null)) {
10001                            pagination = false;
10002                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10003                            finderArgs = new Object[] { threadId, status };
10004                    }
10005                    else {
10006                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10007                            finderArgs = new Object[] {
10008                                            threadId, status,
10009                                            
10010                                            start, end, orderByComparator
10011                                    };
10012                    }
10013    
10014                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10015                                    finderArgs, this);
10016    
10017                    if ((list != null) && !list.isEmpty()) {
10018                            for (MBMessage mbMessage : list) {
10019                                    if ((threadId != mbMessage.getThreadId()) ||
10020                                                    (status != mbMessage.getStatus())) {
10021                                            list = null;
10022    
10023                                            break;
10024                                    }
10025                            }
10026                    }
10027    
10028                    if (list == null) {
10029                            StringBundler query = null;
10030    
10031                            if (orderByComparator != null) {
10032                                    query = new StringBundler(4 +
10033                                                    (orderByComparator.getOrderByFields().length * 3));
10034                            }
10035                            else {
10036                                    query = new StringBundler(4);
10037                            }
10038    
10039                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10040    
10041                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10042    
10043                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10044    
10045                            if (orderByComparator != null) {
10046                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10047                                            orderByComparator);
10048                            }
10049                            else
10050                             if (pagination) {
10051                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10052                            }
10053    
10054                            String sql = query.toString();
10055    
10056                            Session session = null;
10057    
10058                            try {
10059                                    session = openSession();
10060    
10061                                    Query q = session.createQuery(sql);
10062    
10063                                    QueryPos qPos = QueryPos.getInstance(q);
10064    
10065                                    qPos.add(threadId);
10066    
10067                                    qPos.add(status);
10068    
10069                                    if (!pagination) {
10070                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10071                                                            start, end, false);
10072    
10073                                            Collections.sort(list);
10074    
10075                                            list = new UnmodifiableList<MBMessage>(list);
10076                                    }
10077                                    else {
10078                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10079                                                            start, end);
10080                                    }
10081    
10082                                    cacheResult(list);
10083    
10084                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10085                            }
10086                            catch (Exception e) {
10087                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10088    
10089                                    throw processException(e);
10090                            }
10091                            finally {
10092                                    closeSession(session);
10093                            }
10094                    }
10095    
10096                    return list;
10097            }
10098    
10099            /**
10100             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10101             *
10102             * @param threadId the thread ID
10103             * @param status the status
10104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10105             * @return the first matching message-boards message
10106             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10107             * @throws SystemException if a system exception occurred
10108             */
10109            @Override
10110            public MBMessage findByT_S_First(long threadId, int status,
10111                    OrderByComparator orderByComparator)
10112                    throws NoSuchMessageException, SystemException {
10113                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10114                                    orderByComparator);
10115    
10116                    if (mbMessage != null) {
10117                            return mbMessage;
10118                    }
10119    
10120                    StringBundler msg = new StringBundler(6);
10121    
10122                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10123    
10124                    msg.append("threadId=");
10125                    msg.append(threadId);
10126    
10127                    msg.append(", status=");
10128                    msg.append(status);
10129    
10130                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10131    
10132                    throw new NoSuchMessageException(msg.toString());
10133            }
10134    
10135            /**
10136             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10137             *
10138             * @param threadId the thread ID
10139             * @param status the status
10140             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10141             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10142             * @throws SystemException if a system exception occurred
10143             */
10144            @Override
10145            public MBMessage fetchByT_S_First(long threadId, int status,
10146                    OrderByComparator orderByComparator) throws SystemException {
10147                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10148                                    orderByComparator);
10149    
10150                    if (!list.isEmpty()) {
10151                            return list.get(0);
10152                    }
10153    
10154                    return null;
10155            }
10156    
10157            /**
10158             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10159             *
10160             * @param threadId the thread ID
10161             * @param status the status
10162             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10163             * @return the last matching message-boards message
10164             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10165             * @throws SystemException if a system exception occurred
10166             */
10167            @Override
10168            public MBMessage findByT_S_Last(long threadId, int status,
10169                    OrderByComparator orderByComparator)
10170                    throws NoSuchMessageException, SystemException {
10171                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10172                                    orderByComparator);
10173    
10174                    if (mbMessage != null) {
10175                            return mbMessage;
10176                    }
10177    
10178                    StringBundler msg = new StringBundler(6);
10179    
10180                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10181    
10182                    msg.append("threadId=");
10183                    msg.append(threadId);
10184    
10185                    msg.append(", status=");
10186                    msg.append(status);
10187    
10188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10189    
10190                    throw new NoSuchMessageException(msg.toString());
10191            }
10192    
10193            /**
10194             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10195             *
10196             * @param threadId the thread ID
10197             * @param status the status
10198             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10199             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10200             * @throws SystemException if a system exception occurred
10201             */
10202            @Override
10203            public MBMessage fetchByT_S_Last(long threadId, int status,
10204                    OrderByComparator orderByComparator) throws SystemException {
10205                    int count = countByT_S(threadId, status);
10206    
10207                    if (count == 0) {
10208                            return null;
10209                    }
10210    
10211                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10212                                    orderByComparator);
10213    
10214                    if (!list.isEmpty()) {
10215                            return list.get(0);
10216                    }
10217    
10218                    return null;
10219            }
10220    
10221            /**
10222             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10223             *
10224             * @param messageId the primary key of the current message-boards message
10225             * @param threadId the thread ID
10226             * @param status the status
10227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10228             * @return the previous, current, and next message-boards message
10229             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10230             * @throws SystemException if a system exception occurred
10231             */
10232            @Override
10233            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10234                    int status, OrderByComparator orderByComparator)
10235                    throws NoSuchMessageException, SystemException {
10236                    MBMessage mbMessage = findByPrimaryKey(messageId);
10237    
10238                    Session session = null;
10239    
10240                    try {
10241                            session = openSession();
10242    
10243                            MBMessage[] array = new MBMessageImpl[3];
10244    
10245                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10246                                            status, orderByComparator, true);
10247    
10248                            array[1] = mbMessage;
10249    
10250                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10251                                            status, orderByComparator, false);
10252    
10253                            return array;
10254                    }
10255                    catch (Exception e) {
10256                            throw processException(e);
10257                    }
10258                    finally {
10259                            closeSession(session);
10260                    }
10261            }
10262    
10263            protected MBMessage getByT_S_PrevAndNext(Session session,
10264                    MBMessage mbMessage, long threadId, int status,
10265                    OrderByComparator orderByComparator, boolean previous) {
10266                    StringBundler query = null;
10267    
10268                    if (orderByComparator != null) {
10269                            query = new StringBundler(6 +
10270                                            (orderByComparator.getOrderByFields().length * 6));
10271                    }
10272                    else {
10273                            query = new StringBundler(3);
10274                    }
10275    
10276                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10277    
10278                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10279    
10280                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10281    
10282                    if (orderByComparator != null) {
10283                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10284    
10285                            if (orderByConditionFields.length > 0) {
10286                                    query.append(WHERE_AND);
10287                            }
10288    
10289                            for (int i = 0; i < orderByConditionFields.length; i++) {
10290                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10291                                    query.append(orderByConditionFields[i]);
10292    
10293                                    if ((i + 1) < orderByConditionFields.length) {
10294                                            if (orderByComparator.isAscending() ^ previous) {
10295                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10296                                            }
10297                                            else {
10298                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10299                                            }
10300                                    }
10301                                    else {
10302                                            if (orderByComparator.isAscending() ^ previous) {
10303                                                    query.append(WHERE_GREATER_THAN);
10304                                            }
10305                                            else {
10306                                                    query.append(WHERE_LESSER_THAN);
10307                                            }
10308                                    }
10309                            }
10310    
10311                            query.append(ORDER_BY_CLAUSE);
10312    
10313                            String[] orderByFields = orderByComparator.getOrderByFields();
10314    
10315                            for (int i = 0; i < orderByFields.length; i++) {
10316                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10317                                    query.append(orderByFields[i]);
10318    
10319                                    if ((i + 1) < orderByFields.length) {
10320                                            if (orderByComparator.isAscending() ^ previous) {
10321                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10322                                            }
10323                                            else {
10324                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10325                                            }
10326                                    }
10327                                    else {
10328                                            if (orderByComparator.isAscending() ^ previous) {
10329                                                    query.append(ORDER_BY_ASC);
10330                                            }
10331                                            else {
10332                                                    query.append(ORDER_BY_DESC);
10333                                            }
10334                                    }
10335                            }
10336                    }
10337                    else {
10338                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10339                    }
10340    
10341                    String sql = query.toString();
10342    
10343                    Query q = session.createQuery(sql);
10344    
10345                    q.setFirstResult(0);
10346                    q.setMaxResults(2);
10347    
10348                    QueryPos qPos = QueryPos.getInstance(q);
10349    
10350                    qPos.add(threadId);
10351    
10352                    qPos.add(status);
10353    
10354                    if (orderByComparator != null) {
10355                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10356    
10357                            for (Object value : values) {
10358                                    qPos.add(value);
10359                            }
10360                    }
10361    
10362                    List<MBMessage> list = q.list();
10363    
10364                    if (list.size() == 2) {
10365                            return list.get(1);
10366                    }
10367                    else {
10368                            return null;
10369                    }
10370            }
10371    
10372            /**
10373             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10374             *
10375             * @param threadId the thread ID
10376             * @param status the status
10377             * @throws SystemException if a system exception occurred
10378             */
10379            @Override
10380            public void removeByT_S(long threadId, int status)
10381                    throws SystemException {
10382                    for (MBMessage mbMessage : findByT_S(threadId, status,
10383                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10384                            remove(mbMessage);
10385                    }
10386            }
10387    
10388            /**
10389             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10390             *
10391             * @param threadId the thread ID
10392             * @param status the status
10393             * @return the number of matching message-boards messages
10394             * @throws SystemException if a system exception occurred
10395             */
10396            @Override
10397            public int countByT_S(long threadId, int status) throws SystemException {
10398                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10399    
10400                    Object[] finderArgs = new Object[] { threadId, status };
10401    
10402                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10403                                    this);
10404    
10405                    if (count == null) {
10406                            StringBundler query = new StringBundler(3);
10407    
10408                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10409    
10410                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10411    
10412                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10413    
10414                            String sql = query.toString();
10415    
10416                            Session session = null;
10417    
10418                            try {
10419                                    session = openSession();
10420    
10421                                    Query q = session.createQuery(sql);
10422    
10423                                    QueryPos qPos = QueryPos.getInstance(q);
10424    
10425                                    qPos.add(threadId);
10426    
10427                                    qPos.add(status);
10428    
10429                                    count = (Long)q.uniqueResult();
10430    
10431                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10432                            }
10433                            catch (Exception e) {
10434                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10435    
10436                                    throw processException(e);
10437                            }
10438                            finally {
10439                                    closeSession(session);
10440                            }
10441                    }
10442    
10443                    return count.intValue();
10444            }
10445    
10446            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10447            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10448            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10449                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10450                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10451                            new String[] {
10452                                    Long.class.getName(), Integer.class.getName(),
10453                                    
10454                            Integer.class.getName(), Integer.class.getName(),
10455                                    OrderByComparator.class.getName()
10456                            });
10457            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10458                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10459                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10460                            new String[] { Long.class.getName(), Integer.class.getName() },
10461                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10462                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10463                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10464            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10465                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10466                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10467                            new String[] { Long.class.getName(), Integer.class.getName() });
10468    
10469            /**
10470             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10471             *
10472             * @param threadId the thread ID
10473             * @param status the status
10474             * @return the matching message-boards messages
10475             * @throws SystemException if a system exception occurred
10476             */
10477            @Override
10478            public List<MBMessage> findByTR_S(long threadId, int status)
10479                    throws SystemException {
10480                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10481                            QueryUtil.ALL_POS, null);
10482            }
10483    
10484            /**
10485             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10486             *
10487             * <p>
10488             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
10489             * </p>
10490             *
10491             * @param threadId the thread ID
10492             * @param status the status
10493             * @param start the lower bound of the range of message-boards messages
10494             * @param end the upper bound of the range of message-boards messages (not inclusive)
10495             * @return the range of matching message-boards messages
10496             * @throws SystemException if a system exception occurred
10497             */
10498            @Override
10499            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10500                    int end) throws SystemException {
10501                    return findByTR_S(threadId, status, start, end, null);
10502            }
10503    
10504            /**
10505             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10506             *
10507             * <p>
10508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
10509             * </p>
10510             *
10511             * @param threadId the thread ID
10512             * @param status the status
10513             * @param start the lower bound of the range of message-boards messages
10514             * @param end the upper bound of the range of message-boards messages (not inclusive)
10515             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10516             * @return the ordered range of matching message-boards messages
10517             * @throws SystemException if a system exception occurred
10518             */
10519            @Override
10520            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10521                    int end, OrderByComparator orderByComparator) throws SystemException {
10522                    boolean pagination = true;
10523                    FinderPath finderPath = null;
10524                    Object[] finderArgs = null;
10525    
10526                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10527                                    (orderByComparator == null)) {
10528                            pagination = false;
10529                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10530                            finderArgs = new Object[] { threadId, status };
10531                    }
10532                    else {
10533                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10534                            finderArgs = new Object[] {
10535                                            threadId, status,
10536                                            
10537                                            start, end, orderByComparator
10538                                    };
10539                    }
10540    
10541                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10542                                    finderArgs, this);
10543    
10544                    if ((list != null) && !list.isEmpty()) {
10545                            for (MBMessage mbMessage : list) {
10546                                    if ((threadId != mbMessage.getThreadId()) ||
10547                                                    (status != mbMessage.getStatus())) {
10548                                            list = null;
10549    
10550                                            break;
10551                                    }
10552                            }
10553                    }
10554    
10555                    if (list == null) {
10556                            StringBundler query = null;
10557    
10558                            if (orderByComparator != null) {
10559                                    query = new StringBundler(4 +
10560                                                    (orderByComparator.getOrderByFields().length * 3));
10561                            }
10562                            else {
10563                                    query = new StringBundler(4);
10564                            }
10565    
10566                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10567    
10568                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10569    
10570                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10571    
10572                            if (orderByComparator != null) {
10573                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10574                                            orderByComparator);
10575                            }
10576                            else
10577                             if (pagination) {
10578                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10579                            }
10580    
10581                            String sql = query.toString();
10582    
10583                            Session session = null;
10584    
10585                            try {
10586                                    session = openSession();
10587    
10588                                    Query q = session.createQuery(sql);
10589    
10590                                    QueryPos qPos = QueryPos.getInstance(q);
10591    
10592                                    qPos.add(threadId);
10593    
10594                                    qPos.add(status);
10595    
10596                                    if (!pagination) {
10597                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10598                                                            start, end, false);
10599    
10600                                            Collections.sort(list);
10601    
10602                                            list = new UnmodifiableList<MBMessage>(list);
10603                                    }
10604                                    else {
10605                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10606                                                            start, end);
10607                                    }
10608    
10609                                    cacheResult(list);
10610    
10611                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10612                            }
10613                            catch (Exception e) {
10614                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10615    
10616                                    throw processException(e);
10617                            }
10618                            finally {
10619                                    closeSession(session);
10620                            }
10621                    }
10622    
10623                    return list;
10624            }
10625    
10626            /**
10627             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10628             *
10629             * @param threadId the thread ID
10630             * @param status the status
10631             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10632             * @return the first matching message-boards message
10633             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10634             * @throws SystemException if a system exception occurred
10635             */
10636            @Override
10637            public MBMessage findByTR_S_First(long threadId, int status,
10638                    OrderByComparator orderByComparator)
10639                    throws NoSuchMessageException, SystemException {
10640                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10641                                    orderByComparator);
10642    
10643                    if (mbMessage != null) {
10644                            return mbMessage;
10645                    }
10646    
10647                    StringBundler msg = new StringBundler(6);
10648    
10649                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10650    
10651                    msg.append("threadId=");
10652                    msg.append(threadId);
10653    
10654                    msg.append(", status=");
10655                    msg.append(status);
10656    
10657                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10658    
10659                    throw new NoSuchMessageException(msg.toString());
10660            }
10661    
10662            /**
10663             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10664             *
10665             * @param threadId the thread ID
10666             * @param status the status
10667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10668             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10669             * @throws SystemException if a system exception occurred
10670             */
10671            @Override
10672            public MBMessage fetchByTR_S_First(long threadId, int status,
10673                    OrderByComparator orderByComparator) throws SystemException {
10674                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10675                                    orderByComparator);
10676    
10677                    if (!list.isEmpty()) {
10678                            return list.get(0);
10679                    }
10680    
10681                    return null;
10682            }
10683    
10684            /**
10685             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10686             *
10687             * @param threadId the thread ID
10688             * @param status the status
10689             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10690             * @return the last matching message-boards message
10691             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10692             * @throws SystemException if a system exception occurred
10693             */
10694            @Override
10695            public MBMessage findByTR_S_Last(long threadId, int status,
10696                    OrderByComparator orderByComparator)
10697                    throws NoSuchMessageException, SystemException {
10698                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10699                                    orderByComparator);
10700    
10701                    if (mbMessage != null) {
10702                            return mbMessage;
10703                    }
10704    
10705                    StringBundler msg = new StringBundler(6);
10706    
10707                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10708    
10709                    msg.append("threadId=");
10710                    msg.append(threadId);
10711    
10712                    msg.append(", status=");
10713                    msg.append(status);
10714    
10715                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10716    
10717                    throw new NoSuchMessageException(msg.toString());
10718            }
10719    
10720            /**
10721             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10722             *
10723             * @param threadId the thread ID
10724             * @param status the status
10725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10726             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10727             * @throws SystemException if a system exception occurred
10728             */
10729            @Override
10730            public MBMessage fetchByTR_S_Last(long threadId, int status,
10731                    OrderByComparator orderByComparator) throws SystemException {
10732                    int count = countByTR_S(threadId, status);
10733    
10734                    if (count == 0) {
10735                            return null;
10736                    }
10737    
10738                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10739                                    orderByComparator);
10740    
10741                    if (!list.isEmpty()) {
10742                            return list.get(0);
10743                    }
10744    
10745                    return null;
10746            }
10747    
10748            /**
10749             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10750             *
10751             * @param messageId the primary key of the current message-boards message
10752             * @param threadId the thread ID
10753             * @param status the status
10754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10755             * @return the previous, current, and next message-boards message
10756             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10757             * @throws SystemException if a system exception occurred
10758             */
10759            @Override
10760            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10761                    int status, OrderByComparator orderByComparator)
10762                    throws NoSuchMessageException, SystemException {
10763                    MBMessage mbMessage = findByPrimaryKey(messageId);
10764    
10765                    Session session = null;
10766    
10767                    try {
10768                            session = openSession();
10769    
10770                            MBMessage[] array = new MBMessageImpl[3];
10771    
10772                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10773                                            status, orderByComparator, true);
10774    
10775                            array[1] = mbMessage;
10776    
10777                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10778                                            status, orderByComparator, false);
10779    
10780                            return array;
10781                    }
10782                    catch (Exception e) {
10783                            throw processException(e);
10784                    }
10785                    finally {
10786                            closeSession(session);
10787                    }
10788            }
10789    
10790            protected MBMessage getByTR_S_PrevAndNext(Session session,
10791                    MBMessage mbMessage, long threadId, int status,
10792                    OrderByComparator orderByComparator, boolean previous) {
10793                    StringBundler query = null;
10794    
10795                    if (orderByComparator != null) {
10796                            query = new StringBundler(6 +
10797                                            (orderByComparator.getOrderByFields().length * 6));
10798                    }
10799                    else {
10800                            query = new StringBundler(3);
10801                    }
10802    
10803                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10804    
10805                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10806    
10807                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10808    
10809                    if (orderByComparator != null) {
10810                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10811    
10812                            if (orderByConditionFields.length > 0) {
10813                                    query.append(WHERE_AND);
10814                            }
10815    
10816                            for (int i = 0; i < orderByConditionFields.length; i++) {
10817                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10818                                    query.append(orderByConditionFields[i]);
10819    
10820                                    if ((i + 1) < orderByConditionFields.length) {
10821                                            if (orderByComparator.isAscending() ^ previous) {
10822                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10823                                            }
10824                                            else {
10825                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10826                                            }
10827                                    }
10828                                    else {
10829                                            if (orderByComparator.isAscending() ^ previous) {
10830                                                    query.append(WHERE_GREATER_THAN);
10831                                            }
10832                                            else {
10833                                                    query.append(WHERE_LESSER_THAN);
10834                                            }
10835                                    }
10836                            }
10837    
10838                            query.append(ORDER_BY_CLAUSE);
10839    
10840                            String[] orderByFields = orderByComparator.getOrderByFields();
10841    
10842                            for (int i = 0; i < orderByFields.length; i++) {
10843                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10844                                    query.append(orderByFields[i]);
10845    
10846                                    if ((i + 1) < orderByFields.length) {
10847                                            if (orderByComparator.isAscending() ^ previous) {
10848                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10849                                            }
10850                                            else {
10851                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10852                                            }
10853                                    }
10854                                    else {
10855                                            if (orderByComparator.isAscending() ^ previous) {
10856                                                    query.append(ORDER_BY_ASC);
10857                                            }
10858                                            else {
10859                                                    query.append(ORDER_BY_DESC);
10860                                            }
10861                                    }
10862                            }
10863                    }
10864                    else {
10865                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10866                    }
10867    
10868                    String sql = query.toString();
10869    
10870                    Query q = session.createQuery(sql);
10871    
10872                    q.setFirstResult(0);
10873                    q.setMaxResults(2);
10874    
10875                    QueryPos qPos = QueryPos.getInstance(q);
10876    
10877                    qPos.add(threadId);
10878    
10879                    qPos.add(status);
10880    
10881                    if (orderByComparator != null) {
10882                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10883    
10884                            for (Object value : values) {
10885                                    qPos.add(value);
10886                            }
10887                    }
10888    
10889                    List<MBMessage> list = q.list();
10890    
10891                    if (list.size() == 2) {
10892                            return list.get(1);
10893                    }
10894                    else {
10895                            return null;
10896                    }
10897            }
10898    
10899            /**
10900             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10901             *
10902             * @param threadId the thread ID
10903             * @param status the status
10904             * @throws SystemException if a system exception occurred
10905             */
10906            @Override
10907            public void removeByTR_S(long threadId, int status)
10908                    throws SystemException {
10909                    for (MBMessage mbMessage : findByTR_S(threadId, status,
10910                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10911                            remove(mbMessage);
10912                    }
10913            }
10914    
10915            /**
10916             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10917             *
10918             * @param threadId the thread ID
10919             * @param status the status
10920             * @return the number of matching message-boards messages
10921             * @throws SystemException if a system exception occurred
10922             */
10923            @Override
10924            public int countByTR_S(long threadId, int status) throws SystemException {
10925                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10926    
10927                    Object[] finderArgs = new Object[] { threadId, status };
10928    
10929                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10930                                    this);
10931    
10932                    if (count == null) {
10933                            StringBundler query = new StringBundler(3);
10934    
10935                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10936    
10937                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10938    
10939                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10940    
10941                            String sql = query.toString();
10942    
10943                            Session session = null;
10944    
10945                            try {
10946                                    session = openSession();
10947    
10948                                    Query q = session.createQuery(sql);
10949    
10950                                    QueryPos qPos = QueryPos.getInstance(q);
10951    
10952                                    qPos.add(threadId);
10953    
10954                                    qPos.add(status);
10955    
10956                                    count = (Long)q.uniqueResult();
10957    
10958                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10959                            }
10960                            catch (Exception e) {
10961                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10962    
10963                                    throw processException(e);
10964                            }
10965                            finally {
10966                                    closeSession(session);
10967                            }
10968                    }
10969    
10970                    return count.intValue();
10971            }
10972    
10973            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10974            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10975            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10976                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10977                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10978                            new String[] {
10979                                    Long.class.getName(), Long.class.getName(),
10980                                    Integer.class.getName(),
10981                                    
10982                            Integer.class.getName(), Integer.class.getName(),
10983                                    OrderByComparator.class.getName()
10984                            });
10985            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10986                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10987                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10988                            new String[] {
10989                                    Long.class.getName(), Long.class.getName(),
10990                                    Integer.class.getName()
10991                            },
10992                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10993                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
10994                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10995                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10996            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10997                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10998                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10999                            new String[] {
11000                                    Long.class.getName(), Long.class.getName(),
11001                                    Integer.class.getName()
11002                            });
11003    
11004            /**
11005             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11006             *
11007             * @param groupId the group ID
11008             * @param userId the user ID
11009             * @param status the status
11010             * @return the matching message-boards messages
11011             * @throws SystemException if a system exception occurred
11012             */
11013            @Override
11014            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
11015                    throws SystemException {
11016                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11017                            QueryUtil.ALL_POS, null);
11018            }
11019    
11020            /**
11021             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11022             *
11023             * <p>
11024             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
11025             * </p>
11026             *
11027             * @param groupId the group ID
11028             * @param userId the user ID
11029             * @param status the status
11030             * @param start the lower bound of the range of message-boards messages
11031             * @param end the upper bound of the range of message-boards messages (not inclusive)
11032             * @return the range of matching message-boards messages
11033             * @throws SystemException if a system exception occurred
11034             */
11035            @Override
11036            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11037                    int start, int end) throws SystemException {
11038                    return findByG_U_S(groupId, userId, status, start, end, null);
11039            }
11040    
11041            /**
11042             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11043             *
11044             * <p>
11045             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
11046             * </p>
11047             *
11048             * @param groupId the group ID
11049             * @param userId the user ID
11050             * @param status the status
11051             * @param start the lower bound of the range of message-boards messages
11052             * @param end the upper bound of the range of message-boards messages (not inclusive)
11053             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11054             * @return the ordered range of matching message-boards messages
11055             * @throws SystemException if a system exception occurred
11056             */
11057            @Override
11058            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11059                    int start, int end, OrderByComparator orderByComparator)
11060                    throws SystemException {
11061                    boolean pagination = true;
11062                    FinderPath finderPath = null;
11063                    Object[] finderArgs = null;
11064    
11065                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11066                                    (orderByComparator == null)) {
11067                            pagination = false;
11068                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11069                            finderArgs = new Object[] { groupId, userId, status };
11070                    }
11071                    else {
11072                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11073                            finderArgs = new Object[] {
11074                                            groupId, userId, status,
11075                                            
11076                                            start, end, orderByComparator
11077                                    };
11078                    }
11079    
11080                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11081                                    finderArgs, this);
11082    
11083                    if ((list != null) && !list.isEmpty()) {
11084                            for (MBMessage mbMessage : list) {
11085                                    if ((groupId != mbMessage.getGroupId()) ||
11086                                                    (userId != mbMessage.getUserId()) ||
11087                                                    (status != mbMessage.getStatus())) {
11088                                            list = null;
11089    
11090                                            break;
11091                                    }
11092                            }
11093                    }
11094    
11095                    if (list == null) {
11096                            StringBundler query = null;
11097    
11098                            if (orderByComparator != null) {
11099                                    query = new StringBundler(5 +
11100                                                    (orderByComparator.getOrderByFields().length * 3));
11101                            }
11102                            else {
11103                                    query = new StringBundler(5);
11104                            }
11105    
11106                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11107    
11108                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11109    
11110                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11111    
11112                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11113    
11114                            if (orderByComparator != null) {
11115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11116                                            orderByComparator);
11117                            }
11118                            else
11119                             if (pagination) {
11120                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11121                            }
11122    
11123                            String sql = query.toString();
11124    
11125                            Session session = null;
11126    
11127                            try {
11128                                    session = openSession();
11129    
11130                                    Query q = session.createQuery(sql);
11131    
11132                                    QueryPos qPos = QueryPos.getInstance(q);
11133    
11134                                    qPos.add(groupId);
11135    
11136                                    qPos.add(userId);
11137    
11138                                    qPos.add(status);
11139    
11140                                    if (!pagination) {
11141                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11142                                                            start, end, false);
11143    
11144                                            Collections.sort(list);
11145    
11146                                            list = new UnmodifiableList<MBMessage>(list);
11147                                    }
11148                                    else {
11149                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11150                                                            start, end);
11151                                    }
11152    
11153                                    cacheResult(list);
11154    
11155                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11156                            }
11157                            catch (Exception e) {
11158                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11159    
11160                                    throw processException(e);
11161                            }
11162                            finally {
11163                                    closeSession(session);
11164                            }
11165                    }
11166    
11167                    return list;
11168            }
11169    
11170            /**
11171             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11172             *
11173             * @param groupId the group ID
11174             * @param userId the user ID
11175             * @param status the status
11176             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11177             * @return the first matching message-boards message
11178             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11179             * @throws SystemException if a system exception occurred
11180             */
11181            @Override
11182            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11183                    OrderByComparator orderByComparator)
11184                    throws NoSuchMessageException, SystemException {
11185                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11186                                    orderByComparator);
11187    
11188                    if (mbMessage != null) {
11189                            return mbMessage;
11190                    }
11191    
11192                    StringBundler msg = new StringBundler(8);
11193    
11194                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11195    
11196                    msg.append("groupId=");
11197                    msg.append(groupId);
11198    
11199                    msg.append(", userId=");
11200                    msg.append(userId);
11201    
11202                    msg.append(", status=");
11203                    msg.append(status);
11204    
11205                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11206    
11207                    throw new NoSuchMessageException(msg.toString());
11208            }
11209    
11210            /**
11211             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11212             *
11213             * @param groupId the group ID
11214             * @param userId the user ID
11215             * @param status the status
11216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11217             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11218             * @throws SystemException if a system exception occurred
11219             */
11220            @Override
11221            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11222                    OrderByComparator orderByComparator) throws SystemException {
11223                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11224                                    orderByComparator);
11225    
11226                    if (!list.isEmpty()) {
11227                            return list.get(0);
11228                    }
11229    
11230                    return null;
11231            }
11232    
11233            /**
11234             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11235             *
11236             * @param groupId the group ID
11237             * @param userId the user ID
11238             * @param status the status
11239             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11240             * @return the last matching message-boards message
11241             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11242             * @throws SystemException if a system exception occurred
11243             */
11244            @Override
11245            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11246                    OrderByComparator orderByComparator)
11247                    throws NoSuchMessageException, SystemException {
11248                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11249                                    orderByComparator);
11250    
11251                    if (mbMessage != null) {
11252                            return mbMessage;
11253                    }
11254    
11255                    StringBundler msg = new StringBundler(8);
11256    
11257                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11258    
11259                    msg.append("groupId=");
11260                    msg.append(groupId);
11261    
11262                    msg.append(", userId=");
11263                    msg.append(userId);
11264    
11265                    msg.append(", status=");
11266                    msg.append(status);
11267    
11268                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11269    
11270                    throw new NoSuchMessageException(msg.toString());
11271            }
11272    
11273            /**
11274             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11275             *
11276             * @param groupId the group ID
11277             * @param userId the user ID
11278             * @param status the status
11279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11280             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11281             * @throws SystemException if a system exception occurred
11282             */
11283            @Override
11284            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11285                    OrderByComparator orderByComparator) throws SystemException {
11286                    int count = countByG_U_S(groupId, userId, status);
11287    
11288                    if (count == 0) {
11289                            return null;
11290                    }
11291    
11292                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11293                                    count, orderByComparator);
11294    
11295                    if (!list.isEmpty()) {
11296                            return list.get(0);
11297                    }
11298    
11299                    return null;
11300            }
11301    
11302            /**
11303             * 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;.
11304             *
11305             * @param messageId the primary key of the current message-boards message
11306             * @param groupId the group ID
11307             * @param userId the user ID
11308             * @param status the status
11309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11310             * @return the previous, current, and next message-boards message
11311             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11312             * @throws SystemException if a system exception occurred
11313             */
11314            @Override
11315            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11316                    long userId, int status, OrderByComparator orderByComparator)
11317                    throws NoSuchMessageException, SystemException {
11318                    MBMessage mbMessage = findByPrimaryKey(messageId);
11319    
11320                    Session session = null;
11321    
11322                    try {
11323                            session = openSession();
11324    
11325                            MBMessage[] array = new MBMessageImpl[3];
11326    
11327                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11328                                            userId, status, orderByComparator, true);
11329    
11330                            array[1] = mbMessage;
11331    
11332                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11333                                            userId, status, orderByComparator, false);
11334    
11335                            return array;
11336                    }
11337                    catch (Exception e) {
11338                            throw processException(e);
11339                    }
11340                    finally {
11341                            closeSession(session);
11342                    }
11343            }
11344    
11345            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11346                    MBMessage mbMessage, long groupId, long userId, int status,
11347                    OrderByComparator orderByComparator, boolean previous) {
11348                    StringBundler query = null;
11349    
11350                    if (orderByComparator != null) {
11351                            query = new StringBundler(6 +
11352                                            (orderByComparator.getOrderByFields().length * 6));
11353                    }
11354                    else {
11355                            query = new StringBundler(3);
11356                    }
11357    
11358                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11359    
11360                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11361    
11362                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11363    
11364                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11365    
11366                    if (orderByComparator != null) {
11367                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11368    
11369                            if (orderByConditionFields.length > 0) {
11370                                    query.append(WHERE_AND);
11371                            }
11372    
11373                            for (int i = 0; i < orderByConditionFields.length; i++) {
11374                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11375                                    query.append(orderByConditionFields[i]);
11376    
11377                                    if ((i + 1) < orderByConditionFields.length) {
11378                                            if (orderByComparator.isAscending() ^ previous) {
11379                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11380                                            }
11381                                            else {
11382                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11383                                            }
11384                                    }
11385                                    else {
11386                                            if (orderByComparator.isAscending() ^ previous) {
11387                                                    query.append(WHERE_GREATER_THAN);
11388                                            }
11389                                            else {
11390                                                    query.append(WHERE_LESSER_THAN);
11391                                            }
11392                                    }
11393                            }
11394    
11395                            query.append(ORDER_BY_CLAUSE);
11396    
11397                            String[] orderByFields = orderByComparator.getOrderByFields();
11398    
11399                            for (int i = 0; i < orderByFields.length; i++) {
11400                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11401                                    query.append(orderByFields[i]);
11402    
11403                                    if ((i + 1) < orderByFields.length) {
11404                                            if (orderByComparator.isAscending() ^ previous) {
11405                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11406                                            }
11407                                            else {
11408                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11409                                            }
11410                                    }
11411                                    else {
11412                                            if (orderByComparator.isAscending() ^ previous) {
11413                                                    query.append(ORDER_BY_ASC);
11414                                            }
11415                                            else {
11416                                                    query.append(ORDER_BY_DESC);
11417                                            }
11418                                    }
11419                            }
11420                    }
11421                    else {
11422                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11423                    }
11424    
11425                    String sql = query.toString();
11426    
11427                    Query q = session.createQuery(sql);
11428    
11429                    q.setFirstResult(0);
11430                    q.setMaxResults(2);
11431    
11432                    QueryPos qPos = QueryPos.getInstance(q);
11433    
11434                    qPos.add(groupId);
11435    
11436                    qPos.add(userId);
11437    
11438                    qPos.add(status);
11439    
11440                    if (orderByComparator != null) {
11441                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11442    
11443                            for (Object value : values) {
11444                                    qPos.add(value);
11445                            }
11446                    }
11447    
11448                    List<MBMessage> list = q.list();
11449    
11450                    if (list.size() == 2) {
11451                            return list.get(1);
11452                    }
11453                    else {
11454                            return null;
11455                    }
11456            }
11457    
11458            /**
11459             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11460             *
11461             * @param groupId the group ID
11462             * @param userId the user ID
11463             * @param status the status
11464             * @return the matching message-boards messages that the user has permission to view
11465             * @throws SystemException if a system exception occurred
11466             */
11467            @Override
11468            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11469                    int status) throws SystemException {
11470                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11471                            QueryUtil.ALL_POS, null);
11472            }
11473    
11474            /**
11475             * 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;.
11476             *
11477             * <p>
11478             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
11479             * </p>
11480             *
11481             * @param groupId the group ID
11482             * @param userId the user ID
11483             * @param status the status
11484             * @param start the lower bound of the range of message-boards messages
11485             * @param end the upper bound of the range of message-boards messages (not inclusive)
11486             * @return the range of matching message-boards messages that the user has permission to view
11487             * @throws SystemException if a system exception occurred
11488             */
11489            @Override
11490            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11491                    int status, int start, int end) throws SystemException {
11492                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11493            }
11494    
11495            /**
11496             * 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;.
11497             *
11498             * <p>
11499             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
11500             * </p>
11501             *
11502             * @param groupId the group ID
11503             * @param userId the user ID
11504             * @param status the status
11505             * @param start the lower bound of the range of message-boards messages
11506             * @param end the upper bound of the range of message-boards messages (not inclusive)
11507             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11508             * @return the ordered range of matching message-boards messages that the user has permission to view
11509             * @throws SystemException if a system exception occurred
11510             */
11511            @Override
11512            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11513                    int status, int start, int end, OrderByComparator orderByComparator)
11514                    throws SystemException {
11515                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11516                            return findByG_U_S(groupId, userId, status, start, end,
11517                                    orderByComparator);
11518                    }
11519    
11520                    StringBundler query = null;
11521    
11522                    if (orderByComparator != null) {
11523                            query = new StringBundler(5 +
11524                                            (orderByComparator.getOrderByFields().length * 3));
11525                    }
11526                    else {
11527                            query = new StringBundler(5);
11528                    }
11529    
11530                    if (getDB().isSupportsInlineDistinct()) {
11531                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11532                    }
11533                    else {
11534                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11535                    }
11536    
11537                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11538    
11539                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11540    
11541                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11542    
11543                    if (!getDB().isSupportsInlineDistinct()) {
11544                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11545                    }
11546    
11547                    if (orderByComparator != null) {
11548                            if (getDB().isSupportsInlineDistinct()) {
11549                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11550                                            orderByComparator, true);
11551                            }
11552                            else {
11553                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11554                                            orderByComparator, true);
11555                            }
11556                    }
11557                    else {
11558                            if (getDB().isSupportsInlineDistinct()) {
11559                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11560                            }
11561                            else {
11562                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11563                            }
11564                    }
11565    
11566                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11567                                    MBMessage.class.getName(),
11568                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11569    
11570                    Session session = null;
11571    
11572                    try {
11573                            session = openSession();
11574    
11575                            SQLQuery q = session.createSQLQuery(sql);
11576    
11577                            if (getDB().isSupportsInlineDistinct()) {
11578                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11579                            }
11580                            else {
11581                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11582                            }
11583    
11584                            QueryPos qPos = QueryPos.getInstance(q);
11585    
11586                            qPos.add(groupId);
11587    
11588                            qPos.add(userId);
11589    
11590                            qPos.add(status);
11591    
11592                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11593                    }
11594                    catch (Exception e) {
11595                            throw processException(e);
11596                    }
11597                    finally {
11598                            closeSession(session);
11599                    }
11600            }
11601    
11602            /**
11603             * 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;.
11604             *
11605             * @param messageId the primary key of the current message-boards message
11606             * @param groupId the group ID
11607             * @param userId the user ID
11608             * @param status the status
11609             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11610             * @return the previous, current, and next message-boards message
11611             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11612             * @throws SystemException if a system exception occurred
11613             */
11614            @Override
11615            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11616                    long groupId, long userId, int status,
11617                    OrderByComparator orderByComparator)
11618                    throws NoSuchMessageException, SystemException {
11619                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11620                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11621                                    orderByComparator);
11622                    }
11623    
11624                    MBMessage mbMessage = findByPrimaryKey(messageId);
11625    
11626                    Session session = null;
11627    
11628                    try {
11629                            session = openSession();
11630    
11631                            MBMessage[] array = new MBMessageImpl[3];
11632    
11633                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11634                                            groupId, userId, status, orderByComparator, true);
11635    
11636                            array[1] = mbMessage;
11637    
11638                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11639                                            groupId, userId, status, orderByComparator, false);
11640    
11641                            return array;
11642                    }
11643                    catch (Exception e) {
11644                            throw processException(e);
11645                    }
11646                    finally {
11647                            closeSession(session);
11648                    }
11649            }
11650    
11651            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11652                    MBMessage mbMessage, long groupId, long userId, int status,
11653                    OrderByComparator orderByComparator, boolean previous) {
11654                    StringBundler query = null;
11655    
11656                    if (orderByComparator != null) {
11657                            query = new StringBundler(6 +
11658                                            (orderByComparator.getOrderByFields().length * 6));
11659                    }
11660                    else {
11661                            query = new StringBundler(3);
11662                    }
11663    
11664                    if (getDB().isSupportsInlineDistinct()) {
11665                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11666                    }
11667                    else {
11668                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11669                    }
11670    
11671                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11672    
11673                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11674    
11675                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11676    
11677                    if (!getDB().isSupportsInlineDistinct()) {
11678                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11679                    }
11680    
11681                    if (orderByComparator != null) {
11682                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11683    
11684                            if (orderByConditionFields.length > 0) {
11685                                    query.append(WHERE_AND);
11686                            }
11687    
11688                            for (int i = 0; i < orderByConditionFields.length; i++) {
11689                                    if (getDB().isSupportsInlineDistinct()) {
11690                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11691                                    }
11692                                    else {
11693                                            query.append(_ORDER_BY_ENTITY_TABLE);
11694                                    }
11695    
11696                                    query.append(orderByConditionFields[i]);
11697    
11698                                    if ((i + 1) < orderByConditionFields.length) {
11699                                            if (orderByComparator.isAscending() ^ previous) {
11700                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11701                                            }
11702                                            else {
11703                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11704                                            }
11705                                    }
11706                                    else {
11707                                            if (orderByComparator.isAscending() ^ previous) {
11708                                                    query.append(WHERE_GREATER_THAN);
11709                                            }
11710                                            else {
11711                                                    query.append(WHERE_LESSER_THAN);
11712                                            }
11713                                    }
11714                            }
11715    
11716                            query.append(ORDER_BY_CLAUSE);
11717    
11718                            String[] orderByFields = orderByComparator.getOrderByFields();
11719    
11720                            for (int i = 0; i < orderByFields.length; i++) {
11721                                    if (getDB().isSupportsInlineDistinct()) {
11722                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11723                                    }
11724                                    else {
11725                                            query.append(_ORDER_BY_ENTITY_TABLE);
11726                                    }
11727    
11728                                    query.append(orderByFields[i]);
11729    
11730                                    if ((i + 1) < orderByFields.length) {
11731                                            if (orderByComparator.isAscending() ^ previous) {
11732                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11733                                            }
11734                                            else {
11735                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11736                                            }
11737                                    }
11738                                    else {
11739                                            if (orderByComparator.isAscending() ^ previous) {
11740                                                    query.append(ORDER_BY_ASC);
11741                                            }
11742                                            else {
11743                                                    query.append(ORDER_BY_DESC);
11744                                            }
11745                                    }
11746                            }
11747                    }
11748                    else {
11749                            if (getDB().isSupportsInlineDistinct()) {
11750                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11751                            }
11752                            else {
11753                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11754                            }
11755                    }
11756    
11757                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11758                                    MBMessage.class.getName(),
11759                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11760    
11761                    SQLQuery q = session.createSQLQuery(sql);
11762    
11763                    q.setFirstResult(0);
11764                    q.setMaxResults(2);
11765    
11766                    if (getDB().isSupportsInlineDistinct()) {
11767                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11768                    }
11769                    else {
11770                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11771                    }
11772    
11773                    QueryPos qPos = QueryPos.getInstance(q);
11774    
11775                    qPos.add(groupId);
11776    
11777                    qPos.add(userId);
11778    
11779                    qPos.add(status);
11780    
11781                    if (orderByComparator != null) {
11782                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11783    
11784                            for (Object value : values) {
11785                                    qPos.add(value);
11786                            }
11787                    }
11788    
11789                    List<MBMessage> list = q.list();
11790    
11791                    if (list.size() == 2) {
11792                            return list.get(1);
11793                    }
11794                    else {
11795                            return null;
11796                    }
11797            }
11798    
11799            /**
11800             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
11801             *
11802             * @param groupId the group ID
11803             * @param userId the user ID
11804             * @param status the status
11805             * @throws SystemException if a system exception occurred
11806             */
11807            @Override
11808            public void removeByG_U_S(long groupId, long userId, int status)
11809                    throws SystemException {
11810                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11811                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11812                            remove(mbMessage);
11813                    }
11814            }
11815    
11816            /**
11817             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11818             *
11819             * @param groupId the group ID
11820             * @param userId the user ID
11821             * @param status the status
11822             * @return the number of matching message-boards messages
11823             * @throws SystemException if a system exception occurred
11824             */
11825            @Override
11826            public int countByG_U_S(long groupId, long userId, int status)
11827                    throws SystemException {
11828                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11829    
11830                    Object[] finderArgs = new Object[] { groupId, userId, status };
11831    
11832                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11833                                    this);
11834    
11835                    if (count == null) {
11836                            StringBundler query = new StringBundler(4);
11837    
11838                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11839    
11840                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11841    
11842                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11843    
11844                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11845    
11846                            String sql = query.toString();
11847    
11848                            Session session = null;
11849    
11850                            try {
11851                                    session = openSession();
11852    
11853                                    Query q = session.createQuery(sql);
11854    
11855                                    QueryPos qPos = QueryPos.getInstance(q);
11856    
11857                                    qPos.add(groupId);
11858    
11859                                    qPos.add(userId);
11860    
11861                                    qPos.add(status);
11862    
11863                                    count = (Long)q.uniqueResult();
11864    
11865                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11866                            }
11867                            catch (Exception e) {
11868                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11869    
11870                                    throw processException(e);
11871                            }
11872                            finally {
11873                                    closeSession(session);
11874                            }
11875                    }
11876    
11877                    return count.intValue();
11878            }
11879    
11880            /**
11881             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11882             *
11883             * @param groupId the group ID
11884             * @param userId the user ID
11885             * @param status the status
11886             * @return the number of matching message-boards messages that the user has permission to view
11887             * @throws SystemException if a system exception occurred
11888             */
11889            @Override
11890            public int filterCountByG_U_S(long groupId, long userId, int status)
11891                    throws SystemException {
11892                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11893                            return countByG_U_S(groupId, userId, status);
11894                    }
11895    
11896                    StringBundler query = new StringBundler(4);
11897    
11898                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11899    
11900                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11901    
11902                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11903    
11904                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11905    
11906                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11907                                    MBMessage.class.getName(),
11908                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11909    
11910                    Session session = null;
11911    
11912                    try {
11913                            session = openSession();
11914    
11915                            SQLQuery q = session.createSQLQuery(sql);
11916    
11917                            q.addScalar(COUNT_COLUMN_NAME,
11918                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11919    
11920                            QueryPos qPos = QueryPos.getInstance(q);
11921    
11922                            qPos.add(groupId);
11923    
11924                            qPos.add(userId);
11925    
11926                            qPos.add(status);
11927    
11928                            Long count = (Long)q.uniqueResult();
11929    
11930                            return count.intValue();
11931                    }
11932                    catch (Exception e) {
11933                            throw processException(e);
11934                    }
11935                    finally {
11936                            closeSession(session);
11937                    }
11938            }
11939    
11940            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11941            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11942            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11943            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11944                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11945                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11946                            new String[] {
11947                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
11948                                    
11949                            Integer.class.getName(), Integer.class.getName(),
11950                                    OrderByComparator.class.getName()
11951                            });
11952            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11953                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11954                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11955                            new String[] {
11956                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11957                            },
11958                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11959                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11960                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11961                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11962            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11963                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11964                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11965                            new String[] {
11966                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11967                            });
11968    
11969            /**
11970             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11971             *
11972             * @param groupId the group ID
11973             * @param categoryId the category ID
11974             * @param threadId the thread ID
11975             * @return the matching message-boards messages
11976             * @throws SystemException if a system exception occurred
11977             */
11978            @Override
11979            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11980                    long threadId) throws SystemException {
11981                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11982                            QueryUtil.ALL_POS, null);
11983            }
11984    
11985            /**
11986             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11987             *
11988             * <p>
11989             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
11990             * </p>
11991             *
11992             * @param groupId the group ID
11993             * @param categoryId the category ID
11994             * @param threadId the thread ID
11995             * @param start the lower bound of the range of message-boards messages
11996             * @param end the upper bound of the range of message-boards messages (not inclusive)
11997             * @return the range of matching message-boards messages
11998             * @throws SystemException if a system exception occurred
11999             */
12000            @Override
12001            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12002                    long threadId, int start, int end) throws SystemException {
12003                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
12004            }
12005    
12006            /**
12007             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12008             *
12009             * <p>
12010             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
12011             * </p>
12012             *
12013             * @param groupId the group ID
12014             * @param categoryId the category ID
12015             * @param threadId the thread ID
12016             * @param start the lower bound of the range of message-boards messages
12017             * @param end the upper bound of the range of message-boards messages (not inclusive)
12018             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12019             * @return the ordered range of matching message-boards messages
12020             * @throws SystemException if a system exception occurred
12021             */
12022            @Override
12023            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12024                    long threadId, int start, int end, OrderByComparator orderByComparator)
12025                    throws SystemException {
12026                    boolean pagination = true;
12027                    FinderPath finderPath = null;
12028                    Object[] finderArgs = null;
12029    
12030                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12031                                    (orderByComparator == null)) {
12032                            pagination = false;
12033                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12034                            finderArgs = new Object[] { groupId, categoryId, threadId };
12035                    }
12036                    else {
12037                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12038                            finderArgs = new Object[] {
12039                                            groupId, categoryId, threadId,
12040                                            
12041                                            start, end, orderByComparator
12042                                    };
12043                    }
12044    
12045                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12046                                    finderArgs, this);
12047    
12048                    if ((list != null) && !list.isEmpty()) {
12049                            for (MBMessage mbMessage : list) {
12050                                    if ((groupId != mbMessage.getGroupId()) ||
12051                                                    (categoryId != mbMessage.getCategoryId()) ||
12052                                                    (threadId != mbMessage.getThreadId())) {
12053                                            list = null;
12054    
12055                                            break;
12056                                    }
12057                            }
12058                    }
12059    
12060                    if (list == null) {
12061                            StringBundler query = null;
12062    
12063                            if (orderByComparator != null) {
12064                                    query = new StringBundler(5 +
12065                                                    (orderByComparator.getOrderByFields().length * 3));
12066                            }
12067                            else {
12068                                    query = new StringBundler(5);
12069                            }
12070    
12071                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12072    
12073                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12074    
12075                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12076    
12077                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12078    
12079                            if (orderByComparator != null) {
12080                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12081                                            orderByComparator);
12082                            }
12083                            else
12084                             if (pagination) {
12085                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12086                            }
12087    
12088                            String sql = query.toString();
12089    
12090                            Session session = null;
12091    
12092                            try {
12093                                    session = openSession();
12094    
12095                                    Query q = session.createQuery(sql);
12096    
12097                                    QueryPos qPos = QueryPos.getInstance(q);
12098    
12099                                    qPos.add(groupId);
12100    
12101                                    qPos.add(categoryId);
12102    
12103                                    qPos.add(threadId);
12104    
12105                                    if (!pagination) {
12106                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12107                                                            start, end, false);
12108    
12109                                            Collections.sort(list);
12110    
12111                                            list = new UnmodifiableList<MBMessage>(list);
12112                                    }
12113                                    else {
12114                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12115                                                            start, end);
12116                                    }
12117    
12118                                    cacheResult(list);
12119    
12120                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12121                            }
12122                            catch (Exception e) {
12123                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12124    
12125                                    throw processException(e);
12126                            }
12127                            finally {
12128                                    closeSession(session);
12129                            }
12130                    }
12131    
12132                    return list;
12133            }
12134    
12135            /**
12136             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12137             *
12138             * @param groupId the group ID
12139             * @param categoryId the category ID
12140             * @param threadId the thread ID
12141             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12142             * @return the first matching message-boards message
12143             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12144             * @throws SystemException if a system exception occurred
12145             */
12146            @Override
12147            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12148                    long threadId, OrderByComparator orderByComparator)
12149                    throws NoSuchMessageException, SystemException {
12150                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12151                                    orderByComparator);
12152    
12153                    if (mbMessage != null) {
12154                            return mbMessage;
12155                    }
12156    
12157                    StringBundler msg = new StringBundler(8);
12158    
12159                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12160    
12161                    msg.append("groupId=");
12162                    msg.append(groupId);
12163    
12164                    msg.append(", categoryId=");
12165                    msg.append(categoryId);
12166    
12167                    msg.append(", threadId=");
12168                    msg.append(threadId);
12169    
12170                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12171    
12172                    throw new NoSuchMessageException(msg.toString());
12173            }
12174    
12175            /**
12176             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12177             *
12178             * @param groupId the group ID
12179             * @param categoryId the category ID
12180             * @param threadId the thread ID
12181             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12182             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12183             * @throws SystemException if a system exception occurred
12184             */
12185            @Override
12186            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12187                    long threadId, OrderByComparator orderByComparator)
12188                    throws SystemException {
12189                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12190                                    orderByComparator);
12191    
12192                    if (!list.isEmpty()) {
12193                            return list.get(0);
12194                    }
12195    
12196                    return null;
12197            }
12198    
12199            /**
12200             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12201             *
12202             * @param groupId the group ID
12203             * @param categoryId the category ID
12204             * @param threadId the thread ID
12205             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12206             * @return the last matching message-boards message
12207             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12208             * @throws SystemException if a system exception occurred
12209             */
12210            @Override
12211            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12212                    long threadId, OrderByComparator orderByComparator)
12213                    throws NoSuchMessageException, SystemException {
12214                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12215                                    orderByComparator);
12216    
12217                    if (mbMessage != null) {
12218                            return mbMessage;
12219                    }
12220    
12221                    StringBundler msg = new StringBundler(8);
12222    
12223                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12224    
12225                    msg.append("groupId=");
12226                    msg.append(groupId);
12227    
12228                    msg.append(", categoryId=");
12229                    msg.append(categoryId);
12230    
12231                    msg.append(", threadId=");
12232                    msg.append(threadId);
12233    
12234                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12235    
12236                    throw new NoSuchMessageException(msg.toString());
12237            }
12238    
12239            /**
12240             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12241             *
12242             * @param groupId the group ID
12243             * @param categoryId the category ID
12244             * @param threadId the thread ID
12245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12246             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12247             * @throws SystemException if a system exception occurred
12248             */
12249            @Override
12250            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12251                    long threadId, OrderByComparator orderByComparator)
12252                    throws SystemException {
12253                    int count = countByG_C_T(groupId, categoryId, threadId);
12254    
12255                    if (count == 0) {
12256                            return null;
12257                    }
12258    
12259                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12260                                    count - 1, count, orderByComparator);
12261    
12262                    if (!list.isEmpty()) {
12263                            return list.get(0);
12264                    }
12265    
12266                    return null;
12267            }
12268    
12269            /**
12270             * 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;.
12271             *
12272             * @param messageId the primary key of the current message-boards message
12273             * @param groupId the group ID
12274             * @param categoryId the category ID
12275             * @param threadId the thread ID
12276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12277             * @return the previous, current, and next message-boards message
12278             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12279             * @throws SystemException if a system exception occurred
12280             */
12281            @Override
12282            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12283                    long categoryId, long threadId, OrderByComparator orderByComparator)
12284                    throws NoSuchMessageException, SystemException {
12285                    MBMessage mbMessage = findByPrimaryKey(messageId);
12286    
12287                    Session session = null;
12288    
12289                    try {
12290                            session = openSession();
12291    
12292                            MBMessage[] array = new MBMessageImpl[3];
12293    
12294                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12295                                            categoryId, threadId, orderByComparator, true);
12296    
12297                            array[1] = mbMessage;
12298    
12299                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12300                                            categoryId, threadId, orderByComparator, false);
12301    
12302                            return array;
12303                    }
12304                    catch (Exception e) {
12305                            throw processException(e);
12306                    }
12307                    finally {
12308                            closeSession(session);
12309                    }
12310            }
12311    
12312            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12313                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12314                    OrderByComparator orderByComparator, boolean previous) {
12315                    StringBundler query = null;
12316    
12317                    if (orderByComparator != null) {
12318                            query = new StringBundler(6 +
12319                                            (orderByComparator.getOrderByFields().length * 6));
12320                    }
12321                    else {
12322                            query = new StringBundler(3);
12323                    }
12324    
12325                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12326    
12327                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12328    
12329                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12330    
12331                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12332    
12333                    if (orderByComparator != null) {
12334                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12335    
12336                            if (orderByConditionFields.length > 0) {
12337                                    query.append(WHERE_AND);
12338                            }
12339    
12340                            for (int i = 0; i < orderByConditionFields.length; i++) {
12341                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12342                                    query.append(orderByConditionFields[i]);
12343    
12344                                    if ((i + 1) < orderByConditionFields.length) {
12345                                            if (orderByComparator.isAscending() ^ previous) {
12346                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12347                                            }
12348                                            else {
12349                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12350                                            }
12351                                    }
12352                                    else {
12353                                            if (orderByComparator.isAscending() ^ previous) {
12354                                                    query.append(WHERE_GREATER_THAN);
12355                                            }
12356                                            else {
12357                                                    query.append(WHERE_LESSER_THAN);
12358                                            }
12359                                    }
12360                            }
12361    
12362                            query.append(ORDER_BY_CLAUSE);
12363    
12364                            String[] orderByFields = orderByComparator.getOrderByFields();
12365    
12366                            for (int i = 0; i < orderByFields.length; i++) {
12367                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12368                                    query.append(orderByFields[i]);
12369    
12370                                    if ((i + 1) < orderByFields.length) {
12371                                            if (orderByComparator.isAscending() ^ previous) {
12372                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12373                                            }
12374                                            else {
12375                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12376                                            }
12377                                    }
12378                                    else {
12379                                            if (orderByComparator.isAscending() ^ previous) {
12380                                                    query.append(ORDER_BY_ASC);
12381                                            }
12382                                            else {
12383                                                    query.append(ORDER_BY_DESC);
12384                                            }
12385                                    }
12386                            }
12387                    }
12388                    else {
12389                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12390                    }
12391    
12392                    String sql = query.toString();
12393    
12394                    Query q = session.createQuery(sql);
12395    
12396                    q.setFirstResult(0);
12397                    q.setMaxResults(2);
12398    
12399                    QueryPos qPos = QueryPos.getInstance(q);
12400    
12401                    qPos.add(groupId);
12402    
12403                    qPos.add(categoryId);
12404    
12405                    qPos.add(threadId);
12406    
12407                    if (orderByComparator != null) {
12408                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12409    
12410                            for (Object value : values) {
12411                                    qPos.add(value);
12412                            }
12413                    }
12414    
12415                    List<MBMessage> list = q.list();
12416    
12417                    if (list.size() == 2) {
12418                            return list.get(1);
12419                    }
12420                    else {
12421                            return null;
12422                    }
12423            }
12424    
12425            /**
12426             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12427             *
12428             * @param groupId the group ID
12429             * @param categoryId the category ID
12430             * @param threadId the thread ID
12431             * @return the matching message-boards messages that the user has permission to view
12432             * @throws SystemException if a system exception occurred
12433             */
12434            @Override
12435            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12436                    long threadId) throws SystemException {
12437                    return filterFindByG_C_T(groupId, categoryId, threadId,
12438                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12439            }
12440    
12441            /**
12442             * 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;.
12443             *
12444             * <p>
12445             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
12446             * </p>
12447             *
12448             * @param groupId the group ID
12449             * @param categoryId the category ID
12450             * @param threadId the thread ID
12451             * @param start the lower bound of the range of message-boards messages
12452             * @param end the upper bound of the range of message-boards messages (not inclusive)
12453             * @return the range of matching message-boards messages that the user has permission to view
12454             * @throws SystemException if a system exception occurred
12455             */
12456            @Override
12457            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12458                    long threadId, int start, int end) throws SystemException {
12459                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12460            }
12461    
12462            /**
12463             * 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;.
12464             *
12465             * <p>
12466             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
12467             * </p>
12468             *
12469             * @param groupId the group ID
12470             * @param categoryId the category ID
12471             * @param threadId the thread ID
12472             * @param start the lower bound of the range of message-boards messages
12473             * @param end the upper bound of the range of message-boards messages (not inclusive)
12474             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12475             * @return the ordered range of matching message-boards messages that the user has permission to view
12476             * @throws SystemException if a system exception occurred
12477             */
12478            @Override
12479            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12480                    long threadId, int start, int end, OrderByComparator orderByComparator)
12481                    throws SystemException {
12482                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12483                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12484                                    orderByComparator);
12485                    }
12486    
12487                    StringBundler query = null;
12488    
12489                    if (orderByComparator != null) {
12490                            query = new StringBundler(5 +
12491                                            (orderByComparator.getOrderByFields().length * 3));
12492                    }
12493                    else {
12494                            query = new StringBundler(5);
12495                    }
12496    
12497                    if (getDB().isSupportsInlineDistinct()) {
12498                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12499                    }
12500                    else {
12501                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12502                    }
12503    
12504                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12505    
12506                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12507    
12508                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12509    
12510                    if (!getDB().isSupportsInlineDistinct()) {
12511                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12512                    }
12513    
12514                    if (orderByComparator != null) {
12515                            if (getDB().isSupportsInlineDistinct()) {
12516                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12517                                            orderByComparator, true);
12518                            }
12519                            else {
12520                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12521                                            orderByComparator, true);
12522                            }
12523                    }
12524                    else {
12525                            if (getDB().isSupportsInlineDistinct()) {
12526                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12527                            }
12528                            else {
12529                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12530                            }
12531                    }
12532    
12533                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12534                                    MBMessage.class.getName(),
12535                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12536    
12537                    Session session = null;
12538    
12539                    try {
12540                            session = openSession();
12541    
12542                            SQLQuery q = session.createSQLQuery(sql);
12543    
12544                            if (getDB().isSupportsInlineDistinct()) {
12545                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12546                            }
12547                            else {
12548                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12549                            }
12550    
12551                            QueryPos qPos = QueryPos.getInstance(q);
12552    
12553                            qPos.add(groupId);
12554    
12555                            qPos.add(categoryId);
12556    
12557                            qPos.add(threadId);
12558    
12559                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12560                    }
12561                    catch (Exception e) {
12562                            throw processException(e);
12563                    }
12564                    finally {
12565                            closeSession(session);
12566                    }
12567            }
12568    
12569            /**
12570             * 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;.
12571             *
12572             * @param messageId the primary key of the current message-boards message
12573             * @param groupId the group ID
12574             * @param categoryId the category ID
12575             * @param threadId the thread ID
12576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12577             * @return the previous, current, and next message-boards message
12578             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12579             * @throws SystemException if a system exception occurred
12580             */
12581            @Override
12582            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12583                    long groupId, long categoryId, long threadId,
12584                    OrderByComparator orderByComparator)
12585                    throws NoSuchMessageException, SystemException {
12586                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12587                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12588                                    threadId, orderByComparator);
12589                    }
12590    
12591                    MBMessage mbMessage = findByPrimaryKey(messageId);
12592    
12593                    Session session = null;
12594    
12595                    try {
12596                            session = openSession();
12597    
12598                            MBMessage[] array = new MBMessageImpl[3];
12599    
12600                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12601                                            groupId, categoryId, threadId, orderByComparator, true);
12602    
12603                            array[1] = mbMessage;
12604    
12605                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12606                                            groupId, categoryId, threadId, orderByComparator, false);
12607    
12608                            return array;
12609                    }
12610                    catch (Exception e) {
12611                            throw processException(e);
12612                    }
12613                    finally {
12614                            closeSession(session);
12615                    }
12616            }
12617    
12618            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12619                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12620                    OrderByComparator orderByComparator, boolean previous) {
12621                    StringBundler query = null;
12622    
12623                    if (orderByComparator != null) {
12624                            query = new StringBundler(6 +
12625                                            (orderByComparator.getOrderByFields().length * 6));
12626                    }
12627                    else {
12628                            query = new StringBundler(3);
12629                    }
12630    
12631                    if (getDB().isSupportsInlineDistinct()) {
12632                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12633                    }
12634                    else {
12635                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12636                    }
12637    
12638                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12639    
12640                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12641    
12642                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12643    
12644                    if (!getDB().isSupportsInlineDistinct()) {
12645                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12646                    }
12647    
12648                    if (orderByComparator != null) {
12649                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12650    
12651                            if (orderByConditionFields.length > 0) {
12652                                    query.append(WHERE_AND);
12653                            }
12654    
12655                            for (int i = 0; i < orderByConditionFields.length; i++) {
12656                                    if (getDB().isSupportsInlineDistinct()) {
12657                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12658                                    }
12659                                    else {
12660                                            query.append(_ORDER_BY_ENTITY_TABLE);
12661                                    }
12662    
12663                                    query.append(orderByConditionFields[i]);
12664    
12665                                    if ((i + 1) < orderByConditionFields.length) {
12666                                            if (orderByComparator.isAscending() ^ previous) {
12667                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12668                                            }
12669                                            else {
12670                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12671                                            }
12672                                    }
12673                                    else {
12674                                            if (orderByComparator.isAscending() ^ previous) {
12675                                                    query.append(WHERE_GREATER_THAN);
12676                                            }
12677                                            else {
12678                                                    query.append(WHERE_LESSER_THAN);
12679                                            }
12680                                    }
12681                            }
12682    
12683                            query.append(ORDER_BY_CLAUSE);
12684    
12685                            String[] orderByFields = orderByComparator.getOrderByFields();
12686    
12687                            for (int i = 0; i < orderByFields.length; i++) {
12688                                    if (getDB().isSupportsInlineDistinct()) {
12689                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12690                                    }
12691                                    else {
12692                                            query.append(_ORDER_BY_ENTITY_TABLE);
12693                                    }
12694    
12695                                    query.append(orderByFields[i]);
12696    
12697                                    if ((i + 1) < orderByFields.length) {
12698                                            if (orderByComparator.isAscending() ^ previous) {
12699                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12700                                            }
12701                                            else {
12702                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12703                                            }
12704                                    }
12705                                    else {
12706                                            if (orderByComparator.isAscending() ^ previous) {
12707                                                    query.append(ORDER_BY_ASC);
12708                                            }
12709                                            else {
12710                                                    query.append(ORDER_BY_DESC);
12711                                            }
12712                                    }
12713                            }
12714                    }
12715                    else {
12716                            if (getDB().isSupportsInlineDistinct()) {
12717                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12718                            }
12719                            else {
12720                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12721                            }
12722                    }
12723    
12724                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12725                                    MBMessage.class.getName(),
12726                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12727    
12728                    SQLQuery q = session.createSQLQuery(sql);
12729    
12730                    q.setFirstResult(0);
12731                    q.setMaxResults(2);
12732    
12733                    if (getDB().isSupportsInlineDistinct()) {
12734                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12735                    }
12736                    else {
12737                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12738                    }
12739    
12740                    QueryPos qPos = QueryPos.getInstance(q);
12741    
12742                    qPos.add(groupId);
12743    
12744                    qPos.add(categoryId);
12745    
12746                    qPos.add(threadId);
12747    
12748                    if (orderByComparator != null) {
12749                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12750    
12751                            for (Object value : values) {
12752                                    qPos.add(value);
12753                            }
12754                    }
12755    
12756                    List<MBMessage> list = q.list();
12757    
12758                    if (list.size() == 2) {
12759                            return list.get(1);
12760                    }
12761                    else {
12762                            return null;
12763                    }
12764            }
12765    
12766            /**
12767             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12768             *
12769             * @param groupId the group ID
12770             * @param categoryId the category ID
12771             * @param threadId the thread ID
12772             * @throws SystemException if a system exception occurred
12773             */
12774            @Override
12775            public void removeByG_C_T(long groupId, long categoryId, long threadId)
12776                    throws SystemException {
12777                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12778                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12779                            remove(mbMessage);
12780                    }
12781            }
12782    
12783            /**
12784             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12785             *
12786             * @param groupId the group ID
12787             * @param categoryId the category ID
12788             * @param threadId the thread ID
12789             * @return the number of matching message-boards messages
12790             * @throws SystemException if a system exception occurred
12791             */
12792            @Override
12793            public int countByG_C_T(long groupId, long categoryId, long threadId)
12794                    throws SystemException {
12795                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12796    
12797                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12798    
12799                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12800                                    this);
12801    
12802                    if (count == null) {
12803                            StringBundler query = new StringBundler(4);
12804    
12805                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12806    
12807                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12808    
12809                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12810    
12811                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12812    
12813                            String sql = query.toString();
12814    
12815                            Session session = null;
12816    
12817                            try {
12818                                    session = openSession();
12819    
12820                                    Query q = session.createQuery(sql);
12821    
12822                                    QueryPos qPos = QueryPos.getInstance(q);
12823    
12824                                    qPos.add(groupId);
12825    
12826                                    qPos.add(categoryId);
12827    
12828                                    qPos.add(threadId);
12829    
12830                                    count = (Long)q.uniqueResult();
12831    
12832                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12833                            }
12834                            catch (Exception e) {
12835                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12836    
12837                                    throw processException(e);
12838                            }
12839                            finally {
12840                                    closeSession(session);
12841                            }
12842                    }
12843    
12844                    return count.intValue();
12845            }
12846    
12847            /**
12848             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12849             *
12850             * @param groupId the group ID
12851             * @param categoryId the category ID
12852             * @param threadId the thread ID
12853             * @return the number of matching message-boards messages that the user has permission to view
12854             * @throws SystemException if a system exception occurred
12855             */
12856            @Override
12857            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
12858                    throws SystemException {
12859                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12860                            return countByG_C_T(groupId, categoryId, threadId);
12861                    }
12862    
12863                    StringBundler query = new StringBundler(4);
12864    
12865                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12866    
12867                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12868    
12869                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12870    
12871                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12872    
12873                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12874                                    MBMessage.class.getName(),
12875                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12876    
12877                    Session session = null;
12878    
12879                    try {
12880                            session = openSession();
12881    
12882                            SQLQuery q = session.createSQLQuery(sql);
12883    
12884                            q.addScalar(COUNT_COLUMN_NAME,
12885                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12886    
12887                            QueryPos qPos = QueryPos.getInstance(q);
12888    
12889                            qPos.add(groupId);
12890    
12891                            qPos.add(categoryId);
12892    
12893                            qPos.add(threadId);
12894    
12895                            Long count = (Long)q.uniqueResult();
12896    
12897                            return count.intValue();
12898                    }
12899                    catch (Exception e) {
12900                            throw processException(e);
12901                    }
12902                    finally {
12903                            closeSession(session);
12904                    }
12905            }
12906    
12907            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12908            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12909            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12910            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12911                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12912                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12913                            new String[] {
12914                                    Long.class.getName(), Long.class.getName(),
12915                                    Integer.class.getName(),
12916                                    
12917                            Integer.class.getName(), Integer.class.getName(),
12918                                    OrderByComparator.class.getName()
12919                            });
12920            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12921                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12922                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12923                            new String[] {
12924                                    Long.class.getName(), Long.class.getName(),
12925                                    Integer.class.getName()
12926                            },
12927                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12928                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12929                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12930                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12931            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12932                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12933                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12934                            new String[] {
12935                                    Long.class.getName(), Long.class.getName(),
12936                                    Integer.class.getName()
12937                            });
12938    
12939            /**
12940             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12941             *
12942             * @param groupId the group ID
12943             * @param categoryId the category ID
12944             * @param status the status
12945             * @return the matching message-boards messages
12946             * @throws SystemException if a system exception occurred
12947             */
12948            @Override
12949            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
12950                    throws SystemException {
12951                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12952                            QueryUtil.ALL_POS, null);
12953            }
12954    
12955            /**
12956             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12957             *
12958             * <p>
12959             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
12960             * </p>
12961             *
12962             * @param groupId the group ID
12963             * @param categoryId the category ID
12964             * @param status the status
12965             * @param start the lower bound of the range of message-boards messages
12966             * @param end the upper bound of the range of message-boards messages (not inclusive)
12967             * @return the range of matching message-boards messages
12968             * @throws SystemException if a system exception occurred
12969             */
12970            @Override
12971            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12972                    int status, int start, int end) throws SystemException {
12973                    return findByG_C_S(groupId, categoryId, status, start, end, null);
12974            }
12975    
12976            /**
12977             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12978             *
12979             * <p>
12980             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
12981             * </p>
12982             *
12983             * @param groupId the group ID
12984             * @param categoryId the category ID
12985             * @param status the status
12986             * @param start the lower bound of the range of message-boards messages
12987             * @param end the upper bound of the range of message-boards messages (not inclusive)
12988             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12989             * @return the ordered range of matching message-boards messages
12990             * @throws SystemException if a system exception occurred
12991             */
12992            @Override
12993            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12994                    int status, int start, int end, OrderByComparator orderByComparator)
12995                    throws SystemException {
12996                    boolean pagination = true;
12997                    FinderPath finderPath = null;
12998                    Object[] finderArgs = null;
12999    
13000                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13001                                    (orderByComparator == null)) {
13002                            pagination = false;
13003                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13004                            finderArgs = new Object[] { groupId, categoryId, status };
13005                    }
13006                    else {
13007                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13008                            finderArgs = new Object[] {
13009                                            groupId, categoryId, status,
13010                                            
13011                                            start, end, orderByComparator
13012                                    };
13013                    }
13014    
13015                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13016                                    finderArgs, this);
13017    
13018                    if ((list != null) && !list.isEmpty()) {
13019                            for (MBMessage mbMessage : list) {
13020                                    if ((groupId != mbMessage.getGroupId()) ||
13021                                                    (categoryId != mbMessage.getCategoryId()) ||
13022                                                    (status != mbMessage.getStatus())) {
13023                                            list = null;
13024    
13025                                            break;
13026                                    }
13027                            }
13028                    }
13029    
13030                    if (list == null) {
13031                            StringBundler query = null;
13032    
13033                            if (orderByComparator != null) {
13034                                    query = new StringBundler(5 +
13035                                                    (orderByComparator.getOrderByFields().length * 3));
13036                            }
13037                            else {
13038                                    query = new StringBundler(5);
13039                            }
13040    
13041                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13042    
13043                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13044    
13045                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13046    
13047                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13048    
13049                            if (orderByComparator != null) {
13050                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13051                                            orderByComparator);
13052                            }
13053                            else
13054                             if (pagination) {
13055                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13056                            }
13057    
13058                            String sql = query.toString();
13059    
13060                            Session session = null;
13061    
13062                            try {
13063                                    session = openSession();
13064    
13065                                    Query q = session.createQuery(sql);
13066    
13067                                    QueryPos qPos = QueryPos.getInstance(q);
13068    
13069                                    qPos.add(groupId);
13070    
13071                                    qPos.add(categoryId);
13072    
13073                                    qPos.add(status);
13074    
13075                                    if (!pagination) {
13076                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13077                                                            start, end, false);
13078    
13079                                            Collections.sort(list);
13080    
13081                                            list = new UnmodifiableList<MBMessage>(list);
13082                                    }
13083                                    else {
13084                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13085                                                            start, end);
13086                                    }
13087    
13088                                    cacheResult(list);
13089    
13090                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13091                            }
13092                            catch (Exception e) {
13093                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13094    
13095                                    throw processException(e);
13096                            }
13097                            finally {
13098                                    closeSession(session);
13099                            }
13100                    }
13101    
13102                    return list;
13103            }
13104    
13105            /**
13106             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13107             *
13108             * @param groupId the group ID
13109             * @param categoryId the category ID
13110             * @param status the status
13111             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13112             * @return the first matching message-boards message
13113             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13114             * @throws SystemException if a system exception occurred
13115             */
13116            @Override
13117            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13118                    int status, OrderByComparator orderByComparator)
13119                    throws NoSuchMessageException, SystemException {
13120                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13121                                    orderByComparator);
13122    
13123                    if (mbMessage != null) {
13124                            return mbMessage;
13125                    }
13126    
13127                    StringBundler msg = new StringBundler(8);
13128    
13129                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13130    
13131                    msg.append("groupId=");
13132                    msg.append(groupId);
13133    
13134                    msg.append(", categoryId=");
13135                    msg.append(categoryId);
13136    
13137                    msg.append(", status=");
13138                    msg.append(status);
13139    
13140                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13141    
13142                    throw new NoSuchMessageException(msg.toString());
13143            }
13144    
13145            /**
13146             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13147             *
13148             * @param groupId the group ID
13149             * @param categoryId the category ID
13150             * @param status the status
13151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13152             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13153             * @throws SystemException if a system exception occurred
13154             */
13155            @Override
13156            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13157                    int status, OrderByComparator orderByComparator)
13158                    throws SystemException {
13159                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13160                                    orderByComparator);
13161    
13162                    if (!list.isEmpty()) {
13163                            return list.get(0);
13164                    }
13165    
13166                    return null;
13167            }
13168    
13169            /**
13170             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13171             *
13172             * @param groupId the group ID
13173             * @param categoryId the category ID
13174             * @param status the status
13175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13176             * @return the last matching message-boards message
13177             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13178             * @throws SystemException if a system exception occurred
13179             */
13180            @Override
13181            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13182                    int status, OrderByComparator orderByComparator)
13183                    throws NoSuchMessageException, SystemException {
13184                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13185                                    orderByComparator);
13186    
13187                    if (mbMessage != null) {
13188                            return mbMessage;
13189                    }
13190    
13191                    StringBundler msg = new StringBundler(8);
13192    
13193                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13194    
13195                    msg.append("groupId=");
13196                    msg.append(groupId);
13197    
13198                    msg.append(", categoryId=");
13199                    msg.append(categoryId);
13200    
13201                    msg.append(", status=");
13202                    msg.append(status);
13203    
13204                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13205    
13206                    throw new NoSuchMessageException(msg.toString());
13207            }
13208    
13209            /**
13210             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13211             *
13212             * @param groupId the group ID
13213             * @param categoryId the category ID
13214             * @param status the status
13215             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13216             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13217             * @throws SystemException if a system exception occurred
13218             */
13219            @Override
13220            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13221                    int status, OrderByComparator orderByComparator)
13222                    throws SystemException {
13223                    int count = countByG_C_S(groupId, categoryId, status);
13224    
13225                    if (count == 0) {
13226                            return null;
13227                    }
13228    
13229                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13230                                    count - 1, count, orderByComparator);
13231    
13232                    if (!list.isEmpty()) {
13233                            return list.get(0);
13234                    }
13235    
13236                    return null;
13237            }
13238    
13239            /**
13240             * 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;.
13241             *
13242             * @param messageId the primary key of the current message-boards message
13243             * @param groupId the group ID
13244             * @param categoryId the category ID
13245             * @param status the status
13246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13247             * @return the previous, current, and next message-boards message
13248             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13249             * @throws SystemException if a system exception occurred
13250             */
13251            @Override
13252            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13253                    long categoryId, int status, OrderByComparator orderByComparator)
13254                    throws NoSuchMessageException, SystemException {
13255                    MBMessage mbMessage = findByPrimaryKey(messageId);
13256    
13257                    Session session = null;
13258    
13259                    try {
13260                            session = openSession();
13261    
13262                            MBMessage[] array = new MBMessageImpl[3];
13263    
13264                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13265                                            categoryId, status, orderByComparator, true);
13266    
13267                            array[1] = mbMessage;
13268    
13269                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13270                                            categoryId, status, orderByComparator, false);
13271    
13272                            return array;
13273                    }
13274                    catch (Exception e) {
13275                            throw processException(e);
13276                    }
13277                    finally {
13278                            closeSession(session);
13279                    }
13280            }
13281    
13282            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13283                    MBMessage mbMessage, long groupId, long categoryId, int status,
13284                    OrderByComparator orderByComparator, boolean previous) {
13285                    StringBundler query = null;
13286    
13287                    if (orderByComparator != null) {
13288                            query = new StringBundler(6 +
13289                                            (orderByComparator.getOrderByFields().length * 6));
13290                    }
13291                    else {
13292                            query = new StringBundler(3);
13293                    }
13294    
13295                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13296    
13297                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13298    
13299                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13300    
13301                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13302    
13303                    if (orderByComparator != null) {
13304                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13305    
13306                            if (orderByConditionFields.length > 0) {
13307                                    query.append(WHERE_AND);
13308                            }
13309    
13310                            for (int i = 0; i < orderByConditionFields.length; i++) {
13311                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13312                                    query.append(orderByConditionFields[i]);
13313    
13314                                    if ((i + 1) < orderByConditionFields.length) {
13315                                            if (orderByComparator.isAscending() ^ previous) {
13316                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13317                                            }
13318                                            else {
13319                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13320                                            }
13321                                    }
13322                                    else {
13323                                            if (orderByComparator.isAscending() ^ previous) {
13324                                                    query.append(WHERE_GREATER_THAN);
13325                                            }
13326                                            else {
13327                                                    query.append(WHERE_LESSER_THAN);
13328                                            }
13329                                    }
13330                            }
13331    
13332                            query.append(ORDER_BY_CLAUSE);
13333    
13334                            String[] orderByFields = orderByComparator.getOrderByFields();
13335    
13336                            for (int i = 0; i < orderByFields.length; i++) {
13337                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13338                                    query.append(orderByFields[i]);
13339    
13340                                    if ((i + 1) < orderByFields.length) {
13341                                            if (orderByComparator.isAscending() ^ previous) {
13342                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13343                                            }
13344                                            else {
13345                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13346                                            }
13347                                    }
13348                                    else {
13349                                            if (orderByComparator.isAscending() ^ previous) {
13350                                                    query.append(ORDER_BY_ASC);
13351                                            }
13352                                            else {
13353                                                    query.append(ORDER_BY_DESC);
13354                                            }
13355                                    }
13356                            }
13357                    }
13358                    else {
13359                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13360                    }
13361    
13362                    String sql = query.toString();
13363    
13364                    Query q = session.createQuery(sql);
13365    
13366                    q.setFirstResult(0);
13367                    q.setMaxResults(2);
13368    
13369                    QueryPos qPos = QueryPos.getInstance(q);
13370    
13371                    qPos.add(groupId);
13372    
13373                    qPos.add(categoryId);
13374    
13375                    qPos.add(status);
13376    
13377                    if (orderByComparator != null) {
13378                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13379    
13380                            for (Object value : values) {
13381                                    qPos.add(value);
13382                            }
13383                    }
13384    
13385                    List<MBMessage> list = q.list();
13386    
13387                    if (list.size() == 2) {
13388                            return list.get(1);
13389                    }
13390                    else {
13391                            return null;
13392                    }
13393            }
13394    
13395            /**
13396             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13397             *
13398             * @param groupId the group ID
13399             * @param categoryId the category ID
13400             * @param status the status
13401             * @return the matching message-boards messages that the user has permission to view
13402             * @throws SystemException if a system exception occurred
13403             */
13404            @Override
13405            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13406                    int status) throws SystemException {
13407                    return filterFindByG_C_S(groupId, categoryId, status,
13408                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13409            }
13410    
13411            /**
13412             * 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;.
13413             *
13414             * <p>
13415             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
13416             * </p>
13417             *
13418             * @param groupId the group ID
13419             * @param categoryId the category ID
13420             * @param status the status
13421             * @param start the lower bound of the range of message-boards messages
13422             * @param end the upper bound of the range of message-boards messages (not inclusive)
13423             * @return the range of matching message-boards messages that the user has permission to view
13424             * @throws SystemException if a system exception occurred
13425             */
13426            @Override
13427            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13428                    int status, int start, int end) throws SystemException {
13429                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13430            }
13431    
13432            /**
13433             * 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;.
13434             *
13435             * <p>
13436             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
13437             * </p>
13438             *
13439             * @param groupId the group ID
13440             * @param categoryId the category ID
13441             * @param status the status
13442             * @param start the lower bound of the range of message-boards messages
13443             * @param end the upper bound of the range of message-boards messages (not inclusive)
13444             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13445             * @return the ordered range of matching message-boards messages that the user has permission to view
13446             * @throws SystemException if a system exception occurred
13447             */
13448            @Override
13449            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13450                    int status, int start, int end, OrderByComparator orderByComparator)
13451                    throws SystemException {
13452                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13453                            return findByG_C_S(groupId, categoryId, status, start, end,
13454                                    orderByComparator);
13455                    }
13456    
13457                    StringBundler query = null;
13458    
13459                    if (orderByComparator != null) {
13460                            query = new StringBundler(5 +
13461                                            (orderByComparator.getOrderByFields().length * 3));
13462                    }
13463                    else {
13464                            query = new StringBundler(5);
13465                    }
13466    
13467                    if (getDB().isSupportsInlineDistinct()) {
13468                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13469                    }
13470                    else {
13471                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13472                    }
13473    
13474                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13475    
13476                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13477    
13478                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13479    
13480                    if (!getDB().isSupportsInlineDistinct()) {
13481                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13482                    }
13483    
13484                    if (orderByComparator != null) {
13485                            if (getDB().isSupportsInlineDistinct()) {
13486                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13487                                            orderByComparator, true);
13488                            }
13489                            else {
13490                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13491                                            orderByComparator, true);
13492                            }
13493                    }
13494                    else {
13495                            if (getDB().isSupportsInlineDistinct()) {
13496                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13497                            }
13498                            else {
13499                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13500                            }
13501                    }
13502    
13503                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13504                                    MBMessage.class.getName(),
13505                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13506    
13507                    Session session = null;
13508    
13509                    try {
13510                            session = openSession();
13511    
13512                            SQLQuery q = session.createSQLQuery(sql);
13513    
13514                            if (getDB().isSupportsInlineDistinct()) {
13515                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13516                            }
13517                            else {
13518                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13519                            }
13520    
13521                            QueryPos qPos = QueryPos.getInstance(q);
13522    
13523                            qPos.add(groupId);
13524    
13525                            qPos.add(categoryId);
13526    
13527                            qPos.add(status);
13528    
13529                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13530                    }
13531                    catch (Exception e) {
13532                            throw processException(e);
13533                    }
13534                    finally {
13535                            closeSession(session);
13536                    }
13537            }
13538    
13539            /**
13540             * 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;.
13541             *
13542             * @param messageId the primary key of the current message-boards message
13543             * @param groupId the group ID
13544             * @param categoryId the category ID
13545             * @param status the status
13546             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13547             * @return the previous, current, and next message-boards message
13548             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13549             * @throws SystemException if a system exception occurred
13550             */
13551            @Override
13552            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13553                    long groupId, long categoryId, int status,
13554                    OrderByComparator orderByComparator)
13555                    throws NoSuchMessageException, SystemException {
13556                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13557                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13558                                    status, orderByComparator);
13559                    }
13560    
13561                    MBMessage mbMessage = findByPrimaryKey(messageId);
13562    
13563                    Session session = null;
13564    
13565                    try {
13566                            session = openSession();
13567    
13568                            MBMessage[] array = new MBMessageImpl[3];
13569    
13570                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13571                                            groupId, categoryId, status, orderByComparator, true);
13572    
13573                            array[1] = mbMessage;
13574    
13575                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13576                                            groupId, categoryId, status, orderByComparator, false);
13577    
13578                            return array;
13579                    }
13580                    catch (Exception e) {
13581                            throw processException(e);
13582                    }
13583                    finally {
13584                            closeSession(session);
13585                    }
13586            }
13587    
13588            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13589                    MBMessage mbMessage, long groupId, long categoryId, int status,
13590                    OrderByComparator orderByComparator, boolean previous) {
13591                    StringBundler query = null;
13592    
13593                    if (orderByComparator != null) {
13594                            query = new StringBundler(6 +
13595                                            (orderByComparator.getOrderByFields().length * 6));
13596                    }
13597                    else {
13598                            query = new StringBundler(3);
13599                    }
13600    
13601                    if (getDB().isSupportsInlineDistinct()) {
13602                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13603                    }
13604                    else {
13605                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13606                    }
13607    
13608                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13609    
13610                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13611    
13612                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13613    
13614                    if (!getDB().isSupportsInlineDistinct()) {
13615                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13616                    }
13617    
13618                    if (orderByComparator != null) {
13619                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13620    
13621                            if (orderByConditionFields.length > 0) {
13622                                    query.append(WHERE_AND);
13623                            }
13624    
13625                            for (int i = 0; i < orderByConditionFields.length; i++) {
13626                                    if (getDB().isSupportsInlineDistinct()) {
13627                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13628                                    }
13629                                    else {
13630                                            query.append(_ORDER_BY_ENTITY_TABLE);
13631                                    }
13632    
13633                                    query.append(orderByConditionFields[i]);
13634    
13635                                    if ((i + 1) < orderByConditionFields.length) {
13636                                            if (orderByComparator.isAscending() ^ previous) {
13637                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13638                                            }
13639                                            else {
13640                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13641                                            }
13642                                    }
13643                                    else {
13644                                            if (orderByComparator.isAscending() ^ previous) {
13645                                                    query.append(WHERE_GREATER_THAN);
13646                                            }
13647                                            else {
13648                                                    query.append(WHERE_LESSER_THAN);
13649                                            }
13650                                    }
13651                            }
13652    
13653                            query.append(ORDER_BY_CLAUSE);
13654    
13655                            String[] orderByFields = orderByComparator.getOrderByFields();
13656    
13657                            for (int i = 0; i < orderByFields.length; i++) {
13658                                    if (getDB().isSupportsInlineDistinct()) {
13659                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13660                                    }
13661                                    else {
13662                                            query.append(_ORDER_BY_ENTITY_TABLE);
13663                                    }
13664    
13665                                    query.append(orderByFields[i]);
13666    
13667                                    if ((i + 1) < orderByFields.length) {
13668                                            if (orderByComparator.isAscending() ^ previous) {
13669                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13670                                            }
13671                                            else {
13672                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13673                                            }
13674                                    }
13675                                    else {
13676                                            if (orderByComparator.isAscending() ^ previous) {
13677                                                    query.append(ORDER_BY_ASC);
13678                                            }
13679                                            else {
13680                                                    query.append(ORDER_BY_DESC);
13681                                            }
13682                                    }
13683                            }
13684                    }
13685                    else {
13686                            if (getDB().isSupportsInlineDistinct()) {
13687                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13688                            }
13689                            else {
13690                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13691                            }
13692                    }
13693    
13694                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13695                                    MBMessage.class.getName(),
13696                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13697    
13698                    SQLQuery q = session.createSQLQuery(sql);
13699    
13700                    q.setFirstResult(0);
13701                    q.setMaxResults(2);
13702    
13703                    if (getDB().isSupportsInlineDistinct()) {
13704                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13705                    }
13706                    else {
13707                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13708                    }
13709    
13710                    QueryPos qPos = QueryPos.getInstance(q);
13711    
13712                    qPos.add(groupId);
13713    
13714                    qPos.add(categoryId);
13715    
13716                    qPos.add(status);
13717    
13718                    if (orderByComparator != null) {
13719                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13720    
13721                            for (Object value : values) {
13722                                    qPos.add(value);
13723                            }
13724                    }
13725    
13726                    List<MBMessage> list = q.list();
13727    
13728                    if (list.size() == 2) {
13729                            return list.get(1);
13730                    }
13731                    else {
13732                            return null;
13733                    }
13734            }
13735    
13736            /**
13737             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13738             *
13739             * @param groupId the group ID
13740             * @param categoryId the category ID
13741             * @param status the status
13742             * @throws SystemException if a system exception occurred
13743             */
13744            @Override
13745            public void removeByG_C_S(long groupId, long categoryId, int status)
13746                    throws SystemException {
13747                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13748                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13749                            remove(mbMessage);
13750                    }
13751            }
13752    
13753            /**
13754             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13755             *
13756             * @param groupId the group ID
13757             * @param categoryId the category ID
13758             * @param status the status
13759             * @return the number of matching message-boards messages
13760             * @throws SystemException if a system exception occurred
13761             */
13762            @Override
13763            public int countByG_C_S(long groupId, long categoryId, int status)
13764                    throws SystemException {
13765                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13766    
13767                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13768    
13769                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13770                                    this);
13771    
13772                    if (count == null) {
13773                            StringBundler query = new StringBundler(4);
13774    
13775                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13776    
13777                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13778    
13779                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13780    
13781                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13782    
13783                            String sql = query.toString();
13784    
13785                            Session session = null;
13786    
13787                            try {
13788                                    session = openSession();
13789    
13790                                    Query q = session.createQuery(sql);
13791    
13792                                    QueryPos qPos = QueryPos.getInstance(q);
13793    
13794                                    qPos.add(groupId);
13795    
13796                                    qPos.add(categoryId);
13797    
13798                                    qPos.add(status);
13799    
13800                                    count = (Long)q.uniqueResult();
13801    
13802                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13803                            }
13804                            catch (Exception e) {
13805                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13806    
13807                                    throw processException(e);
13808                            }
13809                            finally {
13810                                    closeSession(session);
13811                            }
13812                    }
13813    
13814                    return count.intValue();
13815            }
13816    
13817            /**
13818             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13819             *
13820             * @param groupId the group ID
13821             * @param categoryId the category ID
13822             * @param status the status
13823             * @return the number of matching message-boards messages that the user has permission to view
13824             * @throws SystemException if a system exception occurred
13825             */
13826            @Override
13827            public int filterCountByG_C_S(long groupId, long categoryId, int status)
13828                    throws SystemException {
13829                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13830                            return countByG_C_S(groupId, categoryId, status);
13831                    }
13832    
13833                    StringBundler query = new StringBundler(4);
13834    
13835                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13836    
13837                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13838    
13839                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13840    
13841                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13842    
13843                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13844                                    MBMessage.class.getName(),
13845                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13846    
13847                    Session session = null;
13848    
13849                    try {
13850                            session = openSession();
13851    
13852                            SQLQuery q = session.createSQLQuery(sql);
13853    
13854                            q.addScalar(COUNT_COLUMN_NAME,
13855                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13856    
13857                            QueryPos qPos = QueryPos.getInstance(q);
13858    
13859                            qPos.add(groupId);
13860    
13861                            qPos.add(categoryId);
13862    
13863                            qPos.add(status);
13864    
13865                            Long count = (Long)q.uniqueResult();
13866    
13867                            return count.intValue();
13868                    }
13869                    catch (Exception e) {
13870                            throw processException(e);
13871                    }
13872                    finally {
13873                            closeSession(session);
13874                    }
13875            }
13876    
13877            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13878            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13879            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13880            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13881                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13882                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13883                            new String[] {
13884                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13885                                    
13886                            Integer.class.getName(), Integer.class.getName(),
13887                                    OrderByComparator.class.getName()
13888                            });
13889            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13890                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13891                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13892                            new String[] {
13893                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13894                            },
13895                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
13896                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13897                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13898                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13899            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13900                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13901                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13902                            new String[] {
13903                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13904                            });
13905    
13906            /**
13907             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13908             *
13909             * @param userId the user ID
13910             * @param classNameId the class name ID
13911             * @param classPK the class p k
13912             * @return the matching message-boards messages
13913             * @throws SystemException if a system exception occurred
13914             */
13915            @Override
13916            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13917                    long classPK) throws SystemException {
13918                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13919                            QueryUtil.ALL_POS, null);
13920            }
13921    
13922            /**
13923             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13924             *
13925             * <p>
13926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
13927             * </p>
13928             *
13929             * @param userId the user ID
13930             * @param classNameId the class name ID
13931             * @param classPK the class p k
13932             * @param start the lower bound of the range of message-boards messages
13933             * @param end the upper bound of the range of message-boards messages (not inclusive)
13934             * @return the range of matching message-boards messages
13935             * @throws SystemException if a system exception occurred
13936             */
13937            @Override
13938            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13939                    long classPK, int start, int end) throws SystemException {
13940                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
13941            }
13942    
13943            /**
13944             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13945             *
13946             * <p>
13947             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
13948             * </p>
13949             *
13950             * @param userId the user ID
13951             * @param classNameId the class name ID
13952             * @param classPK the class p k
13953             * @param start the lower bound of the range of message-boards messages
13954             * @param end the upper bound of the range of message-boards messages (not inclusive)
13955             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13956             * @return the ordered range of matching message-boards messages
13957             * @throws SystemException if a system exception occurred
13958             */
13959            @Override
13960            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13961                    long classPK, int start, int end, OrderByComparator orderByComparator)
13962                    throws SystemException {
13963                    boolean pagination = true;
13964                    FinderPath finderPath = null;
13965                    Object[] finderArgs = null;
13966    
13967                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13968                                    (orderByComparator == null)) {
13969                            pagination = false;
13970                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13971                            finderArgs = new Object[] { userId, classNameId, classPK };
13972                    }
13973                    else {
13974                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13975                            finderArgs = new Object[] {
13976                                            userId, classNameId, classPK,
13977                                            
13978                                            start, end, orderByComparator
13979                                    };
13980                    }
13981    
13982                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13983                                    finderArgs, this);
13984    
13985                    if ((list != null) && !list.isEmpty()) {
13986                            for (MBMessage mbMessage : list) {
13987                                    if ((userId != mbMessage.getUserId()) ||
13988                                                    (classNameId != mbMessage.getClassNameId()) ||
13989                                                    (classPK != mbMessage.getClassPK())) {
13990                                            list = null;
13991    
13992                                            break;
13993                                    }
13994                            }
13995                    }
13996    
13997                    if (list == null) {
13998                            StringBundler query = null;
13999    
14000                            if (orderByComparator != null) {
14001                                    query = new StringBundler(5 +
14002                                                    (orderByComparator.getOrderByFields().length * 3));
14003                            }
14004                            else {
14005                                    query = new StringBundler(5);
14006                            }
14007    
14008                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14009    
14010                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14011    
14012                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14013    
14014                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14015    
14016                            if (orderByComparator != null) {
14017                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14018                                            orderByComparator);
14019                            }
14020                            else
14021                             if (pagination) {
14022                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14023                            }
14024    
14025                            String sql = query.toString();
14026    
14027                            Session session = null;
14028    
14029                            try {
14030                                    session = openSession();
14031    
14032                                    Query q = session.createQuery(sql);
14033    
14034                                    QueryPos qPos = QueryPos.getInstance(q);
14035    
14036                                    qPos.add(userId);
14037    
14038                                    qPos.add(classNameId);
14039    
14040                                    qPos.add(classPK);
14041    
14042                                    if (!pagination) {
14043                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14044                                                            start, end, false);
14045    
14046                                            Collections.sort(list);
14047    
14048                                            list = new UnmodifiableList<MBMessage>(list);
14049                                    }
14050                                    else {
14051                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14052                                                            start, end);
14053                                    }
14054    
14055                                    cacheResult(list);
14056    
14057                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14058                            }
14059                            catch (Exception e) {
14060                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14061    
14062                                    throw processException(e);
14063                            }
14064                            finally {
14065                                    closeSession(session);
14066                            }
14067                    }
14068    
14069                    return list;
14070            }
14071    
14072            /**
14073             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14074             *
14075             * @param userId the user ID
14076             * @param classNameId the class name ID
14077             * @param classPK the class p k
14078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14079             * @return the first matching message-boards message
14080             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14081             * @throws SystemException if a system exception occurred
14082             */
14083            @Override
14084            public MBMessage findByU_C_C_First(long userId, long classNameId,
14085                    long classPK, OrderByComparator orderByComparator)
14086                    throws NoSuchMessageException, SystemException {
14087                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14088                                    orderByComparator);
14089    
14090                    if (mbMessage != null) {
14091                            return mbMessage;
14092                    }
14093    
14094                    StringBundler msg = new StringBundler(8);
14095    
14096                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14097    
14098                    msg.append("userId=");
14099                    msg.append(userId);
14100    
14101                    msg.append(", classNameId=");
14102                    msg.append(classNameId);
14103    
14104                    msg.append(", classPK=");
14105                    msg.append(classPK);
14106    
14107                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14108    
14109                    throw new NoSuchMessageException(msg.toString());
14110            }
14111    
14112            /**
14113             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14114             *
14115             * @param userId the user ID
14116             * @param classNameId the class name ID
14117             * @param classPK the class p k
14118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14119             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14120             * @throws SystemException if a system exception occurred
14121             */
14122            @Override
14123            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14124                    long classPK, OrderByComparator orderByComparator)
14125                    throws SystemException {
14126                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14127                                    orderByComparator);
14128    
14129                    if (!list.isEmpty()) {
14130                            return list.get(0);
14131                    }
14132    
14133                    return null;
14134            }
14135    
14136            /**
14137             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14138             *
14139             * @param userId the user ID
14140             * @param classNameId the class name ID
14141             * @param classPK the class p k
14142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14143             * @return the last matching message-boards message
14144             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14145             * @throws SystemException if a system exception occurred
14146             */
14147            @Override
14148            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14149                    long classPK, OrderByComparator orderByComparator)
14150                    throws NoSuchMessageException, SystemException {
14151                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14152                                    orderByComparator);
14153    
14154                    if (mbMessage != null) {
14155                            return mbMessage;
14156                    }
14157    
14158                    StringBundler msg = new StringBundler(8);
14159    
14160                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14161    
14162                    msg.append("userId=");
14163                    msg.append(userId);
14164    
14165                    msg.append(", classNameId=");
14166                    msg.append(classNameId);
14167    
14168                    msg.append(", classPK=");
14169                    msg.append(classPK);
14170    
14171                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14172    
14173                    throw new NoSuchMessageException(msg.toString());
14174            }
14175    
14176            /**
14177             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14178             *
14179             * @param userId the user ID
14180             * @param classNameId the class name ID
14181             * @param classPK the class p k
14182             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14183             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14184             * @throws SystemException if a system exception occurred
14185             */
14186            @Override
14187            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14188                    long classPK, OrderByComparator orderByComparator)
14189                    throws SystemException {
14190                    int count = countByU_C_C(userId, classNameId, classPK);
14191    
14192                    if (count == 0) {
14193                            return null;
14194                    }
14195    
14196                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14197                                    count - 1, count, orderByComparator);
14198    
14199                    if (!list.isEmpty()) {
14200                            return list.get(0);
14201                    }
14202    
14203                    return null;
14204            }
14205    
14206            /**
14207             * 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;.
14208             *
14209             * @param messageId the primary key of the current message-boards message
14210             * @param userId the user ID
14211             * @param classNameId the class name ID
14212             * @param classPK the class p k
14213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14214             * @return the previous, current, and next message-boards message
14215             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14216             * @throws SystemException if a system exception occurred
14217             */
14218            @Override
14219            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14220                    long classNameId, long classPK, OrderByComparator orderByComparator)
14221                    throws NoSuchMessageException, SystemException {
14222                    MBMessage mbMessage = findByPrimaryKey(messageId);
14223    
14224                    Session session = null;
14225    
14226                    try {
14227                            session = openSession();
14228    
14229                            MBMessage[] array = new MBMessageImpl[3];
14230    
14231                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14232                                            classNameId, classPK, orderByComparator, true);
14233    
14234                            array[1] = mbMessage;
14235    
14236                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14237                                            classNameId, classPK, orderByComparator, false);
14238    
14239                            return array;
14240                    }
14241                    catch (Exception e) {
14242                            throw processException(e);
14243                    }
14244                    finally {
14245                            closeSession(session);
14246                    }
14247            }
14248    
14249            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14250                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14251                    OrderByComparator orderByComparator, boolean previous) {
14252                    StringBundler query = null;
14253    
14254                    if (orderByComparator != null) {
14255                            query = new StringBundler(6 +
14256                                            (orderByComparator.getOrderByFields().length * 6));
14257                    }
14258                    else {
14259                            query = new StringBundler(3);
14260                    }
14261    
14262                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14263    
14264                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14265    
14266                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14267    
14268                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14269    
14270                    if (orderByComparator != null) {
14271                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14272    
14273                            if (orderByConditionFields.length > 0) {
14274                                    query.append(WHERE_AND);
14275                            }
14276    
14277                            for (int i = 0; i < orderByConditionFields.length; i++) {
14278                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14279                                    query.append(orderByConditionFields[i]);
14280    
14281                                    if ((i + 1) < orderByConditionFields.length) {
14282                                            if (orderByComparator.isAscending() ^ previous) {
14283                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14284                                            }
14285                                            else {
14286                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14287                                            }
14288                                    }
14289                                    else {
14290                                            if (orderByComparator.isAscending() ^ previous) {
14291                                                    query.append(WHERE_GREATER_THAN);
14292                                            }
14293                                            else {
14294                                                    query.append(WHERE_LESSER_THAN);
14295                                            }
14296                                    }
14297                            }
14298    
14299                            query.append(ORDER_BY_CLAUSE);
14300    
14301                            String[] orderByFields = orderByComparator.getOrderByFields();
14302    
14303                            for (int i = 0; i < orderByFields.length; i++) {
14304                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14305                                    query.append(orderByFields[i]);
14306    
14307                                    if ((i + 1) < orderByFields.length) {
14308                                            if (orderByComparator.isAscending() ^ previous) {
14309                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14310                                            }
14311                                            else {
14312                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14313                                            }
14314                                    }
14315                                    else {
14316                                            if (orderByComparator.isAscending() ^ previous) {
14317                                                    query.append(ORDER_BY_ASC);
14318                                            }
14319                                            else {
14320                                                    query.append(ORDER_BY_DESC);
14321                                            }
14322                                    }
14323                            }
14324                    }
14325                    else {
14326                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14327                    }
14328    
14329                    String sql = query.toString();
14330    
14331                    Query q = session.createQuery(sql);
14332    
14333                    q.setFirstResult(0);
14334                    q.setMaxResults(2);
14335    
14336                    QueryPos qPos = QueryPos.getInstance(q);
14337    
14338                    qPos.add(userId);
14339    
14340                    qPos.add(classNameId);
14341    
14342                    qPos.add(classPK);
14343    
14344                    if (orderByComparator != null) {
14345                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14346    
14347                            for (Object value : values) {
14348                                    qPos.add(value);
14349                            }
14350                    }
14351    
14352                    List<MBMessage> list = q.list();
14353    
14354                    if (list.size() == 2) {
14355                            return list.get(1);
14356                    }
14357                    else {
14358                            return null;
14359                    }
14360            }
14361    
14362            /**
14363             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14364             *
14365             * @param userId the user ID
14366             * @param classNameId the class name ID
14367             * @param classPK the class p k
14368             * @throws SystemException if a system exception occurred
14369             */
14370            @Override
14371            public void removeByU_C_C(long userId, long classNameId, long classPK)
14372                    throws SystemException {
14373                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14374                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14375                            remove(mbMessage);
14376                    }
14377            }
14378    
14379            /**
14380             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14381             *
14382             * @param userId the user ID
14383             * @param classNameId the class name ID
14384             * @param classPK the class p k
14385             * @return the number of matching message-boards messages
14386             * @throws SystemException if a system exception occurred
14387             */
14388            @Override
14389            public int countByU_C_C(long userId, long classNameId, long classPK)
14390                    throws SystemException {
14391                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14392    
14393                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14394    
14395                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14396                                    this);
14397    
14398                    if (count == null) {
14399                            StringBundler query = new StringBundler(4);
14400    
14401                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14402    
14403                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14404    
14405                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14406    
14407                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14408    
14409                            String sql = query.toString();
14410    
14411                            Session session = null;
14412    
14413                            try {
14414                                    session = openSession();
14415    
14416                                    Query q = session.createQuery(sql);
14417    
14418                                    QueryPos qPos = QueryPos.getInstance(q);
14419    
14420                                    qPos.add(userId);
14421    
14422                                    qPos.add(classNameId);
14423    
14424                                    qPos.add(classPK);
14425    
14426                                    count = (Long)q.uniqueResult();
14427    
14428                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14429                            }
14430                            catch (Exception e) {
14431                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14432    
14433                                    throw processException(e);
14434                            }
14435                            finally {
14436                                    closeSession(session);
14437                            }
14438                    }
14439    
14440                    return count.intValue();
14441            }
14442    
14443            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14444            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14445            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14446            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14447                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14448                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14449                            new String[] {
14450                                    Long.class.getName(), Long.class.getName(),
14451                                    Integer.class.getName(),
14452                                    
14453                            Integer.class.getName(), Integer.class.getName(),
14454                                    OrderByComparator.class.getName()
14455                            });
14456            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14457                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14458                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14459                            new String[] {
14460                                    Long.class.getName(), Long.class.getName(),
14461                                    Integer.class.getName()
14462                            },
14463                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14464                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14465                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14466                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14467            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14468                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14469                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14470                            new String[] {
14471                                    Long.class.getName(), Long.class.getName(),
14472                                    Integer.class.getName()
14473                            });
14474            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14475                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14476                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14477                            new String[] {
14478                                    Long.class.getName(), Long.class.getName(),
14479                                    Integer.class.getName()
14480                            });
14481    
14482            /**
14483             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14484             *
14485             * @param userId the user ID
14486             * @param classNameId the class name ID
14487             * @param status the status
14488             * @return the matching message-boards messages
14489             * @throws SystemException if a system exception occurred
14490             */
14491            @Override
14492            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
14493                    throws SystemException {
14494                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14495                            QueryUtil.ALL_POS, null);
14496            }
14497    
14498            /**
14499             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14500             *
14501             * <p>
14502             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14503             * </p>
14504             *
14505             * @param userId the user ID
14506             * @param classNameId the class name ID
14507             * @param status the status
14508             * @param start the lower bound of the range of message-boards messages
14509             * @param end the upper bound of the range of message-boards messages (not inclusive)
14510             * @return the range of matching message-boards messages
14511             * @throws SystemException if a system exception occurred
14512             */
14513            @Override
14514            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14515                    int status, int start, int end) throws SystemException {
14516                    return findByU_C_S(userId, classNameId, status, start, end, null);
14517            }
14518    
14519            /**
14520             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14521             *
14522             * <p>
14523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14524             * </p>
14525             *
14526             * @param userId the user ID
14527             * @param classNameId the class name ID
14528             * @param status the status
14529             * @param start the lower bound of the range of message-boards messages
14530             * @param end the upper bound of the range of message-boards messages (not inclusive)
14531             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14532             * @return the ordered range of matching message-boards messages
14533             * @throws SystemException if a system exception occurred
14534             */
14535            @Override
14536            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14537                    int status, int start, int end, OrderByComparator orderByComparator)
14538                    throws SystemException {
14539                    boolean pagination = true;
14540                    FinderPath finderPath = null;
14541                    Object[] finderArgs = null;
14542    
14543                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14544                                    (orderByComparator == null)) {
14545                            pagination = false;
14546                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14547                            finderArgs = new Object[] { userId, classNameId, status };
14548                    }
14549                    else {
14550                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14551                            finderArgs = new Object[] {
14552                                            userId, classNameId, status,
14553                                            
14554                                            start, end, orderByComparator
14555                                    };
14556                    }
14557    
14558                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14559                                    finderArgs, this);
14560    
14561                    if ((list != null) && !list.isEmpty()) {
14562                            for (MBMessage mbMessage : list) {
14563                                    if ((userId != mbMessage.getUserId()) ||
14564                                                    (classNameId != mbMessage.getClassNameId()) ||
14565                                                    (status != mbMessage.getStatus())) {
14566                                            list = null;
14567    
14568                                            break;
14569                                    }
14570                            }
14571                    }
14572    
14573                    if (list == null) {
14574                            StringBundler query = null;
14575    
14576                            if (orderByComparator != null) {
14577                                    query = new StringBundler(5 +
14578                                                    (orderByComparator.getOrderByFields().length * 3));
14579                            }
14580                            else {
14581                                    query = new StringBundler(5);
14582                            }
14583    
14584                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14585    
14586                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14587    
14588                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14589    
14590                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14591    
14592                            if (orderByComparator != null) {
14593                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14594                                            orderByComparator);
14595                            }
14596                            else
14597                             if (pagination) {
14598                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14599                            }
14600    
14601                            String sql = query.toString();
14602    
14603                            Session session = null;
14604    
14605                            try {
14606                                    session = openSession();
14607    
14608                                    Query q = session.createQuery(sql);
14609    
14610                                    QueryPos qPos = QueryPos.getInstance(q);
14611    
14612                                    qPos.add(userId);
14613    
14614                                    qPos.add(classNameId);
14615    
14616                                    qPos.add(status);
14617    
14618                                    if (!pagination) {
14619                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14620                                                            start, end, false);
14621    
14622                                            Collections.sort(list);
14623    
14624                                            list = new UnmodifiableList<MBMessage>(list);
14625                                    }
14626                                    else {
14627                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14628                                                            start, end);
14629                                    }
14630    
14631                                    cacheResult(list);
14632    
14633                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14634                            }
14635                            catch (Exception e) {
14636                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14637    
14638                                    throw processException(e);
14639                            }
14640                            finally {
14641                                    closeSession(session);
14642                            }
14643                    }
14644    
14645                    return list;
14646            }
14647    
14648            /**
14649             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14650             *
14651             * @param userId the user ID
14652             * @param classNameId the class name ID
14653             * @param status the status
14654             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14655             * @return the first matching message-boards message
14656             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14657             * @throws SystemException if a system exception occurred
14658             */
14659            @Override
14660            public MBMessage findByU_C_S_First(long userId, long classNameId,
14661                    int status, OrderByComparator orderByComparator)
14662                    throws NoSuchMessageException, SystemException {
14663                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14664                                    orderByComparator);
14665    
14666                    if (mbMessage != null) {
14667                            return mbMessage;
14668                    }
14669    
14670                    StringBundler msg = new StringBundler(8);
14671    
14672                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14673    
14674                    msg.append("userId=");
14675                    msg.append(userId);
14676    
14677                    msg.append(", classNameId=");
14678                    msg.append(classNameId);
14679    
14680                    msg.append(", status=");
14681                    msg.append(status);
14682    
14683                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14684    
14685                    throw new NoSuchMessageException(msg.toString());
14686            }
14687    
14688            /**
14689             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14690             *
14691             * @param userId the user ID
14692             * @param classNameId the class name ID
14693             * @param status the status
14694             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14695             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14696             * @throws SystemException if a system exception occurred
14697             */
14698            @Override
14699            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14700                    int status, OrderByComparator orderByComparator)
14701                    throws SystemException {
14702                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14703                                    orderByComparator);
14704    
14705                    if (!list.isEmpty()) {
14706                            return list.get(0);
14707                    }
14708    
14709                    return null;
14710            }
14711    
14712            /**
14713             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14714             *
14715             * @param userId the user ID
14716             * @param classNameId the class name ID
14717             * @param status the status
14718             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14719             * @return the last matching message-boards message
14720             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14721             * @throws SystemException if a system exception occurred
14722             */
14723            @Override
14724            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14725                    int status, OrderByComparator orderByComparator)
14726                    throws NoSuchMessageException, SystemException {
14727                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14728                                    orderByComparator);
14729    
14730                    if (mbMessage != null) {
14731                            return mbMessage;
14732                    }
14733    
14734                    StringBundler msg = new StringBundler(8);
14735    
14736                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14737    
14738                    msg.append("userId=");
14739                    msg.append(userId);
14740    
14741                    msg.append(", classNameId=");
14742                    msg.append(classNameId);
14743    
14744                    msg.append(", status=");
14745                    msg.append(status);
14746    
14747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14748    
14749                    throw new NoSuchMessageException(msg.toString());
14750            }
14751    
14752            /**
14753             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14754             *
14755             * @param userId the user ID
14756             * @param classNameId the class name ID
14757             * @param status the status
14758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14759             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14760             * @throws SystemException if a system exception occurred
14761             */
14762            @Override
14763            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14764                    int status, OrderByComparator orderByComparator)
14765                    throws SystemException {
14766                    int count = countByU_C_S(userId, classNameId, status);
14767    
14768                    if (count == 0) {
14769                            return null;
14770                    }
14771    
14772                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14773                                    count - 1, count, orderByComparator);
14774    
14775                    if (!list.isEmpty()) {
14776                            return list.get(0);
14777                    }
14778    
14779                    return null;
14780            }
14781    
14782            /**
14783             * 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;.
14784             *
14785             * @param messageId the primary key of the current message-boards message
14786             * @param userId the user ID
14787             * @param classNameId the class name ID
14788             * @param status the status
14789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14790             * @return the previous, current, and next message-boards message
14791             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14792             * @throws SystemException if a system exception occurred
14793             */
14794            @Override
14795            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14796                    long classNameId, int status, OrderByComparator orderByComparator)
14797                    throws NoSuchMessageException, SystemException {
14798                    MBMessage mbMessage = findByPrimaryKey(messageId);
14799    
14800                    Session session = null;
14801    
14802                    try {
14803                            session = openSession();
14804    
14805                            MBMessage[] array = new MBMessageImpl[3];
14806    
14807                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14808                                            classNameId, status, orderByComparator, true);
14809    
14810                            array[1] = mbMessage;
14811    
14812                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14813                                            classNameId, status, orderByComparator, false);
14814    
14815                            return array;
14816                    }
14817                    catch (Exception e) {
14818                            throw processException(e);
14819                    }
14820                    finally {
14821                            closeSession(session);
14822                    }
14823            }
14824    
14825            protected MBMessage getByU_C_S_PrevAndNext(Session session,
14826                    MBMessage mbMessage, long userId, long classNameId, int status,
14827                    OrderByComparator orderByComparator, boolean previous) {
14828                    StringBundler query = null;
14829    
14830                    if (orderByComparator != null) {
14831                            query = new StringBundler(6 +
14832                                            (orderByComparator.getOrderByFields().length * 6));
14833                    }
14834                    else {
14835                            query = new StringBundler(3);
14836                    }
14837    
14838                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14839    
14840                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14841    
14842                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14843    
14844                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14845    
14846                    if (orderByComparator != null) {
14847                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14848    
14849                            if (orderByConditionFields.length > 0) {
14850                                    query.append(WHERE_AND);
14851                            }
14852    
14853                            for (int i = 0; i < orderByConditionFields.length; i++) {
14854                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14855                                    query.append(orderByConditionFields[i]);
14856    
14857                                    if ((i + 1) < orderByConditionFields.length) {
14858                                            if (orderByComparator.isAscending() ^ previous) {
14859                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14860                                            }
14861                                            else {
14862                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14863                                            }
14864                                    }
14865                                    else {
14866                                            if (orderByComparator.isAscending() ^ previous) {
14867                                                    query.append(WHERE_GREATER_THAN);
14868                                            }
14869                                            else {
14870                                                    query.append(WHERE_LESSER_THAN);
14871                                            }
14872                                    }
14873                            }
14874    
14875                            query.append(ORDER_BY_CLAUSE);
14876    
14877                            String[] orderByFields = orderByComparator.getOrderByFields();
14878    
14879                            for (int i = 0; i < orderByFields.length; i++) {
14880                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14881                                    query.append(orderByFields[i]);
14882    
14883                                    if ((i + 1) < orderByFields.length) {
14884                                            if (orderByComparator.isAscending() ^ previous) {
14885                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14886                                            }
14887                                            else {
14888                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14889                                            }
14890                                    }
14891                                    else {
14892                                            if (orderByComparator.isAscending() ^ previous) {
14893                                                    query.append(ORDER_BY_ASC);
14894                                            }
14895                                            else {
14896                                                    query.append(ORDER_BY_DESC);
14897                                            }
14898                                    }
14899                            }
14900                    }
14901                    else {
14902                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14903                    }
14904    
14905                    String sql = query.toString();
14906    
14907                    Query q = session.createQuery(sql);
14908    
14909                    q.setFirstResult(0);
14910                    q.setMaxResults(2);
14911    
14912                    QueryPos qPos = QueryPos.getInstance(q);
14913    
14914                    qPos.add(userId);
14915    
14916                    qPos.add(classNameId);
14917    
14918                    qPos.add(status);
14919    
14920                    if (orderByComparator != null) {
14921                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14922    
14923                            for (Object value : values) {
14924                                    qPos.add(value);
14925                            }
14926                    }
14927    
14928                    List<MBMessage> list = q.list();
14929    
14930                    if (list.size() == 2) {
14931                            return list.get(1);
14932                    }
14933                    else {
14934                            return null;
14935                    }
14936            }
14937    
14938            /**
14939             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14940             *
14941             * <p>
14942             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14943             * </p>
14944             *
14945             * @param userId the user ID
14946             * @param classNameIds the class name IDs
14947             * @param status the status
14948             * @return the matching message-boards messages
14949             * @throws SystemException if a system exception occurred
14950             */
14951            @Override
14952            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14953                    int status) throws SystemException {
14954                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14955                            QueryUtil.ALL_POS, null);
14956            }
14957    
14958            /**
14959             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14960             *
14961             * <p>
14962             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14963             * </p>
14964             *
14965             * @param userId the user ID
14966             * @param classNameIds the class name IDs
14967             * @param status the status
14968             * @param start the lower bound of the range of message-boards messages
14969             * @param end the upper bound of the range of message-boards messages (not inclusive)
14970             * @return the range of matching message-boards messages
14971             * @throws SystemException if a system exception occurred
14972             */
14973            @Override
14974            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14975                    int status, int start, int end) throws SystemException {
14976                    return findByU_C_S(userId, classNameIds, status, start, end, null);
14977            }
14978    
14979            /**
14980             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14981             *
14982             * <p>
14983             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14984             * </p>
14985             *
14986             * @param userId the user ID
14987             * @param classNameIds the class name IDs
14988             * @param status the status
14989             * @param start the lower bound of the range of message-boards messages
14990             * @param end the upper bound of the range of message-boards messages (not inclusive)
14991             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14992             * @return the ordered range of matching message-boards messages
14993             * @throws SystemException if a system exception occurred
14994             */
14995            @Override
14996            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14997                    int status, int start, int end, OrderByComparator orderByComparator)
14998                    throws SystemException {
14999                    if ((classNameIds != null) && (classNameIds.length == 1)) {
15000                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15001                                    orderByComparator);
15002                    }
15003    
15004                    boolean pagination = true;
15005                    Object[] finderArgs = null;
15006    
15007                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15008                                    (orderByComparator == null)) {
15009                            pagination = false;
15010                            finderArgs = new Object[] {
15011                                            userId, StringUtil.merge(classNameIds), status
15012                                    };
15013                    }
15014                    else {
15015                            finderArgs = new Object[] {
15016                                            userId, StringUtil.merge(classNameIds), status,
15017                                            
15018                                            start, end, orderByComparator
15019                                    };
15020                    }
15021    
15022                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15023                                    finderArgs, this);
15024    
15025                    if ((list != null) && !list.isEmpty()) {
15026                            for (MBMessage mbMessage : list) {
15027                                    if ((userId != mbMessage.getUserId()) ||
15028                                                    !ArrayUtil.contains(classNameIds,
15029                                                            mbMessage.getClassNameId()) ||
15030                                                    (status != mbMessage.getStatus())) {
15031                                            list = null;
15032    
15033                                            break;
15034                                    }
15035                            }
15036                    }
15037    
15038                    if (list == null) {
15039                            StringBundler query = new StringBundler();
15040    
15041                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15042    
15043                            boolean conjunctionable = false;
15044    
15045                            if (conjunctionable) {
15046                                    query.append(WHERE_AND);
15047                            }
15048    
15049                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
15050    
15051                            conjunctionable = true;
15052    
15053                            if ((classNameIds == null) || (classNameIds.length > 0)) {
15054                                    if (conjunctionable) {
15055                                            query.append(WHERE_AND);
15056                                    }
15057    
15058                                    query.append(StringPool.OPEN_PARENTHESIS);
15059    
15060                                    for (int i = 0; i < classNameIds.length; i++) {
15061                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
15062    
15063                                            if ((i + 1) < classNameIds.length) {
15064                                                    query.append(WHERE_OR);
15065                                            }
15066                                    }
15067    
15068                                    query.append(StringPool.CLOSE_PARENTHESIS);
15069    
15070                                    conjunctionable = true;
15071                            }
15072    
15073                            if (conjunctionable) {
15074                                    query.append(WHERE_AND);
15075                            }
15076    
15077                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
15078    
15079                            conjunctionable = true;
15080    
15081                            if (orderByComparator != null) {
15082                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15083                                            orderByComparator);
15084                            }
15085                            else
15086                             if (pagination) {
15087                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15088                            }
15089    
15090                            String sql = query.toString();
15091    
15092                            Session session = null;
15093    
15094                            try {
15095                                    session = openSession();
15096    
15097                                    Query q = session.createQuery(sql);
15098    
15099                                    QueryPos qPos = QueryPos.getInstance(q);
15100    
15101                                    qPos.add(userId);
15102    
15103                                    if (classNameIds != null) {
15104                                            qPos.add(classNameIds);
15105                                    }
15106    
15107                                    qPos.add(status);
15108    
15109                                    if (!pagination) {
15110                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15111                                                            start, end, false);
15112    
15113                                            Collections.sort(list);
15114    
15115                                            list = new UnmodifiableList<MBMessage>(list);
15116                                    }
15117                                    else {
15118                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15119                                                            start, end);
15120                                    }
15121    
15122                                    cacheResult(list);
15123    
15124                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15125                                            finderArgs, list);
15126                            }
15127                            catch (Exception e) {
15128                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15129                                            finderArgs);
15130    
15131                                    throw processException(e);
15132                            }
15133                            finally {
15134                                    closeSession(session);
15135                            }
15136                    }
15137    
15138                    return list;
15139            }
15140    
15141            /**
15142             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15143             *
15144             * @param userId the user ID
15145             * @param classNameId the class name ID
15146             * @param status the status
15147             * @throws SystemException if a system exception occurred
15148             */
15149            @Override
15150            public void removeByU_C_S(long userId, long classNameId, int status)
15151                    throws SystemException {
15152                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15153                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15154                            remove(mbMessage);
15155                    }
15156            }
15157    
15158            /**
15159             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15160             *
15161             * @param userId the user ID
15162             * @param classNameId the class name ID
15163             * @param status the status
15164             * @return the number of matching message-boards messages
15165             * @throws SystemException if a system exception occurred
15166             */
15167            @Override
15168            public int countByU_C_S(long userId, long classNameId, int status)
15169                    throws SystemException {
15170                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15171    
15172                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15173    
15174                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15175                                    this);
15176    
15177                    if (count == null) {
15178                            StringBundler query = new StringBundler(4);
15179    
15180                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15181    
15182                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15183    
15184                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15185    
15186                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15187    
15188                            String sql = query.toString();
15189    
15190                            Session session = null;
15191    
15192                            try {
15193                                    session = openSession();
15194    
15195                                    Query q = session.createQuery(sql);
15196    
15197                                    QueryPos qPos = QueryPos.getInstance(q);
15198    
15199                                    qPos.add(userId);
15200    
15201                                    qPos.add(classNameId);
15202    
15203                                    qPos.add(status);
15204    
15205                                    count = (Long)q.uniqueResult();
15206    
15207                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15208                            }
15209                            catch (Exception e) {
15210                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15211    
15212                                    throw processException(e);
15213                            }
15214                            finally {
15215                                    closeSession(session);
15216                            }
15217                    }
15218    
15219                    return count.intValue();
15220            }
15221    
15222            /**
15223             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15224             *
15225             * @param userId the user ID
15226             * @param classNameIds the class name IDs
15227             * @param status the status
15228             * @return the number of matching message-boards messages
15229             * @throws SystemException if a system exception occurred
15230             */
15231            @Override
15232            public int countByU_C_S(long userId, long[] classNameIds, int status)
15233                    throws SystemException {
15234                    Object[] finderArgs = new Object[] {
15235                                    userId, StringUtil.merge(classNameIds), status
15236                            };
15237    
15238                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15239                                    finderArgs, this);
15240    
15241                    if (count == null) {
15242                            StringBundler query = new StringBundler();
15243    
15244                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15245    
15246                            boolean conjunctionable = false;
15247    
15248                            if (conjunctionable) {
15249                                    query.append(WHERE_AND);
15250                            }
15251    
15252                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
15253    
15254                            conjunctionable = true;
15255    
15256                            if ((classNameIds == null) || (classNameIds.length > 0)) {
15257                                    if (conjunctionable) {
15258                                            query.append(WHERE_AND);
15259                                    }
15260    
15261                                    query.append(StringPool.OPEN_PARENTHESIS);
15262    
15263                                    for (int i = 0; i < classNameIds.length; i++) {
15264                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
15265    
15266                                            if ((i + 1) < classNameIds.length) {
15267                                                    query.append(WHERE_OR);
15268                                            }
15269                                    }
15270    
15271                                    query.append(StringPool.CLOSE_PARENTHESIS);
15272    
15273                                    conjunctionable = true;
15274                            }
15275    
15276                            if (conjunctionable) {
15277                                    query.append(WHERE_AND);
15278                            }
15279    
15280                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
15281    
15282                            conjunctionable = true;
15283    
15284                            String sql = query.toString();
15285    
15286                            Session session = null;
15287    
15288                            try {
15289                                    session = openSession();
15290    
15291                                    Query q = session.createQuery(sql);
15292    
15293                                    QueryPos qPos = QueryPos.getInstance(q);
15294    
15295                                    qPos.add(userId);
15296    
15297                                    if (classNameIds != null) {
15298                                            qPos.add(classNameIds);
15299                                    }
15300    
15301                                    qPos.add(status);
15302    
15303                                    count = (Long)q.uniqueResult();
15304    
15305                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15306                                            finderArgs, count);
15307                            }
15308                            catch (Exception e) {
15309                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15310                                            finderArgs);
15311    
15312                                    throw processException(e);
15313                            }
15314                            finally {
15315                                    closeSession(session);
15316                            }
15317                    }
15318    
15319                    return count.intValue();
15320            }
15321    
15322            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15323            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
15324                    removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
15325            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15326            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
15327                    removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
15328            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15329            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
15330                    removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
15331            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15332                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15333                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15334                            new String[] {
15335                                    Long.class.getName(), Long.class.getName(),
15336                                    Integer.class.getName(),
15337                                    
15338                            Integer.class.getName(), Integer.class.getName(),
15339                                    OrderByComparator.class.getName()
15340                            });
15341            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15342                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15343                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15344                            new String[] {
15345                                    Long.class.getName(), Long.class.getName(),
15346                                    Integer.class.getName()
15347                            },
15348                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15349                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15350                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15351                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15352            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15353                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15354                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15355                            new String[] {
15356                                    Long.class.getName(), Long.class.getName(),
15357                                    Integer.class.getName()
15358                            });
15359    
15360            /**
15361             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15362             *
15363             * @param classNameId the class name ID
15364             * @param classPK the class p k
15365             * @param status the status
15366             * @return the matching message-boards messages
15367             * @throws SystemException if a system exception occurred
15368             */
15369            @Override
15370            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15371                    int status) throws SystemException {
15372                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15373                            QueryUtil.ALL_POS, null);
15374            }
15375    
15376            /**
15377             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15378             *
15379             * <p>
15380             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15381             * </p>
15382             *
15383             * @param classNameId the class name ID
15384             * @param classPK the class p k
15385             * @param status the status
15386             * @param start the lower bound of the range of message-boards messages
15387             * @param end the upper bound of the range of message-boards messages (not inclusive)
15388             * @return the range of matching message-boards messages
15389             * @throws SystemException if a system exception occurred
15390             */
15391            @Override
15392            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15393                    int status, int start, int end) throws SystemException {
15394                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15395            }
15396    
15397            /**
15398             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15399             *
15400             * <p>
15401             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15402             * </p>
15403             *
15404             * @param classNameId the class name ID
15405             * @param classPK the class p k
15406             * @param status the status
15407             * @param start the lower bound of the range of message-boards messages
15408             * @param end the upper bound of the range of message-boards messages (not inclusive)
15409             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15410             * @return the ordered range of matching message-boards messages
15411             * @throws SystemException if a system exception occurred
15412             */
15413            @Override
15414            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15415                    int status, int start, int end, OrderByComparator orderByComparator)
15416                    throws SystemException {
15417                    boolean pagination = true;
15418                    FinderPath finderPath = null;
15419                    Object[] finderArgs = null;
15420    
15421                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15422                                    (orderByComparator == null)) {
15423                            pagination = false;
15424                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15425                            finderArgs = new Object[] { classNameId, classPK, status };
15426                    }
15427                    else {
15428                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15429                            finderArgs = new Object[] {
15430                                            classNameId, classPK, status,
15431                                            
15432                                            start, end, orderByComparator
15433                                    };
15434                    }
15435    
15436                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15437                                    finderArgs, this);
15438    
15439                    if ((list != null) && !list.isEmpty()) {
15440                            for (MBMessage mbMessage : list) {
15441                                    if ((classNameId != mbMessage.getClassNameId()) ||
15442                                                    (classPK != mbMessage.getClassPK()) ||
15443                                                    (status != mbMessage.getStatus())) {
15444                                            list = null;
15445    
15446                                            break;
15447                                    }
15448                            }
15449                    }
15450    
15451                    if (list == null) {
15452                            StringBundler query = null;
15453    
15454                            if (orderByComparator != null) {
15455                                    query = new StringBundler(5 +
15456                                                    (orderByComparator.getOrderByFields().length * 3));
15457                            }
15458                            else {
15459                                    query = new StringBundler(5);
15460                            }
15461    
15462                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15463    
15464                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15465    
15466                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15467    
15468                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15469    
15470                            if (orderByComparator != null) {
15471                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15472                                            orderByComparator);
15473                            }
15474                            else
15475                             if (pagination) {
15476                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15477                            }
15478    
15479                            String sql = query.toString();
15480    
15481                            Session session = null;
15482    
15483                            try {
15484                                    session = openSession();
15485    
15486                                    Query q = session.createQuery(sql);
15487    
15488                                    QueryPos qPos = QueryPos.getInstance(q);
15489    
15490                                    qPos.add(classNameId);
15491    
15492                                    qPos.add(classPK);
15493    
15494                                    qPos.add(status);
15495    
15496                                    if (!pagination) {
15497                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15498                                                            start, end, false);
15499    
15500                                            Collections.sort(list);
15501    
15502                                            list = new UnmodifiableList<MBMessage>(list);
15503                                    }
15504                                    else {
15505                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15506                                                            start, end);
15507                                    }
15508    
15509                                    cacheResult(list);
15510    
15511                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15512                            }
15513                            catch (Exception e) {
15514                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15515    
15516                                    throw processException(e);
15517                            }
15518                            finally {
15519                                    closeSession(session);
15520                            }
15521                    }
15522    
15523                    return list;
15524            }
15525    
15526            /**
15527             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15528             *
15529             * @param classNameId the class name ID
15530             * @param classPK the class p k
15531             * @param status the status
15532             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15533             * @return the first matching message-boards message
15534             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15535             * @throws SystemException if a system exception occurred
15536             */
15537            @Override
15538            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15539                    int status, OrderByComparator orderByComparator)
15540                    throws NoSuchMessageException, SystemException {
15541                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15542                                    orderByComparator);
15543    
15544                    if (mbMessage != null) {
15545                            return mbMessage;
15546                    }
15547    
15548                    StringBundler msg = new StringBundler(8);
15549    
15550                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15551    
15552                    msg.append("classNameId=");
15553                    msg.append(classNameId);
15554    
15555                    msg.append(", classPK=");
15556                    msg.append(classPK);
15557    
15558                    msg.append(", status=");
15559                    msg.append(status);
15560    
15561                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15562    
15563                    throw new NoSuchMessageException(msg.toString());
15564            }
15565    
15566            /**
15567             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15568             *
15569             * @param classNameId the class name ID
15570             * @param classPK the class p k
15571             * @param status the status
15572             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15573             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15574             * @throws SystemException if a system exception occurred
15575             */
15576            @Override
15577            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15578                    int status, OrderByComparator orderByComparator)
15579                    throws SystemException {
15580                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15581                                    orderByComparator);
15582    
15583                    if (!list.isEmpty()) {
15584                            return list.get(0);
15585                    }
15586    
15587                    return null;
15588            }
15589    
15590            /**
15591             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15592             *
15593             * @param classNameId the class name ID
15594             * @param classPK the class p k
15595             * @param status the status
15596             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15597             * @return the last matching message-boards message
15598             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15599             * @throws SystemException if a system exception occurred
15600             */
15601            @Override
15602            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15603                    int status, OrderByComparator orderByComparator)
15604                    throws NoSuchMessageException, SystemException {
15605                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15606                                    orderByComparator);
15607    
15608                    if (mbMessage != null) {
15609                            return mbMessage;
15610                    }
15611    
15612                    StringBundler msg = new StringBundler(8);
15613    
15614                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15615    
15616                    msg.append("classNameId=");
15617                    msg.append(classNameId);
15618    
15619                    msg.append(", classPK=");
15620                    msg.append(classPK);
15621    
15622                    msg.append(", status=");
15623                    msg.append(status);
15624    
15625                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15626    
15627                    throw new NoSuchMessageException(msg.toString());
15628            }
15629    
15630            /**
15631             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15632             *
15633             * @param classNameId the class name ID
15634             * @param classPK the class p k
15635             * @param status the status
15636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15637             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15638             * @throws SystemException if a system exception occurred
15639             */
15640            @Override
15641            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15642                    int status, OrderByComparator orderByComparator)
15643                    throws SystemException {
15644                    int count = countByC_C_S(classNameId, classPK, status);
15645    
15646                    if (count == 0) {
15647                            return null;
15648                    }
15649    
15650                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15651                                    count - 1, count, orderByComparator);
15652    
15653                    if (!list.isEmpty()) {
15654                            return list.get(0);
15655                    }
15656    
15657                    return null;
15658            }
15659    
15660            /**
15661             * 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;.
15662             *
15663             * @param messageId the primary key of the current message-boards message
15664             * @param classNameId the class name ID
15665             * @param classPK the class p k
15666             * @param status the status
15667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15668             * @return the previous, current, and next message-boards message
15669             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15670             * @throws SystemException if a system exception occurred
15671             */
15672            @Override
15673            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15674                    long classNameId, long classPK, int status,
15675                    OrderByComparator orderByComparator)
15676                    throws NoSuchMessageException, SystemException {
15677                    MBMessage mbMessage = findByPrimaryKey(messageId);
15678    
15679                    Session session = null;
15680    
15681                    try {
15682                            session = openSession();
15683    
15684                            MBMessage[] array = new MBMessageImpl[3];
15685    
15686                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15687                                            classPK, status, orderByComparator, true);
15688    
15689                            array[1] = mbMessage;
15690    
15691                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15692                                            classPK, status, orderByComparator, false);
15693    
15694                            return array;
15695                    }
15696                    catch (Exception e) {
15697                            throw processException(e);
15698                    }
15699                    finally {
15700                            closeSession(session);
15701                    }
15702            }
15703    
15704            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15705                    MBMessage mbMessage, long classNameId, long classPK, int status,
15706                    OrderByComparator orderByComparator, boolean previous) {
15707                    StringBundler query = null;
15708    
15709                    if (orderByComparator != null) {
15710                            query = new StringBundler(6 +
15711                                            (orderByComparator.getOrderByFields().length * 6));
15712                    }
15713                    else {
15714                            query = new StringBundler(3);
15715                    }
15716    
15717                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15718    
15719                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15720    
15721                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15722    
15723                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15724    
15725                    if (orderByComparator != null) {
15726                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15727    
15728                            if (orderByConditionFields.length > 0) {
15729                                    query.append(WHERE_AND);
15730                            }
15731    
15732                            for (int i = 0; i < orderByConditionFields.length; i++) {
15733                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15734                                    query.append(orderByConditionFields[i]);
15735    
15736                                    if ((i + 1) < orderByConditionFields.length) {
15737                                            if (orderByComparator.isAscending() ^ previous) {
15738                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15739                                            }
15740                                            else {
15741                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15742                                            }
15743                                    }
15744                                    else {
15745                                            if (orderByComparator.isAscending() ^ previous) {
15746                                                    query.append(WHERE_GREATER_THAN);
15747                                            }
15748                                            else {
15749                                                    query.append(WHERE_LESSER_THAN);
15750                                            }
15751                                    }
15752                            }
15753    
15754                            query.append(ORDER_BY_CLAUSE);
15755    
15756                            String[] orderByFields = orderByComparator.getOrderByFields();
15757    
15758                            for (int i = 0; i < orderByFields.length; i++) {
15759                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15760                                    query.append(orderByFields[i]);
15761    
15762                                    if ((i + 1) < orderByFields.length) {
15763                                            if (orderByComparator.isAscending() ^ previous) {
15764                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15765                                            }
15766                                            else {
15767                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15768                                            }
15769                                    }
15770                                    else {
15771                                            if (orderByComparator.isAscending() ^ previous) {
15772                                                    query.append(ORDER_BY_ASC);
15773                                            }
15774                                            else {
15775                                                    query.append(ORDER_BY_DESC);
15776                                            }
15777                                    }
15778                            }
15779                    }
15780                    else {
15781                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15782                    }
15783    
15784                    String sql = query.toString();
15785    
15786                    Query q = session.createQuery(sql);
15787    
15788                    q.setFirstResult(0);
15789                    q.setMaxResults(2);
15790    
15791                    QueryPos qPos = QueryPos.getInstance(q);
15792    
15793                    qPos.add(classNameId);
15794    
15795                    qPos.add(classPK);
15796    
15797                    qPos.add(status);
15798    
15799                    if (orderByComparator != null) {
15800                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15801    
15802                            for (Object value : values) {
15803                                    qPos.add(value);
15804                            }
15805                    }
15806    
15807                    List<MBMessage> list = q.list();
15808    
15809                    if (list.size() == 2) {
15810                            return list.get(1);
15811                    }
15812                    else {
15813                            return null;
15814                    }
15815            }
15816    
15817            /**
15818             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15819             *
15820             * @param classNameId the class name ID
15821             * @param classPK the class p k
15822             * @param status the status
15823             * @throws SystemException if a system exception occurred
15824             */
15825            @Override
15826            public void removeByC_C_S(long classNameId, long classPK, int status)
15827                    throws SystemException {
15828                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15829                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15830                            remove(mbMessage);
15831                    }
15832            }
15833    
15834            /**
15835             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15836             *
15837             * @param classNameId the class name ID
15838             * @param classPK the class p k
15839             * @param status the status
15840             * @return the number of matching message-boards messages
15841             * @throws SystemException if a system exception occurred
15842             */
15843            @Override
15844            public int countByC_C_S(long classNameId, long classPK, int status)
15845                    throws SystemException {
15846                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15847    
15848                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
15849    
15850                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15851                                    this);
15852    
15853                    if (count == null) {
15854                            StringBundler query = new StringBundler(4);
15855    
15856                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15857    
15858                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15859    
15860                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15861    
15862                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15863    
15864                            String sql = query.toString();
15865    
15866                            Session session = null;
15867    
15868                            try {
15869                                    session = openSession();
15870    
15871                                    Query q = session.createQuery(sql);
15872    
15873                                    QueryPos qPos = QueryPos.getInstance(q);
15874    
15875                                    qPos.add(classNameId);
15876    
15877                                    qPos.add(classPK);
15878    
15879                                    qPos.add(status);
15880    
15881                                    count = (Long)q.uniqueResult();
15882    
15883                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15884                            }
15885                            catch (Exception e) {
15886                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15887    
15888                                    throw processException(e);
15889                            }
15890                            finally {
15891                                    closeSession(session);
15892                            }
15893                    }
15894    
15895                    return count.intValue();
15896            }
15897    
15898            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15899            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15900            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15901            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15902                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15903                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
15904                            new String[] {
15905                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15906                                    Boolean.class.getName(),
15907                                    
15908                            Integer.class.getName(), Integer.class.getName(),
15909                                    OrderByComparator.class.getName()
15910                            });
15911            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
15912                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15913                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15914                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
15915                            new String[] {
15916                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15917                                    Boolean.class.getName()
15918                            },
15919                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15920                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15921                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
15922                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
15923                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15924            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15925                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15926                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
15927                            new String[] {
15928                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15929                                    Boolean.class.getName()
15930                            });
15931    
15932            /**
15933             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15934             *
15935             * @param groupId the group ID
15936             * @param categoryId the category ID
15937             * @param threadId the thread ID
15938             * @param answer the answer
15939             * @return the matching message-boards messages
15940             * @throws SystemException if a system exception occurred
15941             */
15942            @Override
15943            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15944                    long threadId, boolean answer) throws SystemException {
15945                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
15946                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15947            }
15948    
15949            /**
15950             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15951             *
15952             * <p>
15953             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15954             * </p>
15955             *
15956             * @param groupId the group ID
15957             * @param categoryId the category ID
15958             * @param threadId the thread ID
15959             * @param answer the answer
15960             * @param start the lower bound of the range of message-boards messages
15961             * @param end the upper bound of the range of message-boards messages (not inclusive)
15962             * @return the range of matching message-boards messages
15963             * @throws SystemException if a system exception occurred
15964             */
15965            @Override
15966            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15967                    long threadId, boolean answer, int start, int end)
15968                    throws SystemException {
15969                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
15970                            null);
15971            }
15972    
15973            /**
15974             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15975             *
15976             * <p>
15977             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15978             * </p>
15979             *
15980             * @param groupId the group ID
15981             * @param categoryId the category ID
15982             * @param threadId the thread ID
15983             * @param answer the answer
15984             * @param start the lower bound of the range of message-boards messages
15985             * @param end the upper bound of the range of message-boards messages (not inclusive)
15986             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15987             * @return the ordered range of matching message-boards messages
15988             * @throws SystemException if a system exception occurred
15989             */
15990            @Override
15991            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15992                    long threadId, boolean answer, int start, int end,
15993                    OrderByComparator orderByComparator) throws SystemException {
15994                    boolean pagination = true;
15995                    FinderPath finderPath = null;
15996                    Object[] finderArgs = null;
15997    
15998                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15999                                    (orderByComparator == null)) {
16000                            pagination = false;
16001                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16002                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16003                    }
16004                    else {
16005                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16006                            finderArgs = new Object[] {
16007                                            groupId, categoryId, threadId, answer,
16008                                            
16009                                            start, end, orderByComparator
16010                                    };
16011                    }
16012    
16013                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16014                                    finderArgs, this);
16015    
16016                    if ((list != null) && !list.isEmpty()) {
16017                            for (MBMessage mbMessage : list) {
16018                                    if ((groupId != mbMessage.getGroupId()) ||
16019                                                    (categoryId != mbMessage.getCategoryId()) ||
16020                                                    (threadId != mbMessage.getThreadId()) ||
16021                                                    (answer != mbMessage.getAnswer())) {
16022                                            list = null;
16023    
16024                                            break;
16025                                    }
16026                            }
16027                    }
16028    
16029                    if (list == null) {
16030                            StringBundler query = null;
16031    
16032                            if (orderByComparator != null) {
16033                                    query = new StringBundler(6 +
16034                                                    (orderByComparator.getOrderByFields().length * 3));
16035                            }
16036                            else {
16037                                    query = new StringBundler(6);
16038                            }
16039    
16040                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16041    
16042                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16043    
16044                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16045    
16046                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16047    
16048                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16049    
16050                            if (orderByComparator != null) {
16051                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16052                                            orderByComparator);
16053                            }
16054                            else
16055                             if (pagination) {
16056                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16057                            }
16058    
16059                            String sql = query.toString();
16060    
16061                            Session session = null;
16062    
16063                            try {
16064                                    session = openSession();
16065    
16066                                    Query q = session.createQuery(sql);
16067    
16068                                    QueryPos qPos = QueryPos.getInstance(q);
16069    
16070                                    qPos.add(groupId);
16071    
16072                                    qPos.add(categoryId);
16073    
16074                                    qPos.add(threadId);
16075    
16076                                    qPos.add(answer);
16077    
16078                                    if (!pagination) {
16079                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16080                                                            start, end, false);
16081    
16082                                            Collections.sort(list);
16083    
16084                                            list = new UnmodifiableList<MBMessage>(list);
16085                                    }
16086                                    else {
16087                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16088                                                            start, end);
16089                                    }
16090    
16091                                    cacheResult(list);
16092    
16093                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16094                            }
16095                            catch (Exception e) {
16096                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16097    
16098                                    throw processException(e);
16099                            }
16100                            finally {
16101                                    closeSession(session);
16102                            }
16103                    }
16104    
16105                    return list;
16106            }
16107    
16108            /**
16109             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16110             *
16111             * @param groupId the group ID
16112             * @param categoryId the category ID
16113             * @param threadId the thread ID
16114             * @param answer the answer
16115             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16116             * @return the first matching message-boards message
16117             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16118             * @throws SystemException if a system exception occurred
16119             */
16120            @Override
16121            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16122                    long threadId, boolean answer, OrderByComparator orderByComparator)
16123                    throws NoSuchMessageException, SystemException {
16124                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16125                                    threadId, answer, orderByComparator);
16126    
16127                    if (mbMessage != null) {
16128                            return mbMessage;
16129                    }
16130    
16131                    StringBundler msg = new StringBundler(10);
16132    
16133                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16134    
16135                    msg.append("groupId=");
16136                    msg.append(groupId);
16137    
16138                    msg.append(", categoryId=");
16139                    msg.append(categoryId);
16140    
16141                    msg.append(", threadId=");
16142                    msg.append(threadId);
16143    
16144                    msg.append(", answer=");
16145                    msg.append(answer);
16146    
16147                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16148    
16149                    throw new NoSuchMessageException(msg.toString());
16150            }
16151    
16152            /**
16153             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16154             *
16155             * @param groupId the group ID
16156             * @param categoryId the category ID
16157             * @param threadId the thread ID
16158             * @param answer the answer
16159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16160             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16161             * @throws SystemException if a system exception occurred
16162             */
16163            @Override
16164            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16165                    long threadId, boolean answer, OrderByComparator orderByComparator)
16166                    throws SystemException {
16167                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16168                                    answer, 0, 1, orderByComparator);
16169    
16170                    if (!list.isEmpty()) {
16171                            return list.get(0);
16172                    }
16173    
16174                    return null;
16175            }
16176    
16177            /**
16178             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16179             *
16180             * @param groupId the group ID
16181             * @param categoryId the category ID
16182             * @param threadId the thread ID
16183             * @param answer the answer
16184             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16185             * @return the last matching message-boards message
16186             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16187             * @throws SystemException if a system exception occurred
16188             */
16189            @Override
16190            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16191                    long threadId, boolean answer, OrderByComparator orderByComparator)
16192                    throws NoSuchMessageException, SystemException {
16193                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16194                                    threadId, answer, orderByComparator);
16195    
16196                    if (mbMessage != null) {
16197                            return mbMessage;
16198                    }
16199    
16200                    StringBundler msg = new StringBundler(10);
16201    
16202                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16203    
16204                    msg.append("groupId=");
16205                    msg.append(groupId);
16206    
16207                    msg.append(", categoryId=");
16208                    msg.append(categoryId);
16209    
16210                    msg.append(", threadId=");
16211                    msg.append(threadId);
16212    
16213                    msg.append(", answer=");
16214                    msg.append(answer);
16215    
16216                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16217    
16218                    throw new NoSuchMessageException(msg.toString());
16219            }
16220    
16221            /**
16222             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16223             *
16224             * @param groupId the group ID
16225             * @param categoryId the category ID
16226             * @param threadId the thread ID
16227             * @param answer the answer
16228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16229             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16230             * @throws SystemException if a system exception occurred
16231             */
16232            @Override
16233            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16234                    long threadId, boolean answer, OrderByComparator orderByComparator)
16235                    throws SystemException {
16236                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16237    
16238                    if (count == 0) {
16239                            return null;
16240                    }
16241    
16242                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16243                                    answer, count - 1, count, orderByComparator);
16244    
16245                    if (!list.isEmpty()) {
16246                            return list.get(0);
16247                    }
16248    
16249                    return null;
16250            }
16251    
16252            /**
16253             * 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;.
16254             *
16255             * @param messageId the primary key of the current message-boards message
16256             * @param groupId the group ID
16257             * @param categoryId the category ID
16258             * @param threadId the thread ID
16259             * @param answer the answer
16260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16261             * @return the previous, current, and next message-boards message
16262             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16263             * @throws SystemException if a system exception occurred
16264             */
16265            @Override
16266            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16267                    long categoryId, long threadId, boolean answer,
16268                    OrderByComparator orderByComparator)
16269                    throws NoSuchMessageException, SystemException {
16270                    MBMessage mbMessage = findByPrimaryKey(messageId);
16271    
16272                    Session session = null;
16273    
16274                    try {
16275                            session = openSession();
16276    
16277                            MBMessage[] array = new MBMessageImpl[3];
16278    
16279                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16280                                            categoryId, threadId, answer, orderByComparator, true);
16281    
16282                            array[1] = mbMessage;
16283    
16284                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16285                                            categoryId, threadId, answer, orderByComparator, false);
16286    
16287                            return array;
16288                    }
16289                    catch (Exception e) {
16290                            throw processException(e);
16291                    }
16292                    finally {
16293                            closeSession(session);
16294                    }
16295            }
16296    
16297            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16298                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16299                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
16300                    StringBundler query = null;
16301    
16302                    if (orderByComparator != null) {
16303                            query = new StringBundler(6 +
16304                                            (orderByComparator.getOrderByFields().length * 6));
16305                    }
16306                    else {
16307                            query = new StringBundler(3);
16308                    }
16309    
16310                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16311    
16312                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16313    
16314                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16315    
16316                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16317    
16318                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16319    
16320                    if (orderByComparator != null) {
16321                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16322    
16323                            if (orderByConditionFields.length > 0) {
16324                                    query.append(WHERE_AND);
16325                            }
16326    
16327                            for (int i = 0; i < orderByConditionFields.length; i++) {
16328                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16329                                    query.append(orderByConditionFields[i]);
16330    
16331                                    if ((i + 1) < orderByConditionFields.length) {
16332                                            if (orderByComparator.isAscending() ^ previous) {
16333                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16334                                            }
16335                                            else {
16336                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16337                                            }
16338                                    }
16339                                    else {
16340                                            if (orderByComparator.isAscending() ^ previous) {
16341                                                    query.append(WHERE_GREATER_THAN);
16342                                            }
16343                                            else {
16344                                                    query.append(WHERE_LESSER_THAN);
16345                                            }
16346                                    }
16347                            }
16348    
16349                            query.append(ORDER_BY_CLAUSE);
16350    
16351                            String[] orderByFields = orderByComparator.getOrderByFields();
16352    
16353                            for (int i = 0; i < orderByFields.length; i++) {
16354                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16355                                    query.append(orderByFields[i]);
16356    
16357                                    if ((i + 1) < orderByFields.length) {
16358                                            if (orderByComparator.isAscending() ^ previous) {
16359                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16360                                            }
16361                                            else {
16362                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16363                                            }
16364                                    }
16365                                    else {
16366                                            if (orderByComparator.isAscending() ^ previous) {
16367                                                    query.append(ORDER_BY_ASC);
16368                                            }
16369                                            else {
16370                                                    query.append(ORDER_BY_DESC);
16371                                            }
16372                                    }
16373                            }
16374                    }
16375                    else {
16376                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16377                    }
16378    
16379                    String sql = query.toString();
16380    
16381                    Query q = session.createQuery(sql);
16382    
16383                    q.setFirstResult(0);
16384                    q.setMaxResults(2);
16385    
16386                    QueryPos qPos = QueryPos.getInstance(q);
16387    
16388                    qPos.add(groupId);
16389    
16390                    qPos.add(categoryId);
16391    
16392                    qPos.add(threadId);
16393    
16394                    qPos.add(answer);
16395    
16396                    if (orderByComparator != null) {
16397                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16398    
16399                            for (Object value : values) {
16400                                    qPos.add(value);
16401                            }
16402                    }
16403    
16404                    List<MBMessage> list = q.list();
16405    
16406                    if (list.size() == 2) {
16407                            return list.get(1);
16408                    }
16409                    else {
16410                            return null;
16411                    }
16412            }
16413    
16414            /**
16415             * 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;.
16416             *
16417             * @param groupId the group ID
16418             * @param categoryId the category ID
16419             * @param threadId the thread ID
16420             * @param answer the answer
16421             * @return the matching message-boards messages that the user has permission to view
16422             * @throws SystemException if a system exception occurred
16423             */
16424            @Override
16425            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16426                    long threadId, boolean answer) throws SystemException {
16427                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16428                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16429            }
16430    
16431            /**
16432             * 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;.
16433             *
16434             * <p>
16435             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16436             * </p>
16437             *
16438             * @param groupId the group ID
16439             * @param categoryId the category ID
16440             * @param threadId the thread ID
16441             * @param answer the answer
16442             * @param start the lower bound of the range of message-boards messages
16443             * @param end the upper bound of the range of message-boards messages (not inclusive)
16444             * @return the range of matching message-boards messages that the user has permission to view
16445             * @throws SystemException if a system exception occurred
16446             */
16447            @Override
16448            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16449                    long threadId, boolean answer, int start, int end)
16450                    throws SystemException {
16451                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16452                            start, end, null);
16453            }
16454    
16455            /**
16456             * 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;.
16457             *
16458             * <p>
16459             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16460             * </p>
16461             *
16462             * @param groupId the group ID
16463             * @param categoryId the category ID
16464             * @param threadId the thread ID
16465             * @param answer the answer
16466             * @param start the lower bound of the range of message-boards messages
16467             * @param end the upper bound of the range of message-boards messages (not inclusive)
16468             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16469             * @return the ordered range of matching message-boards messages that the user has permission to view
16470             * @throws SystemException if a system exception occurred
16471             */
16472            @Override
16473            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16474                    long threadId, boolean answer, int start, int end,
16475                    OrderByComparator orderByComparator) throws SystemException {
16476                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16477                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16478                                    end, orderByComparator);
16479                    }
16480    
16481                    StringBundler query = null;
16482    
16483                    if (orderByComparator != null) {
16484                            query = new StringBundler(6 +
16485                                            (orderByComparator.getOrderByFields().length * 3));
16486                    }
16487                    else {
16488                            query = new StringBundler(6);
16489                    }
16490    
16491                    if (getDB().isSupportsInlineDistinct()) {
16492                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16493                    }
16494                    else {
16495                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16496                    }
16497    
16498                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16499    
16500                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16501    
16502                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16503    
16504                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16505    
16506                    if (!getDB().isSupportsInlineDistinct()) {
16507                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16508                    }
16509    
16510                    if (orderByComparator != null) {
16511                            if (getDB().isSupportsInlineDistinct()) {
16512                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16513                                            orderByComparator, true);
16514                            }
16515                            else {
16516                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16517                                            orderByComparator, true);
16518                            }
16519                    }
16520                    else {
16521                            if (getDB().isSupportsInlineDistinct()) {
16522                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16523                            }
16524                            else {
16525                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16526                            }
16527                    }
16528    
16529                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16530                                    MBMessage.class.getName(),
16531                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16532    
16533                    Session session = null;
16534    
16535                    try {
16536                            session = openSession();
16537    
16538                            SQLQuery q = session.createSQLQuery(sql);
16539    
16540                            if (getDB().isSupportsInlineDistinct()) {
16541                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16542                            }
16543                            else {
16544                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16545                            }
16546    
16547                            QueryPos qPos = QueryPos.getInstance(q);
16548    
16549                            qPos.add(groupId);
16550    
16551                            qPos.add(categoryId);
16552    
16553                            qPos.add(threadId);
16554    
16555                            qPos.add(answer);
16556    
16557                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16558                    }
16559                    catch (Exception e) {
16560                            throw processException(e);
16561                    }
16562                    finally {
16563                            closeSession(session);
16564                    }
16565            }
16566    
16567            /**
16568             * 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;.
16569             *
16570             * @param messageId the primary key of the current message-boards message
16571             * @param groupId the group ID
16572             * @param categoryId the category ID
16573             * @param threadId the thread ID
16574             * @param answer the answer
16575             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16576             * @return the previous, current, and next message-boards message
16577             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16578             * @throws SystemException if a system exception occurred
16579             */
16580            @Override
16581            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16582                    long groupId, long categoryId, long threadId, boolean answer,
16583                    OrderByComparator orderByComparator)
16584                    throws NoSuchMessageException, SystemException {
16585                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16586                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16587                                    threadId, answer, orderByComparator);
16588                    }
16589    
16590                    MBMessage mbMessage = findByPrimaryKey(messageId);
16591    
16592                    Session session = null;
16593    
16594                    try {
16595                            session = openSession();
16596    
16597                            MBMessage[] array = new MBMessageImpl[3];
16598    
16599                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16600                                            groupId, categoryId, threadId, answer, orderByComparator,
16601                                            true);
16602    
16603                            array[1] = mbMessage;
16604    
16605                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16606                                            groupId, categoryId, threadId, answer, orderByComparator,
16607                                            false);
16608    
16609                            return array;
16610                    }
16611                    catch (Exception e) {
16612                            throw processException(e);
16613                    }
16614                    finally {
16615                            closeSession(session);
16616                    }
16617            }
16618    
16619            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16620                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16621                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
16622                    StringBundler query = null;
16623    
16624                    if (orderByComparator != null) {
16625                            query = new StringBundler(6 +
16626                                            (orderByComparator.getOrderByFields().length * 6));
16627                    }
16628                    else {
16629                            query = new StringBundler(3);
16630                    }
16631    
16632                    if (getDB().isSupportsInlineDistinct()) {
16633                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16634                    }
16635                    else {
16636                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16637                    }
16638    
16639                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16640    
16641                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16642    
16643                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16644    
16645                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16646    
16647                    if (!getDB().isSupportsInlineDistinct()) {
16648                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16649                    }
16650    
16651                    if (orderByComparator != null) {
16652                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16653    
16654                            if (orderByConditionFields.length > 0) {
16655                                    query.append(WHERE_AND);
16656                            }
16657    
16658                            for (int i = 0; i < orderByConditionFields.length; i++) {
16659                                    if (getDB().isSupportsInlineDistinct()) {
16660                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16661                                    }
16662                                    else {
16663                                            query.append(_ORDER_BY_ENTITY_TABLE);
16664                                    }
16665    
16666                                    query.append(orderByConditionFields[i]);
16667    
16668                                    if ((i + 1) < orderByConditionFields.length) {
16669                                            if (orderByComparator.isAscending() ^ previous) {
16670                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16671                                            }
16672                                            else {
16673                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16674                                            }
16675                                    }
16676                                    else {
16677                                            if (orderByComparator.isAscending() ^ previous) {
16678                                                    query.append(WHERE_GREATER_THAN);
16679                                            }
16680                                            else {
16681                                                    query.append(WHERE_LESSER_THAN);
16682                                            }
16683                                    }
16684                            }
16685    
16686                            query.append(ORDER_BY_CLAUSE);
16687    
16688                            String[] orderByFields = orderByComparator.getOrderByFields();
16689    
16690                            for (int i = 0; i < orderByFields.length; i++) {
16691                                    if (getDB().isSupportsInlineDistinct()) {
16692                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16693                                    }
16694                                    else {
16695                                            query.append(_ORDER_BY_ENTITY_TABLE);
16696                                    }
16697    
16698                                    query.append(orderByFields[i]);
16699    
16700                                    if ((i + 1) < orderByFields.length) {
16701                                            if (orderByComparator.isAscending() ^ previous) {
16702                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16703                                            }
16704                                            else {
16705                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16706                                            }
16707                                    }
16708                                    else {
16709                                            if (orderByComparator.isAscending() ^ previous) {
16710                                                    query.append(ORDER_BY_ASC);
16711                                            }
16712                                            else {
16713                                                    query.append(ORDER_BY_DESC);
16714                                            }
16715                                    }
16716                            }
16717                    }
16718                    else {
16719                            if (getDB().isSupportsInlineDistinct()) {
16720                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16721                            }
16722                            else {
16723                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16724                            }
16725                    }
16726    
16727                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16728                                    MBMessage.class.getName(),
16729                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16730    
16731                    SQLQuery q = session.createSQLQuery(sql);
16732    
16733                    q.setFirstResult(0);
16734                    q.setMaxResults(2);
16735    
16736                    if (getDB().isSupportsInlineDistinct()) {
16737                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16738                    }
16739                    else {
16740                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16741                    }
16742    
16743                    QueryPos qPos = QueryPos.getInstance(q);
16744    
16745                    qPos.add(groupId);
16746    
16747                    qPos.add(categoryId);
16748    
16749                    qPos.add(threadId);
16750    
16751                    qPos.add(answer);
16752    
16753                    if (orderByComparator != null) {
16754                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16755    
16756                            for (Object value : values) {
16757                                    qPos.add(value);
16758                            }
16759                    }
16760    
16761                    List<MBMessage> list = q.list();
16762    
16763                    if (list.size() == 2) {
16764                            return list.get(1);
16765                    }
16766                    else {
16767                            return null;
16768                    }
16769            }
16770    
16771            /**
16772             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16773             *
16774             * @param groupId the group ID
16775             * @param categoryId the category ID
16776             * @param threadId the thread ID
16777             * @param answer the answer
16778             * @throws SystemException if a system exception occurred
16779             */
16780            @Override
16781            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16782                    boolean answer) throws SystemException {
16783                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16784                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16785                            remove(mbMessage);
16786                    }
16787            }
16788    
16789            /**
16790             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16791             *
16792             * @param groupId the group ID
16793             * @param categoryId the category ID
16794             * @param threadId the thread ID
16795             * @param answer the answer
16796             * @return the number of matching message-boards messages
16797             * @throws SystemException if a system exception occurred
16798             */
16799            @Override
16800            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16801                    boolean answer) throws SystemException {
16802                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
16803    
16804                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16805    
16806                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16807                                    this);
16808    
16809                    if (count == null) {
16810                            StringBundler query = new StringBundler(5);
16811    
16812                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16813    
16814                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16815    
16816                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16817    
16818                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16819    
16820                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16821    
16822                            String sql = query.toString();
16823    
16824                            Session session = null;
16825    
16826                            try {
16827                                    session = openSession();
16828    
16829                                    Query q = session.createQuery(sql);
16830    
16831                                    QueryPos qPos = QueryPos.getInstance(q);
16832    
16833                                    qPos.add(groupId);
16834    
16835                                    qPos.add(categoryId);
16836    
16837                                    qPos.add(threadId);
16838    
16839                                    qPos.add(answer);
16840    
16841                                    count = (Long)q.uniqueResult();
16842    
16843                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16844                            }
16845                            catch (Exception e) {
16846                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16847    
16848                                    throw processException(e);
16849                            }
16850                            finally {
16851                                    closeSession(session);
16852                            }
16853                    }
16854    
16855                    return count.intValue();
16856            }
16857    
16858            /**
16859             * 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;.
16860             *
16861             * @param groupId the group ID
16862             * @param categoryId the category ID
16863             * @param threadId the thread ID
16864             * @param answer the answer
16865             * @return the number of matching message-boards messages that the user has permission to view
16866             * @throws SystemException if a system exception occurred
16867             */
16868            @Override
16869            public int filterCountByG_C_T_A(long groupId, long categoryId,
16870                    long threadId, boolean answer) throws SystemException {
16871                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16872                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
16873                    }
16874    
16875                    StringBundler query = new StringBundler(5);
16876    
16877                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16878    
16879                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16880    
16881                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16882    
16883                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16884    
16885                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16886    
16887                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16888                                    MBMessage.class.getName(),
16889                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16890    
16891                    Session session = null;
16892    
16893                    try {
16894                            session = openSession();
16895    
16896                            SQLQuery q = session.createSQLQuery(sql);
16897    
16898                            q.addScalar(COUNT_COLUMN_NAME,
16899                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16900    
16901                            QueryPos qPos = QueryPos.getInstance(q);
16902    
16903                            qPos.add(groupId);
16904    
16905                            qPos.add(categoryId);
16906    
16907                            qPos.add(threadId);
16908    
16909                            qPos.add(answer);
16910    
16911                            Long count = (Long)q.uniqueResult();
16912    
16913                            return count.intValue();
16914                    }
16915                    catch (Exception e) {
16916                            throw processException(e);
16917                    }
16918                    finally {
16919                            closeSession(session);
16920                    }
16921            }
16922    
16923            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
16924            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
16925            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
16926            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
16927            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16928                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16929                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
16930                            new String[] {
16931                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16932                                    Integer.class.getName(),
16933                                    
16934                            Integer.class.getName(), Integer.class.getName(),
16935                                    OrderByComparator.class.getName()
16936                            });
16937            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
16938                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16939                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16940                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
16941                            new String[] {
16942                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16943                                    Integer.class.getName()
16944                            },
16945                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16946                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16947                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16948                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
16949                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16950            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16951                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16952                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
16953                            new String[] {
16954                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16955                                    Integer.class.getName()
16956                            });
16957    
16958            /**
16959             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16960             *
16961             * @param groupId the group ID
16962             * @param categoryId the category ID
16963             * @param threadId the thread ID
16964             * @param status the status
16965             * @return the matching message-boards messages
16966             * @throws SystemException if a system exception occurred
16967             */
16968            @Override
16969            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16970                    long threadId, int status) throws SystemException {
16971                    return findByG_C_T_S(groupId, categoryId, threadId, status,
16972                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16973            }
16974    
16975            /**
16976             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16977             *
16978             * <p>
16979             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16980             * </p>
16981             *
16982             * @param groupId the group ID
16983             * @param categoryId the category ID
16984             * @param threadId the thread ID
16985             * @param status the status
16986             * @param start the lower bound of the range of message-boards messages
16987             * @param end the upper bound of the range of message-boards messages (not inclusive)
16988             * @return the range of matching message-boards messages
16989             * @throws SystemException if a system exception occurred
16990             */
16991            @Override
16992            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16993                    long threadId, int status, int start, int end)
16994                    throws SystemException {
16995                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
16996                            null);
16997            }
16998    
16999            /**
17000             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17001             *
17002             * <p>
17003             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17004             * </p>
17005             *
17006             * @param groupId the group ID
17007             * @param categoryId the category ID
17008             * @param threadId the thread ID
17009             * @param status the status
17010             * @param start the lower bound of the range of message-boards messages
17011             * @param end the upper bound of the range of message-boards messages (not inclusive)
17012             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17013             * @return the ordered range of matching message-boards messages
17014             * @throws SystemException if a system exception occurred
17015             */
17016            @Override
17017            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17018                    long threadId, int status, int start, int end,
17019                    OrderByComparator orderByComparator) throws SystemException {
17020                    boolean pagination = true;
17021                    FinderPath finderPath = null;
17022                    Object[] finderArgs = null;
17023    
17024                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17025                                    (orderByComparator == null)) {
17026                            pagination = false;
17027                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17028                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17029                    }
17030                    else {
17031                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17032                            finderArgs = new Object[] {
17033                                            groupId, categoryId, threadId, status,
17034                                            
17035                                            start, end, orderByComparator
17036                                    };
17037                    }
17038    
17039                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17040                                    finderArgs, this);
17041    
17042                    if ((list != null) && !list.isEmpty()) {
17043                            for (MBMessage mbMessage : list) {
17044                                    if ((groupId != mbMessage.getGroupId()) ||
17045                                                    (categoryId != mbMessage.getCategoryId()) ||
17046                                                    (threadId != mbMessage.getThreadId()) ||
17047                                                    (status != mbMessage.getStatus())) {
17048                                            list = null;
17049    
17050                                            break;
17051                                    }
17052                            }
17053                    }
17054    
17055                    if (list == null) {
17056                            StringBundler query = null;
17057    
17058                            if (orderByComparator != null) {
17059                                    query = new StringBundler(6 +
17060                                                    (orderByComparator.getOrderByFields().length * 3));
17061                            }
17062                            else {
17063                                    query = new StringBundler(6);
17064                            }
17065    
17066                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17067    
17068                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17069    
17070                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17071    
17072                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17073    
17074                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17075    
17076                            if (orderByComparator != null) {
17077                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17078                                            orderByComparator);
17079                            }
17080                            else
17081                             if (pagination) {
17082                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17083                            }
17084    
17085                            String sql = query.toString();
17086    
17087                            Session session = null;
17088    
17089                            try {
17090                                    session = openSession();
17091    
17092                                    Query q = session.createQuery(sql);
17093    
17094                                    QueryPos qPos = QueryPos.getInstance(q);
17095    
17096                                    qPos.add(groupId);
17097    
17098                                    qPos.add(categoryId);
17099    
17100                                    qPos.add(threadId);
17101    
17102                                    qPos.add(status);
17103    
17104                                    if (!pagination) {
17105                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17106                                                            start, end, false);
17107    
17108                                            Collections.sort(list);
17109    
17110                                            list = new UnmodifiableList<MBMessage>(list);
17111                                    }
17112                                    else {
17113                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17114                                                            start, end);
17115                                    }
17116    
17117                                    cacheResult(list);
17118    
17119                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17120                            }
17121                            catch (Exception e) {
17122                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17123    
17124                                    throw processException(e);
17125                            }
17126                            finally {
17127                                    closeSession(session);
17128                            }
17129                    }
17130    
17131                    return list;
17132            }
17133    
17134            /**
17135             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17136             *
17137             * @param groupId the group ID
17138             * @param categoryId the category ID
17139             * @param threadId the thread ID
17140             * @param status the status
17141             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17142             * @return the first matching message-boards message
17143             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17144             * @throws SystemException if a system exception occurred
17145             */
17146            @Override
17147            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17148                    long threadId, int status, OrderByComparator orderByComparator)
17149                    throws NoSuchMessageException, SystemException {
17150                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17151                                    threadId, status, orderByComparator);
17152    
17153                    if (mbMessage != null) {
17154                            return mbMessage;
17155                    }
17156    
17157                    StringBundler msg = new StringBundler(10);
17158    
17159                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17160    
17161                    msg.append("groupId=");
17162                    msg.append(groupId);
17163    
17164                    msg.append(", categoryId=");
17165                    msg.append(categoryId);
17166    
17167                    msg.append(", threadId=");
17168                    msg.append(threadId);
17169    
17170                    msg.append(", status=");
17171                    msg.append(status);
17172    
17173                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17174    
17175                    throw new NoSuchMessageException(msg.toString());
17176            }
17177    
17178            /**
17179             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17180             *
17181             * @param groupId the group ID
17182             * @param categoryId the category ID
17183             * @param threadId the thread ID
17184             * @param status the status
17185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17186             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17187             * @throws SystemException if a system exception occurred
17188             */
17189            @Override
17190            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17191                    long threadId, int status, OrderByComparator orderByComparator)
17192                    throws SystemException {
17193                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17194                                    status, 0, 1, orderByComparator);
17195    
17196                    if (!list.isEmpty()) {
17197                            return list.get(0);
17198                    }
17199    
17200                    return null;
17201            }
17202    
17203            /**
17204             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17205             *
17206             * @param groupId the group ID
17207             * @param categoryId the category ID
17208             * @param threadId the thread ID
17209             * @param status the status
17210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17211             * @return the last matching message-boards message
17212             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17213             * @throws SystemException if a system exception occurred
17214             */
17215            @Override
17216            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17217                    long threadId, int status, OrderByComparator orderByComparator)
17218                    throws NoSuchMessageException, SystemException {
17219                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17220                                    threadId, status, orderByComparator);
17221    
17222                    if (mbMessage != null) {
17223                            return mbMessage;
17224                    }
17225    
17226                    StringBundler msg = new StringBundler(10);
17227    
17228                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17229    
17230                    msg.append("groupId=");
17231                    msg.append(groupId);
17232    
17233                    msg.append(", categoryId=");
17234                    msg.append(categoryId);
17235    
17236                    msg.append(", threadId=");
17237                    msg.append(threadId);
17238    
17239                    msg.append(", status=");
17240                    msg.append(status);
17241    
17242                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17243    
17244                    throw new NoSuchMessageException(msg.toString());
17245            }
17246    
17247            /**
17248             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17249             *
17250             * @param groupId the group ID
17251             * @param categoryId the category ID
17252             * @param threadId the thread ID
17253             * @param status the status
17254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17255             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17256             * @throws SystemException if a system exception occurred
17257             */
17258            @Override
17259            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17260                    long threadId, int status, OrderByComparator orderByComparator)
17261                    throws SystemException {
17262                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17263    
17264                    if (count == 0) {
17265                            return null;
17266                    }
17267    
17268                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17269                                    status, count - 1, count, orderByComparator);
17270    
17271                    if (!list.isEmpty()) {
17272                            return list.get(0);
17273                    }
17274    
17275                    return null;
17276            }
17277    
17278            /**
17279             * 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;.
17280             *
17281             * @param messageId the primary key of the current message-boards message
17282             * @param groupId the group ID
17283             * @param categoryId the category ID
17284             * @param threadId the thread ID
17285             * @param status the status
17286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17287             * @return the previous, current, and next message-boards message
17288             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17289             * @throws SystemException if a system exception occurred
17290             */
17291            @Override
17292            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17293                    long categoryId, long threadId, int status,
17294                    OrderByComparator orderByComparator)
17295                    throws NoSuchMessageException, SystemException {
17296                    MBMessage mbMessage = findByPrimaryKey(messageId);
17297    
17298                    Session session = null;
17299    
17300                    try {
17301                            session = openSession();
17302    
17303                            MBMessage[] array = new MBMessageImpl[3];
17304    
17305                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17306                                            categoryId, threadId, status, orderByComparator, true);
17307    
17308                            array[1] = mbMessage;
17309    
17310                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17311                                            categoryId, threadId, status, orderByComparator, false);
17312    
17313                            return array;
17314                    }
17315                    catch (Exception e) {
17316                            throw processException(e);
17317                    }
17318                    finally {
17319                            closeSession(session);
17320                    }
17321            }
17322    
17323            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17324                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17325                    int status, OrderByComparator orderByComparator, boolean previous) {
17326                    StringBundler query = null;
17327    
17328                    if (orderByComparator != null) {
17329                            query = new StringBundler(6 +
17330                                            (orderByComparator.getOrderByFields().length * 6));
17331                    }
17332                    else {
17333                            query = new StringBundler(3);
17334                    }
17335    
17336                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17337    
17338                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17339    
17340                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17341    
17342                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17343    
17344                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17345    
17346                    if (orderByComparator != null) {
17347                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17348    
17349                            if (orderByConditionFields.length > 0) {
17350                                    query.append(WHERE_AND);
17351                            }
17352    
17353                            for (int i = 0; i < orderByConditionFields.length; i++) {
17354                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17355                                    query.append(orderByConditionFields[i]);
17356    
17357                                    if ((i + 1) < orderByConditionFields.length) {
17358                                            if (orderByComparator.isAscending() ^ previous) {
17359                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17360                                            }
17361                                            else {
17362                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17363                                            }
17364                                    }
17365                                    else {
17366                                            if (orderByComparator.isAscending() ^ previous) {
17367                                                    query.append(WHERE_GREATER_THAN);
17368                                            }
17369                                            else {
17370                                                    query.append(WHERE_LESSER_THAN);
17371                                            }
17372                                    }
17373                            }
17374    
17375                            query.append(ORDER_BY_CLAUSE);
17376    
17377                            String[] orderByFields = orderByComparator.getOrderByFields();
17378    
17379                            for (int i = 0; i < orderByFields.length; i++) {
17380                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17381                                    query.append(orderByFields[i]);
17382    
17383                                    if ((i + 1) < orderByFields.length) {
17384                                            if (orderByComparator.isAscending() ^ previous) {
17385                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17386                                            }
17387                                            else {
17388                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17389                                            }
17390                                    }
17391                                    else {
17392                                            if (orderByComparator.isAscending() ^ previous) {
17393                                                    query.append(ORDER_BY_ASC);
17394                                            }
17395                                            else {
17396                                                    query.append(ORDER_BY_DESC);
17397                                            }
17398                                    }
17399                            }
17400                    }
17401                    else {
17402                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17403                    }
17404    
17405                    String sql = query.toString();
17406    
17407                    Query q = session.createQuery(sql);
17408    
17409                    q.setFirstResult(0);
17410                    q.setMaxResults(2);
17411    
17412                    QueryPos qPos = QueryPos.getInstance(q);
17413    
17414                    qPos.add(groupId);
17415    
17416                    qPos.add(categoryId);
17417    
17418                    qPos.add(threadId);
17419    
17420                    qPos.add(status);
17421    
17422                    if (orderByComparator != null) {
17423                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17424    
17425                            for (Object value : values) {
17426                                    qPos.add(value);
17427                            }
17428                    }
17429    
17430                    List<MBMessage> list = q.list();
17431    
17432                    if (list.size() == 2) {
17433                            return list.get(1);
17434                    }
17435                    else {
17436                            return null;
17437                    }
17438            }
17439    
17440            /**
17441             * 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;.
17442             *
17443             * @param groupId the group ID
17444             * @param categoryId the category ID
17445             * @param threadId the thread ID
17446             * @param status the status
17447             * @return the matching message-boards messages that the user has permission to view
17448             * @throws SystemException if a system exception occurred
17449             */
17450            @Override
17451            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17452                    long threadId, int status) throws SystemException {
17453                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17454                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17455            }
17456    
17457            /**
17458             * 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;.
17459             *
17460             * <p>
17461             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17462             * </p>
17463             *
17464             * @param groupId the group ID
17465             * @param categoryId the category ID
17466             * @param threadId the thread ID
17467             * @param status the status
17468             * @param start the lower bound of the range of message-boards messages
17469             * @param end the upper bound of the range of message-boards messages (not inclusive)
17470             * @return the range of matching message-boards messages that the user has permission to view
17471             * @throws SystemException if a system exception occurred
17472             */
17473            @Override
17474            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17475                    long threadId, int status, int start, int end)
17476                    throws SystemException {
17477                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17478                            start, end, null);
17479            }
17480    
17481            /**
17482             * 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;.
17483             *
17484             * <p>
17485             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17486             * </p>
17487             *
17488             * @param groupId the group ID
17489             * @param categoryId the category ID
17490             * @param threadId the thread ID
17491             * @param status the status
17492             * @param start the lower bound of the range of message-boards messages
17493             * @param end the upper bound of the range of message-boards messages (not inclusive)
17494             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17495             * @return the ordered range of matching message-boards messages that the user has permission to view
17496             * @throws SystemException if a system exception occurred
17497             */
17498            @Override
17499            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17500                    long threadId, int status, int start, int end,
17501                    OrderByComparator orderByComparator) throws SystemException {
17502                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17503                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17504                                    end, orderByComparator);
17505                    }
17506    
17507                    StringBundler query = null;
17508    
17509                    if (orderByComparator != null) {
17510                            query = new StringBundler(6 +
17511                                            (orderByComparator.getOrderByFields().length * 3));
17512                    }
17513                    else {
17514                            query = new StringBundler(6);
17515                    }
17516    
17517                    if (getDB().isSupportsInlineDistinct()) {
17518                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17519                    }
17520                    else {
17521                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17522                    }
17523    
17524                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17525    
17526                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17527    
17528                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17529    
17530                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17531    
17532                    if (!getDB().isSupportsInlineDistinct()) {
17533                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17534                    }
17535    
17536                    if (orderByComparator != null) {
17537                            if (getDB().isSupportsInlineDistinct()) {
17538                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17539                                            orderByComparator, true);
17540                            }
17541                            else {
17542                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17543                                            orderByComparator, true);
17544                            }
17545                    }
17546                    else {
17547                            if (getDB().isSupportsInlineDistinct()) {
17548                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17549                            }
17550                            else {
17551                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17552                            }
17553                    }
17554    
17555                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17556                                    MBMessage.class.getName(),
17557                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17558    
17559                    Session session = null;
17560    
17561                    try {
17562                            session = openSession();
17563    
17564                            SQLQuery q = session.createSQLQuery(sql);
17565    
17566                            if (getDB().isSupportsInlineDistinct()) {
17567                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17568                            }
17569                            else {
17570                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17571                            }
17572    
17573                            QueryPos qPos = QueryPos.getInstance(q);
17574    
17575                            qPos.add(groupId);
17576    
17577                            qPos.add(categoryId);
17578    
17579                            qPos.add(threadId);
17580    
17581                            qPos.add(status);
17582    
17583                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17584                    }
17585                    catch (Exception e) {
17586                            throw processException(e);
17587                    }
17588                    finally {
17589                            closeSession(session);
17590                    }
17591            }
17592    
17593            /**
17594             * 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;.
17595             *
17596             * @param messageId the primary key of the current message-boards message
17597             * @param groupId the group ID
17598             * @param categoryId the category ID
17599             * @param threadId the thread ID
17600             * @param status the status
17601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17602             * @return the previous, current, and next message-boards message
17603             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17604             * @throws SystemException if a system exception occurred
17605             */
17606            @Override
17607            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17608                    long groupId, long categoryId, long threadId, int status,
17609                    OrderByComparator orderByComparator)
17610                    throws NoSuchMessageException, SystemException {
17611                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17612                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17613                                    threadId, status, orderByComparator);
17614                    }
17615    
17616                    MBMessage mbMessage = findByPrimaryKey(messageId);
17617    
17618                    Session session = null;
17619    
17620                    try {
17621                            session = openSession();
17622    
17623                            MBMessage[] array = new MBMessageImpl[3];
17624    
17625                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17626                                            groupId, categoryId, threadId, status, orderByComparator,
17627                                            true);
17628    
17629                            array[1] = mbMessage;
17630    
17631                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17632                                            groupId, categoryId, threadId, status, orderByComparator,
17633                                            false);
17634    
17635                            return array;
17636                    }
17637                    catch (Exception e) {
17638                            throw processException(e);
17639                    }
17640                    finally {
17641                            closeSession(session);
17642                    }
17643            }
17644    
17645            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17646                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17647                    int status, OrderByComparator orderByComparator, boolean previous) {
17648                    StringBundler query = null;
17649    
17650                    if (orderByComparator != null) {
17651                            query = new StringBundler(6 +
17652                                            (orderByComparator.getOrderByFields().length * 6));
17653                    }
17654                    else {
17655                            query = new StringBundler(3);
17656                    }
17657    
17658                    if (getDB().isSupportsInlineDistinct()) {
17659                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17660                    }
17661                    else {
17662                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17663                    }
17664    
17665                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17666    
17667                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17668    
17669                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17670    
17671                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17672    
17673                    if (!getDB().isSupportsInlineDistinct()) {
17674                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17675                    }
17676    
17677                    if (orderByComparator != null) {
17678                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17679    
17680                            if (orderByConditionFields.length > 0) {
17681                                    query.append(WHERE_AND);
17682                            }
17683    
17684                            for (int i = 0; i < orderByConditionFields.length; i++) {
17685                                    if (getDB().isSupportsInlineDistinct()) {
17686                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17687                                    }
17688                                    else {
17689                                            query.append(_ORDER_BY_ENTITY_TABLE);
17690                                    }
17691    
17692                                    query.append(orderByConditionFields[i]);
17693    
17694                                    if ((i + 1) < orderByConditionFields.length) {
17695                                            if (orderByComparator.isAscending() ^ previous) {
17696                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17697                                            }
17698                                            else {
17699                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17700                                            }
17701                                    }
17702                                    else {
17703                                            if (orderByComparator.isAscending() ^ previous) {
17704                                                    query.append(WHERE_GREATER_THAN);
17705                                            }
17706                                            else {
17707                                                    query.append(WHERE_LESSER_THAN);
17708                                            }
17709                                    }
17710                            }
17711    
17712                            query.append(ORDER_BY_CLAUSE);
17713    
17714                            String[] orderByFields = orderByComparator.getOrderByFields();
17715    
17716                            for (int i = 0; i < orderByFields.length; i++) {
17717                                    if (getDB().isSupportsInlineDistinct()) {
17718                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17719                                    }
17720                                    else {
17721                                            query.append(_ORDER_BY_ENTITY_TABLE);
17722                                    }
17723    
17724                                    query.append(orderByFields[i]);
17725    
17726                                    if ((i + 1) < orderByFields.length) {
17727                                            if (orderByComparator.isAscending() ^ previous) {
17728                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17729                                            }
17730                                            else {
17731                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17732                                            }
17733                                    }
17734                                    else {
17735                                            if (orderByComparator.isAscending() ^ previous) {
17736                                                    query.append(ORDER_BY_ASC);
17737                                            }
17738                                            else {
17739                                                    query.append(ORDER_BY_DESC);
17740                                            }
17741                                    }
17742                            }
17743                    }
17744                    else {
17745                            if (getDB().isSupportsInlineDistinct()) {
17746                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17747                            }
17748                            else {
17749                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17750                            }
17751                    }
17752    
17753                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17754                                    MBMessage.class.getName(),
17755                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17756    
17757                    SQLQuery q = session.createSQLQuery(sql);
17758    
17759                    q.setFirstResult(0);
17760                    q.setMaxResults(2);
17761    
17762                    if (getDB().isSupportsInlineDistinct()) {
17763                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17764                    }
17765                    else {
17766                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17767                    }
17768    
17769                    QueryPos qPos = QueryPos.getInstance(q);
17770    
17771                    qPos.add(groupId);
17772    
17773                    qPos.add(categoryId);
17774    
17775                    qPos.add(threadId);
17776    
17777                    qPos.add(status);
17778    
17779                    if (orderByComparator != null) {
17780                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17781    
17782                            for (Object value : values) {
17783                                    qPos.add(value);
17784                            }
17785                    }
17786    
17787                    List<MBMessage> list = q.list();
17788    
17789                    if (list.size() == 2) {
17790                            return list.get(1);
17791                    }
17792                    else {
17793                            return null;
17794                    }
17795            }
17796    
17797            /**
17798             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
17799             *
17800             * @param groupId the group ID
17801             * @param categoryId the category ID
17802             * @param threadId the thread ID
17803             * @param status the status
17804             * @throws SystemException if a system exception occurred
17805             */
17806            @Override
17807            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
17808                    int status) throws SystemException {
17809                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
17810                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17811                            remove(mbMessage);
17812                    }
17813            }
17814    
17815            /**
17816             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17817             *
17818             * @param groupId the group ID
17819             * @param categoryId the category ID
17820             * @param threadId the thread ID
17821             * @param status the status
17822             * @return the number of matching message-boards messages
17823             * @throws SystemException if a system exception occurred
17824             */
17825            @Override
17826            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17827                    int status) throws SystemException {
17828                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
17829    
17830                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17831    
17832                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17833                                    this);
17834    
17835                    if (count == null) {
17836                            StringBundler query = new StringBundler(5);
17837    
17838                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17839    
17840                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17841    
17842                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17843    
17844                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17845    
17846                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17847    
17848                            String sql = query.toString();
17849    
17850                            Session session = null;
17851    
17852                            try {
17853                                    session = openSession();
17854    
17855                                    Query q = session.createQuery(sql);
17856    
17857                                    QueryPos qPos = QueryPos.getInstance(q);
17858    
17859                                    qPos.add(groupId);
17860    
17861                                    qPos.add(categoryId);
17862    
17863                                    qPos.add(threadId);
17864    
17865                                    qPos.add(status);
17866    
17867                                    count = (Long)q.uniqueResult();
17868    
17869                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17870                            }
17871                            catch (Exception e) {
17872                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17873    
17874                                    throw processException(e);
17875                            }
17876                            finally {
17877                                    closeSession(session);
17878                            }
17879                    }
17880    
17881                    return count.intValue();
17882            }
17883    
17884            /**
17885             * 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;.
17886             *
17887             * @param groupId the group ID
17888             * @param categoryId the category ID
17889             * @param threadId the thread ID
17890             * @param status the status
17891             * @return the number of matching message-boards messages that the user has permission to view
17892             * @throws SystemException if a system exception occurred
17893             */
17894            @Override
17895            public int filterCountByG_C_T_S(long groupId, long categoryId,
17896                    long threadId, int status) throws SystemException {
17897                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17898                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17899                    }
17900    
17901                    StringBundler query = new StringBundler(5);
17902    
17903                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17904    
17905                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17906    
17907                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17908    
17909                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17910    
17911                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17912    
17913                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17914                                    MBMessage.class.getName(),
17915                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17916    
17917                    Session session = null;
17918    
17919                    try {
17920                            session = openSession();
17921    
17922                            SQLQuery q = session.createSQLQuery(sql);
17923    
17924                            q.addScalar(COUNT_COLUMN_NAME,
17925                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17926    
17927                            QueryPos qPos = QueryPos.getInstance(q);
17928    
17929                            qPos.add(groupId);
17930    
17931                            qPos.add(categoryId);
17932    
17933                            qPos.add(threadId);
17934    
17935                            qPos.add(status);
17936    
17937                            Long count = (Long)q.uniqueResult();
17938    
17939                            return count.intValue();
17940                    }
17941                    catch (Exception e) {
17942                            throw processException(e);
17943                    }
17944                    finally {
17945                            closeSession(session);
17946                    }
17947            }
17948    
17949            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17950            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17951            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17952            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17953            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17954                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17955                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
17956                            new String[] {
17957                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17958                                    Integer.class.getName(),
17959                                    
17960                            Integer.class.getName(), Integer.class.getName(),
17961                                    OrderByComparator.class.getName()
17962                            });
17963            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
17964                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17965                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17966                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
17967                            new String[] {
17968                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17969                                    Integer.class.getName()
17970                            },
17971                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
17972                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17973                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
17974                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17975                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17976            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17977                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17978                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
17979                            new String[] {
17980                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17981                                    Integer.class.getName()
17982                            });
17983    
17984            /**
17985             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17986             *
17987             * @param userId the user ID
17988             * @param classNameId the class name ID
17989             * @param classPK the class p k
17990             * @param status the status
17991             * @return the matching message-boards messages
17992             * @throws SystemException if a system exception occurred
17993             */
17994            @Override
17995            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17996                    long classPK, int status) throws SystemException {
17997                    return findByU_C_C_S(userId, classNameId, classPK, status,
17998                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17999            }
18000    
18001            /**
18002             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18003             *
18004             * <p>
18005             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
18006             * </p>
18007             *
18008             * @param userId the user ID
18009             * @param classNameId the class name ID
18010             * @param classPK the class p k
18011             * @param status the status
18012             * @param start the lower bound of the range of message-boards messages
18013             * @param end the upper bound of the range of message-boards messages (not inclusive)
18014             * @return the range of matching message-boards messages
18015             * @throws SystemException if a system exception occurred
18016             */
18017            @Override
18018            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18019                    long classPK, int status, int start, int end) throws SystemException {
18020                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18021                            null);
18022            }
18023    
18024            /**
18025             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18026             *
18027             * <p>
18028             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
18029             * </p>
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             * @param start the lower bound of the range of message-boards messages
18036             * @param end the upper bound of the range of message-boards messages (not inclusive)
18037             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18038             * @return the ordered range of matching message-boards messages
18039             * @throws SystemException if a system exception occurred
18040             */
18041            @Override
18042            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18043                    long classPK, int status, int start, int end,
18044                    OrderByComparator orderByComparator) throws SystemException {
18045                    boolean pagination = true;
18046                    FinderPath finderPath = null;
18047                    Object[] finderArgs = null;
18048    
18049                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18050                                    (orderByComparator == null)) {
18051                            pagination = false;
18052                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18053                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18054                    }
18055                    else {
18056                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18057                            finderArgs = new Object[] {
18058                                            userId, classNameId, classPK, status,
18059                                            
18060                                            start, end, orderByComparator
18061                                    };
18062                    }
18063    
18064                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
18065                                    finderArgs, this);
18066    
18067                    if ((list != null) && !list.isEmpty()) {
18068                            for (MBMessage mbMessage : list) {
18069                                    if ((userId != mbMessage.getUserId()) ||
18070                                                    (classNameId != mbMessage.getClassNameId()) ||
18071                                                    (classPK != mbMessage.getClassPK()) ||
18072                                                    (status != mbMessage.getStatus())) {
18073                                            list = null;
18074    
18075                                            break;
18076                                    }
18077                            }
18078                    }
18079    
18080                    if (list == null) {
18081                            StringBundler query = null;
18082    
18083                            if (orderByComparator != null) {
18084                                    query = new StringBundler(6 +
18085                                                    (orderByComparator.getOrderByFields().length * 3));
18086                            }
18087                            else {
18088                                    query = new StringBundler(6);
18089                            }
18090    
18091                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18092    
18093                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18094    
18095                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18096    
18097                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18098    
18099                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18100    
18101                            if (orderByComparator != null) {
18102                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18103                                            orderByComparator);
18104                            }
18105                            else
18106                             if (pagination) {
18107                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18108                            }
18109    
18110                            String sql = query.toString();
18111    
18112                            Session session = null;
18113    
18114                            try {
18115                                    session = openSession();
18116    
18117                                    Query q = session.createQuery(sql);
18118    
18119                                    QueryPos qPos = QueryPos.getInstance(q);
18120    
18121                                    qPos.add(userId);
18122    
18123                                    qPos.add(classNameId);
18124    
18125                                    qPos.add(classPK);
18126    
18127                                    qPos.add(status);
18128    
18129                                    if (!pagination) {
18130                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18131                                                            start, end, false);
18132    
18133                                            Collections.sort(list);
18134    
18135                                            list = new UnmodifiableList<MBMessage>(list);
18136                                    }
18137                                    else {
18138                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18139                                                            start, end);
18140                                    }
18141    
18142                                    cacheResult(list);
18143    
18144                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18145                            }
18146                            catch (Exception e) {
18147                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18148    
18149                                    throw processException(e);
18150                            }
18151                            finally {
18152                                    closeSession(session);
18153                            }
18154                    }
18155    
18156                    return list;
18157            }
18158    
18159            /**
18160             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18161             *
18162             * @param userId the user ID
18163             * @param classNameId the class name ID
18164             * @param classPK the class p k
18165             * @param status the status
18166             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18167             * @return the first matching message-boards message
18168             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
18169             * @throws SystemException if a system exception occurred
18170             */
18171            @Override
18172            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18173                    long classPK, int status, OrderByComparator orderByComparator)
18174                    throws NoSuchMessageException, SystemException {
18175                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18176                                    classPK, status, orderByComparator);
18177    
18178                    if (mbMessage != null) {
18179                            return mbMessage;
18180                    }
18181    
18182                    StringBundler msg = new StringBundler(10);
18183    
18184                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18185    
18186                    msg.append("userId=");
18187                    msg.append(userId);
18188    
18189                    msg.append(", classNameId=");
18190                    msg.append(classNameId);
18191    
18192                    msg.append(", classPK=");
18193                    msg.append(classPK);
18194    
18195                    msg.append(", status=");
18196                    msg.append(status);
18197    
18198                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18199    
18200                    throw new NoSuchMessageException(msg.toString());
18201            }
18202    
18203            /**
18204             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18205             *
18206             * @param userId the user ID
18207             * @param classNameId the class name ID
18208             * @param classPK the class p k
18209             * @param status the status
18210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18211             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18212             * @throws SystemException if a system exception occurred
18213             */
18214            @Override
18215            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18216                    long classPK, int status, OrderByComparator orderByComparator)
18217                    throws SystemException {
18218                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18219                                    status, 0, 1, orderByComparator);
18220    
18221                    if (!list.isEmpty()) {
18222                            return list.get(0);
18223                    }
18224    
18225                    return null;
18226            }
18227    
18228            /**
18229             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18230             *
18231             * @param userId the user ID
18232             * @param classNameId the class name ID
18233             * @param classPK the class p k
18234             * @param status the status
18235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18236             * @return the last matching message-boards message
18237             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
18238             * @throws SystemException if a system exception occurred
18239             */
18240            @Override
18241            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18242                    long classPK, int status, OrderByComparator orderByComparator)
18243                    throws NoSuchMessageException, SystemException {
18244                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18245                                    status, orderByComparator);
18246    
18247                    if (mbMessage != null) {
18248                            return mbMessage;
18249                    }
18250    
18251                    StringBundler msg = new StringBundler(10);
18252    
18253                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18254    
18255                    msg.append("userId=");
18256                    msg.append(userId);
18257    
18258                    msg.append(", classNameId=");
18259                    msg.append(classNameId);
18260    
18261                    msg.append(", classPK=");
18262                    msg.append(classPK);
18263    
18264                    msg.append(", status=");
18265                    msg.append(status);
18266    
18267                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18268    
18269                    throw new NoSuchMessageException(msg.toString());
18270            }
18271    
18272            /**
18273             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18274             *
18275             * @param userId the user ID
18276             * @param classNameId the class name ID
18277             * @param classPK the class p k
18278             * @param status the status
18279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18280             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18281             * @throws SystemException if a system exception occurred
18282             */
18283            @Override
18284            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18285                    long classPK, int status, OrderByComparator orderByComparator)
18286                    throws SystemException {
18287                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18288    
18289                    if (count == 0) {
18290                            return null;
18291                    }
18292    
18293                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18294                                    status, count - 1, count, orderByComparator);
18295    
18296                    if (!list.isEmpty()) {
18297                            return list.get(0);
18298                    }
18299    
18300                    return null;
18301            }
18302    
18303            /**
18304             * 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;.
18305             *
18306             * @param messageId the primary key of the current message-boards message
18307             * @param userId the user ID
18308             * @param classNameId the class name ID
18309             * @param classPK the class p k
18310             * @param status the status
18311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18312             * @return the previous, current, and next message-boards message
18313             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18314             * @throws SystemException if a system exception occurred
18315             */
18316            @Override
18317            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18318                    long classNameId, long classPK, int status,
18319                    OrderByComparator orderByComparator)
18320                    throws NoSuchMessageException, SystemException {
18321                    MBMessage mbMessage = findByPrimaryKey(messageId);
18322    
18323                    Session session = null;
18324    
18325                    try {
18326                            session = openSession();
18327    
18328                            MBMessage[] array = new MBMessageImpl[3];
18329    
18330                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18331                                            classNameId, classPK, status, orderByComparator, true);
18332    
18333                            array[1] = mbMessage;
18334    
18335                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18336                                            classNameId, classPK, status, orderByComparator, false);
18337    
18338                            return array;
18339                    }
18340                    catch (Exception e) {
18341                            throw processException(e);
18342                    }
18343                    finally {
18344                            closeSession(session);
18345                    }
18346            }
18347    
18348            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18349                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18350                    int status, OrderByComparator orderByComparator, boolean previous) {
18351                    StringBundler query = null;
18352    
18353                    if (orderByComparator != null) {
18354                            query = new StringBundler(6 +
18355                                            (orderByComparator.getOrderByFields().length * 6));
18356                    }
18357                    else {
18358                            query = new StringBundler(3);
18359                    }
18360    
18361                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18362    
18363                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18364    
18365                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18366    
18367                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18368    
18369                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18370    
18371                    if (orderByComparator != null) {
18372                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18373    
18374                            if (orderByConditionFields.length > 0) {
18375                                    query.append(WHERE_AND);
18376                            }
18377    
18378                            for (int i = 0; i < orderByConditionFields.length; i++) {
18379                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18380                                    query.append(orderByConditionFields[i]);
18381    
18382                                    if ((i + 1) < orderByConditionFields.length) {
18383                                            if (orderByComparator.isAscending() ^ previous) {
18384                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18385                                            }
18386                                            else {
18387                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18388                                            }
18389                                    }
18390                                    else {
18391                                            if (orderByComparator.isAscending() ^ previous) {
18392                                                    query.append(WHERE_GREATER_THAN);
18393                                            }
18394                                            else {
18395                                                    query.append(WHERE_LESSER_THAN);
18396                                            }
18397                                    }
18398                            }
18399    
18400                            query.append(ORDER_BY_CLAUSE);
18401    
18402                            String[] orderByFields = orderByComparator.getOrderByFields();
18403    
18404                            for (int i = 0; i < orderByFields.length; i++) {
18405                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18406                                    query.append(orderByFields[i]);
18407    
18408                                    if ((i + 1) < orderByFields.length) {
18409                                            if (orderByComparator.isAscending() ^ previous) {
18410                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18411                                            }
18412                                            else {
18413                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18414                                            }
18415                                    }
18416                                    else {
18417                                            if (orderByComparator.isAscending() ^ previous) {
18418                                                    query.append(ORDER_BY_ASC);
18419                                            }
18420                                            else {
18421                                                    query.append(ORDER_BY_DESC);
18422                                            }
18423                                    }
18424                            }
18425                    }
18426                    else {
18427                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18428                    }
18429    
18430                    String sql = query.toString();
18431    
18432                    Query q = session.createQuery(sql);
18433    
18434                    q.setFirstResult(0);
18435                    q.setMaxResults(2);
18436    
18437                    QueryPos qPos = QueryPos.getInstance(q);
18438    
18439                    qPos.add(userId);
18440    
18441                    qPos.add(classNameId);
18442    
18443                    qPos.add(classPK);
18444    
18445                    qPos.add(status);
18446    
18447                    if (orderByComparator != null) {
18448                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18449    
18450                            for (Object value : values) {
18451                                    qPos.add(value);
18452                            }
18453                    }
18454    
18455                    List<MBMessage> list = q.list();
18456    
18457                    if (list.size() == 2) {
18458                            return list.get(1);
18459                    }
18460                    else {
18461                            return null;
18462                    }
18463            }
18464    
18465            /**
18466             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18467             *
18468             * @param userId the user ID
18469             * @param classNameId the class name ID
18470             * @param classPK the class p k
18471             * @param status the status
18472             * @throws SystemException if a system exception occurred
18473             */
18474            @Override
18475            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18476                    int status) throws SystemException {
18477                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18478                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18479                            remove(mbMessage);
18480                    }
18481            }
18482    
18483            /**
18484             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18485             *
18486             * @param userId the user ID
18487             * @param classNameId the class name ID
18488             * @param classPK the class p k
18489             * @param status the status
18490             * @return the number of matching message-boards messages
18491             * @throws SystemException if a system exception occurred
18492             */
18493            @Override
18494            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18495                    int status) throws SystemException {
18496                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18497    
18498                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18499    
18500                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18501                                    this);
18502    
18503                    if (count == null) {
18504                            StringBundler query = new StringBundler(5);
18505    
18506                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18507    
18508                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18509    
18510                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18511    
18512                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18513    
18514                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18515    
18516                            String sql = query.toString();
18517    
18518                            Session session = null;
18519    
18520                            try {
18521                                    session = openSession();
18522    
18523                                    Query q = session.createQuery(sql);
18524    
18525                                    QueryPos qPos = QueryPos.getInstance(q);
18526    
18527                                    qPos.add(userId);
18528    
18529                                    qPos.add(classNameId);
18530    
18531                                    qPos.add(classPK);
18532    
18533                                    qPos.add(status);
18534    
18535                                    count = (Long)q.uniqueResult();
18536    
18537                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18538                            }
18539                            catch (Exception e) {
18540                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18541    
18542                                    throw processException(e);
18543                            }
18544                            finally {
18545                                    closeSession(session);
18546                            }
18547                    }
18548    
18549                    return count.intValue();
18550            }
18551    
18552            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18553            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18554            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18555            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18556    
18557            public MBMessagePersistenceImpl() {
18558                    setModelClass(MBMessage.class);
18559            }
18560    
18561            /**
18562             * Caches the message-boards message in the entity cache if it is enabled.
18563             *
18564             * @param mbMessage the message-boards message
18565             */
18566            @Override
18567            public void cacheResult(MBMessage mbMessage) {
18568                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18569                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18570    
18571                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18572                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18573                            mbMessage);
18574    
18575                    mbMessage.resetOriginalValues();
18576            }
18577    
18578            /**
18579             * Caches the message-boards messages in the entity cache if it is enabled.
18580             *
18581             * @param mbMessages the message-boards messages
18582             */
18583            @Override
18584            public void cacheResult(List<MBMessage> mbMessages) {
18585                    for (MBMessage mbMessage : mbMessages) {
18586                            if (EntityCacheUtil.getResult(
18587                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18588                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18589                                    cacheResult(mbMessage);
18590                            }
18591                            else {
18592                                    mbMessage.resetOriginalValues();
18593                            }
18594                    }
18595            }
18596    
18597            /**
18598             * Clears the cache for all message-boards messages.
18599             *
18600             * <p>
18601             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18602             * </p>
18603             */
18604            @Override
18605            public void clearCache() {
18606                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
18607                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
18608                    }
18609    
18610                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
18611    
18612                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18613                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18614                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18615            }
18616    
18617            /**
18618             * Clears the cache for the message-boards message.
18619             *
18620             * <p>
18621             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18622             * </p>
18623             */
18624            @Override
18625            public void clearCache(MBMessage mbMessage) {
18626                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18627                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18628    
18629                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18630                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18631    
18632                    clearUniqueFindersCache(mbMessage);
18633            }
18634    
18635            @Override
18636            public void clearCache(List<MBMessage> mbMessages) {
18637                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18638                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18639    
18640                    for (MBMessage mbMessage : mbMessages) {
18641                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18642                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18643    
18644                            clearUniqueFindersCache(mbMessage);
18645                    }
18646            }
18647    
18648            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
18649                    if (mbMessage.isNew()) {
18650                            Object[] args = new Object[] {
18651                                            mbMessage.getUuid(), mbMessage.getGroupId()
18652                                    };
18653    
18654                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18655                                    Long.valueOf(1));
18656                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18657                                    mbMessage);
18658                    }
18659                    else {
18660                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18661    
18662                            if ((mbMessageModelImpl.getColumnBitmask() &
18663                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18664                                    Object[] args = new Object[] {
18665                                                    mbMessage.getUuid(), mbMessage.getGroupId()
18666                                            };
18667    
18668                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18669                                            Long.valueOf(1));
18670                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18671                                            mbMessage);
18672                            }
18673                    }
18674            }
18675    
18676            protected void clearUniqueFindersCache(MBMessage mbMessage) {
18677                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18678    
18679                    Object[] args = new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() };
18680    
18681                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18682                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18683    
18684                    if ((mbMessageModelImpl.getColumnBitmask() &
18685                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18686                            args = new Object[] {
18687                                            mbMessageModelImpl.getOriginalUuid(),
18688                                            mbMessageModelImpl.getOriginalGroupId()
18689                                    };
18690    
18691                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18692                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18693                    }
18694            }
18695    
18696            /**
18697             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18698             *
18699             * @param messageId the primary key for the new message-boards message
18700             * @return the new message-boards message
18701             */
18702            @Override
18703            public MBMessage create(long messageId) {
18704                    MBMessage mbMessage = new MBMessageImpl();
18705    
18706                    mbMessage.setNew(true);
18707                    mbMessage.setPrimaryKey(messageId);
18708    
18709                    String uuid = PortalUUIDUtil.generate();
18710    
18711                    mbMessage.setUuid(uuid);
18712    
18713                    return mbMessage;
18714            }
18715    
18716            /**
18717             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18718             *
18719             * @param messageId the primary key of the message-boards message
18720             * @return the message-boards message that was removed
18721             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18722             * @throws SystemException if a system exception occurred
18723             */
18724            @Override
18725            public MBMessage remove(long messageId)
18726                    throws NoSuchMessageException, SystemException {
18727                    return remove((Serializable)messageId);
18728            }
18729    
18730            /**
18731             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18732             *
18733             * @param primaryKey the primary key of the message-boards message
18734             * @return the message-boards message that was removed
18735             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18736             * @throws SystemException if a system exception occurred
18737             */
18738            @Override
18739            public MBMessage remove(Serializable primaryKey)
18740                    throws NoSuchMessageException, SystemException {
18741                    Session session = null;
18742    
18743                    try {
18744                            session = openSession();
18745    
18746                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18747                                            primaryKey);
18748    
18749                            if (mbMessage == null) {
18750                                    if (_log.isWarnEnabled()) {
18751                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18752                                    }
18753    
18754                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18755                                            primaryKey);
18756                            }
18757    
18758                            return remove(mbMessage);
18759                    }
18760                    catch (NoSuchMessageException nsee) {
18761                            throw nsee;
18762                    }
18763                    catch (Exception e) {
18764                            throw processException(e);
18765                    }
18766                    finally {
18767                            closeSession(session);
18768                    }
18769            }
18770    
18771            @Override
18772            protected MBMessage removeImpl(MBMessage mbMessage)
18773                    throws SystemException {
18774                    mbMessage = toUnwrappedModel(mbMessage);
18775    
18776                    Session session = null;
18777    
18778                    try {
18779                            session = openSession();
18780    
18781                            if (!session.contains(mbMessage)) {
18782                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18783                                                    mbMessage.getPrimaryKeyObj());
18784                            }
18785    
18786                            if (mbMessage != null) {
18787                                    session.delete(mbMessage);
18788                            }
18789                    }
18790                    catch (Exception e) {
18791                            throw processException(e);
18792                    }
18793                    finally {
18794                            closeSession(session);
18795                    }
18796    
18797                    if (mbMessage != null) {
18798                            clearCache(mbMessage);
18799                    }
18800    
18801                    return mbMessage;
18802            }
18803    
18804            @Override
18805            public MBMessage updateImpl(
18806                    com.liferay.portlet.messageboards.model.MBMessage mbMessage)
18807                    throws SystemException {
18808                    mbMessage = toUnwrappedModel(mbMessage);
18809    
18810                    boolean isNew = mbMessage.isNew();
18811    
18812                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18813    
18814                    if (Validator.isNull(mbMessage.getUuid())) {
18815                            String uuid = PortalUUIDUtil.generate();
18816    
18817                            mbMessage.setUuid(uuid);
18818                    }
18819    
18820                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18821    
18822                    if (userId > 0) {
18823                            long companyId = mbMessage.getCompanyId();
18824    
18825                            long groupId = mbMessage.getGroupId();
18826    
18827                            long messageId = 0;
18828    
18829                            if (!isNew) {
18830                                    messageId = mbMessage.getPrimaryKey();
18831                            }
18832    
18833                            try {
18834                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
18835                                                    userId,
18836                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
18837                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18838                                                    mbMessage.getSubject(), null));
18839                            }
18840                            catch (SanitizerException se) {
18841                                    throw new SystemException(se);
18842                            }
18843                    }
18844    
18845                    Session session = null;
18846    
18847                    try {
18848                            session = openSession();
18849    
18850                            if (mbMessage.isNew()) {
18851                                    session.save(mbMessage);
18852    
18853                                    mbMessage.setNew(false);
18854                            }
18855                            else {
18856                                    session.merge(mbMessage);
18857                            }
18858                    }
18859                    catch (Exception e) {
18860                            throw processException(e);
18861                    }
18862                    finally {
18863                            closeSession(session);
18864                    }
18865    
18866                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18867    
18868                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
18869                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18870                    }
18871    
18872                    else {
18873                            if ((mbMessageModelImpl.getColumnBitmask() &
18874                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18875                                    Object[] args = new Object[] {
18876                                                    mbMessageModelImpl.getOriginalUuid()
18877                                            };
18878    
18879                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18880                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18881                                            args);
18882    
18883                                    args = new Object[] { mbMessageModelImpl.getUuid() };
18884    
18885                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18886                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18887                                            args);
18888                            }
18889    
18890                            if ((mbMessageModelImpl.getColumnBitmask() &
18891                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18892                                    Object[] args = new Object[] {
18893                                                    mbMessageModelImpl.getOriginalUuid(),
18894                                                    mbMessageModelImpl.getOriginalCompanyId()
18895                                            };
18896    
18897                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18898                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18899                                            args);
18900    
18901                                    args = new Object[] {
18902                                                    mbMessageModelImpl.getUuid(),
18903                                                    mbMessageModelImpl.getCompanyId()
18904                                            };
18905    
18906                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18907                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18908                                            args);
18909                            }
18910    
18911                            if ((mbMessageModelImpl.getColumnBitmask() &
18912                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
18913                                    Object[] args = new Object[] {
18914                                                    mbMessageModelImpl.getOriginalGroupId()
18915                                            };
18916    
18917                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18918                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18919                                            args);
18920    
18921                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
18922    
18923                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18924                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18925                                            args);
18926                            }
18927    
18928                            if ((mbMessageModelImpl.getColumnBitmask() &
18929                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
18930                                    Object[] args = new Object[] {
18931                                                    mbMessageModelImpl.getOriginalCompanyId()
18932                                            };
18933    
18934                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18935                                            args);
18936                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18937                                            args);
18938    
18939                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
18940    
18941                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18942                                            args);
18943                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18944                                            args);
18945                            }
18946    
18947                            if ((mbMessageModelImpl.getColumnBitmask() &
18948                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
18949                                    Object[] args = new Object[] {
18950                                                    mbMessageModelImpl.getOriginalThreadId()
18951                                            };
18952    
18953                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18954                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18955                                            args);
18956    
18957                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18958    
18959                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18960                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18961                                            args);
18962                            }
18963    
18964                            if ((mbMessageModelImpl.getColumnBitmask() &
18965                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
18966                                    Object[] args = new Object[] {
18967                                                    mbMessageModelImpl.getOriginalThreadId()
18968                                            };
18969    
18970                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18971                                            args);
18972                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18973                                            args);
18974    
18975                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18976    
18977                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18978                                            args);
18979                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18980                                            args);
18981                            }
18982    
18983                            if ((mbMessageModelImpl.getColumnBitmask() &
18984                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
18985                                    Object[] args = new Object[] {
18986                                                    mbMessageModelImpl.getOriginalUserId()
18987                                            };
18988    
18989                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18990                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18991                                            args);
18992    
18993                                    args = new Object[] { mbMessageModelImpl.getUserId() };
18994    
18995                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18996                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18997                                            args);
18998                            }
18999    
19000                            if ((mbMessageModelImpl.getColumnBitmask() &
19001                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19002                                    Object[] args = new Object[] {
19003                                                    mbMessageModelImpl.getOriginalGroupId(),
19004                                                    mbMessageModelImpl.getOriginalUserId()
19005                                            };
19006    
19007                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19008                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19009                                            args);
19010    
19011                                    args = new Object[] {
19012                                                    mbMessageModelImpl.getGroupId(),
19013                                                    mbMessageModelImpl.getUserId()
19014                                            };
19015    
19016                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19017                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19018                                            args);
19019                            }
19020    
19021                            if ((mbMessageModelImpl.getColumnBitmask() &
19022                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19023                                    Object[] args = new Object[] {
19024                                                    mbMessageModelImpl.getOriginalGroupId(),
19025                                                    mbMessageModelImpl.getOriginalCategoryId()
19026                                            };
19027    
19028                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19029                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19030                                            args);
19031    
19032                                    args = new Object[] {
19033                                                    mbMessageModelImpl.getGroupId(),
19034                                                    mbMessageModelImpl.getCategoryId()
19035                                            };
19036    
19037                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19038                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19039                                            args);
19040                            }
19041    
19042                            if ((mbMessageModelImpl.getColumnBitmask() &
19043                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19044                                    Object[] args = new Object[] {
19045                                                    mbMessageModelImpl.getOriginalGroupId(),
19046                                                    mbMessageModelImpl.getOriginalStatus()
19047                                            };
19048    
19049                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19050                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19051                                            args);
19052    
19053                                    args = new Object[] {
19054                                                    mbMessageModelImpl.getGroupId(),
19055                                                    mbMessageModelImpl.getStatus()
19056                                            };
19057    
19058                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19059                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19060                                            args);
19061                            }
19062    
19063                            if ((mbMessageModelImpl.getColumnBitmask() &
19064                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19065                                    Object[] args = new Object[] {
19066                                                    mbMessageModelImpl.getOriginalCompanyId(),
19067                                                    mbMessageModelImpl.getOriginalStatus()
19068                                            };
19069    
19070                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19071                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19072                                            args);
19073    
19074                                    args = new Object[] {
19075                                                    mbMessageModelImpl.getCompanyId(),
19076                                                    mbMessageModelImpl.getStatus()
19077                                            };
19078    
19079                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19080                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19081                                            args);
19082                            }
19083    
19084                            if ((mbMessageModelImpl.getColumnBitmask() &
19085                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19086                                    Object[] args = new Object[] {
19087                                                    mbMessageModelImpl.getOriginalUserId(),
19088                                                    mbMessageModelImpl.getOriginalClassNameId()
19089                                            };
19090    
19091                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19092                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19093                                            args);
19094    
19095                                    args = new Object[] {
19096                                                    mbMessageModelImpl.getUserId(),
19097                                                    mbMessageModelImpl.getClassNameId()
19098                                            };
19099    
19100                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19101                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19102                                            args);
19103                            }
19104    
19105                            if ((mbMessageModelImpl.getColumnBitmask() &
19106                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19107                                    Object[] args = new Object[] {
19108                                                    mbMessageModelImpl.getOriginalClassNameId(),
19109                                                    mbMessageModelImpl.getOriginalClassPK()
19110                                            };
19111    
19112                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19113                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19114                                            args);
19115    
19116                                    args = new Object[] {
19117                                                    mbMessageModelImpl.getClassNameId(),
19118                                                    mbMessageModelImpl.getClassPK()
19119                                            };
19120    
19121                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19122                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19123                                            args);
19124                            }
19125    
19126                            if ((mbMessageModelImpl.getColumnBitmask() &
19127                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19128                                    Object[] args = new Object[] {
19129                                                    mbMessageModelImpl.getOriginalThreadId(),
19130                                                    mbMessageModelImpl.getOriginalParentMessageId()
19131                                            };
19132    
19133                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19134                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19135                                            args);
19136    
19137                                    args = new Object[] {
19138                                                    mbMessageModelImpl.getThreadId(),
19139                                                    mbMessageModelImpl.getParentMessageId()
19140                                            };
19141    
19142                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19143                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19144                                            args);
19145                            }
19146    
19147                            if ((mbMessageModelImpl.getColumnBitmask() &
19148                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19149                                    Object[] args = new Object[] {
19150                                                    mbMessageModelImpl.getOriginalThreadId(),
19151                                                    mbMessageModelImpl.getOriginalAnswer()
19152                                            };
19153    
19154                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19155                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19156                                            args);
19157    
19158                                    args = new Object[] {
19159                                                    mbMessageModelImpl.getThreadId(),
19160                                                    mbMessageModelImpl.getAnswer()
19161                                            };
19162    
19163                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19164                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19165                                            args);
19166                            }
19167    
19168                            if ((mbMessageModelImpl.getColumnBitmask() &
19169                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19170                                    Object[] args = new Object[] {
19171                                                    mbMessageModelImpl.getOriginalThreadId(),
19172                                                    mbMessageModelImpl.getOriginalStatus()
19173                                            };
19174    
19175                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19176                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19177                                            args);
19178    
19179                                    args = new Object[] {
19180                                                    mbMessageModelImpl.getThreadId(),
19181                                                    mbMessageModelImpl.getStatus()
19182                                            };
19183    
19184                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19185                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19186                                            args);
19187                            }
19188    
19189                            if ((mbMessageModelImpl.getColumnBitmask() &
19190                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19191                                    Object[] args = new Object[] {
19192                                                    mbMessageModelImpl.getOriginalThreadId(),
19193                                                    mbMessageModelImpl.getOriginalStatus()
19194                                            };
19195    
19196                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19197                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19198                                            args);
19199    
19200                                    args = new Object[] {
19201                                                    mbMessageModelImpl.getThreadId(),
19202                                                    mbMessageModelImpl.getStatus()
19203                                            };
19204    
19205                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19206                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19207                                            args);
19208                            }
19209    
19210                            if ((mbMessageModelImpl.getColumnBitmask() &
19211                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19212                                    Object[] args = new Object[] {
19213                                                    mbMessageModelImpl.getOriginalGroupId(),
19214                                                    mbMessageModelImpl.getOriginalUserId(),
19215                                                    mbMessageModelImpl.getOriginalStatus()
19216                                            };
19217    
19218                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19219                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19220                                            args);
19221    
19222                                    args = new Object[] {
19223                                                    mbMessageModelImpl.getGroupId(),
19224                                                    mbMessageModelImpl.getUserId(),
19225                                                    mbMessageModelImpl.getStatus()
19226                                            };
19227    
19228                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19229                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19230                                            args);
19231                            }
19232    
19233                            if ((mbMessageModelImpl.getColumnBitmask() &
19234                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19235                                    Object[] args = new Object[] {
19236                                                    mbMessageModelImpl.getOriginalGroupId(),
19237                                                    mbMessageModelImpl.getOriginalCategoryId(),
19238                                                    mbMessageModelImpl.getOriginalThreadId()
19239                                            };
19240    
19241                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19242                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19243                                            args);
19244    
19245                                    args = new Object[] {
19246                                                    mbMessageModelImpl.getGroupId(),
19247                                                    mbMessageModelImpl.getCategoryId(),
19248                                                    mbMessageModelImpl.getThreadId()
19249                                            };
19250    
19251                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19252                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19253                                            args);
19254                            }
19255    
19256                            if ((mbMessageModelImpl.getColumnBitmask() &
19257                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19258                                    Object[] args = new Object[] {
19259                                                    mbMessageModelImpl.getOriginalGroupId(),
19260                                                    mbMessageModelImpl.getOriginalCategoryId(),
19261                                                    mbMessageModelImpl.getOriginalStatus()
19262                                            };
19263    
19264                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19265                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19266                                            args);
19267    
19268                                    args = new Object[] {
19269                                                    mbMessageModelImpl.getGroupId(),
19270                                                    mbMessageModelImpl.getCategoryId(),
19271                                                    mbMessageModelImpl.getStatus()
19272                                            };
19273    
19274                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19275                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19276                                            args);
19277                            }
19278    
19279                            if ((mbMessageModelImpl.getColumnBitmask() &
19280                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19281                                    Object[] args = new Object[] {
19282                                                    mbMessageModelImpl.getOriginalUserId(),
19283                                                    mbMessageModelImpl.getOriginalClassNameId(),
19284                                                    mbMessageModelImpl.getOriginalClassPK()
19285                                            };
19286    
19287                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19288                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19289                                            args);
19290    
19291                                    args = new Object[] {
19292                                                    mbMessageModelImpl.getUserId(),
19293                                                    mbMessageModelImpl.getClassNameId(),
19294                                                    mbMessageModelImpl.getClassPK()
19295                                            };
19296    
19297                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19298                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19299                                            args);
19300                            }
19301    
19302                            if ((mbMessageModelImpl.getColumnBitmask() &
19303                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19304                                    Object[] args = new Object[] {
19305                                                    mbMessageModelImpl.getOriginalUserId(),
19306                                                    mbMessageModelImpl.getOriginalClassNameId(),
19307                                                    mbMessageModelImpl.getOriginalStatus()
19308                                            };
19309    
19310                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19311                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19312                                            args);
19313    
19314                                    args = new Object[] {
19315                                                    mbMessageModelImpl.getUserId(),
19316                                                    mbMessageModelImpl.getClassNameId(),
19317                                                    mbMessageModelImpl.getStatus()
19318                                            };
19319    
19320                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19321                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19322                                            args);
19323                            }
19324    
19325                            if ((mbMessageModelImpl.getColumnBitmask() &
19326                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19327                                    Object[] args = new Object[] {
19328                                                    mbMessageModelImpl.getOriginalClassNameId(),
19329                                                    mbMessageModelImpl.getOriginalClassPK(),
19330                                                    mbMessageModelImpl.getOriginalStatus()
19331                                            };
19332    
19333                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19334                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19335                                            args);
19336    
19337                                    args = new Object[] {
19338                                                    mbMessageModelImpl.getClassNameId(),
19339                                                    mbMessageModelImpl.getClassPK(),
19340                                                    mbMessageModelImpl.getStatus()
19341                                            };
19342    
19343                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19344                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19345                                            args);
19346                            }
19347    
19348                            if ((mbMessageModelImpl.getColumnBitmask() &
19349                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19350                                    Object[] args = new Object[] {
19351                                                    mbMessageModelImpl.getOriginalGroupId(),
19352                                                    mbMessageModelImpl.getOriginalCategoryId(),
19353                                                    mbMessageModelImpl.getOriginalThreadId(),
19354                                                    mbMessageModelImpl.getOriginalAnswer()
19355                                            };
19356    
19357                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19358                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19359                                            args);
19360    
19361                                    args = new Object[] {
19362                                                    mbMessageModelImpl.getGroupId(),
19363                                                    mbMessageModelImpl.getCategoryId(),
19364                                                    mbMessageModelImpl.getThreadId(),
19365                                                    mbMessageModelImpl.getAnswer()
19366                                            };
19367    
19368                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19369                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19370                                            args);
19371                            }
19372    
19373                            if ((mbMessageModelImpl.getColumnBitmask() &
19374                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19375                                    Object[] args = new Object[] {
19376                                                    mbMessageModelImpl.getOriginalGroupId(),
19377                                                    mbMessageModelImpl.getOriginalCategoryId(),
19378                                                    mbMessageModelImpl.getOriginalThreadId(),
19379                                                    mbMessageModelImpl.getOriginalStatus()
19380                                            };
19381    
19382                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19383                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19384                                            args);
19385    
19386                                    args = new Object[] {
19387                                                    mbMessageModelImpl.getGroupId(),
19388                                                    mbMessageModelImpl.getCategoryId(),
19389                                                    mbMessageModelImpl.getThreadId(),
19390                                                    mbMessageModelImpl.getStatus()
19391                                            };
19392    
19393                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19394                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19395                                            args);
19396                            }
19397    
19398                            if ((mbMessageModelImpl.getColumnBitmask() &
19399                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19400                                    Object[] args = new Object[] {
19401                                                    mbMessageModelImpl.getOriginalUserId(),
19402                                                    mbMessageModelImpl.getOriginalClassNameId(),
19403                                                    mbMessageModelImpl.getOriginalClassPK(),
19404                                                    mbMessageModelImpl.getOriginalStatus()
19405                                            };
19406    
19407                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19408                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19409                                            args);
19410    
19411                                    args = new Object[] {
19412                                                    mbMessageModelImpl.getUserId(),
19413                                                    mbMessageModelImpl.getClassNameId(),
19414                                                    mbMessageModelImpl.getClassPK(),
19415                                                    mbMessageModelImpl.getStatus()
19416                                            };
19417    
19418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19420                                            args);
19421                            }
19422                    }
19423    
19424                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19425                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
19426    
19427                    clearUniqueFindersCache(mbMessage);
19428                    cacheUniqueFindersCache(mbMessage);
19429    
19430                    return mbMessage;
19431            }
19432    
19433            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19434                    if (mbMessage instanceof MBMessageImpl) {
19435                            return mbMessage;
19436                    }
19437    
19438                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19439    
19440                    mbMessageImpl.setNew(mbMessage.isNew());
19441                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19442    
19443                    mbMessageImpl.setUuid(mbMessage.getUuid());
19444                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19445                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19446                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19447                    mbMessageImpl.setUserId(mbMessage.getUserId());
19448                    mbMessageImpl.setUserName(mbMessage.getUserName());
19449                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19450                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19451                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19452                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19453                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19454                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19455                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19456                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19457                    mbMessageImpl.setSubject(mbMessage.getSubject());
19458                    mbMessageImpl.setBody(mbMessage.getBody());
19459                    mbMessageImpl.setFormat(mbMessage.getFormat());
19460                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19461                    mbMessageImpl.setPriority(mbMessage.getPriority());
19462                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19463                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19464                    mbMessageImpl.setStatus(mbMessage.getStatus());
19465                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19466                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19467                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19468    
19469                    return mbMessageImpl;
19470            }
19471    
19472            /**
19473             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19474             *
19475             * @param primaryKey the primary key of the message-boards message
19476             * @return the message-boards message
19477             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19478             * @throws SystemException if a system exception occurred
19479             */
19480            @Override
19481            public MBMessage findByPrimaryKey(Serializable primaryKey)
19482                    throws NoSuchMessageException, SystemException {
19483                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19484    
19485                    if (mbMessage == null) {
19486                            if (_log.isWarnEnabled()) {
19487                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19488                            }
19489    
19490                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19491                                    primaryKey);
19492                    }
19493    
19494                    return mbMessage;
19495            }
19496    
19497            /**
19498             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
19499             *
19500             * @param messageId the primary key of the message-boards message
19501             * @return the message-boards message
19502             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19503             * @throws SystemException if a system exception occurred
19504             */
19505            @Override
19506            public MBMessage findByPrimaryKey(long messageId)
19507                    throws NoSuchMessageException, SystemException {
19508                    return findByPrimaryKey((Serializable)messageId);
19509            }
19510    
19511            /**
19512             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19513             *
19514             * @param primaryKey the primary key of the message-boards message
19515             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19516             * @throws SystemException if a system exception occurred
19517             */
19518            @Override
19519            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
19520                    throws SystemException {
19521                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19522                                    MBMessageImpl.class, primaryKey);
19523    
19524                    if (mbMessage == _nullMBMessage) {
19525                            return null;
19526                    }
19527    
19528                    if (mbMessage == null) {
19529                            Session session = null;
19530    
19531                            try {
19532                                    session = openSession();
19533    
19534                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19535                                                    primaryKey);
19536    
19537                                    if (mbMessage != null) {
19538                                            cacheResult(mbMessage);
19539                                    }
19540                                    else {
19541                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19542                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19543                                    }
19544                            }
19545                            catch (Exception e) {
19546                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19547                                            MBMessageImpl.class, primaryKey);
19548    
19549                                    throw processException(e);
19550                            }
19551                            finally {
19552                                    closeSession(session);
19553                            }
19554                    }
19555    
19556                    return mbMessage;
19557            }
19558    
19559            /**
19560             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19561             *
19562             * @param messageId the primary key of the message-boards message
19563             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19564             * @throws SystemException if a system exception occurred
19565             */
19566            @Override
19567            public MBMessage fetchByPrimaryKey(long messageId)
19568                    throws SystemException {
19569                    return fetchByPrimaryKey((Serializable)messageId);
19570            }
19571    
19572            /**
19573             * Returns all the message-boards messages.
19574             *
19575             * @return the message-boards messages
19576             * @throws SystemException if a system exception occurred
19577             */
19578            @Override
19579            public List<MBMessage> findAll() throws SystemException {
19580                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19581            }
19582    
19583            /**
19584             * Returns a range of all the message-boards messages.
19585             *
19586             * <p>
19587             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
19588             * </p>
19589             *
19590             * @param start the lower bound of the range of message-boards messages
19591             * @param end the upper bound of the range of message-boards messages (not inclusive)
19592             * @return the range of message-boards messages
19593             * @throws SystemException if a system exception occurred
19594             */
19595            @Override
19596            public List<MBMessage> findAll(int start, int end)
19597                    throws SystemException {
19598                    return findAll(start, end, null);
19599            }
19600    
19601            /**
19602             * Returns an ordered range of all the message-boards messages.
19603             *
19604             * <p>
19605             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
19606             * </p>
19607             *
19608             * @param start the lower bound of the range of message-boards messages
19609             * @param end the upper bound of the range of message-boards messages (not inclusive)
19610             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19611             * @return the ordered range of message-boards messages
19612             * @throws SystemException if a system exception occurred
19613             */
19614            @Override
19615            public List<MBMessage> findAll(int start, int end,
19616                    OrderByComparator orderByComparator) throws SystemException {
19617                    boolean pagination = true;
19618                    FinderPath finderPath = null;
19619                    Object[] finderArgs = null;
19620    
19621                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19622                                    (orderByComparator == null)) {
19623                            pagination = false;
19624                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19625                            finderArgs = FINDER_ARGS_EMPTY;
19626                    }
19627                    else {
19628                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19629                            finderArgs = new Object[] { start, end, orderByComparator };
19630                    }
19631    
19632                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19633                                    finderArgs, this);
19634    
19635                    if (list == null) {
19636                            StringBundler query = null;
19637                            String sql = null;
19638    
19639                            if (orderByComparator != null) {
19640                                    query = new StringBundler(2 +
19641                                                    (orderByComparator.getOrderByFields().length * 3));
19642    
19643                                    query.append(_SQL_SELECT_MBMESSAGE);
19644    
19645                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19646                                            orderByComparator);
19647    
19648                                    sql = query.toString();
19649                            }
19650                            else {
19651                                    sql = _SQL_SELECT_MBMESSAGE;
19652    
19653                                    if (pagination) {
19654                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
19655                                    }
19656                            }
19657    
19658                            Session session = null;
19659    
19660                            try {
19661                                    session = openSession();
19662    
19663                                    Query q = session.createQuery(sql);
19664    
19665                                    if (!pagination) {
19666                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19667                                                            start, end, false);
19668    
19669                                            Collections.sort(list);
19670    
19671                                            list = new UnmodifiableList<MBMessage>(list);
19672                                    }
19673                                    else {
19674                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19675                                                            start, end);
19676                                    }
19677    
19678                                    cacheResult(list);
19679    
19680                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19681                            }
19682                            catch (Exception e) {
19683                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19684    
19685                                    throw processException(e);
19686                            }
19687                            finally {
19688                                    closeSession(session);
19689                            }
19690                    }
19691    
19692                    return list;
19693            }
19694    
19695            /**
19696             * Removes all the message-boards messages from the database.
19697             *
19698             * @throws SystemException if a system exception occurred
19699             */
19700            @Override
19701            public void removeAll() throws SystemException {
19702                    for (MBMessage mbMessage : findAll()) {
19703                            remove(mbMessage);
19704                    }
19705            }
19706    
19707            /**
19708             * Returns the number of message-boards messages.
19709             *
19710             * @return the number of message-boards messages
19711             * @throws SystemException if a system exception occurred
19712             */
19713            @Override
19714            public int countAll() throws SystemException {
19715                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19716                                    FINDER_ARGS_EMPTY, this);
19717    
19718                    if (count == null) {
19719                            Session session = null;
19720    
19721                            try {
19722                                    session = openSession();
19723    
19724                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
19725    
19726                                    count = (Long)q.uniqueResult();
19727    
19728                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19729                                            FINDER_ARGS_EMPTY, count);
19730                            }
19731                            catch (Exception e) {
19732                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19733                                            FINDER_ARGS_EMPTY);
19734    
19735                                    throw processException(e);
19736                            }
19737                            finally {
19738                                    closeSession(session);
19739                            }
19740                    }
19741    
19742                    return count.intValue();
19743            }
19744    
19745            @Override
19746            protected Set<String> getBadColumnNames() {
19747                    return _badColumnNames;
19748            }
19749    
19750            /**
19751             * Initializes the message-boards message persistence.
19752             */
19753            public void afterPropertiesSet() {
19754                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
19755                                            com.liferay.portal.util.PropsUtil.get(
19756                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
19757    
19758                    if (listenerClassNames.length > 0) {
19759                            try {
19760                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
19761    
19762                                    for (String listenerClassName : listenerClassNames) {
19763                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
19764                                                            getClassLoader(), listenerClassName));
19765                                    }
19766    
19767                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
19768                            }
19769                            catch (Exception e) {
19770                                    _log.error(e);
19771                            }
19772                    }
19773            }
19774    
19775            public void destroy() {
19776                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
19777                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19778                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19779                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19780            }
19781    
19782            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19783            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19784            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19785            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19786            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19787            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19788            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19789                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19790            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19791                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19792            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19793            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19794            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19795            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19796            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19797            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19798            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19799            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19800            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19801            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
19802                                    "uuid"
19803                            });
19804            private static MBMessage _nullMBMessage = new MBMessageImpl() {
19805                            @Override
19806                            public Object clone() {
19807                                    return this;
19808                            }
19809    
19810                            @Override
19811                            public CacheModel<MBMessage> toCacheModel() {
19812                                    return _nullMBMessageCacheModel;
19813                            }
19814                    };
19815    
19816            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19817                            @Override
19818                            public MBMessage toEntityModel() {
19819                                    return _nullMBMessage;
19820                            }
19821                    };
19822    }