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_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15902                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15903                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_C_S",
15904                            new String[] {
15905                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15906                                    Integer.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_U_C_S =
15912                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15913                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15914                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_C_S",
15915                            new String[] {
15916                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15917                                    Integer.class.getName()
15918                            },
15919                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15920                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
15921                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15922                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15923                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15924            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15925                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15926                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C_S",
15927                            new String[] {
15928                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15929                                    Integer.class.getName()
15930                            });
15931            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15932                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15933                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_U_C_S",
15934                            new String[] {
15935                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15936                                    Integer.class.getName()
15937                            });
15938    
15939            /**
15940             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15941             *
15942             * @param groupId the group ID
15943             * @param userId the user ID
15944             * @param categoryId the category ID
15945             * @param status the status
15946             * @return the matching message-boards messages
15947             * @throws SystemException if a system exception occurred
15948             */
15949            @Override
15950            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
15951                    long categoryId, int status) throws SystemException {
15952                    return findByG_U_C_S(groupId, userId, categoryId, status,
15953                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15954            }
15955    
15956            /**
15957             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15958             *
15959             * <p>
15960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15961             * </p>
15962             *
15963             * @param groupId the group ID
15964             * @param userId the user ID
15965             * @param categoryId the category ID
15966             * @param status the status
15967             * @param start the lower bound of the range of message-boards messages
15968             * @param end the upper bound of the range of message-boards messages (not inclusive)
15969             * @return the range of matching message-boards messages
15970             * @throws SystemException if a system exception occurred
15971             */
15972            @Override
15973            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
15974                    long categoryId, int status, int start, int end)
15975                    throws SystemException {
15976                    return findByG_U_C_S(groupId, userId, categoryId, status, start, end,
15977                            null);
15978            }
15979    
15980            /**
15981             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15982             *
15983             * <p>
15984             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15985             * </p>
15986             *
15987             * @param groupId the group ID
15988             * @param userId the user ID
15989             * @param categoryId the category ID
15990             * @param status the status
15991             * @param start the lower bound of the range of message-boards messages
15992             * @param end the upper bound of the range of message-boards messages (not inclusive)
15993             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15994             * @return the ordered range of matching message-boards messages
15995             * @throws SystemException if a system exception occurred
15996             */
15997            @Override
15998            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
15999                    long categoryId, int status, int start, int end,
16000                    OrderByComparator orderByComparator) throws SystemException {
16001                    boolean pagination = true;
16002                    FinderPath finderPath = null;
16003                    Object[] finderArgs = null;
16004    
16005                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16006                                    (orderByComparator == null)) {
16007                            pagination = false;
16008                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S;
16009                            finderArgs = new Object[] { groupId, userId, categoryId, status };
16010                    }
16011                    else {
16012                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S;
16013                            finderArgs = new Object[] {
16014                                            groupId, userId, categoryId, status,
16015                                            
16016                                            start, end, orderByComparator
16017                                    };
16018                    }
16019    
16020                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16021                                    finderArgs, this);
16022    
16023                    if ((list != null) && !list.isEmpty()) {
16024                            for (MBMessage mbMessage : list) {
16025                                    if ((groupId != mbMessage.getGroupId()) ||
16026                                                    (userId != mbMessage.getUserId()) ||
16027                                                    (categoryId != mbMessage.getCategoryId()) ||
16028                                                    (status != mbMessage.getStatus())) {
16029                                            list = null;
16030    
16031                                            break;
16032                                    }
16033                            }
16034                    }
16035    
16036                    if (list == null) {
16037                            StringBundler query = null;
16038    
16039                            if (orderByComparator != null) {
16040                                    query = new StringBundler(6 +
16041                                                    (orderByComparator.getOrderByFields().length * 3));
16042                            }
16043                            else {
16044                                    query = new StringBundler(6);
16045                            }
16046    
16047                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16048    
16049                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16050    
16051                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16052    
16053                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16054    
16055                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16056    
16057                            if (orderByComparator != null) {
16058                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16059                                            orderByComparator);
16060                            }
16061                            else
16062                             if (pagination) {
16063                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16064                            }
16065    
16066                            String sql = query.toString();
16067    
16068                            Session session = null;
16069    
16070                            try {
16071                                    session = openSession();
16072    
16073                                    Query q = session.createQuery(sql);
16074    
16075                                    QueryPos qPos = QueryPos.getInstance(q);
16076    
16077                                    qPos.add(groupId);
16078    
16079                                    qPos.add(userId);
16080    
16081                                    qPos.add(categoryId);
16082    
16083                                    qPos.add(status);
16084    
16085                                    if (!pagination) {
16086                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16087                                                            start, end, false);
16088    
16089                                            Collections.sort(list);
16090    
16091                                            list = new UnmodifiableList<MBMessage>(list);
16092                                    }
16093                                    else {
16094                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16095                                                            start, end);
16096                                    }
16097    
16098                                    cacheResult(list);
16099    
16100                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16101                            }
16102                            catch (Exception e) {
16103                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16104    
16105                                    throw processException(e);
16106                            }
16107                            finally {
16108                                    closeSession(session);
16109                            }
16110                    }
16111    
16112                    return list;
16113            }
16114    
16115            /**
16116             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16117             *
16118             * @param groupId the group ID
16119             * @param userId the user ID
16120             * @param categoryId the category ID
16121             * @param status the status
16122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16123             * @return the first matching message-boards message
16124             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16125             * @throws SystemException if a system exception occurred
16126             */
16127            @Override
16128            public MBMessage findByG_U_C_S_First(long groupId, long userId,
16129                    long categoryId, int status, OrderByComparator orderByComparator)
16130                    throws NoSuchMessageException, SystemException {
16131                    MBMessage mbMessage = fetchByG_U_C_S_First(groupId, userId, categoryId,
16132                                    status, orderByComparator);
16133    
16134                    if (mbMessage != null) {
16135                            return mbMessage;
16136                    }
16137    
16138                    StringBundler msg = new StringBundler(10);
16139    
16140                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16141    
16142                    msg.append("groupId=");
16143                    msg.append(groupId);
16144    
16145                    msg.append(", userId=");
16146                    msg.append(userId);
16147    
16148                    msg.append(", categoryId=");
16149                    msg.append(categoryId);
16150    
16151                    msg.append(", status=");
16152                    msg.append(status);
16153    
16154                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16155    
16156                    throw new NoSuchMessageException(msg.toString());
16157            }
16158    
16159            /**
16160             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16161             *
16162             * @param groupId the group ID
16163             * @param userId the user ID
16164             * @param categoryId the category ID
16165             * @param status the status
16166             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16167             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16168             * @throws SystemException if a system exception occurred
16169             */
16170            @Override
16171            public MBMessage fetchByG_U_C_S_First(long groupId, long userId,
16172                    long categoryId, int status, OrderByComparator orderByComparator)
16173                    throws SystemException {
16174                    List<MBMessage> list = findByG_U_C_S(groupId, userId, categoryId,
16175                                    status, 0, 1, orderByComparator);
16176    
16177                    if (!list.isEmpty()) {
16178                            return list.get(0);
16179                    }
16180    
16181                    return null;
16182            }
16183    
16184            /**
16185             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16186             *
16187             * @param groupId the group ID
16188             * @param userId the user ID
16189             * @param categoryId the category ID
16190             * @param status the status
16191             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16192             * @return the last matching message-boards message
16193             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16194             * @throws SystemException if a system exception occurred
16195             */
16196            @Override
16197            public MBMessage findByG_U_C_S_Last(long groupId, long userId,
16198                    long categoryId, int status, OrderByComparator orderByComparator)
16199                    throws NoSuchMessageException, SystemException {
16200                    MBMessage mbMessage = fetchByG_U_C_S_Last(groupId, userId, categoryId,
16201                                    status, orderByComparator);
16202    
16203                    if (mbMessage != null) {
16204                            return mbMessage;
16205                    }
16206    
16207                    StringBundler msg = new StringBundler(10);
16208    
16209                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16210    
16211                    msg.append("groupId=");
16212                    msg.append(groupId);
16213    
16214                    msg.append(", userId=");
16215                    msg.append(userId);
16216    
16217                    msg.append(", categoryId=");
16218                    msg.append(categoryId);
16219    
16220                    msg.append(", status=");
16221                    msg.append(status);
16222    
16223                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16224    
16225                    throw new NoSuchMessageException(msg.toString());
16226            }
16227    
16228            /**
16229             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16230             *
16231             * @param groupId the group ID
16232             * @param userId the user ID
16233             * @param categoryId the category ID
16234             * @param status the status
16235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16236             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16237             * @throws SystemException if a system exception occurred
16238             */
16239            @Override
16240            public MBMessage fetchByG_U_C_S_Last(long groupId, long userId,
16241                    long categoryId, int status, OrderByComparator orderByComparator)
16242                    throws SystemException {
16243                    int count = countByG_U_C_S(groupId, userId, categoryId, status);
16244    
16245                    if (count == 0) {
16246                            return null;
16247                    }
16248    
16249                    List<MBMessage> list = findByG_U_C_S(groupId, userId, categoryId,
16250                                    status, count - 1, count, orderByComparator);
16251    
16252                    if (!list.isEmpty()) {
16253                            return list.get(0);
16254                    }
16255    
16256                    return null;
16257            }
16258    
16259            /**
16260             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16261             *
16262             * @param messageId the primary key of the current message-boards message
16263             * @param groupId the group ID
16264             * @param userId the user ID
16265             * @param categoryId the category ID
16266             * @param status the status
16267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16268             * @return the previous, current, and next message-boards message
16269             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16270             * @throws SystemException if a system exception occurred
16271             */
16272            @Override
16273            public MBMessage[] findByG_U_C_S_PrevAndNext(long messageId, long groupId,
16274                    long userId, long categoryId, int status,
16275                    OrderByComparator orderByComparator)
16276                    throws NoSuchMessageException, SystemException {
16277                    MBMessage mbMessage = findByPrimaryKey(messageId);
16278    
16279                    Session session = null;
16280    
16281                    try {
16282                            session = openSession();
16283    
16284                            MBMessage[] array = new MBMessageImpl[3];
16285    
16286                            array[0] = getByG_U_C_S_PrevAndNext(session, mbMessage, groupId,
16287                                            userId, categoryId, status, orderByComparator, true);
16288    
16289                            array[1] = mbMessage;
16290    
16291                            array[2] = getByG_U_C_S_PrevAndNext(session, mbMessage, groupId,
16292                                            userId, categoryId, status, orderByComparator, false);
16293    
16294                            return array;
16295                    }
16296                    catch (Exception e) {
16297                            throw processException(e);
16298                    }
16299                    finally {
16300                            closeSession(session);
16301                    }
16302            }
16303    
16304            protected MBMessage getByG_U_C_S_PrevAndNext(Session session,
16305                    MBMessage mbMessage, long groupId, long userId, long categoryId,
16306                    int status, OrderByComparator orderByComparator, boolean previous) {
16307                    StringBundler query = null;
16308    
16309                    if (orderByComparator != null) {
16310                            query = new StringBundler(6 +
16311                                            (orderByComparator.getOrderByFields().length * 6));
16312                    }
16313                    else {
16314                            query = new StringBundler(3);
16315                    }
16316    
16317                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16318    
16319                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16320    
16321                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16322    
16323                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16324    
16325                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16326    
16327                    if (orderByComparator != null) {
16328                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16329    
16330                            if (orderByConditionFields.length > 0) {
16331                                    query.append(WHERE_AND);
16332                            }
16333    
16334                            for (int i = 0; i < orderByConditionFields.length; i++) {
16335                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16336                                    query.append(orderByConditionFields[i]);
16337    
16338                                    if ((i + 1) < orderByConditionFields.length) {
16339                                            if (orderByComparator.isAscending() ^ previous) {
16340                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16341                                            }
16342                                            else {
16343                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16344                                            }
16345                                    }
16346                                    else {
16347                                            if (orderByComparator.isAscending() ^ previous) {
16348                                                    query.append(WHERE_GREATER_THAN);
16349                                            }
16350                                            else {
16351                                                    query.append(WHERE_LESSER_THAN);
16352                                            }
16353                                    }
16354                            }
16355    
16356                            query.append(ORDER_BY_CLAUSE);
16357    
16358                            String[] orderByFields = orderByComparator.getOrderByFields();
16359    
16360                            for (int i = 0; i < orderByFields.length; i++) {
16361                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16362                                    query.append(orderByFields[i]);
16363    
16364                                    if ((i + 1) < orderByFields.length) {
16365                                            if (orderByComparator.isAscending() ^ previous) {
16366                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16367                                            }
16368                                            else {
16369                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16370                                            }
16371                                    }
16372                                    else {
16373                                            if (orderByComparator.isAscending() ^ previous) {
16374                                                    query.append(ORDER_BY_ASC);
16375                                            }
16376                                            else {
16377                                                    query.append(ORDER_BY_DESC);
16378                                            }
16379                                    }
16380                            }
16381                    }
16382                    else {
16383                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16384                    }
16385    
16386                    String sql = query.toString();
16387    
16388                    Query q = session.createQuery(sql);
16389    
16390                    q.setFirstResult(0);
16391                    q.setMaxResults(2);
16392    
16393                    QueryPos qPos = QueryPos.getInstance(q);
16394    
16395                    qPos.add(groupId);
16396    
16397                    qPos.add(userId);
16398    
16399                    qPos.add(categoryId);
16400    
16401                    qPos.add(status);
16402    
16403                    if (orderByComparator != null) {
16404                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16405    
16406                            for (Object value : values) {
16407                                    qPos.add(value);
16408                            }
16409                    }
16410    
16411                    List<MBMessage> list = q.list();
16412    
16413                    if (list.size() == 2) {
16414                            return list.get(1);
16415                    }
16416                    else {
16417                            return null;
16418                    }
16419            }
16420    
16421            /**
16422             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16423             *
16424             * @param groupId the group ID
16425             * @param userId the user ID
16426             * @param categoryId the category ID
16427             * @param status the status
16428             * @return the matching message-boards messages that the user has permission to view
16429             * @throws SystemException if a system exception occurred
16430             */
16431            @Override
16432            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16433                    long categoryId, int status) throws SystemException {
16434                    return filterFindByG_U_C_S(groupId, userId, categoryId, status,
16435                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16436            }
16437    
16438            /**
16439             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16440             *
16441             * <p>
16442             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16443             * </p>
16444             *
16445             * @param groupId the group ID
16446             * @param userId the user ID
16447             * @param categoryId the category ID
16448             * @param status the status
16449             * @param start the lower bound of the range of message-boards messages
16450             * @param end the upper bound of the range of message-boards messages (not inclusive)
16451             * @return the range of matching message-boards messages that the user has permission to view
16452             * @throws SystemException if a system exception occurred
16453             */
16454            @Override
16455            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16456                    long categoryId, int status, int start, int end)
16457                    throws SystemException {
16458                    return filterFindByG_U_C_S(groupId, userId, categoryId, status, start,
16459                            end, null);
16460            }
16461    
16462            /**
16463             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16464             *
16465             * <p>
16466             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16467             * </p>
16468             *
16469             * @param groupId the group ID
16470             * @param userId the user ID
16471             * @param categoryId the category ID
16472             * @param status the status
16473             * @param start the lower bound of the range of message-boards messages
16474             * @param end the upper bound of the range of message-boards messages (not inclusive)
16475             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16476             * @return the ordered range of matching message-boards messages that the user has permission to view
16477             * @throws SystemException if a system exception occurred
16478             */
16479            @Override
16480            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16481                    long categoryId, int status, int start, int end,
16482                    OrderByComparator orderByComparator) throws SystemException {
16483                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16484                            return findByG_U_C_S(groupId, userId, categoryId, status, start,
16485                                    end, orderByComparator);
16486                    }
16487    
16488                    StringBundler query = null;
16489    
16490                    if (orderByComparator != null) {
16491                            query = new StringBundler(6 +
16492                                            (orderByComparator.getOrderByFields().length * 3));
16493                    }
16494                    else {
16495                            query = new StringBundler(6);
16496                    }
16497    
16498                    if (getDB().isSupportsInlineDistinct()) {
16499                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16500                    }
16501                    else {
16502                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16503                    }
16504    
16505                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16506    
16507                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16508    
16509                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16510    
16511                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16512    
16513                    if (!getDB().isSupportsInlineDistinct()) {
16514                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16515                    }
16516    
16517                    if (orderByComparator != null) {
16518                            if (getDB().isSupportsInlineDistinct()) {
16519                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16520                                            orderByComparator, true);
16521                            }
16522                            else {
16523                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16524                                            orderByComparator, true);
16525                            }
16526                    }
16527                    else {
16528                            if (getDB().isSupportsInlineDistinct()) {
16529                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16530                            }
16531                            else {
16532                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16533                            }
16534                    }
16535    
16536                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16537                                    MBMessage.class.getName(),
16538                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16539    
16540                    Session session = null;
16541    
16542                    try {
16543                            session = openSession();
16544    
16545                            SQLQuery q = session.createSQLQuery(sql);
16546    
16547                            if (getDB().isSupportsInlineDistinct()) {
16548                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16549                            }
16550                            else {
16551                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16552                            }
16553    
16554                            QueryPos qPos = QueryPos.getInstance(q);
16555    
16556                            qPos.add(groupId);
16557    
16558                            qPos.add(userId);
16559    
16560                            qPos.add(categoryId);
16561    
16562                            qPos.add(status);
16563    
16564                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16565                    }
16566                    catch (Exception e) {
16567                            throw processException(e);
16568                    }
16569                    finally {
16570                            closeSession(session);
16571                    }
16572            }
16573    
16574            /**
16575             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16576             *
16577             * @param messageId the primary key of the current message-boards message
16578             * @param groupId the group ID
16579             * @param userId the user ID
16580             * @param categoryId the category ID
16581             * @param status the status
16582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16583             * @return the previous, current, and next message-boards message
16584             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16585             * @throws SystemException if a system exception occurred
16586             */
16587            @Override
16588            public MBMessage[] filterFindByG_U_C_S_PrevAndNext(long messageId,
16589                    long groupId, long userId, long categoryId, int status,
16590                    OrderByComparator orderByComparator)
16591                    throws NoSuchMessageException, SystemException {
16592                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16593                            return findByG_U_C_S_PrevAndNext(messageId, groupId, userId,
16594                                    categoryId, status, orderByComparator);
16595                    }
16596    
16597                    MBMessage mbMessage = findByPrimaryKey(messageId);
16598    
16599                    Session session = null;
16600    
16601                    try {
16602                            session = openSession();
16603    
16604                            MBMessage[] array = new MBMessageImpl[3];
16605    
16606                            array[0] = filterGetByG_U_C_S_PrevAndNext(session, mbMessage,
16607                                            groupId, userId, categoryId, status, orderByComparator, true);
16608    
16609                            array[1] = mbMessage;
16610    
16611                            array[2] = filterGetByG_U_C_S_PrevAndNext(session, mbMessage,
16612                                            groupId, userId, categoryId, status, orderByComparator,
16613                                            false);
16614    
16615                            return array;
16616                    }
16617                    catch (Exception e) {
16618                            throw processException(e);
16619                    }
16620                    finally {
16621                            closeSession(session);
16622                    }
16623            }
16624    
16625            protected MBMessage filterGetByG_U_C_S_PrevAndNext(Session session,
16626                    MBMessage mbMessage, long groupId, long userId, long categoryId,
16627                    int status, OrderByComparator orderByComparator, boolean previous) {
16628                    StringBundler query = null;
16629    
16630                    if (orderByComparator != null) {
16631                            query = new StringBundler(6 +
16632                                            (orderByComparator.getOrderByFields().length * 6));
16633                    }
16634                    else {
16635                            query = new StringBundler(3);
16636                    }
16637    
16638                    if (getDB().isSupportsInlineDistinct()) {
16639                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16640                    }
16641                    else {
16642                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16643                    }
16644    
16645                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16646    
16647                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16648    
16649                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16650    
16651                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16652    
16653                    if (!getDB().isSupportsInlineDistinct()) {
16654                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16655                    }
16656    
16657                    if (orderByComparator != null) {
16658                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16659    
16660                            if (orderByConditionFields.length > 0) {
16661                                    query.append(WHERE_AND);
16662                            }
16663    
16664                            for (int i = 0; i < orderByConditionFields.length; i++) {
16665                                    if (getDB().isSupportsInlineDistinct()) {
16666                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16667                                    }
16668                                    else {
16669                                            query.append(_ORDER_BY_ENTITY_TABLE);
16670                                    }
16671    
16672                                    query.append(orderByConditionFields[i]);
16673    
16674                                    if ((i + 1) < orderByConditionFields.length) {
16675                                            if (orderByComparator.isAscending() ^ previous) {
16676                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16677                                            }
16678                                            else {
16679                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16680                                            }
16681                                    }
16682                                    else {
16683                                            if (orderByComparator.isAscending() ^ previous) {
16684                                                    query.append(WHERE_GREATER_THAN);
16685                                            }
16686                                            else {
16687                                                    query.append(WHERE_LESSER_THAN);
16688                                            }
16689                                    }
16690                            }
16691    
16692                            query.append(ORDER_BY_CLAUSE);
16693    
16694                            String[] orderByFields = orderByComparator.getOrderByFields();
16695    
16696                            for (int i = 0; i < orderByFields.length; i++) {
16697                                    if (getDB().isSupportsInlineDistinct()) {
16698                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16699                                    }
16700                                    else {
16701                                            query.append(_ORDER_BY_ENTITY_TABLE);
16702                                    }
16703    
16704                                    query.append(orderByFields[i]);
16705    
16706                                    if ((i + 1) < orderByFields.length) {
16707                                            if (orderByComparator.isAscending() ^ previous) {
16708                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16709                                            }
16710                                            else {
16711                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16712                                            }
16713                                    }
16714                                    else {
16715                                            if (orderByComparator.isAscending() ^ previous) {
16716                                                    query.append(ORDER_BY_ASC);
16717                                            }
16718                                            else {
16719                                                    query.append(ORDER_BY_DESC);
16720                                            }
16721                                    }
16722                            }
16723                    }
16724                    else {
16725                            if (getDB().isSupportsInlineDistinct()) {
16726                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16727                            }
16728                            else {
16729                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16730                            }
16731                    }
16732    
16733                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16734                                    MBMessage.class.getName(),
16735                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16736    
16737                    SQLQuery q = session.createSQLQuery(sql);
16738    
16739                    q.setFirstResult(0);
16740                    q.setMaxResults(2);
16741    
16742                    if (getDB().isSupportsInlineDistinct()) {
16743                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16744                    }
16745                    else {
16746                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16747                    }
16748    
16749                    QueryPos qPos = QueryPos.getInstance(q);
16750    
16751                    qPos.add(groupId);
16752    
16753                    qPos.add(userId);
16754    
16755                    qPos.add(categoryId);
16756    
16757                    qPos.add(status);
16758    
16759                    if (orderByComparator != null) {
16760                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16761    
16762                            for (Object value : values) {
16763                                    qPos.add(value);
16764                            }
16765                    }
16766    
16767                    List<MBMessage> list = q.list();
16768    
16769                    if (list.size() == 2) {
16770                            return list.get(1);
16771                    }
16772                    else {
16773                            return null;
16774                    }
16775            }
16776    
16777            /**
16778             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16779             *
16780             * @param groupId the group ID
16781             * @param userId the user ID
16782             * @param categoryIds the category IDs
16783             * @param status the status
16784             * @return the matching message-boards messages that the user has permission to view
16785             * @throws SystemException if a system exception occurred
16786             */
16787            @Override
16788            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16789                    long[] categoryIds, int status) throws SystemException {
16790                    return filterFindByG_U_C_S(groupId, userId, categoryIds, status,
16791                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16792            }
16793    
16794            /**
16795             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16796             *
16797             * <p>
16798             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16799             * </p>
16800             *
16801             * @param groupId the group ID
16802             * @param userId the user ID
16803             * @param categoryIds the category IDs
16804             * @param status the status
16805             * @param start the lower bound of the range of message-boards messages
16806             * @param end the upper bound of the range of message-boards messages (not inclusive)
16807             * @return the range of matching message-boards messages that the user has permission to view
16808             * @throws SystemException if a system exception occurred
16809             */
16810            @Override
16811            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16812                    long[] categoryIds, int status, int start, int end)
16813                    throws SystemException {
16814                    return filterFindByG_U_C_S(groupId, userId, categoryIds, status, start,
16815                            end, null);
16816            }
16817    
16818            /**
16819             * Returns an ordered range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16820             *
16821             * <p>
16822             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16823             * </p>
16824             *
16825             * @param groupId the group ID
16826             * @param userId the user ID
16827             * @param categoryIds the category IDs
16828             * @param status the status
16829             * @param start the lower bound of the range of message-boards messages
16830             * @param end the upper bound of the range of message-boards messages (not inclusive)
16831             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16832             * @return the ordered range of matching message-boards messages that the user has permission to view
16833             * @throws SystemException if a system exception occurred
16834             */
16835            @Override
16836            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16837                    long[] categoryIds, int status, int start, int end,
16838                    OrderByComparator orderByComparator) throws SystemException {
16839                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16840                            return findByG_U_C_S(groupId, userId, categoryIds, status, start,
16841                                    end, orderByComparator);
16842                    }
16843    
16844                    StringBundler query = new StringBundler();
16845    
16846                    if (getDB().isSupportsInlineDistinct()) {
16847                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16848                    }
16849                    else {
16850                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16851                    }
16852    
16853                    boolean conjunctionable = false;
16854    
16855                    if (conjunctionable) {
16856                            query.append(WHERE_AND);
16857                    }
16858    
16859                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
16860    
16861                    conjunctionable = true;
16862    
16863                    if (conjunctionable) {
16864                            query.append(WHERE_AND);
16865                    }
16866    
16867                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
16868    
16869                    conjunctionable = true;
16870    
16871                    if ((categoryIds == null) || (categoryIds.length > 0)) {
16872                            if (conjunctionable) {
16873                                    query.append(WHERE_AND);
16874                            }
16875    
16876                            query.append(StringPool.OPEN_PARENTHESIS);
16877    
16878                            for (int i = 0; i < categoryIds.length; i++) {
16879                                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
16880    
16881                                    if ((i + 1) < categoryIds.length) {
16882                                            query.append(WHERE_OR);
16883                                    }
16884                            }
16885    
16886                            query.append(StringPool.CLOSE_PARENTHESIS);
16887    
16888                            conjunctionable = true;
16889                    }
16890    
16891                    if (conjunctionable) {
16892                            query.append(WHERE_AND);
16893                    }
16894    
16895                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
16896    
16897                    conjunctionable = true;
16898    
16899                    if (!getDB().isSupportsInlineDistinct()) {
16900                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16901                    }
16902    
16903                    if (orderByComparator != null) {
16904                            if (getDB().isSupportsInlineDistinct()) {
16905                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16906                                            orderByComparator, true);
16907                            }
16908                            else {
16909                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16910                                            orderByComparator, true);
16911                            }
16912                    }
16913                    else {
16914                            if (getDB().isSupportsInlineDistinct()) {
16915                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16916                            }
16917                            else {
16918                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16919                            }
16920                    }
16921    
16922                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16923                                    MBMessage.class.getName(),
16924                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16925    
16926                    Session session = null;
16927    
16928                    try {
16929                            session = openSession();
16930    
16931                            SQLQuery q = session.createSQLQuery(sql);
16932    
16933                            if (getDB().isSupportsInlineDistinct()) {
16934                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16935                            }
16936                            else {
16937                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16938                            }
16939    
16940                            QueryPos qPos = QueryPos.getInstance(q);
16941    
16942                            qPos.add(groupId);
16943    
16944                            qPos.add(userId);
16945    
16946                            if (categoryIds != null) {
16947                                    qPos.add(categoryIds);
16948                            }
16949    
16950                            qPos.add(status);
16951    
16952                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16953                    }
16954                    catch (Exception e) {
16955                            throw processException(e);
16956                    }
16957                    finally {
16958                            closeSession(session);
16959                    }
16960            }
16961    
16962            /**
16963             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16964             *
16965             * <p>
16966             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16967             * </p>
16968             *
16969             * @param groupId the group ID
16970             * @param userId the user ID
16971             * @param categoryIds the category IDs
16972             * @param status the status
16973             * @return the matching message-boards messages
16974             * @throws SystemException if a system exception occurred
16975             */
16976            @Override
16977            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
16978                    long[] categoryIds, int status) throws SystemException {
16979                    return findByG_U_C_S(groupId, userId, categoryIds, status,
16980                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16981            }
16982    
16983            /**
16984             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16985             *
16986             * <p>
16987             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16988             * </p>
16989             *
16990             * @param groupId the group ID
16991             * @param userId the user ID
16992             * @param categoryIds the category IDs
16993             * @param status the status
16994             * @param start the lower bound of the range of message-boards messages
16995             * @param end the upper bound of the range of message-boards messages (not inclusive)
16996             * @return the range of matching message-boards messages
16997             * @throws SystemException if a system exception occurred
16998             */
16999            @Override
17000            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
17001                    long[] categoryIds, int status, int start, int end)
17002                    throws SystemException {
17003                    return findByG_U_C_S(groupId, userId, categoryIds, status, start, end,
17004                            null);
17005            }
17006    
17007            /**
17008             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
17009             *
17010             * <p>
17011             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17012             * </p>
17013             *
17014             * @param groupId the group ID
17015             * @param userId the user ID
17016             * @param categoryIds the category IDs
17017             * @param status the status
17018             * @param start the lower bound of the range of message-boards messages
17019             * @param end the upper bound of the range of message-boards messages (not inclusive)
17020             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17021             * @return the ordered range of matching message-boards messages
17022             * @throws SystemException if a system exception occurred
17023             */
17024            @Override
17025            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
17026                    long[] categoryIds, int status, int start, int end,
17027                    OrderByComparator orderByComparator) throws SystemException {
17028                    if ((categoryIds != null) && (categoryIds.length == 1)) {
17029                            return findByG_U_C_S(groupId, userId, categoryIds[0], status,
17030                                    start, end, orderByComparator);
17031                    }
17032    
17033                    boolean pagination = true;
17034                    Object[] finderArgs = null;
17035    
17036                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17037                                    (orderByComparator == null)) {
17038                            pagination = false;
17039                            finderArgs = new Object[] {
17040                                            groupId, userId, StringUtil.merge(categoryIds), status
17041                                    };
17042                    }
17043                    else {
17044                            finderArgs = new Object[] {
17045                                            groupId, userId, StringUtil.merge(categoryIds), status,
17046                                            
17047                                            start, end, orderByComparator
17048                                    };
17049                    }
17050    
17051                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S,
17052                                    finderArgs, this);
17053    
17054                    if ((list != null) && !list.isEmpty()) {
17055                            for (MBMessage mbMessage : list) {
17056                                    if ((groupId != mbMessage.getGroupId()) ||
17057                                                    (userId != mbMessage.getUserId()) ||
17058                                                    !ArrayUtil.contains(categoryIds,
17059                                                            mbMessage.getCategoryId()) ||
17060                                                    (status != mbMessage.getStatus())) {
17061                                            list = null;
17062    
17063                                            break;
17064                                    }
17065                            }
17066                    }
17067    
17068                    if (list == null) {
17069                            StringBundler query = new StringBundler();
17070    
17071                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17072    
17073                            boolean conjunctionable = false;
17074    
17075                            if (conjunctionable) {
17076                                    query.append(WHERE_AND);
17077                            }
17078    
17079                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
17080    
17081                            conjunctionable = true;
17082    
17083                            if (conjunctionable) {
17084                                    query.append(WHERE_AND);
17085                            }
17086    
17087                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
17088    
17089                            conjunctionable = true;
17090    
17091                            if ((categoryIds == null) || (categoryIds.length > 0)) {
17092                                    if (conjunctionable) {
17093                                            query.append(WHERE_AND);
17094                                    }
17095    
17096                                    query.append(StringPool.OPEN_PARENTHESIS);
17097    
17098                                    for (int i = 0; i < categoryIds.length; i++) {
17099                                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
17100    
17101                                            if ((i + 1) < categoryIds.length) {
17102                                                    query.append(WHERE_OR);
17103                                            }
17104                                    }
17105    
17106                                    query.append(StringPool.CLOSE_PARENTHESIS);
17107    
17108                                    conjunctionable = true;
17109                            }
17110    
17111                            if (conjunctionable) {
17112                                    query.append(WHERE_AND);
17113                            }
17114    
17115                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
17116    
17117                            conjunctionable = true;
17118    
17119                            if (orderByComparator != null) {
17120                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17121                                            orderByComparator);
17122                            }
17123                            else
17124                             if (pagination) {
17125                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17126                            }
17127    
17128                            String sql = query.toString();
17129    
17130                            Session session = null;
17131    
17132                            try {
17133                                    session = openSession();
17134    
17135                                    Query q = session.createQuery(sql);
17136    
17137                                    QueryPos qPos = QueryPos.getInstance(q);
17138    
17139                                    qPos.add(groupId);
17140    
17141                                    qPos.add(userId);
17142    
17143                                    if (categoryIds != null) {
17144                                            qPos.add(categoryIds);
17145                                    }
17146    
17147                                    qPos.add(status);
17148    
17149                                    if (!pagination) {
17150                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17151                                                            start, end, false);
17152    
17153                                            Collections.sort(list);
17154    
17155                                            list = new UnmodifiableList<MBMessage>(list);
17156                                    }
17157                                    else {
17158                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17159                                                            start, end);
17160                                    }
17161    
17162                                    cacheResult(list);
17163    
17164                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S,
17165                                            finderArgs, list);
17166                            }
17167                            catch (Exception e) {
17168                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S,
17169                                            finderArgs);
17170    
17171                                    throw processException(e);
17172                            }
17173                            finally {
17174                                    closeSession(session);
17175                            }
17176                    }
17177    
17178                    return list;
17179            }
17180    
17181            /**
17182             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63; from the database.
17183             *
17184             * @param groupId the group ID
17185             * @param userId the user ID
17186             * @param categoryId the category ID
17187             * @param status the status
17188             * @throws SystemException if a system exception occurred
17189             */
17190            @Override
17191            public void removeByG_U_C_S(long groupId, long userId, long categoryId,
17192                    int status) throws SystemException {
17193                    for (MBMessage mbMessage : findByG_U_C_S(groupId, userId, categoryId,
17194                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17195                            remove(mbMessage);
17196                    }
17197            }
17198    
17199            /**
17200             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
17201             *
17202             * @param groupId the group ID
17203             * @param userId the user ID
17204             * @param categoryId the category ID
17205             * @param status the status
17206             * @return the number of matching message-boards messages
17207             * @throws SystemException if a system exception occurred
17208             */
17209            @Override
17210            public int countByG_U_C_S(long groupId, long userId, long categoryId,
17211                    int status) throws SystemException {
17212                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_C_S;
17213    
17214                    Object[] finderArgs = new Object[] { groupId, userId, categoryId, status };
17215    
17216                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17217                                    this);
17218    
17219                    if (count == null) {
17220                            StringBundler query = new StringBundler(5);
17221    
17222                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17223    
17224                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
17225    
17226                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
17227    
17228                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
17229    
17230                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
17231    
17232                            String sql = query.toString();
17233    
17234                            Session session = null;
17235    
17236                            try {
17237                                    session = openSession();
17238    
17239                                    Query q = session.createQuery(sql);
17240    
17241                                    QueryPos qPos = QueryPos.getInstance(q);
17242    
17243                                    qPos.add(groupId);
17244    
17245                                    qPos.add(userId);
17246    
17247                                    qPos.add(categoryId);
17248    
17249                                    qPos.add(status);
17250    
17251                                    count = (Long)q.uniqueResult();
17252    
17253                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17254                            }
17255                            catch (Exception e) {
17256                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17257    
17258                                    throw processException(e);
17259                            }
17260                            finally {
17261                                    closeSession(session);
17262                            }
17263                    }
17264    
17265                    return count.intValue();
17266            }
17267    
17268            /**
17269             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
17270             *
17271             * @param groupId the group ID
17272             * @param userId the user ID
17273             * @param categoryIds the category IDs
17274             * @param status the status
17275             * @return the number of matching message-boards messages
17276             * @throws SystemException if a system exception occurred
17277             */
17278            @Override
17279            public int countByG_U_C_S(long groupId, long userId, long[] categoryIds,
17280                    int status) throws SystemException {
17281                    Object[] finderArgs = new Object[] {
17282                                    groupId, userId, StringUtil.merge(categoryIds), status
17283                            };
17284    
17285                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S,
17286                                    finderArgs, this);
17287    
17288                    if (count == null) {
17289                            StringBundler query = new StringBundler();
17290    
17291                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17292    
17293                            boolean conjunctionable = false;
17294    
17295                            if (conjunctionable) {
17296                                    query.append(WHERE_AND);
17297                            }
17298    
17299                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
17300    
17301                            conjunctionable = true;
17302    
17303                            if (conjunctionable) {
17304                                    query.append(WHERE_AND);
17305                            }
17306    
17307                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
17308    
17309                            conjunctionable = true;
17310    
17311                            if ((categoryIds == null) || (categoryIds.length > 0)) {
17312                                    if (conjunctionable) {
17313                                            query.append(WHERE_AND);
17314                                    }
17315    
17316                                    query.append(StringPool.OPEN_PARENTHESIS);
17317    
17318                                    for (int i = 0; i < categoryIds.length; i++) {
17319                                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
17320    
17321                                            if ((i + 1) < categoryIds.length) {
17322                                                    query.append(WHERE_OR);
17323                                            }
17324                                    }
17325    
17326                                    query.append(StringPool.CLOSE_PARENTHESIS);
17327    
17328                                    conjunctionable = true;
17329                            }
17330    
17331                            if (conjunctionable) {
17332                                    query.append(WHERE_AND);
17333                            }
17334    
17335                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
17336    
17337                            conjunctionable = true;
17338    
17339                            String sql = query.toString();
17340    
17341                            Session session = null;
17342    
17343                            try {
17344                                    session = openSession();
17345    
17346                                    Query q = session.createQuery(sql);
17347    
17348                                    QueryPos qPos = QueryPos.getInstance(q);
17349    
17350                                    qPos.add(groupId);
17351    
17352                                    qPos.add(userId);
17353    
17354                                    if (categoryIds != null) {
17355                                            qPos.add(categoryIds);
17356                                    }
17357    
17358                                    qPos.add(status);
17359    
17360                                    count = (Long)q.uniqueResult();
17361    
17362                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S,
17363                                            finderArgs, count);
17364                            }
17365                            catch (Exception e) {
17366                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S,
17367                                            finderArgs);
17368    
17369                                    throw processException(e);
17370                            }
17371                            finally {
17372                                    closeSession(session);
17373                            }
17374                    }
17375    
17376                    return count.intValue();
17377            }
17378    
17379            /**
17380             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
17381             *
17382             * @param groupId the group ID
17383             * @param userId the user ID
17384             * @param categoryId the category ID
17385             * @param status the status
17386             * @return the number of matching message-boards messages that the user has permission to view
17387             * @throws SystemException if a system exception occurred
17388             */
17389            @Override
17390            public int filterCountByG_U_C_S(long groupId, long userId, long categoryId,
17391                    int status) throws SystemException {
17392                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17393                            return countByG_U_C_S(groupId, userId, categoryId, status);
17394                    }
17395    
17396                    StringBundler query = new StringBundler(5);
17397    
17398                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17399    
17400                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
17401    
17402                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
17403    
17404                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
17405    
17406                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
17407    
17408                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17409                                    MBMessage.class.getName(),
17410                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17411    
17412                    Session session = null;
17413    
17414                    try {
17415                            session = openSession();
17416    
17417                            SQLQuery q = session.createSQLQuery(sql);
17418    
17419                            q.addScalar(COUNT_COLUMN_NAME,
17420                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17421    
17422                            QueryPos qPos = QueryPos.getInstance(q);
17423    
17424                            qPos.add(groupId);
17425    
17426                            qPos.add(userId);
17427    
17428                            qPos.add(categoryId);
17429    
17430                            qPos.add(status);
17431    
17432                            Long count = (Long)q.uniqueResult();
17433    
17434                            return count.intValue();
17435                    }
17436                    catch (Exception e) {
17437                            throw processException(e);
17438                    }
17439                    finally {
17440                            closeSession(session);
17441                    }
17442            }
17443    
17444            /**
17445             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
17446             *
17447             * @param groupId the group ID
17448             * @param userId the user ID
17449             * @param categoryIds the category IDs
17450             * @param status the status
17451             * @return the number of matching message-boards messages that the user has permission to view
17452             * @throws SystemException if a system exception occurred
17453             */
17454            @Override
17455            public int filterCountByG_U_C_S(long groupId, long userId,
17456                    long[] categoryIds, int status) throws SystemException {
17457                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17458                            return countByG_U_C_S(groupId, userId, categoryIds, status);
17459                    }
17460    
17461                    StringBundler query = new StringBundler();
17462    
17463                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17464    
17465                    boolean conjunctionable = false;
17466    
17467                    if (conjunctionable) {
17468                            query.append(WHERE_AND);
17469                    }
17470    
17471                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
17472    
17473                    conjunctionable = true;
17474    
17475                    if (conjunctionable) {
17476                            query.append(WHERE_AND);
17477                    }
17478    
17479                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
17480    
17481                    conjunctionable = true;
17482    
17483                    if ((categoryIds == null) || (categoryIds.length > 0)) {
17484                            if (conjunctionable) {
17485                                    query.append(WHERE_AND);
17486                            }
17487    
17488                            query.append(StringPool.OPEN_PARENTHESIS);
17489    
17490                            for (int i = 0; i < categoryIds.length; i++) {
17491                                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
17492    
17493                                    if ((i + 1) < categoryIds.length) {
17494                                            query.append(WHERE_OR);
17495                                    }
17496                            }
17497    
17498                            query.append(StringPool.CLOSE_PARENTHESIS);
17499    
17500                            conjunctionable = true;
17501                    }
17502    
17503                    if (conjunctionable) {
17504                            query.append(WHERE_AND);
17505                    }
17506    
17507                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
17508    
17509                    conjunctionable = true;
17510    
17511                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17512                                    MBMessage.class.getName(),
17513                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17514    
17515                    Session session = null;
17516    
17517                    try {
17518                            session = openSession();
17519    
17520                            SQLQuery q = session.createSQLQuery(sql);
17521    
17522                            q.addScalar(COUNT_COLUMN_NAME,
17523                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17524    
17525                            QueryPos qPos = QueryPos.getInstance(q);
17526    
17527                            qPos.add(groupId);
17528    
17529                            qPos.add(userId);
17530    
17531                            if (categoryIds != null) {
17532                                    qPos.add(categoryIds);
17533                            }
17534    
17535                            qPos.add(status);
17536    
17537                            Long count = (Long)q.uniqueResult();
17538    
17539                            return count.intValue();
17540                    }
17541                    catch (Exception e) {
17542                            throw processException(e);
17543                    }
17544                    finally {
17545                            closeSession(session);
17546                    }
17547            }
17548    
17549            private static final String _FINDER_COLUMN_G_U_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17550            private static final String _FINDER_COLUMN_G_U_C_S_GROUPID_5 = "(" +
17551                    removeConjunction(_FINDER_COLUMN_G_U_C_S_GROUPID_2) + ")";
17552            private static final String _FINDER_COLUMN_G_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
17553            private static final String _FINDER_COLUMN_G_U_C_S_USERID_5 = "(" +
17554                    removeConjunction(_FINDER_COLUMN_G_U_C_S_USERID_2) + ")";
17555            private static final String _FINDER_COLUMN_G_U_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17556            private static final String _FINDER_COLUMN_G_U_C_S_CATEGORYID_5 = "(" +
17557                    removeConjunction(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2) + ")";
17558            private static final String _FINDER_COLUMN_G_U_C_S_STATUS_2 = "mbMessage.status = ?";
17559            private static final String _FINDER_COLUMN_G_U_C_S_STATUS_5 = "(" +
17560                    removeConjunction(_FINDER_COLUMN_G_U_C_S_STATUS_2) + ")";
17561            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17562                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
17564                            new String[] {
17565                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17566                                    Boolean.class.getName(),
17567                                    
17568                            Integer.class.getName(), Integer.class.getName(),
17569                                    OrderByComparator.class.getName()
17570                            });
17571            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
17572                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17573                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17574                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
17575                            new String[] {
17576                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17577                                    Boolean.class.getName()
17578                            },
17579                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17580                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17581                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17582                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
17583                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17584            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17585                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17586                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
17587                            new String[] {
17588                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17589                                    Boolean.class.getName()
17590                            });
17591    
17592            /**
17593             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17594             *
17595             * @param groupId the group ID
17596             * @param categoryId the category ID
17597             * @param threadId the thread ID
17598             * @param answer the answer
17599             * @return the matching message-boards messages
17600             * @throws SystemException if a system exception occurred
17601             */
17602            @Override
17603            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
17604                    long threadId, boolean answer) throws SystemException {
17605                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
17606                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17607            }
17608    
17609            /**
17610             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17611             *
17612             * <p>
17613             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17614             * </p>
17615             *
17616             * @param groupId the group ID
17617             * @param categoryId the category ID
17618             * @param threadId the thread ID
17619             * @param answer the answer
17620             * @param start the lower bound of the range of message-boards messages
17621             * @param end the upper bound of the range of message-boards messages (not inclusive)
17622             * @return the range of matching message-boards messages
17623             * @throws SystemException if a system exception occurred
17624             */
17625            @Override
17626            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
17627                    long threadId, boolean answer, int start, int end)
17628                    throws SystemException {
17629                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
17630                            null);
17631            }
17632    
17633            /**
17634             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17635             *
17636             * <p>
17637             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17638             * </p>
17639             *
17640             * @param groupId the group ID
17641             * @param categoryId the category ID
17642             * @param threadId the thread ID
17643             * @param answer the answer
17644             * @param start the lower bound of the range of message-boards messages
17645             * @param end the upper bound of the range of message-boards messages (not inclusive)
17646             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17647             * @return the ordered range of matching message-boards messages
17648             * @throws SystemException if a system exception occurred
17649             */
17650            @Override
17651            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
17652                    long threadId, boolean answer, int start, int end,
17653                    OrderByComparator orderByComparator) throws SystemException {
17654                    boolean pagination = true;
17655                    FinderPath finderPath = null;
17656                    Object[] finderArgs = null;
17657    
17658                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17659                                    (orderByComparator == null)) {
17660                            pagination = false;
17661                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
17662                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17663                    }
17664                    else {
17665                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
17666                            finderArgs = new Object[] {
17667                                            groupId, categoryId, threadId, answer,
17668                                            
17669                                            start, end, orderByComparator
17670                                    };
17671                    }
17672    
17673                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17674                                    finderArgs, this);
17675    
17676                    if ((list != null) && !list.isEmpty()) {
17677                            for (MBMessage mbMessage : list) {
17678                                    if ((groupId != mbMessage.getGroupId()) ||
17679                                                    (categoryId != mbMessage.getCategoryId()) ||
17680                                                    (threadId != mbMessage.getThreadId()) ||
17681                                                    (answer != mbMessage.getAnswer())) {
17682                                            list = null;
17683    
17684                                            break;
17685                                    }
17686                            }
17687                    }
17688    
17689                    if (list == null) {
17690                            StringBundler query = null;
17691    
17692                            if (orderByComparator != null) {
17693                                    query = new StringBundler(6 +
17694                                                    (orderByComparator.getOrderByFields().length * 3));
17695                            }
17696                            else {
17697                                    query = new StringBundler(6);
17698                            }
17699    
17700                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17701    
17702                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17703    
17704                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17705    
17706                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17707    
17708                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17709    
17710                            if (orderByComparator != null) {
17711                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17712                                            orderByComparator);
17713                            }
17714                            else
17715                             if (pagination) {
17716                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17717                            }
17718    
17719                            String sql = query.toString();
17720    
17721                            Session session = null;
17722    
17723                            try {
17724                                    session = openSession();
17725    
17726                                    Query q = session.createQuery(sql);
17727    
17728                                    QueryPos qPos = QueryPos.getInstance(q);
17729    
17730                                    qPos.add(groupId);
17731    
17732                                    qPos.add(categoryId);
17733    
17734                                    qPos.add(threadId);
17735    
17736                                    qPos.add(answer);
17737    
17738                                    if (!pagination) {
17739                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17740                                                            start, end, false);
17741    
17742                                            Collections.sort(list);
17743    
17744                                            list = new UnmodifiableList<MBMessage>(list);
17745                                    }
17746                                    else {
17747                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17748                                                            start, end);
17749                                    }
17750    
17751                                    cacheResult(list);
17752    
17753                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17754                            }
17755                            catch (Exception e) {
17756                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17757    
17758                                    throw processException(e);
17759                            }
17760                            finally {
17761                                    closeSession(session);
17762                            }
17763                    }
17764    
17765                    return list;
17766            }
17767    
17768            /**
17769             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17770             *
17771             * @param groupId the group ID
17772             * @param categoryId the category ID
17773             * @param threadId the thread ID
17774             * @param answer the answer
17775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17776             * @return the first matching message-boards message
17777             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17778             * @throws SystemException if a system exception occurred
17779             */
17780            @Override
17781            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
17782                    long threadId, boolean answer, OrderByComparator orderByComparator)
17783                    throws NoSuchMessageException, SystemException {
17784                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
17785                                    threadId, answer, orderByComparator);
17786    
17787                    if (mbMessage != null) {
17788                            return mbMessage;
17789                    }
17790    
17791                    StringBundler msg = new StringBundler(10);
17792    
17793                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17794    
17795                    msg.append("groupId=");
17796                    msg.append(groupId);
17797    
17798                    msg.append(", categoryId=");
17799                    msg.append(categoryId);
17800    
17801                    msg.append(", threadId=");
17802                    msg.append(threadId);
17803    
17804                    msg.append(", answer=");
17805                    msg.append(answer);
17806    
17807                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17808    
17809                    throw new NoSuchMessageException(msg.toString());
17810            }
17811    
17812            /**
17813             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17814             *
17815             * @param groupId the group ID
17816             * @param categoryId the category ID
17817             * @param threadId the thread ID
17818             * @param answer the answer
17819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17820             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17821             * @throws SystemException if a system exception occurred
17822             */
17823            @Override
17824            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
17825                    long threadId, boolean answer, OrderByComparator orderByComparator)
17826                    throws SystemException {
17827                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
17828                                    answer, 0, 1, orderByComparator);
17829    
17830                    if (!list.isEmpty()) {
17831                            return list.get(0);
17832                    }
17833    
17834                    return null;
17835            }
17836    
17837            /**
17838             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17839             *
17840             * @param groupId the group ID
17841             * @param categoryId the category ID
17842             * @param threadId the thread ID
17843             * @param answer the answer
17844             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17845             * @return the last matching message-boards message
17846             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17847             * @throws SystemException if a system exception occurred
17848             */
17849            @Override
17850            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
17851                    long threadId, boolean answer, OrderByComparator orderByComparator)
17852                    throws NoSuchMessageException, SystemException {
17853                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
17854                                    threadId, answer, orderByComparator);
17855    
17856                    if (mbMessage != null) {
17857                            return mbMessage;
17858                    }
17859    
17860                    StringBundler msg = new StringBundler(10);
17861    
17862                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17863    
17864                    msg.append("groupId=");
17865                    msg.append(groupId);
17866    
17867                    msg.append(", categoryId=");
17868                    msg.append(categoryId);
17869    
17870                    msg.append(", threadId=");
17871                    msg.append(threadId);
17872    
17873                    msg.append(", answer=");
17874                    msg.append(answer);
17875    
17876                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17877    
17878                    throw new NoSuchMessageException(msg.toString());
17879            }
17880    
17881            /**
17882             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17883             *
17884             * @param groupId the group ID
17885             * @param categoryId the category ID
17886             * @param threadId the thread ID
17887             * @param answer the answer
17888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17889             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17890             * @throws SystemException if a system exception occurred
17891             */
17892            @Override
17893            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
17894                    long threadId, boolean answer, OrderByComparator orderByComparator)
17895                    throws SystemException {
17896                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
17897    
17898                    if (count == 0) {
17899                            return null;
17900                    }
17901    
17902                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
17903                                    answer, count - 1, count, orderByComparator);
17904    
17905                    if (!list.isEmpty()) {
17906                            return list.get(0);
17907                    }
17908    
17909                    return null;
17910            }
17911    
17912            /**
17913             * 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;.
17914             *
17915             * @param messageId the primary key of the current message-boards message
17916             * @param groupId the group ID
17917             * @param categoryId the category ID
17918             * @param threadId the thread ID
17919             * @param answer the answer
17920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17921             * @return the previous, current, and next message-boards message
17922             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17923             * @throws SystemException if a system exception occurred
17924             */
17925            @Override
17926            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
17927                    long categoryId, long threadId, boolean answer,
17928                    OrderByComparator orderByComparator)
17929                    throws NoSuchMessageException, SystemException {
17930                    MBMessage mbMessage = findByPrimaryKey(messageId);
17931    
17932                    Session session = null;
17933    
17934                    try {
17935                            session = openSession();
17936    
17937                            MBMessage[] array = new MBMessageImpl[3];
17938    
17939                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
17940                                            categoryId, threadId, answer, orderByComparator, true);
17941    
17942                            array[1] = mbMessage;
17943    
17944                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
17945                                            categoryId, threadId, answer, orderByComparator, false);
17946    
17947                            return array;
17948                    }
17949                    catch (Exception e) {
17950                            throw processException(e);
17951                    }
17952                    finally {
17953                            closeSession(session);
17954                    }
17955            }
17956    
17957            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
17958                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17959                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
17960                    StringBundler query = null;
17961    
17962                    if (orderByComparator != null) {
17963                            query = new StringBundler(6 +
17964                                            (orderByComparator.getOrderByFields().length * 6));
17965                    }
17966                    else {
17967                            query = new StringBundler(3);
17968                    }
17969    
17970                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17971    
17972                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17973    
17974                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17975    
17976                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17977    
17978                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17979    
17980                    if (orderByComparator != null) {
17981                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17982    
17983                            if (orderByConditionFields.length > 0) {
17984                                    query.append(WHERE_AND);
17985                            }
17986    
17987                            for (int i = 0; i < orderByConditionFields.length; i++) {
17988                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17989                                    query.append(orderByConditionFields[i]);
17990    
17991                                    if ((i + 1) < orderByConditionFields.length) {
17992                                            if (orderByComparator.isAscending() ^ previous) {
17993                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17994                                            }
17995                                            else {
17996                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17997                                            }
17998                                    }
17999                                    else {
18000                                            if (orderByComparator.isAscending() ^ previous) {
18001                                                    query.append(WHERE_GREATER_THAN);
18002                                            }
18003                                            else {
18004                                                    query.append(WHERE_LESSER_THAN);
18005                                            }
18006                                    }
18007                            }
18008    
18009                            query.append(ORDER_BY_CLAUSE);
18010    
18011                            String[] orderByFields = orderByComparator.getOrderByFields();
18012    
18013                            for (int i = 0; i < orderByFields.length; i++) {
18014                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18015                                    query.append(orderByFields[i]);
18016    
18017                                    if ((i + 1) < orderByFields.length) {
18018                                            if (orderByComparator.isAscending() ^ previous) {
18019                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18020                                            }
18021                                            else {
18022                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18023                                            }
18024                                    }
18025                                    else {
18026                                            if (orderByComparator.isAscending() ^ previous) {
18027                                                    query.append(ORDER_BY_ASC);
18028                                            }
18029                                            else {
18030                                                    query.append(ORDER_BY_DESC);
18031                                            }
18032                                    }
18033                            }
18034                    }
18035                    else {
18036                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18037                    }
18038    
18039                    String sql = query.toString();
18040    
18041                    Query q = session.createQuery(sql);
18042    
18043                    q.setFirstResult(0);
18044                    q.setMaxResults(2);
18045    
18046                    QueryPos qPos = QueryPos.getInstance(q);
18047    
18048                    qPos.add(groupId);
18049    
18050                    qPos.add(categoryId);
18051    
18052                    qPos.add(threadId);
18053    
18054                    qPos.add(answer);
18055    
18056                    if (orderByComparator != null) {
18057                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18058    
18059                            for (Object value : values) {
18060                                    qPos.add(value);
18061                            }
18062                    }
18063    
18064                    List<MBMessage> list = q.list();
18065    
18066                    if (list.size() == 2) {
18067                            return list.get(1);
18068                    }
18069                    else {
18070                            return null;
18071                    }
18072            }
18073    
18074            /**
18075             * 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;.
18076             *
18077             * @param groupId the group ID
18078             * @param categoryId the category ID
18079             * @param threadId the thread ID
18080             * @param answer the answer
18081             * @return the matching message-boards messages that the user has permission to view
18082             * @throws SystemException if a system exception occurred
18083             */
18084            @Override
18085            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
18086                    long threadId, boolean answer) throws SystemException {
18087                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
18088                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18089            }
18090    
18091            /**
18092             * 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;.
18093             *
18094             * <p>
18095             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18096             * </p>
18097             *
18098             * @param groupId the group ID
18099             * @param categoryId the category ID
18100             * @param threadId the thread ID
18101             * @param answer the answer
18102             * @param start the lower bound of the range of message-boards messages
18103             * @param end the upper bound of the range of message-boards messages (not inclusive)
18104             * @return the range of matching message-boards messages that the user has permission to view
18105             * @throws SystemException if a system exception occurred
18106             */
18107            @Override
18108            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
18109                    long threadId, boolean answer, int start, int end)
18110                    throws SystemException {
18111                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
18112                            start, end, null);
18113            }
18114    
18115            /**
18116             * 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;.
18117             *
18118             * <p>
18119             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18120             * </p>
18121             *
18122             * @param groupId the group ID
18123             * @param categoryId the category ID
18124             * @param threadId the thread ID
18125             * @param answer the answer
18126             * @param start the lower bound of the range of message-boards messages
18127             * @param end the upper bound of the range of message-boards messages (not inclusive)
18128             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18129             * @return the ordered range of matching message-boards messages that the user has permission to view
18130             * @throws SystemException if a system exception occurred
18131             */
18132            @Override
18133            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
18134                    long threadId, boolean answer, int start, int end,
18135                    OrderByComparator orderByComparator) throws SystemException {
18136                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18137                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
18138                                    end, orderByComparator);
18139                    }
18140    
18141                    StringBundler query = null;
18142    
18143                    if (orderByComparator != null) {
18144                            query = new StringBundler(6 +
18145                                            (orderByComparator.getOrderByFields().length * 3));
18146                    }
18147                    else {
18148                            query = new StringBundler(6);
18149                    }
18150    
18151                    if (getDB().isSupportsInlineDistinct()) {
18152                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
18153                    }
18154                    else {
18155                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
18156                    }
18157    
18158                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18159    
18160                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18161    
18162                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18163    
18164                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18165    
18166                    if (!getDB().isSupportsInlineDistinct()) {
18167                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
18168                    }
18169    
18170                    if (orderByComparator != null) {
18171                            if (getDB().isSupportsInlineDistinct()) {
18172                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18173                                            orderByComparator, true);
18174                            }
18175                            else {
18176                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
18177                                            orderByComparator, true);
18178                            }
18179                    }
18180                    else {
18181                            if (getDB().isSupportsInlineDistinct()) {
18182                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18183                            }
18184                            else {
18185                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18186                            }
18187                    }
18188    
18189                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18190                                    MBMessage.class.getName(),
18191                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18192    
18193                    Session session = null;
18194    
18195                    try {
18196                            session = openSession();
18197    
18198                            SQLQuery q = session.createSQLQuery(sql);
18199    
18200                            if (getDB().isSupportsInlineDistinct()) {
18201                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18202                            }
18203                            else {
18204                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18205                            }
18206    
18207                            QueryPos qPos = QueryPos.getInstance(q);
18208    
18209                            qPos.add(groupId);
18210    
18211                            qPos.add(categoryId);
18212    
18213                            qPos.add(threadId);
18214    
18215                            qPos.add(answer);
18216    
18217                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
18218                    }
18219                    catch (Exception e) {
18220                            throw processException(e);
18221                    }
18222                    finally {
18223                            closeSession(session);
18224                    }
18225            }
18226    
18227            /**
18228             * 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;.
18229             *
18230             * @param messageId the primary key of the current message-boards message
18231             * @param groupId the group ID
18232             * @param categoryId the category ID
18233             * @param threadId the thread ID
18234             * @param answer the answer
18235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18236             * @return the previous, current, and next message-boards message
18237             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18238             * @throws SystemException if a system exception occurred
18239             */
18240            @Override
18241            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
18242                    long groupId, long categoryId, long threadId, boolean answer,
18243                    OrderByComparator orderByComparator)
18244                    throws NoSuchMessageException, SystemException {
18245                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18246                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
18247                                    threadId, answer, orderByComparator);
18248                    }
18249    
18250                    MBMessage mbMessage = findByPrimaryKey(messageId);
18251    
18252                    Session session = null;
18253    
18254                    try {
18255                            session = openSession();
18256    
18257                            MBMessage[] array = new MBMessageImpl[3];
18258    
18259                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
18260                                            groupId, categoryId, threadId, answer, orderByComparator,
18261                                            true);
18262    
18263                            array[1] = mbMessage;
18264    
18265                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
18266                                            groupId, categoryId, threadId, answer, orderByComparator,
18267                                            false);
18268    
18269                            return array;
18270                    }
18271                    catch (Exception e) {
18272                            throw processException(e);
18273                    }
18274                    finally {
18275                            closeSession(session);
18276                    }
18277            }
18278    
18279            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
18280                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
18281                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
18282                    StringBundler query = null;
18283    
18284                    if (orderByComparator != null) {
18285                            query = new StringBundler(6 +
18286                                            (orderByComparator.getOrderByFields().length * 6));
18287                    }
18288                    else {
18289                            query = new StringBundler(3);
18290                    }
18291    
18292                    if (getDB().isSupportsInlineDistinct()) {
18293                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
18294                    }
18295                    else {
18296                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
18297                    }
18298    
18299                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18300    
18301                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18302    
18303                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18304    
18305                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18306    
18307                    if (!getDB().isSupportsInlineDistinct()) {
18308                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
18309                    }
18310    
18311                    if (orderByComparator != null) {
18312                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18313    
18314                            if (orderByConditionFields.length > 0) {
18315                                    query.append(WHERE_AND);
18316                            }
18317    
18318                            for (int i = 0; i < orderByConditionFields.length; i++) {
18319                                    if (getDB().isSupportsInlineDistinct()) {
18320                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18321                                    }
18322                                    else {
18323                                            query.append(_ORDER_BY_ENTITY_TABLE);
18324                                    }
18325    
18326                                    query.append(orderByConditionFields[i]);
18327    
18328                                    if ((i + 1) < orderByConditionFields.length) {
18329                                            if (orderByComparator.isAscending() ^ previous) {
18330                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18331                                            }
18332                                            else {
18333                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18334                                            }
18335                                    }
18336                                    else {
18337                                            if (orderByComparator.isAscending() ^ previous) {
18338                                                    query.append(WHERE_GREATER_THAN);
18339                                            }
18340                                            else {
18341                                                    query.append(WHERE_LESSER_THAN);
18342                                            }
18343                                    }
18344                            }
18345    
18346                            query.append(ORDER_BY_CLAUSE);
18347    
18348                            String[] orderByFields = orderByComparator.getOrderByFields();
18349    
18350                            for (int i = 0; i < orderByFields.length; i++) {
18351                                    if (getDB().isSupportsInlineDistinct()) {
18352                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18353                                    }
18354                                    else {
18355                                            query.append(_ORDER_BY_ENTITY_TABLE);
18356                                    }
18357    
18358                                    query.append(orderByFields[i]);
18359    
18360                                    if ((i + 1) < orderByFields.length) {
18361                                            if (orderByComparator.isAscending() ^ previous) {
18362                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18363                                            }
18364                                            else {
18365                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18366                                            }
18367                                    }
18368                                    else {
18369                                            if (orderByComparator.isAscending() ^ previous) {
18370                                                    query.append(ORDER_BY_ASC);
18371                                            }
18372                                            else {
18373                                                    query.append(ORDER_BY_DESC);
18374                                            }
18375                                    }
18376                            }
18377                    }
18378                    else {
18379                            if (getDB().isSupportsInlineDistinct()) {
18380                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18381                            }
18382                            else {
18383                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18384                            }
18385                    }
18386    
18387                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18388                                    MBMessage.class.getName(),
18389                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18390    
18391                    SQLQuery q = session.createSQLQuery(sql);
18392    
18393                    q.setFirstResult(0);
18394                    q.setMaxResults(2);
18395    
18396                    if (getDB().isSupportsInlineDistinct()) {
18397                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18398                    }
18399                    else {
18400                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18401                    }
18402    
18403                    QueryPos qPos = QueryPos.getInstance(q);
18404    
18405                    qPos.add(groupId);
18406    
18407                    qPos.add(categoryId);
18408    
18409                    qPos.add(threadId);
18410    
18411                    qPos.add(answer);
18412    
18413                    if (orderByComparator != null) {
18414                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18415    
18416                            for (Object value : values) {
18417                                    qPos.add(value);
18418                            }
18419                    }
18420    
18421                    List<MBMessage> list = q.list();
18422    
18423                    if (list.size() == 2) {
18424                            return list.get(1);
18425                    }
18426                    else {
18427                            return null;
18428                    }
18429            }
18430    
18431            /**
18432             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
18433             *
18434             * @param groupId the group ID
18435             * @param categoryId the category ID
18436             * @param threadId the thread ID
18437             * @param answer the answer
18438             * @throws SystemException if a system exception occurred
18439             */
18440            @Override
18441            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
18442                    boolean answer) throws SystemException {
18443                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
18444                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18445                            remove(mbMessage);
18446                    }
18447            }
18448    
18449            /**
18450             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
18451             *
18452             * @param groupId the group ID
18453             * @param categoryId the category ID
18454             * @param threadId the thread ID
18455             * @param answer the answer
18456             * @return the number of matching message-boards messages
18457             * @throws SystemException if a system exception occurred
18458             */
18459            @Override
18460            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
18461                    boolean answer) throws SystemException {
18462                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
18463    
18464                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
18465    
18466                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18467                                    this);
18468    
18469                    if (count == null) {
18470                            StringBundler query = new StringBundler(5);
18471    
18472                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18473    
18474                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18475    
18476                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18477    
18478                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18479    
18480                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18481    
18482                            String sql = query.toString();
18483    
18484                            Session session = null;
18485    
18486                            try {
18487                                    session = openSession();
18488    
18489                                    Query q = session.createQuery(sql);
18490    
18491                                    QueryPos qPos = QueryPos.getInstance(q);
18492    
18493                                    qPos.add(groupId);
18494    
18495                                    qPos.add(categoryId);
18496    
18497                                    qPos.add(threadId);
18498    
18499                                    qPos.add(answer);
18500    
18501                                    count = (Long)q.uniqueResult();
18502    
18503                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18504                            }
18505                            catch (Exception e) {
18506                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18507    
18508                                    throw processException(e);
18509                            }
18510                            finally {
18511                                    closeSession(session);
18512                            }
18513                    }
18514    
18515                    return count.intValue();
18516            }
18517    
18518            /**
18519             * 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;.
18520             *
18521             * @param groupId the group ID
18522             * @param categoryId the category ID
18523             * @param threadId the thread ID
18524             * @param answer the answer
18525             * @return the number of matching message-boards messages that the user has permission to view
18526             * @throws SystemException if a system exception occurred
18527             */
18528            @Override
18529            public int filterCountByG_C_T_A(long groupId, long categoryId,
18530                    long threadId, boolean answer) throws SystemException {
18531                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18532                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
18533                    }
18534    
18535                    StringBundler query = new StringBundler(5);
18536    
18537                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18538    
18539                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18540    
18541                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18542    
18543                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18544    
18545                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18546    
18547                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18548                                    MBMessage.class.getName(),
18549                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18550    
18551                    Session session = null;
18552    
18553                    try {
18554                            session = openSession();
18555    
18556                            SQLQuery q = session.createSQLQuery(sql);
18557    
18558                            q.addScalar(COUNT_COLUMN_NAME,
18559                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18560    
18561                            QueryPos qPos = QueryPos.getInstance(q);
18562    
18563                            qPos.add(groupId);
18564    
18565                            qPos.add(categoryId);
18566    
18567                            qPos.add(threadId);
18568    
18569                            qPos.add(answer);
18570    
18571                            Long count = (Long)q.uniqueResult();
18572    
18573                            return count.intValue();
18574                    }
18575                    catch (Exception e) {
18576                            throw processException(e);
18577                    }
18578                    finally {
18579                            closeSession(session);
18580                    }
18581            }
18582    
18583            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
18584            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18585            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
18586            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
18587            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18588                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18589                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
18590                            new String[] {
18591                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18592                                    Integer.class.getName(),
18593                                    
18594                            Integer.class.getName(), Integer.class.getName(),
18595                                    OrderByComparator.class.getName()
18596                            });
18597            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
18598                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18599                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18600                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
18601                            new String[] {
18602                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18603                                    Integer.class.getName()
18604                            },
18605                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
18606                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
18607                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
18608                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18609                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18610            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18611                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18612                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
18613                            new String[] {
18614                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18615                                    Integer.class.getName()
18616                            });
18617    
18618            /**
18619             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18620             *
18621             * @param groupId the group ID
18622             * @param categoryId the category ID
18623             * @param threadId the thread ID
18624             * @param status the status
18625             * @return the matching message-boards messages
18626             * @throws SystemException if a system exception occurred
18627             */
18628            @Override
18629            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
18630                    long threadId, int status) throws SystemException {
18631                    return findByG_C_T_S(groupId, categoryId, threadId, status,
18632                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18633            }
18634    
18635            /**
18636             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18637             *
18638             * <p>
18639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18640             * </p>
18641             *
18642             * @param groupId the group ID
18643             * @param categoryId the category ID
18644             * @param threadId the thread ID
18645             * @param status the status
18646             * @param start the lower bound of the range of message-boards messages
18647             * @param end the upper bound of the range of message-boards messages (not inclusive)
18648             * @return the range of matching message-boards messages
18649             * @throws SystemException if a system exception occurred
18650             */
18651            @Override
18652            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
18653                    long threadId, int status, int start, int end)
18654                    throws SystemException {
18655                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
18656                            null);
18657            }
18658    
18659            /**
18660             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18661             *
18662             * <p>
18663             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18664             * </p>
18665             *
18666             * @param groupId the group ID
18667             * @param categoryId the category ID
18668             * @param threadId the thread ID
18669             * @param status the status
18670             * @param start the lower bound of the range of message-boards messages
18671             * @param end the upper bound of the range of message-boards messages (not inclusive)
18672             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18673             * @return the ordered range of matching message-boards messages
18674             * @throws SystemException if a system exception occurred
18675             */
18676            @Override
18677            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
18678                    long threadId, int status, int start, int end,
18679                    OrderByComparator orderByComparator) throws SystemException {
18680                    boolean pagination = true;
18681                    FinderPath finderPath = null;
18682                    Object[] finderArgs = null;
18683    
18684                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18685                                    (orderByComparator == null)) {
18686                            pagination = false;
18687                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
18688                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
18689                    }
18690                    else {
18691                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
18692                            finderArgs = new Object[] {
18693                                            groupId, categoryId, threadId, status,
18694                                            
18695                                            start, end, orderByComparator
18696                                    };
18697                    }
18698    
18699                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
18700                                    finderArgs, this);
18701    
18702                    if ((list != null) && !list.isEmpty()) {
18703                            for (MBMessage mbMessage : list) {
18704                                    if ((groupId != mbMessage.getGroupId()) ||
18705                                                    (categoryId != mbMessage.getCategoryId()) ||
18706                                                    (threadId != mbMessage.getThreadId()) ||
18707                                                    (status != mbMessage.getStatus())) {
18708                                            list = null;
18709    
18710                                            break;
18711                                    }
18712                            }
18713                    }
18714    
18715                    if (list == null) {
18716                            StringBundler query = null;
18717    
18718                            if (orderByComparator != null) {
18719                                    query = new StringBundler(6 +
18720                                                    (orderByComparator.getOrderByFields().length * 3));
18721                            }
18722                            else {
18723                                    query = new StringBundler(6);
18724                            }
18725    
18726                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18727    
18728                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18729    
18730                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18731    
18732                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18733    
18734                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18735    
18736                            if (orderByComparator != null) {
18737                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18738                                            orderByComparator);
18739                            }
18740                            else
18741                             if (pagination) {
18742                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18743                            }
18744    
18745                            String sql = query.toString();
18746    
18747                            Session session = null;
18748    
18749                            try {
18750                                    session = openSession();
18751    
18752                                    Query q = session.createQuery(sql);
18753    
18754                                    QueryPos qPos = QueryPos.getInstance(q);
18755    
18756                                    qPos.add(groupId);
18757    
18758                                    qPos.add(categoryId);
18759    
18760                                    qPos.add(threadId);
18761    
18762                                    qPos.add(status);
18763    
18764                                    if (!pagination) {
18765                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18766                                                            start, end, false);
18767    
18768                                            Collections.sort(list);
18769    
18770                                            list = new UnmodifiableList<MBMessage>(list);
18771                                    }
18772                                    else {
18773                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18774                                                            start, end);
18775                                    }
18776    
18777                                    cacheResult(list);
18778    
18779                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18780                            }
18781                            catch (Exception e) {
18782                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18783    
18784                                    throw processException(e);
18785                            }
18786                            finally {
18787                                    closeSession(session);
18788                            }
18789                    }
18790    
18791                    return list;
18792            }
18793    
18794            /**
18795             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18796             *
18797             * @param groupId the group ID
18798             * @param categoryId the category ID
18799             * @param threadId the thread ID
18800             * @param status the status
18801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18802             * @return the first matching message-boards message
18803             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
18804             * @throws SystemException if a system exception occurred
18805             */
18806            @Override
18807            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
18808                    long threadId, int status, OrderByComparator orderByComparator)
18809                    throws NoSuchMessageException, SystemException {
18810                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
18811                                    threadId, status, orderByComparator);
18812    
18813                    if (mbMessage != null) {
18814                            return mbMessage;
18815                    }
18816    
18817                    StringBundler msg = new StringBundler(10);
18818    
18819                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18820    
18821                    msg.append("groupId=");
18822                    msg.append(groupId);
18823    
18824                    msg.append(", categoryId=");
18825                    msg.append(categoryId);
18826    
18827                    msg.append(", threadId=");
18828                    msg.append(threadId);
18829    
18830                    msg.append(", status=");
18831                    msg.append(status);
18832    
18833                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18834    
18835                    throw new NoSuchMessageException(msg.toString());
18836            }
18837    
18838            /**
18839             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18840             *
18841             * @param groupId the group ID
18842             * @param categoryId the category ID
18843             * @param threadId the thread ID
18844             * @param status the status
18845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18846             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18847             * @throws SystemException if a system exception occurred
18848             */
18849            @Override
18850            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
18851                    long threadId, int status, OrderByComparator orderByComparator)
18852                    throws SystemException {
18853                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
18854                                    status, 0, 1, orderByComparator);
18855    
18856                    if (!list.isEmpty()) {
18857                            return list.get(0);
18858                    }
18859    
18860                    return null;
18861            }
18862    
18863            /**
18864             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18865             *
18866             * @param groupId the group ID
18867             * @param categoryId the category ID
18868             * @param threadId the thread ID
18869             * @param status the status
18870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18871             * @return the last matching message-boards message
18872             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
18873             * @throws SystemException if a system exception occurred
18874             */
18875            @Override
18876            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
18877                    long threadId, int status, OrderByComparator orderByComparator)
18878                    throws NoSuchMessageException, SystemException {
18879                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
18880                                    threadId, status, orderByComparator);
18881    
18882                    if (mbMessage != null) {
18883                            return mbMessage;
18884                    }
18885    
18886                    StringBundler msg = new StringBundler(10);
18887    
18888                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18889    
18890                    msg.append("groupId=");
18891                    msg.append(groupId);
18892    
18893                    msg.append(", categoryId=");
18894                    msg.append(categoryId);
18895    
18896                    msg.append(", threadId=");
18897                    msg.append(threadId);
18898    
18899                    msg.append(", status=");
18900                    msg.append(status);
18901    
18902                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18903    
18904                    throw new NoSuchMessageException(msg.toString());
18905            }
18906    
18907            /**
18908             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18909             *
18910             * @param groupId the group ID
18911             * @param categoryId the category ID
18912             * @param threadId the thread ID
18913             * @param status the status
18914             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18915             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18916             * @throws SystemException if a system exception occurred
18917             */
18918            @Override
18919            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
18920                    long threadId, int status, OrderByComparator orderByComparator)
18921                    throws SystemException {
18922                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
18923    
18924                    if (count == 0) {
18925                            return null;
18926                    }
18927    
18928                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
18929                                    status, count - 1, count, orderByComparator);
18930    
18931                    if (!list.isEmpty()) {
18932                            return list.get(0);
18933                    }
18934    
18935                    return null;
18936            }
18937    
18938            /**
18939             * 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;.
18940             *
18941             * @param messageId the primary key of the current message-boards message
18942             * @param groupId the group ID
18943             * @param categoryId the category ID
18944             * @param threadId the thread ID
18945             * @param status the status
18946             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18947             * @return the previous, current, and next message-boards message
18948             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18949             * @throws SystemException if a system exception occurred
18950             */
18951            @Override
18952            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
18953                    long categoryId, long threadId, int status,
18954                    OrderByComparator orderByComparator)
18955                    throws NoSuchMessageException, SystemException {
18956                    MBMessage mbMessage = findByPrimaryKey(messageId);
18957    
18958                    Session session = null;
18959    
18960                    try {
18961                            session = openSession();
18962    
18963                            MBMessage[] array = new MBMessageImpl[3];
18964    
18965                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
18966                                            categoryId, threadId, status, orderByComparator, true);
18967    
18968                            array[1] = mbMessage;
18969    
18970                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
18971                                            categoryId, threadId, status, orderByComparator, false);
18972    
18973                            return array;
18974                    }
18975                    catch (Exception e) {
18976                            throw processException(e);
18977                    }
18978                    finally {
18979                            closeSession(session);
18980                    }
18981            }
18982    
18983            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
18984                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
18985                    int status, OrderByComparator orderByComparator, boolean previous) {
18986                    StringBundler query = null;
18987    
18988                    if (orderByComparator != null) {
18989                            query = new StringBundler(6 +
18990                                            (orderByComparator.getOrderByFields().length * 6));
18991                    }
18992                    else {
18993                            query = new StringBundler(3);
18994                    }
18995    
18996                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18997    
18998                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18999    
19000                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19001    
19002                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19003    
19004                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19005    
19006                    if (orderByComparator != null) {
19007                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
19008    
19009                            if (orderByConditionFields.length > 0) {
19010                                    query.append(WHERE_AND);
19011                            }
19012    
19013                            for (int i = 0; i < orderByConditionFields.length; i++) {
19014                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19015                                    query.append(orderByConditionFields[i]);
19016    
19017                                    if ((i + 1) < orderByConditionFields.length) {
19018                                            if (orderByComparator.isAscending() ^ previous) {
19019                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
19020                                            }
19021                                            else {
19022                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
19023                                            }
19024                                    }
19025                                    else {
19026                                            if (orderByComparator.isAscending() ^ previous) {
19027                                                    query.append(WHERE_GREATER_THAN);
19028                                            }
19029                                            else {
19030                                                    query.append(WHERE_LESSER_THAN);
19031                                            }
19032                                    }
19033                            }
19034    
19035                            query.append(ORDER_BY_CLAUSE);
19036    
19037                            String[] orderByFields = orderByComparator.getOrderByFields();
19038    
19039                            for (int i = 0; i < orderByFields.length; i++) {
19040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19041                                    query.append(orderByFields[i]);
19042    
19043                                    if ((i + 1) < orderByFields.length) {
19044                                            if (orderByComparator.isAscending() ^ previous) {
19045                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
19046                                            }
19047                                            else {
19048                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
19049                                            }
19050                                    }
19051                                    else {
19052                                            if (orderByComparator.isAscending() ^ previous) {
19053                                                    query.append(ORDER_BY_ASC);
19054                                            }
19055                                            else {
19056                                                    query.append(ORDER_BY_DESC);
19057                                            }
19058                                    }
19059                            }
19060                    }
19061                    else {
19062                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
19063                    }
19064    
19065                    String sql = query.toString();
19066    
19067                    Query q = session.createQuery(sql);
19068    
19069                    q.setFirstResult(0);
19070                    q.setMaxResults(2);
19071    
19072                    QueryPos qPos = QueryPos.getInstance(q);
19073    
19074                    qPos.add(groupId);
19075    
19076                    qPos.add(categoryId);
19077    
19078                    qPos.add(threadId);
19079    
19080                    qPos.add(status);
19081    
19082                    if (orderByComparator != null) {
19083                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
19084    
19085                            for (Object value : values) {
19086                                    qPos.add(value);
19087                            }
19088                    }
19089    
19090                    List<MBMessage> list = q.list();
19091    
19092                    if (list.size() == 2) {
19093                            return list.get(1);
19094                    }
19095                    else {
19096                            return null;
19097                    }
19098            }
19099    
19100            /**
19101             * 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;.
19102             *
19103             * @param groupId the group ID
19104             * @param categoryId the category ID
19105             * @param threadId the thread ID
19106             * @param status the status
19107             * @return the matching message-boards messages that the user has permission to view
19108             * @throws SystemException if a system exception occurred
19109             */
19110            @Override
19111            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
19112                    long threadId, int status) throws SystemException {
19113                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
19114                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19115            }
19116    
19117            /**
19118             * 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;.
19119             *
19120             * <p>
19121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19122             * </p>
19123             *
19124             * @param groupId the group ID
19125             * @param categoryId the category ID
19126             * @param threadId the thread ID
19127             * @param status the status
19128             * @param start the lower bound of the range of message-boards messages
19129             * @param end the upper bound of the range of message-boards messages (not inclusive)
19130             * @return the range of matching message-boards messages that the user has permission to view
19131             * @throws SystemException if a system exception occurred
19132             */
19133            @Override
19134            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
19135                    long threadId, int status, int start, int end)
19136                    throws SystemException {
19137                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
19138                            start, end, null);
19139            }
19140    
19141            /**
19142             * 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;.
19143             *
19144             * <p>
19145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19146             * </p>
19147             *
19148             * @param groupId the group ID
19149             * @param categoryId the category ID
19150             * @param threadId the thread ID
19151             * @param status the status
19152             * @param start the lower bound of the range of message-boards messages
19153             * @param end the upper bound of the range of message-boards messages (not inclusive)
19154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19155             * @return the ordered range of matching message-boards messages that the user has permission to view
19156             * @throws SystemException if a system exception occurred
19157             */
19158            @Override
19159            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
19160                    long threadId, int status, int start, int end,
19161                    OrderByComparator orderByComparator) throws SystemException {
19162                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19163                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
19164                                    end, orderByComparator);
19165                    }
19166    
19167                    StringBundler query = null;
19168    
19169                    if (orderByComparator != null) {
19170                            query = new StringBundler(6 +
19171                                            (orderByComparator.getOrderByFields().length * 3));
19172                    }
19173                    else {
19174                            query = new StringBundler(6);
19175                    }
19176    
19177                    if (getDB().isSupportsInlineDistinct()) {
19178                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
19179                    }
19180                    else {
19181                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
19182                    }
19183    
19184                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
19185    
19186                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19187    
19188                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19189    
19190                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19191    
19192                    if (!getDB().isSupportsInlineDistinct()) {
19193                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
19194                    }
19195    
19196                    if (orderByComparator != null) {
19197                            if (getDB().isSupportsInlineDistinct()) {
19198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19199                                            orderByComparator, true);
19200                            }
19201                            else {
19202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
19203                                            orderByComparator, true);
19204                            }
19205                    }
19206                    else {
19207                            if (getDB().isSupportsInlineDistinct()) {
19208                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
19209                            }
19210                            else {
19211                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
19212                            }
19213                    }
19214    
19215                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19216                                    MBMessage.class.getName(),
19217                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19218    
19219                    Session session = null;
19220    
19221                    try {
19222                            session = openSession();
19223    
19224                            SQLQuery q = session.createSQLQuery(sql);
19225    
19226                            if (getDB().isSupportsInlineDistinct()) {
19227                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
19228                            }
19229                            else {
19230                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
19231                            }
19232    
19233                            QueryPos qPos = QueryPos.getInstance(q);
19234    
19235                            qPos.add(groupId);
19236    
19237                            qPos.add(categoryId);
19238    
19239                            qPos.add(threadId);
19240    
19241                            qPos.add(status);
19242    
19243                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
19244                    }
19245                    catch (Exception e) {
19246                            throw processException(e);
19247                    }
19248                    finally {
19249                            closeSession(session);
19250                    }
19251            }
19252    
19253            /**
19254             * 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;.
19255             *
19256             * @param messageId the primary key of the current message-boards message
19257             * @param groupId the group ID
19258             * @param categoryId the category ID
19259             * @param threadId the thread ID
19260             * @param status the status
19261             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19262             * @return the previous, current, and next message-boards message
19263             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19264             * @throws SystemException if a system exception occurred
19265             */
19266            @Override
19267            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
19268                    long groupId, long categoryId, long threadId, int status,
19269                    OrderByComparator orderByComparator)
19270                    throws NoSuchMessageException, SystemException {
19271                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19272                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
19273                                    threadId, status, orderByComparator);
19274                    }
19275    
19276                    MBMessage mbMessage = findByPrimaryKey(messageId);
19277    
19278                    Session session = null;
19279    
19280                    try {
19281                            session = openSession();
19282    
19283                            MBMessage[] array = new MBMessageImpl[3];
19284    
19285                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
19286                                            groupId, categoryId, threadId, status, orderByComparator,
19287                                            true);
19288    
19289                            array[1] = mbMessage;
19290    
19291                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
19292                                            groupId, categoryId, threadId, status, orderByComparator,
19293                                            false);
19294    
19295                            return array;
19296                    }
19297                    catch (Exception e) {
19298                            throw processException(e);
19299                    }
19300                    finally {
19301                            closeSession(session);
19302                    }
19303            }
19304    
19305            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
19306                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
19307                    int status, OrderByComparator orderByComparator, boolean previous) {
19308                    StringBundler query = null;
19309    
19310                    if (orderByComparator != null) {
19311                            query = new StringBundler(6 +
19312                                            (orderByComparator.getOrderByFields().length * 6));
19313                    }
19314                    else {
19315                            query = new StringBundler(3);
19316                    }
19317    
19318                    if (getDB().isSupportsInlineDistinct()) {
19319                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
19320                    }
19321                    else {
19322                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
19323                    }
19324    
19325                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
19326    
19327                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19328    
19329                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19330    
19331                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19332    
19333                    if (!getDB().isSupportsInlineDistinct()) {
19334                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
19335                    }
19336    
19337                    if (orderByComparator != null) {
19338                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
19339    
19340                            if (orderByConditionFields.length > 0) {
19341                                    query.append(WHERE_AND);
19342                            }
19343    
19344                            for (int i = 0; i < orderByConditionFields.length; i++) {
19345                                    if (getDB().isSupportsInlineDistinct()) {
19346                                            query.append(_ORDER_BY_ENTITY_ALIAS);
19347                                    }
19348                                    else {
19349                                            query.append(_ORDER_BY_ENTITY_TABLE);
19350                                    }
19351    
19352                                    query.append(orderByConditionFields[i]);
19353    
19354                                    if ((i + 1) < orderByConditionFields.length) {
19355                                            if (orderByComparator.isAscending() ^ previous) {
19356                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
19357                                            }
19358                                            else {
19359                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
19360                                            }
19361                                    }
19362                                    else {
19363                                            if (orderByComparator.isAscending() ^ previous) {
19364                                                    query.append(WHERE_GREATER_THAN);
19365                                            }
19366                                            else {
19367                                                    query.append(WHERE_LESSER_THAN);
19368                                            }
19369                                    }
19370                            }
19371    
19372                            query.append(ORDER_BY_CLAUSE);
19373    
19374                            String[] orderByFields = orderByComparator.getOrderByFields();
19375    
19376                            for (int i = 0; i < orderByFields.length; i++) {
19377                                    if (getDB().isSupportsInlineDistinct()) {
19378                                            query.append(_ORDER_BY_ENTITY_ALIAS);
19379                                    }
19380                                    else {
19381                                            query.append(_ORDER_BY_ENTITY_TABLE);
19382                                    }
19383    
19384                                    query.append(orderByFields[i]);
19385    
19386                                    if ((i + 1) < orderByFields.length) {
19387                                            if (orderByComparator.isAscending() ^ previous) {
19388                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
19389                                            }
19390                                            else {
19391                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
19392                                            }
19393                                    }
19394                                    else {
19395                                            if (orderByComparator.isAscending() ^ previous) {
19396                                                    query.append(ORDER_BY_ASC);
19397                                            }
19398                                            else {
19399                                                    query.append(ORDER_BY_DESC);
19400                                            }
19401                                    }
19402                            }
19403                    }
19404                    else {
19405                            if (getDB().isSupportsInlineDistinct()) {
19406                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
19407                            }
19408                            else {
19409                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
19410                            }
19411                    }
19412    
19413                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19414                                    MBMessage.class.getName(),
19415                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19416    
19417                    SQLQuery q = session.createSQLQuery(sql);
19418    
19419                    q.setFirstResult(0);
19420                    q.setMaxResults(2);
19421    
19422                    if (getDB().isSupportsInlineDistinct()) {
19423                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
19424                    }
19425                    else {
19426                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
19427                    }
19428    
19429                    QueryPos qPos = QueryPos.getInstance(q);
19430    
19431                    qPos.add(groupId);
19432    
19433                    qPos.add(categoryId);
19434    
19435                    qPos.add(threadId);
19436    
19437                    qPos.add(status);
19438    
19439                    if (orderByComparator != null) {
19440                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
19441    
19442                            for (Object value : values) {
19443                                    qPos.add(value);
19444                            }
19445                    }
19446    
19447                    List<MBMessage> list = q.list();
19448    
19449                    if (list.size() == 2) {
19450                            return list.get(1);
19451                    }
19452                    else {
19453                            return null;
19454                    }
19455            }
19456    
19457            /**
19458             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
19459             *
19460             * @param groupId the group ID
19461             * @param categoryId the category ID
19462             * @param threadId the thread ID
19463             * @param status the status
19464             * @throws SystemException if a system exception occurred
19465             */
19466            @Override
19467            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
19468                    int status) throws SystemException {
19469                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
19470                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
19471                            remove(mbMessage);
19472                    }
19473            }
19474    
19475            /**
19476             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
19477             *
19478             * @param groupId the group ID
19479             * @param categoryId the category ID
19480             * @param threadId the thread ID
19481             * @param status the status
19482             * @return the number of matching message-boards messages
19483             * @throws SystemException if a system exception occurred
19484             */
19485            @Override
19486            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
19487                    int status) throws SystemException {
19488                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
19489    
19490                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
19491    
19492                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
19493                                    this);
19494    
19495                    if (count == null) {
19496                            StringBundler query = new StringBundler(5);
19497    
19498                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
19499    
19500                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
19501    
19502                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19503    
19504                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19505    
19506                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19507    
19508                            String sql = query.toString();
19509    
19510                            Session session = null;
19511    
19512                            try {
19513                                    session = openSession();
19514    
19515                                    Query q = session.createQuery(sql);
19516    
19517                                    QueryPos qPos = QueryPos.getInstance(q);
19518    
19519                                    qPos.add(groupId);
19520    
19521                                    qPos.add(categoryId);
19522    
19523                                    qPos.add(threadId);
19524    
19525                                    qPos.add(status);
19526    
19527                                    count = (Long)q.uniqueResult();
19528    
19529                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19530                            }
19531                            catch (Exception e) {
19532                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19533    
19534                                    throw processException(e);
19535                            }
19536                            finally {
19537                                    closeSession(session);
19538                            }
19539                    }
19540    
19541                    return count.intValue();
19542            }
19543    
19544            /**
19545             * 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;.
19546             *
19547             * @param groupId the group ID
19548             * @param categoryId the category ID
19549             * @param threadId the thread ID
19550             * @param status the status
19551             * @return the number of matching message-boards messages that the user has permission to view
19552             * @throws SystemException if a system exception occurred
19553             */
19554            @Override
19555            public int filterCountByG_C_T_S(long groupId, long categoryId,
19556                    long threadId, int status) throws SystemException {
19557                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19558                            return countByG_C_T_S(groupId, categoryId, threadId, status);
19559                    }
19560    
19561                    StringBundler query = new StringBundler(5);
19562    
19563                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
19564    
19565                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
19566    
19567                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19568    
19569                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19570    
19571                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19572    
19573                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19574                                    MBMessage.class.getName(),
19575                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19576    
19577                    Session session = null;
19578    
19579                    try {
19580                            session = openSession();
19581    
19582                            SQLQuery q = session.createSQLQuery(sql);
19583    
19584                            q.addScalar(COUNT_COLUMN_NAME,
19585                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
19586    
19587                            QueryPos qPos = QueryPos.getInstance(q);
19588    
19589                            qPos.add(groupId);
19590    
19591                            qPos.add(categoryId);
19592    
19593                            qPos.add(threadId);
19594    
19595                            qPos.add(status);
19596    
19597                            Long count = (Long)q.uniqueResult();
19598    
19599                            return count.intValue();
19600                    }
19601                    catch (Exception e) {
19602                            throw processException(e);
19603                    }
19604                    finally {
19605                            closeSession(session);
19606                    }
19607            }
19608    
19609            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
19610            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
19611            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
19612            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
19613            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19614                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
19615                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
19616                            new String[] {
19617                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
19618                                    Integer.class.getName(),
19619                                    
19620                            Integer.class.getName(), Integer.class.getName(),
19621                                    OrderByComparator.class.getName()
19622                            });
19623            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
19624                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19625                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
19626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
19627                            new String[] {
19628                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
19629                                    Integer.class.getName()
19630                            },
19631                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
19632                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
19633                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
19634                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
19635                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
19636            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19637                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
19638                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
19639                            new String[] {
19640                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
19641                                    Integer.class.getName()
19642                            });
19643    
19644            /**
19645             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19646             *
19647             * @param userId the user ID
19648             * @param classNameId the class name ID
19649             * @param classPK the class p k
19650             * @param status the status
19651             * @return the matching message-boards messages
19652             * @throws SystemException if a system exception occurred
19653             */
19654            @Override
19655            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
19656                    long classPK, int status) throws SystemException {
19657                    return findByU_C_C_S(userId, classNameId, classPK, status,
19658                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19659            }
19660    
19661            /**
19662             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19663             *
19664             * <p>
19665             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19666             * </p>
19667             *
19668             * @param userId the user ID
19669             * @param classNameId the class name ID
19670             * @param classPK the class p k
19671             * @param status the status
19672             * @param start the lower bound of the range of message-boards messages
19673             * @param end the upper bound of the range of message-boards messages (not inclusive)
19674             * @return the range of matching message-boards messages
19675             * @throws SystemException if a system exception occurred
19676             */
19677            @Override
19678            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
19679                    long classPK, int status, int start, int end) throws SystemException {
19680                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
19681                            null);
19682            }
19683    
19684            /**
19685             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19686             *
19687             * <p>
19688             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19689             * </p>
19690             *
19691             * @param userId the user ID
19692             * @param classNameId the class name ID
19693             * @param classPK the class p k
19694             * @param status the status
19695             * @param start the lower bound of the range of message-boards messages
19696             * @param end the upper bound of the range of message-boards messages (not inclusive)
19697             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19698             * @return the ordered range of matching message-boards messages
19699             * @throws SystemException if a system exception occurred
19700             */
19701            @Override
19702            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
19703                    long classPK, int status, int start, int end,
19704                    OrderByComparator orderByComparator) throws SystemException {
19705                    boolean pagination = true;
19706                    FinderPath finderPath = null;
19707                    Object[] finderArgs = null;
19708    
19709                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19710                                    (orderByComparator == null)) {
19711                            pagination = false;
19712                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
19713                            finderArgs = new Object[] { userId, classNameId, classPK, status };
19714                    }
19715                    else {
19716                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
19717                            finderArgs = new Object[] {
19718                                            userId, classNameId, classPK, status,
19719                                            
19720                                            start, end, orderByComparator
19721                                    };
19722                    }
19723    
19724                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19725                                    finderArgs, this);
19726    
19727                    if ((list != null) && !list.isEmpty()) {
19728                            for (MBMessage mbMessage : list) {
19729                                    if ((userId != mbMessage.getUserId()) ||
19730                                                    (classNameId != mbMessage.getClassNameId()) ||
19731                                                    (classPK != mbMessage.getClassPK()) ||
19732                                                    (status != mbMessage.getStatus())) {
19733                                            list = null;
19734    
19735                                            break;
19736                                    }
19737                            }
19738                    }
19739    
19740                    if (list == null) {
19741                            StringBundler query = null;
19742    
19743                            if (orderByComparator != null) {
19744                                    query = new StringBundler(6 +
19745                                                    (orderByComparator.getOrderByFields().length * 3));
19746                            }
19747                            else {
19748                                    query = new StringBundler(6);
19749                            }
19750    
19751                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
19752    
19753                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
19754    
19755                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
19756    
19757                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
19758    
19759                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
19760    
19761                            if (orderByComparator != null) {
19762                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19763                                            orderByComparator);
19764                            }
19765                            else
19766                             if (pagination) {
19767                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
19768                            }
19769    
19770                            String sql = query.toString();
19771    
19772                            Session session = null;
19773    
19774                            try {
19775                                    session = openSession();
19776    
19777                                    Query q = session.createQuery(sql);
19778    
19779                                    QueryPos qPos = QueryPos.getInstance(q);
19780    
19781                                    qPos.add(userId);
19782    
19783                                    qPos.add(classNameId);
19784    
19785                                    qPos.add(classPK);
19786    
19787                                    qPos.add(status);
19788    
19789                                    if (!pagination) {
19790                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19791                                                            start, end, false);
19792    
19793                                            Collections.sort(list);
19794    
19795                                            list = new UnmodifiableList<MBMessage>(list);
19796                                    }
19797                                    else {
19798                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19799                                                            start, end);
19800                                    }
19801    
19802                                    cacheResult(list);
19803    
19804                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19805                            }
19806                            catch (Exception e) {
19807                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19808    
19809                                    throw processException(e);
19810                            }
19811                            finally {
19812                                    closeSession(session);
19813                            }
19814                    }
19815    
19816                    return list;
19817            }
19818    
19819            /**
19820             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19821             *
19822             * @param userId the user ID
19823             * @param classNameId the class name ID
19824             * @param classPK the class p k
19825             * @param status the status
19826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19827             * @return the first matching message-boards message
19828             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
19829             * @throws SystemException if a system exception occurred
19830             */
19831            @Override
19832            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
19833                    long classPK, int status, OrderByComparator orderByComparator)
19834                    throws NoSuchMessageException, SystemException {
19835                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
19836                                    classPK, status, orderByComparator);
19837    
19838                    if (mbMessage != null) {
19839                            return mbMessage;
19840                    }
19841    
19842                    StringBundler msg = new StringBundler(10);
19843    
19844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19845    
19846                    msg.append("userId=");
19847                    msg.append(userId);
19848    
19849                    msg.append(", classNameId=");
19850                    msg.append(classNameId);
19851    
19852                    msg.append(", classPK=");
19853                    msg.append(classPK);
19854    
19855                    msg.append(", status=");
19856                    msg.append(status);
19857    
19858                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19859    
19860                    throw new NoSuchMessageException(msg.toString());
19861            }
19862    
19863            /**
19864             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19865             *
19866             * @param userId the user ID
19867             * @param classNameId the class name ID
19868             * @param classPK the class p k
19869             * @param status the status
19870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19871             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
19872             * @throws SystemException if a system exception occurred
19873             */
19874            @Override
19875            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
19876                    long classPK, int status, OrderByComparator orderByComparator)
19877                    throws SystemException {
19878                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
19879                                    status, 0, 1, orderByComparator);
19880    
19881                    if (!list.isEmpty()) {
19882                            return list.get(0);
19883                    }
19884    
19885                    return null;
19886            }
19887    
19888            /**
19889             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19890             *
19891             * @param userId the user ID
19892             * @param classNameId the class name ID
19893             * @param classPK the class p k
19894             * @param status the status
19895             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19896             * @return the last matching message-boards message
19897             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
19898             * @throws SystemException if a system exception occurred
19899             */
19900            @Override
19901            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
19902                    long classPK, int status, OrderByComparator orderByComparator)
19903                    throws NoSuchMessageException, SystemException {
19904                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
19905                                    status, orderByComparator);
19906    
19907                    if (mbMessage != null) {
19908                            return mbMessage;
19909                    }
19910    
19911                    StringBundler msg = new StringBundler(10);
19912    
19913                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19914    
19915                    msg.append("userId=");
19916                    msg.append(userId);
19917    
19918                    msg.append(", classNameId=");
19919                    msg.append(classNameId);
19920    
19921                    msg.append(", classPK=");
19922                    msg.append(classPK);
19923    
19924                    msg.append(", status=");
19925                    msg.append(status);
19926    
19927                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19928    
19929                    throw new NoSuchMessageException(msg.toString());
19930            }
19931    
19932            /**
19933             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19934             *
19935             * @param userId the user ID
19936             * @param classNameId the class name ID
19937             * @param classPK the class p k
19938             * @param status the status
19939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19940             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
19941             * @throws SystemException if a system exception occurred
19942             */
19943            @Override
19944            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
19945                    long classPK, int status, OrderByComparator orderByComparator)
19946                    throws SystemException {
19947                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
19948    
19949                    if (count == 0) {
19950                            return null;
19951                    }
19952    
19953                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
19954                                    status, count - 1, count, orderByComparator);
19955    
19956                    if (!list.isEmpty()) {
19957                            return list.get(0);
19958                    }
19959    
19960                    return null;
19961            }
19962    
19963            /**
19964             * 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;.
19965             *
19966             * @param messageId the primary key of the current message-boards message
19967             * @param userId the user ID
19968             * @param classNameId the class name ID
19969             * @param classPK the class p k
19970             * @param status the status
19971             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19972             * @return the previous, current, and next message-boards message
19973             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19974             * @throws SystemException if a system exception occurred
19975             */
19976            @Override
19977            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
19978                    long classNameId, long classPK, int status,
19979                    OrderByComparator orderByComparator)
19980                    throws NoSuchMessageException, SystemException {
19981                    MBMessage mbMessage = findByPrimaryKey(messageId);
19982    
19983                    Session session = null;
19984    
19985                    try {
19986                            session = openSession();
19987    
19988                            MBMessage[] array = new MBMessageImpl[3];
19989    
19990                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
19991                                            classNameId, classPK, status, orderByComparator, true);
19992    
19993                            array[1] = mbMessage;
19994    
19995                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
19996                                            classNameId, classPK, status, orderByComparator, false);
19997    
19998                            return array;
19999                    }
20000                    catch (Exception e) {
20001                            throw processException(e);
20002                    }
20003                    finally {
20004                            closeSession(session);
20005                    }
20006            }
20007    
20008            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
20009                    MBMessage mbMessage, long userId, long classNameId, long classPK,
20010                    int status, OrderByComparator orderByComparator, boolean previous) {
20011                    StringBundler query = null;
20012    
20013                    if (orderByComparator != null) {
20014                            query = new StringBundler(6 +
20015                                            (orderByComparator.getOrderByFields().length * 6));
20016                    }
20017                    else {
20018                            query = new StringBundler(3);
20019                    }
20020    
20021                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
20022    
20023                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
20024    
20025                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
20026    
20027                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
20028    
20029                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
20030    
20031                    if (orderByComparator != null) {
20032                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20033    
20034                            if (orderByConditionFields.length > 0) {
20035                                    query.append(WHERE_AND);
20036                            }
20037    
20038                            for (int i = 0; i < orderByConditionFields.length; i++) {
20039                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20040                                    query.append(orderByConditionFields[i]);
20041    
20042                                    if ((i + 1) < orderByConditionFields.length) {
20043                                            if (orderByComparator.isAscending() ^ previous) {
20044                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20045                                            }
20046                                            else {
20047                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20048                                            }
20049                                    }
20050                                    else {
20051                                            if (orderByComparator.isAscending() ^ previous) {
20052                                                    query.append(WHERE_GREATER_THAN);
20053                                            }
20054                                            else {
20055                                                    query.append(WHERE_LESSER_THAN);
20056                                            }
20057                                    }
20058                            }
20059    
20060                            query.append(ORDER_BY_CLAUSE);
20061    
20062                            String[] orderByFields = orderByComparator.getOrderByFields();
20063    
20064                            for (int i = 0; i < orderByFields.length; i++) {
20065                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20066                                    query.append(orderByFields[i]);
20067    
20068                                    if ((i + 1) < orderByFields.length) {
20069                                            if (orderByComparator.isAscending() ^ previous) {
20070                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20071                                            }
20072                                            else {
20073                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20074                                            }
20075                                    }
20076                                    else {
20077                                            if (orderByComparator.isAscending() ^ previous) {
20078                                                    query.append(ORDER_BY_ASC);
20079                                            }
20080                                            else {
20081                                                    query.append(ORDER_BY_DESC);
20082                                            }
20083                                    }
20084                            }
20085                    }
20086                    else {
20087                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
20088                    }
20089    
20090                    String sql = query.toString();
20091    
20092                    Query q = session.createQuery(sql);
20093    
20094                    q.setFirstResult(0);
20095                    q.setMaxResults(2);
20096    
20097                    QueryPos qPos = QueryPos.getInstance(q);
20098    
20099                    qPos.add(userId);
20100    
20101                    qPos.add(classNameId);
20102    
20103                    qPos.add(classPK);
20104    
20105                    qPos.add(status);
20106    
20107                    if (orderByComparator != null) {
20108                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
20109    
20110                            for (Object value : values) {
20111                                    qPos.add(value);
20112                            }
20113                    }
20114    
20115                    List<MBMessage> list = q.list();
20116    
20117                    if (list.size() == 2) {
20118                            return list.get(1);
20119                    }
20120                    else {
20121                            return null;
20122                    }
20123            }
20124    
20125            /**
20126             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
20127             *
20128             * @param userId the user ID
20129             * @param classNameId the class name ID
20130             * @param classPK the class p k
20131             * @param status the status
20132             * @throws SystemException if a system exception occurred
20133             */
20134            @Override
20135            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
20136                    int status) throws SystemException {
20137                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
20138                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
20139                            remove(mbMessage);
20140                    }
20141            }
20142    
20143            /**
20144             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
20145             *
20146             * @param userId the user ID
20147             * @param classNameId the class name ID
20148             * @param classPK the class p k
20149             * @param status the status
20150             * @return the number of matching message-boards messages
20151             * @throws SystemException if a system exception occurred
20152             */
20153            @Override
20154            public int countByU_C_C_S(long userId, long classNameId, long classPK,
20155                    int status) throws SystemException {
20156                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
20157    
20158                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
20159    
20160                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
20161                                    this);
20162    
20163                    if (count == null) {
20164                            StringBundler query = new StringBundler(5);
20165    
20166                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
20167    
20168                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
20169    
20170                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
20171    
20172                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
20173    
20174                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
20175    
20176                            String sql = query.toString();
20177    
20178                            Session session = null;
20179    
20180                            try {
20181                                    session = openSession();
20182    
20183                                    Query q = session.createQuery(sql);
20184    
20185                                    QueryPos qPos = QueryPos.getInstance(q);
20186    
20187                                    qPos.add(userId);
20188    
20189                                    qPos.add(classNameId);
20190    
20191                                    qPos.add(classPK);
20192    
20193                                    qPos.add(status);
20194    
20195                                    count = (Long)q.uniqueResult();
20196    
20197                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
20198                            }
20199                            catch (Exception e) {
20200                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20201    
20202                                    throw processException(e);
20203                            }
20204                            finally {
20205                                    closeSession(session);
20206                            }
20207                    }
20208    
20209                    return count.intValue();
20210            }
20211    
20212            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
20213            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
20214            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
20215            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
20216    
20217            public MBMessagePersistenceImpl() {
20218                    setModelClass(MBMessage.class);
20219            }
20220    
20221            /**
20222             * Caches the message-boards message in the entity cache if it is enabled.
20223             *
20224             * @param mbMessage the message-boards message
20225             */
20226            @Override
20227            public void cacheResult(MBMessage mbMessage) {
20228                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20229                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
20230    
20231                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
20232                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
20233                            mbMessage);
20234    
20235                    mbMessage.resetOriginalValues();
20236            }
20237    
20238            /**
20239             * Caches the message-boards messages in the entity cache if it is enabled.
20240             *
20241             * @param mbMessages the message-boards messages
20242             */
20243            @Override
20244            public void cacheResult(List<MBMessage> mbMessages) {
20245                    for (MBMessage mbMessage : mbMessages) {
20246                            if (EntityCacheUtil.getResult(
20247                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20248                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
20249                                    cacheResult(mbMessage);
20250                            }
20251                            else {
20252                                    mbMessage.resetOriginalValues();
20253                            }
20254                    }
20255            }
20256    
20257            /**
20258             * Clears the cache for all message-boards messages.
20259             *
20260             * <p>
20261             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
20262             * </p>
20263             */
20264            @Override
20265            public void clearCache() {
20266                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
20267                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
20268                    }
20269    
20270                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
20271    
20272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
20273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20274                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20275            }
20276    
20277            /**
20278             * Clears the cache for the message-boards message.
20279             *
20280             * <p>
20281             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
20282             * </p>
20283             */
20284            @Override
20285            public void clearCache(MBMessage mbMessage) {
20286                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20287                            MBMessageImpl.class, mbMessage.getPrimaryKey());
20288    
20289                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20291    
20292                    clearUniqueFindersCache(mbMessage);
20293            }
20294    
20295            @Override
20296            public void clearCache(List<MBMessage> mbMessages) {
20297                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20298                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20299    
20300                    for (MBMessage mbMessage : mbMessages) {
20301                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20302                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
20303    
20304                            clearUniqueFindersCache(mbMessage);
20305                    }
20306            }
20307    
20308            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
20309                    if (mbMessage.isNew()) {
20310                            Object[] args = new Object[] {
20311                                            mbMessage.getUuid(), mbMessage.getGroupId()
20312                                    };
20313    
20314                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
20315                                    Long.valueOf(1));
20316                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
20317                                    mbMessage);
20318                    }
20319                    else {
20320                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
20321    
20322                            if ((mbMessageModelImpl.getColumnBitmask() &
20323                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
20324                                    Object[] args = new Object[] {
20325                                                    mbMessage.getUuid(), mbMessage.getGroupId()
20326                                            };
20327    
20328                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
20329                                            Long.valueOf(1));
20330                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
20331                                            mbMessage);
20332                            }
20333                    }
20334            }
20335    
20336            protected void clearUniqueFindersCache(MBMessage mbMessage) {
20337                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
20338    
20339                    Object[] args = new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() };
20340    
20341                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
20342                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
20343    
20344                    if ((mbMessageModelImpl.getColumnBitmask() &
20345                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
20346                            args = new Object[] {
20347                                            mbMessageModelImpl.getOriginalUuid(),
20348                                            mbMessageModelImpl.getOriginalGroupId()
20349                                    };
20350    
20351                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
20352                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
20353                    }
20354            }
20355    
20356            /**
20357             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
20358             *
20359             * @param messageId the primary key for the new message-boards message
20360             * @return the new message-boards message
20361             */
20362            @Override
20363            public MBMessage create(long messageId) {
20364                    MBMessage mbMessage = new MBMessageImpl();
20365    
20366                    mbMessage.setNew(true);
20367                    mbMessage.setPrimaryKey(messageId);
20368    
20369                    String uuid = PortalUUIDUtil.generate();
20370    
20371                    mbMessage.setUuid(uuid);
20372    
20373                    return mbMessage;
20374            }
20375    
20376            /**
20377             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
20378             *
20379             * @param messageId the primary key of the message-boards message
20380             * @return the message-boards message that was removed
20381             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
20382             * @throws SystemException if a system exception occurred
20383             */
20384            @Override
20385            public MBMessage remove(long messageId)
20386                    throws NoSuchMessageException, SystemException {
20387                    return remove((Serializable)messageId);
20388            }
20389    
20390            /**
20391             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
20392             *
20393             * @param primaryKey the primary key of the message-boards message
20394             * @return the message-boards message that was removed
20395             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
20396             * @throws SystemException if a system exception occurred
20397             */
20398            @Override
20399            public MBMessage remove(Serializable primaryKey)
20400                    throws NoSuchMessageException, SystemException {
20401                    Session session = null;
20402    
20403                    try {
20404                            session = openSession();
20405    
20406                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
20407                                            primaryKey);
20408    
20409                            if (mbMessage == null) {
20410                                    if (_log.isWarnEnabled()) {
20411                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
20412                                    }
20413    
20414                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
20415                                            primaryKey);
20416                            }
20417    
20418                            return remove(mbMessage);
20419                    }
20420                    catch (NoSuchMessageException nsee) {
20421                            throw nsee;
20422                    }
20423                    catch (Exception e) {
20424                            throw processException(e);
20425                    }
20426                    finally {
20427                            closeSession(session);
20428                    }
20429            }
20430    
20431            @Override
20432            protected MBMessage removeImpl(MBMessage mbMessage)
20433                    throws SystemException {
20434                    mbMessage = toUnwrappedModel(mbMessage);
20435    
20436                    Session session = null;
20437    
20438                    try {
20439                            session = openSession();
20440    
20441                            if (!session.contains(mbMessage)) {
20442                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
20443                                                    mbMessage.getPrimaryKeyObj());
20444                            }
20445    
20446                            if (mbMessage != null) {
20447                                    session.delete(mbMessage);
20448                            }
20449                    }
20450                    catch (Exception e) {
20451                            throw processException(e);
20452                    }
20453                    finally {
20454                            closeSession(session);
20455                    }
20456    
20457                    if (mbMessage != null) {
20458                            clearCache(mbMessage);
20459                    }
20460    
20461                    return mbMessage;
20462            }
20463    
20464            @Override
20465            public MBMessage updateImpl(
20466                    com.liferay.portlet.messageboards.model.MBMessage mbMessage)
20467                    throws SystemException {
20468                    mbMessage = toUnwrappedModel(mbMessage);
20469    
20470                    boolean isNew = mbMessage.isNew();
20471    
20472                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
20473    
20474                    if (Validator.isNull(mbMessage.getUuid())) {
20475                            String uuid = PortalUUIDUtil.generate();
20476    
20477                            mbMessage.setUuid(uuid);
20478                    }
20479    
20480                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
20481    
20482                    if (userId > 0) {
20483                            long companyId = mbMessage.getCompanyId();
20484    
20485                            long groupId = mbMessage.getGroupId();
20486    
20487                            long messageId = 0;
20488    
20489                            if (!isNew) {
20490                                    messageId = mbMessage.getPrimaryKey();
20491                            }
20492    
20493                            try {
20494                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
20495                                                    userId,
20496                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
20497                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
20498                                                    mbMessage.getSubject(), null));
20499                            }
20500                            catch (SanitizerException se) {
20501                                    throw new SystemException(se);
20502                            }
20503                    }
20504    
20505                    Session session = null;
20506    
20507                    try {
20508                            session = openSession();
20509    
20510                            if (mbMessage.isNew()) {
20511                                    session.save(mbMessage);
20512    
20513                                    mbMessage.setNew(false);
20514                            }
20515                            else {
20516                                    session.merge(mbMessage);
20517                            }
20518                    }
20519                    catch (Exception e) {
20520                            throw processException(e);
20521                    }
20522                    finally {
20523                            closeSession(session);
20524                    }
20525    
20526                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20527    
20528                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
20529                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20530                    }
20531    
20532                    else {
20533                            if ((mbMessageModelImpl.getColumnBitmask() &
20534                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
20535                                    Object[] args = new Object[] {
20536                                                    mbMessageModelImpl.getOriginalUuid()
20537                                            };
20538    
20539                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
20540                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
20541                                            args);
20542    
20543                                    args = new Object[] { mbMessageModelImpl.getUuid() };
20544    
20545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
20546                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
20547                                            args);
20548                            }
20549    
20550                            if ((mbMessageModelImpl.getColumnBitmask() &
20551                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
20552                                    Object[] args = new Object[] {
20553                                                    mbMessageModelImpl.getOriginalUuid(),
20554                                                    mbMessageModelImpl.getOriginalCompanyId()
20555                                            };
20556    
20557                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
20558                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
20559                                            args);
20560    
20561                                    args = new Object[] {
20562                                                    mbMessageModelImpl.getUuid(),
20563                                                    mbMessageModelImpl.getCompanyId()
20564                                            };
20565    
20566                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
20567                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
20568                                            args);
20569                            }
20570    
20571                            if ((mbMessageModelImpl.getColumnBitmask() &
20572                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
20573                                    Object[] args = new Object[] {
20574                                                    mbMessageModelImpl.getOriginalGroupId()
20575                                            };
20576    
20577                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
20578                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
20579                                            args);
20580    
20581                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
20582    
20583                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
20584                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
20585                                            args);
20586                            }
20587    
20588                            if ((mbMessageModelImpl.getColumnBitmask() &
20589                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
20590                                    Object[] args = new Object[] {
20591                                                    mbMessageModelImpl.getOriginalCompanyId()
20592                                            };
20593    
20594                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
20595                                            args);
20596                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
20597                                            args);
20598    
20599                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
20600    
20601                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
20602                                            args);
20603                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
20604                                            args);
20605                            }
20606    
20607                            if ((mbMessageModelImpl.getColumnBitmask() &
20608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
20609                                    Object[] args = new Object[] {
20610                                                    mbMessageModelImpl.getOriginalThreadId()
20611                                            };
20612    
20613                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
20614                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
20615                                            args);
20616    
20617                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
20618    
20619                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
20620                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
20621                                            args);
20622                            }
20623    
20624                            if ((mbMessageModelImpl.getColumnBitmask() &
20625                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
20626                                    Object[] args = new Object[] {
20627                                                    mbMessageModelImpl.getOriginalThreadId()
20628                                            };
20629    
20630                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
20631                                            args);
20632                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
20633                                            args);
20634    
20635                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
20636    
20637                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
20638                                            args);
20639                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
20640                                            args);
20641                            }
20642    
20643                            if ((mbMessageModelImpl.getColumnBitmask() &
20644                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
20645                                    Object[] args = new Object[] {
20646                                                    mbMessageModelImpl.getOriginalUserId()
20647                                            };
20648    
20649                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
20650                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
20651                                            args);
20652    
20653                                    args = new Object[] { mbMessageModelImpl.getUserId() };
20654    
20655                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
20656                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
20657                                            args);
20658                            }
20659    
20660                            if ((mbMessageModelImpl.getColumnBitmask() &
20661                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
20662                                    Object[] args = new Object[] {
20663                                                    mbMessageModelImpl.getOriginalGroupId(),
20664                                                    mbMessageModelImpl.getOriginalUserId()
20665                                            };
20666    
20667                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
20668                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
20669                                            args);
20670    
20671                                    args = new Object[] {
20672                                                    mbMessageModelImpl.getGroupId(),
20673                                                    mbMessageModelImpl.getUserId()
20674                                            };
20675    
20676                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
20677                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
20678                                            args);
20679                            }
20680    
20681                            if ((mbMessageModelImpl.getColumnBitmask() &
20682                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
20683                                    Object[] args = new Object[] {
20684                                                    mbMessageModelImpl.getOriginalGroupId(),
20685                                                    mbMessageModelImpl.getOriginalCategoryId()
20686                                            };
20687    
20688                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
20689                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
20690                                            args);
20691    
20692                                    args = new Object[] {
20693                                                    mbMessageModelImpl.getGroupId(),
20694                                                    mbMessageModelImpl.getCategoryId()
20695                                            };
20696    
20697                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
20698                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
20699                                            args);
20700                            }
20701    
20702                            if ((mbMessageModelImpl.getColumnBitmask() &
20703                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
20704                                    Object[] args = new Object[] {
20705                                                    mbMessageModelImpl.getOriginalGroupId(),
20706                                                    mbMessageModelImpl.getOriginalStatus()
20707                                            };
20708    
20709                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
20710                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
20711                                            args);
20712    
20713                                    args = new Object[] {
20714                                                    mbMessageModelImpl.getGroupId(),
20715                                                    mbMessageModelImpl.getStatus()
20716                                            };
20717    
20718                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
20719                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
20720                                            args);
20721                            }
20722    
20723                            if ((mbMessageModelImpl.getColumnBitmask() &
20724                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
20725                                    Object[] args = new Object[] {
20726                                                    mbMessageModelImpl.getOriginalCompanyId(),
20727                                                    mbMessageModelImpl.getOriginalStatus()
20728                                            };
20729    
20730                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
20731                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
20732                                            args);
20733    
20734                                    args = new Object[] {
20735                                                    mbMessageModelImpl.getCompanyId(),
20736                                                    mbMessageModelImpl.getStatus()
20737                                            };
20738    
20739                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
20740                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
20741                                            args);
20742                            }
20743    
20744                            if ((mbMessageModelImpl.getColumnBitmask() &
20745                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
20746                                    Object[] args = new Object[] {
20747                                                    mbMessageModelImpl.getOriginalUserId(),
20748                                                    mbMessageModelImpl.getOriginalClassNameId()
20749                                            };
20750    
20751                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
20752                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
20753                                            args);
20754    
20755                                    args = new Object[] {
20756                                                    mbMessageModelImpl.getUserId(),
20757                                                    mbMessageModelImpl.getClassNameId()
20758                                            };
20759    
20760                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
20761                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
20762                                            args);
20763                            }
20764    
20765                            if ((mbMessageModelImpl.getColumnBitmask() &
20766                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
20767                                    Object[] args = new Object[] {
20768                                                    mbMessageModelImpl.getOriginalClassNameId(),
20769                                                    mbMessageModelImpl.getOriginalClassPK()
20770                                            };
20771    
20772                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
20773                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
20774                                            args);
20775    
20776                                    args = new Object[] {
20777                                                    mbMessageModelImpl.getClassNameId(),
20778                                                    mbMessageModelImpl.getClassPK()
20779                                            };
20780    
20781                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
20782                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
20783                                            args);
20784                            }
20785    
20786                            if ((mbMessageModelImpl.getColumnBitmask() &
20787                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
20788                                    Object[] args = new Object[] {
20789                                                    mbMessageModelImpl.getOriginalThreadId(),
20790                                                    mbMessageModelImpl.getOriginalParentMessageId()
20791                                            };
20792    
20793                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
20794                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
20795                                            args);
20796    
20797                                    args = new Object[] {
20798                                                    mbMessageModelImpl.getThreadId(),
20799                                                    mbMessageModelImpl.getParentMessageId()
20800                                            };
20801    
20802                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
20803                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
20804                                            args);
20805                            }
20806    
20807                            if ((mbMessageModelImpl.getColumnBitmask() &
20808                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
20809                                    Object[] args = new Object[] {
20810                                                    mbMessageModelImpl.getOriginalThreadId(),
20811                                                    mbMessageModelImpl.getOriginalAnswer()
20812                                            };
20813    
20814                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
20815                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
20816                                            args);
20817    
20818                                    args = new Object[] {
20819                                                    mbMessageModelImpl.getThreadId(),
20820                                                    mbMessageModelImpl.getAnswer()
20821                                            };
20822    
20823                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
20824                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
20825                                            args);
20826                            }
20827    
20828                            if ((mbMessageModelImpl.getColumnBitmask() &
20829                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
20830                                    Object[] args = new Object[] {
20831                                                    mbMessageModelImpl.getOriginalThreadId(),
20832                                                    mbMessageModelImpl.getOriginalStatus()
20833                                            };
20834    
20835                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
20836                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
20837                                            args);
20838    
20839                                    args = new Object[] {
20840                                                    mbMessageModelImpl.getThreadId(),
20841                                                    mbMessageModelImpl.getStatus()
20842                                            };
20843    
20844                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
20845                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
20846                                            args);
20847                            }
20848    
20849                            if ((mbMessageModelImpl.getColumnBitmask() &
20850                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
20851                                    Object[] args = new Object[] {
20852                                                    mbMessageModelImpl.getOriginalThreadId(),
20853                                                    mbMessageModelImpl.getOriginalStatus()
20854                                            };
20855    
20856                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
20857                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
20858                                            args);
20859    
20860                                    args = new Object[] {
20861                                                    mbMessageModelImpl.getThreadId(),
20862                                                    mbMessageModelImpl.getStatus()
20863                                            };
20864    
20865                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
20866                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
20867                                            args);
20868                            }
20869    
20870                            if ((mbMessageModelImpl.getColumnBitmask() &
20871                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
20872                                    Object[] args = new Object[] {
20873                                                    mbMessageModelImpl.getOriginalGroupId(),
20874                                                    mbMessageModelImpl.getOriginalUserId(),
20875                                                    mbMessageModelImpl.getOriginalStatus()
20876                                            };
20877    
20878                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
20879                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
20880                                            args);
20881    
20882                                    args = new Object[] {
20883                                                    mbMessageModelImpl.getGroupId(),
20884                                                    mbMessageModelImpl.getUserId(),
20885                                                    mbMessageModelImpl.getStatus()
20886                                            };
20887    
20888                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
20889                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
20890                                            args);
20891                            }
20892    
20893                            if ((mbMessageModelImpl.getColumnBitmask() &
20894                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
20895                                    Object[] args = new Object[] {
20896                                                    mbMessageModelImpl.getOriginalGroupId(),
20897                                                    mbMessageModelImpl.getOriginalCategoryId(),
20898                                                    mbMessageModelImpl.getOriginalThreadId()
20899                                            };
20900    
20901                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
20902                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
20903                                            args);
20904    
20905                                    args = new Object[] {
20906                                                    mbMessageModelImpl.getGroupId(),
20907                                                    mbMessageModelImpl.getCategoryId(),
20908                                                    mbMessageModelImpl.getThreadId()
20909                                            };
20910    
20911                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
20912                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
20913                                            args);
20914                            }
20915    
20916                            if ((mbMessageModelImpl.getColumnBitmask() &
20917                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
20918                                    Object[] args = new Object[] {
20919                                                    mbMessageModelImpl.getOriginalGroupId(),
20920                                                    mbMessageModelImpl.getOriginalCategoryId(),
20921                                                    mbMessageModelImpl.getOriginalStatus()
20922                                            };
20923    
20924                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
20925                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
20926                                            args);
20927    
20928                                    args = new Object[] {
20929                                                    mbMessageModelImpl.getGroupId(),
20930                                                    mbMessageModelImpl.getCategoryId(),
20931                                                    mbMessageModelImpl.getStatus()
20932                                            };
20933    
20934                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
20935                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
20936                                            args);
20937                            }
20938    
20939                            if ((mbMessageModelImpl.getColumnBitmask() &
20940                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
20941                                    Object[] args = new Object[] {
20942                                                    mbMessageModelImpl.getOriginalUserId(),
20943                                                    mbMessageModelImpl.getOriginalClassNameId(),
20944                                                    mbMessageModelImpl.getOriginalClassPK()
20945                                            };
20946    
20947                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
20948                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
20949                                            args);
20950    
20951                                    args = new Object[] {
20952                                                    mbMessageModelImpl.getUserId(),
20953                                                    mbMessageModelImpl.getClassNameId(),
20954                                                    mbMessageModelImpl.getClassPK()
20955                                            };
20956    
20957                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
20958                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
20959                                            args);
20960                            }
20961    
20962                            if ((mbMessageModelImpl.getColumnBitmask() &
20963                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
20964                                    Object[] args = new Object[] {
20965                                                    mbMessageModelImpl.getOriginalUserId(),
20966                                                    mbMessageModelImpl.getOriginalClassNameId(),
20967                                                    mbMessageModelImpl.getOriginalStatus()
20968                                            };
20969    
20970                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
20971                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
20972                                            args);
20973    
20974                                    args = new Object[] {
20975                                                    mbMessageModelImpl.getUserId(),
20976                                                    mbMessageModelImpl.getClassNameId(),
20977                                                    mbMessageModelImpl.getStatus()
20978                                            };
20979    
20980                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
20981                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
20982                                            args);
20983                            }
20984    
20985                            if ((mbMessageModelImpl.getColumnBitmask() &
20986                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
20987                                    Object[] args = new Object[] {
20988                                                    mbMessageModelImpl.getOriginalClassNameId(),
20989                                                    mbMessageModelImpl.getOriginalClassPK(),
20990                                                    mbMessageModelImpl.getOriginalStatus()
20991                                            };
20992    
20993                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
20994                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
20995                                            args);
20996    
20997                                    args = new Object[] {
20998                                                    mbMessageModelImpl.getClassNameId(),
20999                                                    mbMessageModelImpl.getClassPK(),
21000                                                    mbMessageModelImpl.getStatus()
21001                                            };
21002    
21003                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
21004                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
21005                                            args);
21006                            }
21007    
21008                            if ((mbMessageModelImpl.getColumnBitmask() &
21009                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S.getColumnBitmask()) != 0) {
21010                                    Object[] args = new Object[] {
21011                                                    mbMessageModelImpl.getOriginalGroupId(),
21012                                                    mbMessageModelImpl.getOriginalUserId(),
21013                                                    mbMessageModelImpl.getOriginalCategoryId(),
21014                                                    mbMessageModelImpl.getOriginalStatus()
21015                                            };
21016    
21017                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_S, args);
21018                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S,
21019                                            args);
21020    
21021                                    args = new Object[] {
21022                                                    mbMessageModelImpl.getGroupId(),
21023                                                    mbMessageModelImpl.getUserId(),
21024                                                    mbMessageModelImpl.getCategoryId(),
21025                                                    mbMessageModelImpl.getStatus()
21026                                            };
21027    
21028                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_S, args);
21029                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S,
21030                                            args);
21031                            }
21032    
21033                            if ((mbMessageModelImpl.getColumnBitmask() &
21034                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
21035                                    Object[] args = new Object[] {
21036                                                    mbMessageModelImpl.getOriginalGroupId(),
21037                                                    mbMessageModelImpl.getOriginalCategoryId(),
21038                                                    mbMessageModelImpl.getOriginalThreadId(),
21039                                                    mbMessageModelImpl.getOriginalAnswer()
21040                                            };
21041    
21042                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
21043                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
21044                                            args);
21045    
21046                                    args = new Object[] {
21047                                                    mbMessageModelImpl.getGroupId(),
21048                                                    mbMessageModelImpl.getCategoryId(),
21049                                                    mbMessageModelImpl.getThreadId(),
21050                                                    mbMessageModelImpl.getAnswer()
21051                                            };
21052    
21053                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
21054                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
21055                                            args);
21056                            }
21057    
21058                            if ((mbMessageModelImpl.getColumnBitmask() &
21059                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
21060                                    Object[] args = new Object[] {
21061                                                    mbMessageModelImpl.getOriginalGroupId(),
21062                                                    mbMessageModelImpl.getOriginalCategoryId(),
21063                                                    mbMessageModelImpl.getOriginalThreadId(),
21064                                                    mbMessageModelImpl.getOriginalStatus()
21065                                            };
21066    
21067                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
21068                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
21069                                            args);
21070    
21071                                    args = new Object[] {
21072                                                    mbMessageModelImpl.getGroupId(),
21073                                                    mbMessageModelImpl.getCategoryId(),
21074                                                    mbMessageModelImpl.getThreadId(),
21075                                                    mbMessageModelImpl.getStatus()
21076                                            };
21077    
21078                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
21079                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
21080                                            args);
21081                            }
21082    
21083                            if ((mbMessageModelImpl.getColumnBitmask() &
21084                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
21085                                    Object[] args = new Object[] {
21086                                                    mbMessageModelImpl.getOriginalUserId(),
21087                                                    mbMessageModelImpl.getOriginalClassNameId(),
21088                                                    mbMessageModelImpl.getOriginalClassPK(),
21089                                                    mbMessageModelImpl.getOriginalStatus()
21090                                            };
21091    
21092                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
21093                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
21094                                            args);
21095    
21096                                    args = new Object[] {
21097                                                    mbMessageModelImpl.getUserId(),
21098                                                    mbMessageModelImpl.getClassNameId(),
21099                                                    mbMessageModelImpl.getClassPK(),
21100                                                    mbMessageModelImpl.getStatus()
21101                                            };
21102    
21103                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
21104                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
21105                                            args);
21106                            }
21107                    }
21108    
21109                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
21110                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
21111    
21112                    clearUniqueFindersCache(mbMessage);
21113                    cacheUniqueFindersCache(mbMessage);
21114    
21115                    return mbMessage;
21116            }
21117    
21118            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
21119                    if (mbMessage instanceof MBMessageImpl) {
21120                            return mbMessage;
21121                    }
21122    
21123                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
21124    
21125                    mbMessageImpl.setNew(mbMessage.isNew());
21126                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
21127    
21128                    mbMessageImpl.setUuid(mbMessage.getUuid());
21129                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
21130                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
21131                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
21132                    mbMessageImpl.setUserId(mbMessage.getUserId());
21133                    mbMessageImpl.setUserName(mbMessage.getUserName());
21134                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
21135                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
21136                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
21137                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
21138                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
21139                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
21140                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
21141                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
21142                    mbMessageImpl.setSubject(mbMessage.getSubject());
21143                    mbMessageImpl.setBody(mbMessage.getBody());
21144                    mbMessageImpl.setFormat(mbMessage.getFormat());
21145                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
21146                    mbMessageImpl.setPriority(mbMessage.getPriority());
21147                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
21148                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
21149                    mbMessageImpl.setStatus(mbMessage.getStatus());
21150                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
21151                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
21152                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
21153    
21154                    return mbMessageImpl;
21155            }
21156    
21157            /**
21158             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
21159             *
21160             * @param primaryKey the primary key of the message-boards message
21161             * @return the message-boards message
21162             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
21163             * @throws SystemException if a system exception occurred
21164             */
21165            @Override
21166            public MBMessage findByPrimaryKey(Serializable primaryKey)
21167                    throws NoSuchMessageException, SystemException {
21168                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
21169    
21170                    if (mbMessage == null) {
21171                            if (_log.isWarnEnabled()) {
21172                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
21173                            }
21174    
21175                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
21176                                    primaryKey);
21177                    }
21178    
21179                    return mbMessage;
21180            }
21181    
21182            /**
21183             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
21184             *
21185             * @param messageId the primary key of the message-boards message
21186             * @return the message-boards message
21187             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
21188             * @throws SystemException if a system exception occurred
21189             */
21190            @Override
21191            public MBMessage findByPrimaryKey(long messageId)
21192                    throws NoSuchMessageException, SystemException {
21193                    return findByPrimaryKey((Serializable)messageId);
21194            }
21195    
21196            /**
21197             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
21198             *
21199             * @param primaryKey the primary key of the message-boards message
21200             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
21201             * @throws SystemException if a system exception occurred
21202             */
21203            @Override
21204            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
21205                    throws SystemException {
21206                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
21207                                    MBMessageImpl.class, primaryKey);
21208    
21209                    if (mbMessage == _nullMBMessage) {
21210                            return null;
21211                    }
21212    
21213                    if (mbMessage == null) {
21214                            Session session = null;
21215    
21216                            try {
21217                                    session = openSession();
21218    
21219                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
21220                                                    primaryKey);
21221    
21222                                    if (mbMessage != null) {
21223                                            cacheResult(mbMessage);
21224                                    }
21225                                    else {
21226                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
21227                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
21228                                    }
21229                            }
21230                            catch (Exception e) {
21231                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
21232                                            MBMessageImpl.class, primaryKey);
21233    
21234                                    throw processException(e);
21235                            }
21236                            finally {
21237                                    closeSession(session);
21238                            }
21239                    }
21240    
21241                    return mbMessage;
21242            }
21243    
21244            /**
21245             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
21246             *
21247             * @param messageId the primary key of the message-boards message
21248             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
21249             * @throws SystemException if a system exception occurred
21250             */
21251            @Override
21252            public MBMessage fetchByPrimaryKey(long messageId)
21253                    throws SystemException {
21254                    return fetchByPrimaryKey((Serializable)messageId);
21255            }
21256    
21257            /**
21258             * Returns all the message-boards messages.
21259             *
21260             * @return the message-boards messages
21261             * @throws SystemException if a system exception occurred
21262             */
21263            @Override
21264            public List<MBMessage> findAll() throws SystemException {
21265                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
21266            }
21267    
21268            /**
21269             * Returns a range of all the message-boards messages.
21270             *
21271             * <p>
21272             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
21273             * </p>
21274             *
21275             * @param start the lower bound of the range of message-boards messages
21276             * @param end the upper bound of the range of message-boards messages (not inclusive)
21277             * @return the range of message-boards messages
21278             * @throws SystemException if a system exception occurred
21279             */
21280            @Override
21281            public List<MBMessage> findAll(int start, int end)
21282                    throws SystemException {
21283                    return findAll(start, end, null);
21284            }
21285    
21286            /**
21287             * Returns an ordered range of all the message-boards messages.
21288             *
21289             * <p>
21290             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
21291             * </p>
21292             *
21293             * @param start the lower bound of the range of message-boards messages
21294             * @param end the upper bound of the range of message-boards messages (not inclusive)
21295             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
21296             * @return the ordered range of message-boards messages
21297             * @throws SystemException if a system exception occurred
21298             */
21299            @Override
21300            public List<MBMessage> findAll(int start, int end,
21301                    OrderByComparator orderByComparator) throws SystemException {
21302                    boolean pagination = true;
21303                    FinderPath finderPath = null;
21304                    Object[] finderArgs = null;
21305    
21306                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
21307                                    (orderByComparator == null)) {
21308                            pagination = false;
21309                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
21310                            finderArgs = FINDER_ARGS_EMPTY;
21311                    }
21312                    else {
21313                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
21314                            finderArgs = new Object[] { start, end, orderByComparator };
21315                    }
21316    
21317                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
21318                                    finderArgs, this);
21319    
21320                    if (list == null) {
21321                            StringBundler query = null;
21322                            String sql = null;
21323    
21324                            if (orderByComparator != null) {
21325                                    query = new StringBundler(2 +
21326                                                    (orderByComparator.getOrderByFields().length * 3));
21327    
21328                                    query.append(_SQL_SELECT_MBMESSAGE);
21329    
21330                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
21331                                            orderByComparator);
21332    
21333                                    sql = query.toString();
21334                            }
21335                            else {
21336                                    sql = _SQL_SELECT_MBMESSAGE;
21337    
21338                                    if (pagination) {
21339                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
21340                                    }
21341                            }
21342    
21343                            Session session = null;
21344    
21345                            try {
21346                                    session = openSession();
21347    
21348                                    Query q = session.createQuery(sql);
21349    
21350                                    if (!pagination) {
21351                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
21352                                                            start, end, false);
21353    
21354                                            Collections.sort(list);
21355    
21356                                            list = new UnmodifiableList<MBMessage>(list);
21357                                    }
21358                                    else {
21359                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
21360                                                            start, end);
21361                                    }
21362    
21363                                    cacheResult(list);
21364    
21365                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
21366                            }
21367                            catch (Exception e) {
21368                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
21369    
21370                                    throw processException(e);
21371                            }
21372                            finally {
21373                                    closeSession(session);
21374                            }
21375                    }
21376    
21377                    return list;
21378            }
21379    
21380            /**
21381             * Removes all the message-boards messages from the database.
21382             *
21383             * @throws SystemException if a system exception occurred
21384             */
21385            @Override
21386            public void removeAll() throws SystemException {
21387                    for (MBMessage mbMessage : findAll()) {
21388                            remove(mbMessage);
21389                    }
21390            }
21391    
21392            /**
21393             * Returns the number of message-boards messages.
21394             *
21395             * @return the number of message-boards messages
21396             * @throws SystemException if a system exception occurred
21397             */
21398            @Override
21399            public int countAll() throws SystemException {
21400                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
21401                                    FINDER_ARGS_EMPTY, this);
21402    
21403                    if (count == null) {
21404                            Session session = null;
21405    
21406                            try {
21407                                    session = openSession();
21408    
21409                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
21410    
21411                                    count = (Long)q.uniqueResult();
21412    
21413                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
21414                                            FINDER_ARGS_EMPTY, count);
21415                            }
21416                            catch (Exception e) {
21417                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
21418                                            FINDER_ARGS_EMPTY);
21419    
21420                                    throw processException(e);
21421                            }
21422                            finally {
21423                                    closeSession(session);
21424                            }
21425                    }
21426    
21427                    return count.intValue();
21428            }
21429    
21430            @Override
21431            protected Set<String> getBadColumnNames() {
21432                    return _badColumnNames;
21433            }
21434    
21435            /**
21436             * Initializes the message-boards message persistence.
21437             */
21438            public void afterPropertiesSet() {
21439                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
21440                                            com.liferay.portal.util.PropsUtil.get(
21441                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
21442    
21443                    if (listenerClassNames.length > 0) {
21444                            try {
21445                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
21446    
21447                                    for (String listenerClassName : listenerClassNames) {
21448                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
21449                                                            getClassLoader(), listenerClassName));
21450                                    }
21451    
21452                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
21453                            }
21454                            catch (Exception e) {
21455                                    _log.error(e);
21456                            }
21457                    }
21458            }
21459    
21460            public void destroy() {
21461                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
21462                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
21463                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21464                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21465            }
21466    
21467            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
21468            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
21469            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
21470            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
21471            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
21472            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
21473            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
21474                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
21475            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
21476                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
21477            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
21478            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
21479            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
21480            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
21481            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
21482            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
21483            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
21484            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
21485            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
21486            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
21487                                    "uuid"
21488                            });
21489            private static MBMessage _nullMBMessage = new MBMessageImpl() {
21490                            @Override
21491                            public Object clone() {
21492                                    return this;
21493                            }
21494    
21495                            @Override
21496                            public CacheModel<MBMessage> toCacheModel() {
21497                                    return _nullMBMessageCacheModel;
21498                            }
21499                    };
21500    
21501            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
21502                            @Override
21503                            public MBMessage toEntityModel() {
21504                                    return _nullMBMessage;
21505                            }
21506                    };
21507    }