001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.sanitizer.Sanitizer;
032    import com.liferay.portal.kernel.sanitizer.SanitizerException;
033    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
034    import com.liferay.portal.kernel.util.ArrayUtil;
035    import com.liferay.portal.kernel.util.ContentTypes;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.OrderByComparator;
038    import com.liferay.portal.kernel.util.SetUtil;
039    import com.liferay.portal.kernel.util.StringBundler;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
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.security.auth.PrincipalThreadLocal;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.messageboards.NoSuchMessageException;
050    import com.liferay.portlet.messageboards.model.MBMessage;
051    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
052    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
053    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
054    
055    import java.io.Serializable;
056    
057    import java.util.Collections;
058    import java.util.HashMap;
059    import java.util.HashSet;
060    import java.util.Iterator;
061    import java.util.List;
062    import java.util.Map;
063    import java.util.Set;
064    
065    /**
066     * The persistence implementation for the message-boards message service.
067     *
068     * <p>
069     * Caching information and settings can be found in <code>portal.properties</code>
070     * </p>
071     *
072     * @author Brian Wing Shun Chan
073     * @see MBMessagePersistence
074     * @see MBMessageUtil
075     * @generated
076     */
077    @ProviderType
078    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
079            implements MBMessagePersistence {
080            /*
081             * NOTE FOR DEVELOPERS:
082             *
083             * 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.
084             */
085            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
086            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087                    ".List1";
088            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
089                    ".List2";
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
091                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
094                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
096            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
097                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
099            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
100                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
102                            new String[] {
103                                    String.class.getName(),
104                                    
105                            Integer.class.getName(), Integer.class.getName(),
106                                    OrderByComparator.class.getName()
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
109                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
111                            new String[] { String.class.getName() },
112                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
113                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118    
119            /**
120             * Returns all the message-boards messages where uuid = &#63;.
121             *
122             * @param uuid the uuid
123             * @return the matching message-boards messages
124             */
125            @Override
126            public List<MBMessage> findByUuid(String uuid) {
127                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128            }
129    
130            /**
131             * Returns a range of all the message-boards messages where uuid = &#63;.
132             *
133             * <p>
134             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
135             * </p>
136             *
137             * @param uuid the uuid
138             * @param start the lower bound of the range of message-boards messages
139             * @param end the upper bound of the range of message-boards messages (not inclusive)
140             * @return the range of matching message-boards messages
141             */
142            @Override
143            public List<MBMessage> findByUuid(String uuid, int start, int end) {
144                    return findByUuid(uuid, start, end, null);
145            }
146    
147            /**
148             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
149             *
150             * <p>
151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
152             * </p>
153             *
154             * @param uuid the uuid
155             * @param start the lower bound of the range of message-boards messages
156             * @param end the upper bound of the range of message-boards messages (not inclusive)
157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
158             * @return the ordered range of matching message-boards messages
159             */
160            @Override
161            public List<MBMessage> findByUuid(String uuid, int start, int end,
162                    OrderByComparator<MBMessage> orderByComparator) {
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 = Collections.unmodifiableList(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             */
280            @Override
281            public MBMessage findByUuid_First(String uuid,
282                    OrderByComparator<MBMessage> orderByComparator)
283                    throws NoSuchMessageException {
284                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
285    
286                    if (mbMessage != null) {
287                            return mbMessage;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("uuid=");
295                    msg.append(uuid);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchMessageException(msg.toString());
300            }
301    
302            /**
303             * Returns the first message-boards message in the ordered set where uuid = &#63;.
304             *
305             * @param uuid the uuid
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
308             */
309            @Override
310            public MBMessage fetchByUuid_First(String uuid,
311                    OrderByComparator<MBMessage> orderByComparator) {
312                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last message-boards message in the ordered set where uuid = &#63;.
323             *
324             * @param uuid the uuid
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching message-boards message
327             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
328             */
329            @Override
330            public MBMessage findByUuid_Last(String uuid,
331                    OrderByComparator<MBMessage> orderByComparator)
332                    throws NoSuchMessageException {
333                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
334    
335                    if (mbMessage != null) {
336                            return mbMessage;
337                    }
338    
339                    StringBundler msg = new StringBundler(4);
340    
341                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342    
343                    msg.append("uuid=");
344                    msg.append(uuid);
345    
346                    msg.append(StringPool.CLOSE_CURLY_BRACE);
347    
348                    throw new NoSuchMessageException(msg.toString());
349            }
350    
351            /**
352             * Returns the last message-boards message in the ordered set where uuid = &#63;.
353             *
354             * @param uuid the uuid
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
357             */
358            @Override
359            public MBMessage fetchByUuid_Last(String uuid,
360                    OrderByComparator<MBMessage> orderByComparator) {
361                    int count = countByUuid(uuid);
362    
363                    if (count == 0) {
364                            return null;
365                    }
366    
367                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
368                                    orderByComparator);
369    
370                    if (!list.isEmpty()) {
371                            return list.get(0);
372                    }
373    
374                    return null;
375            }
376    
377            /**
378             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
379             *
380             * @param messageId the primary key of the current message-boards message
381             * @param uuid the uuid
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the previous, current, and next message-boards message
384             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
385             */
386            @Override
387            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
388                    OrderByComparator<MBMessage> orderByComparator)
389                    throws NoSuchMessageException {
390                    MBMessage mbMessage = findByPrimaryKey(messageId);
391    
392                    Session session = null;
393    
394                    try {
395                            session = openSession();
396    
397                            MBMessage[] array = new MBMessageImpl[3];
398    
399                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
400                                            orderByComparator, true);
401    
402                            array[1] = mbMessage;
403    
404                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
405                                            orderByComparator, false);
406    
407                            return array;
408                    }
409                    catch (Exception e) {
410                            throw processException(e);
411                    }
412                    finally {
413                            closeSession(session);
414                    }
415            }
416    
417            protected MBMessage getByUuid_PrevAndNext(Session session,
418                    MBMessage mbMessage, String uuid,
419                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
420                    StringBundler query = null;
421    
422                    if (orderByComparator != null) {
423                            query = new StringBundler(6 +
424                                            (orderByComparator.getOrderByFields().length * 6));
425                    }
426                    else {
427                            query = new StringBundler(3);
428                    }
429    
430                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
431    
432                    boolean bindUuid = false;
433    
434                    if (uuid == null) {
435                            query.append(_FINDER_COLUMN_UUID_UUID_1);
436                    }
437                    else if (uuid.equals(StringPool.BLANK)) {
438                            query.append(_FINDER_COLUMN_UUID_UUID_3);
439                    }
440                    else {
441                            bindUuid = true;
442    
443                            query.append(_FINDER_COLUMN_UUID_UUID_2);
444                    }
445    
446                    if (orderByComparator != null) {
447                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
448    
449                            if (orderByConditionFields.length > 0) {
450                                    query.append(WHERE_AND);
451                            }
452    
453                            for (int i = 0; i < orderByConditionFields.length; i++) {
454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
455                                    query.append(orderByConditionFields[i]);
456    
457                                    if ((i + 1) < orderByConditionFields.length) {
458                                            if (orderByComparator.isAscending() ^ previous) {
459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
460                                            }
461                                            else {
462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
463                                            }
464                                    }
465                                    else {
466                                            if (orderByComparator.isAscending() ^ previous) {
467                                                    query.append(WHERE_GREATER_THAN);
468                                            }
469                                            else {
470                                                    query.append(WHERE_LESSER_THAN);
471                                            }
472                                    }
473                            }
474    
475                            query.append(ORDER_BY_CLAUSE);
476    
477                            String[] orderByFields = orderByComparator.getOrderByFields();
478    
479                            for (int i = 0; i < orderByFields.length; i++) {
480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
481                                    query.append(orderByFields[i]);
482    
483                                    if ((i + 1) < orderByFields.length) {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
486                                            }
487                                            else {
488                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
489                                            }
490                                    }
491                                    else {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(ORDER_BY_ASC);
494                                            }
495                                            else {
496                                                    query.append(ORDER_BY_DESC);
497                                            }
498                                    }
499                            }
500                    }
501                    else {
502                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
503                    }
504    
505                    String sql = query.toString();
506    
507                    Query q = session.createQuery(sql);
508    
509                    q.setFirstResult(0);
510                    q.setMaxResults(2);
511    
512                    QueryPos qPos = QueryPos.getInstance(q);
513    
514                    if (bindUuid) {
515                            qPos.add(uuid);
516                    }
517    
518                    if (orderByComparator != null) {
519                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
520    
521                            for (Object value : values) {
522                                    qPos.add(value);
523                            }
524                    }
525    
526                    List<MBMessage> list = q.list();
527    
528                    if (list.size() == 2) {
529                            return list.get(1);
530                    }
531                    else {
532                            return null;
533                    }
534            }
535    
536            /**
537             * Removes all the message-boards messages where uuid = &#63; from the database.
538             *
539             * @param uuid the uuid
540             */
541            @Override
542            public void removeByUuid(String uuid) {
543                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
544                                    QueryUtil.ALL_POS, null)) {
545                            remove(mbMessage);
546                    }
547            }
548    
549            /**
550             * Returns the number of message-boards messages where uuid = &#63;.
551             *
552             * @param uuid the uuid
553             * @return the number of matching message-boards messages
554             */
555            @Override
556            public int countByUuid(String uuid) {
557                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
558    
559                    Object[] finderArgs = new Object[] { uuid };
560    
561                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
562                                    this);
563    
564                    if (count == null) {
565                            StringBundler query = new StringBundler(2);
566    
567                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
568    
569                            boolean bindUuid = false;
570    
571                            if (uuid == null) {
572                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
573                            }
574                            else if (uuid.equals(StringPool.BLANK)) {
575                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
576                            }
577                            else {
578                                    bindUuid = true;
579    
580                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
581                            }
582    
583                            String sql = query.toString();
584    
585                            Session session = null;
586    
587                            try {
588                                    session = openSession();
589    
590                                    Query q = session.createQuery(sql);
591    
592                                    QueryPos qPos = QueryPos.getInstance(q);
593    
594                                    if (bindUuid) {
595                                            qPos.add(uuid);
596                                    }
597    
598                                    count = (Long)q.uniqueResult();
599    
600                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
601                            }
602                            catch (Exception e) {
603                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
604    
605                                    throw processException(e);
606                            }
607                            finally {
608                                    closeSession(session);
609                            }
610                    }
611    
612                    return count.intValue();
613            }
614    
615            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
616            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
617            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
618            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
619                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
620                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
621                            new String[] { String.class.getName(), Long.class.getName() },
622                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
623                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
624            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
625                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
627                            new String[] { String.class.getName(), Long.class.getName() });
628    
629            /**
630             * 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.
631             *
632             * @param uuid the uuid
633             * @param groupId the group ID
634             * @return the matching message-boards message
635             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
636             */
637            @Override
638            public MBMessage findByUUID_G(String uuid, long groupId)
639                    throws NoSuchMessageException {
640                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
641    
642                    if (mbMessage == null) {
643                            StringBundler msg = new StringBundler(6);
644    
645                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646    
647                            msg.append("uuid=");
648                            msg.append(uuid);
649    
650                            msg.append(", groupId=");
651                            msg.append(groupId);
652    
653                            msg.append(StringPool.CLOSE_CURLY_BRACE);
654    
655                            if (_log.isWarnEnabled()) {
656                                    _log.warn(msg.toString());
657                            }
658    
659                            throw new NoSuchMessageException(msg.toString());
660                    }
661    
662                    return mbMessage;
663            }
664    
665            /**
666             * 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.
667             *
668             * @param uuid the uuid
669             * @param groupId the group ID
670             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
671             */
672            @Override
673            public MBMessage fetchByUUID_G(String uuid, long groupId) {
674                    return fetchByUUID_G(uuid, groupId, true);
675            }
676    
677            /**
678             * 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.
679             *
680             * @param uuid the uuid
681             * @param groupId the group ID
682             * @param retrieveFromCache whether to use the finder cache
683             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
684             */
685            @Override
686            public MBMessage fetchByUUID_G(String uuid, long groupId,
687                    boolean retrieveFromCache) {
688                    Object[] finderArgs = new Object[] { uuid, groupId };
689    
690                    Object result = null;
691    
692                    if (retrieveFromCache) {
693                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
694                                            finderArgs, this);
695                    }
696    
697                    if (result instanceof MBMessage) {
698                            MBMessage mbMessage = (MBMessage)result;
699    
700                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
701                                            (groupId != mbMessage.getGroupId())) {
702                                    result = null;
703                            }
704                    }
705    
706                    if (result == null) {
707                            StringBundler query = new StringBundler(4);
708    
709                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
710    
711                            boolean bindUuid = false;
712    
713                            if (uuid == null) {
714                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
715                            }
716                            else if (uuid.equals(StringPool.BLANK)) {
717                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
718                            }
719                            else {
720                                    bindUuid = true;
721    
722                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
723                            }
724    
725                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
726    
727                            String sql = query.toString();
728    
729                            Session session = null;
730    
731                            try {
732                                    session = openSession();
733    
734                                    Query q = session.createQuery(sql);
735    
736                                    QueryPos qPos = QueryPos.getInstance(q);
737    
738                                    if (bindUuid) {
739                                            qPos.add(uuid);
740                                    }
741    
742                                    qPos.add(groupId);
743    
744                                    List<MBMessage> list = q.list();
745    
746                                    if (list.isEmpty()) {
747                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
748                                                    finderArgs, list);
749                                    }
750                                    else {
751                                            MBMessage mbMessage = list.get(0);
752    
753                                            result = mbMessage;
754    
755                                            cacheResult(mbMessage);
756    
757                                            if ((mbMessage.getUuid() == null) ||
758                                                            !mbMessage.getUuid().equals(uuid) ||
759                                                            (mbMessage.getGroupId() != groupId)) {
760                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
761                                                            finderArgs, mbMessage);
762                                            }
763                                    }
764                            }
765                            catch (Exception e) {
766                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
767                                            finderArgs);
768    
769                                    throw processException(e);
770                            }
771                            finally {
772                                    closeSession(session);
773                            }
774                    }
775    
776                    if (result instanceof List<?>) {
777                            return null;
778                    }
779                    else {
780                            return (MBMessage)result;
781                    }
782            }
783    
784            /**
785             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
786             *
787             * @param uuid the uuid
788             * @param groupId the group ID
789             * @return the message-boards message that was removed
790             */
791            @Override
792            public MBMessage removeByUUID_G(String uuid, long groupId)
793                    throws NoSuchMessageException {
794                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
795    
796                    return remove(mbMessage);
797            }
798    
799            /**
800             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
801             *
802             * @param uuid the uuid
803             * @param groupId the group ID
804             * @return the number of matching message-boards messages
805             */
806            @Override
807            public int countByUUID_G(String uuid, long groupId) {
808                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
809    
810                    Object[] finderArgs = new Object[] { uuid, groupId };
811    
812                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
813                                    this);
814    
815                    if (count == null) {
816                            StringBundler query = new StringBundler(3);
817    
818                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
819    
820                            boolean bindUuid = false;
821    
822                            if (uuid == null) {
823                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
824                            }
825                            else if (uuid.equals(StringPool.BLANK)) {
826                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
827                            }
828                            else {
829                                    bindUuid = true;
830    
831                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
832                            }
833    
834                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
835    
836                            String sql = query.toString();
837    
838                            Session session = null;
839    
840                            try {
841                                    session = openSession();
842    
843                                    Query q = session.createQuery(sql);
844    
845                                    QueryPos qPos = QueryPos.getInstance(q);
846    
847                                    if (bindUuid) {
848                                            qPos.add(uuid);
849                                    }
850    
851                                    qPos.add(groupId);
852    
853                                    count = (Long)q.uniqueResult();
854    
855                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
856                            }
857                            catch (Exception e) {
858                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
859    
860                                    throw processException(e);
861                            }
862                            finally {
863                                    closeSession(session);
864                            }
865                    }
866    
867                    return count.intValue();
868            }
869    
870            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
871            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
872            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
873            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
874            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
875                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
876                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
877                            new String[] {
878                                    String.class.getName(), Long.class.getName(),
879                                    
880                            Integer.class.getName(), Integer.class.getName(),
881                                    OrderByComparator.class.getName()
882                            });
883            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
884                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
885                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
886                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
887                            new String[] { String.class.getName(), Long.class.getName() },
888                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
889                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
890                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
891            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
892                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
893                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
894                            new String[] { String.class.getName(), Long.class.getName() });
895    
896            /**
897             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
898             *
899             * @param uuid the uuid
900             * @param companyId the company ID
901             * @return the matching message-boards messages
902             */
903            @Override
904            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
905                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
906                            QueryUtil.ALL_POS, null);
907            }
908    
909            /**
910             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
911             *
912             * <p>
913             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
914             * </p>
915             *
916             * @param uuid the uuid
917             * @param companyId the company ID
918             * @param start the lower bound of the range of message-boards messages
919             * @param end the upper bound of the range of message-boards messages (not inclusive)
920             * @return the range of matching message-boards messages
921             */
922            @Override
923            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
924                    int end) {
925                    return findByUuid_C(uuid, companyId, start, end, null);
926            }
927    
928            /**
929             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
930             *
931             * <p>
932             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
933             * </p>
934             *
935             * @param uuid the uuid
936             * @param companyId the company ID
937             * @param start the lower bound of the range of message-boards messages
938             * @param end the upper bound of the range of message-boards messages (not inclusive)
939             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
940             * @return the ordered range of matching message-boards messages
941             */
942            @Override
943            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
944                    int end, OrderByComparator<MBMessage> orderByComparator) {
945                    boolean pagination = true;
946                    FinderPath finderPath = null;
947                    Object[] finderArgs = null;
948    
949                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
950                                    (orderByComparator == null)) {
951                            pagination = false;
952                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
953                            finderArgs = new Object[] { uuid, companyId };
954                    }
955                    else {
956                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
957                            finderArgs = new Object[] {
958                                            uuid, companyId,
959                                            
960                                            start, end, orderByComparator
961                                    };
962                    }
963    
964                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
965                                    finderArgs, this);
966    
967                    if ((list != null) && !list.isEmpty()) {
968                            for (MBMessage mbMessage : list) {
969                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
970                                                    (companyId != mbMessage.getCompanyId())) {
971                                            list = null;
972    
973                                            break;
974                                    }
975                            }
976                    }
977    
978                    if (list == null) {
979                            StringBundler query = null;
980    
981                            if (orderByComparator != null) {
982                                    query = new StringBundler(4 +
983                                                    (orderByComparator.getOrderByFields().length * 3));
984                            }
985                            else {
986                                    query = new StringBundler(4);
987                            }
988    
989                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
990    
991                            boolean bindUuid = false;
992    
993                            if (uuid == null) {
994                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
995                            }
996                            else if (uuid.equals(StringPool.BLANK)) {
997                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
998                            }
999                            else {
1000                                    bindUuid = true;
1001    
1002                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1003                            }
1004    
1005                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1006    
1007                            if (orderByComparator != null) {
1008                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1009                                            orderByComparator);
1010                            }
1011                            else
1012                             if (pagination) {
1013                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1014                            }
1015    
1016                            String sql = query.toString();
1017    
1018                            Session session = null;
1019    
1020                            try {
1021                                    session = openSession();
1022    
1023                                    Query q = session.createQuery(sql);
1024    
1025                                    QueryPos qPos = QueryPos.getInstance(q);
1026    
1027                                    if (bindUuid) {
1028                                            qPos.add(uuid);
1029                                    }
1030    
1031                                    qPos.add(companyId);
1032    
1033                                    if (!pagination) {
1034                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1035                                                            start, end, false);
1036    
1037                                            Collections.sort(list);
1038    
1039                                            list = Collections.unmodifiableList(list);
1040                                    }
1041                                    else {
1042                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1043                                                            start, end);
1044                                    }
1045    
1046                                    cacheResult(list);
1047    
1048                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1049                            }
1050                            catch (Exception e) {
1051                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1052    
1053                                    throw processException(e);
1054                            }
1055                            finally {
1056                                    closeSession(session);
1057                            }
1058                    }
1059    
1060                    return list;
1061            }
1062    
1063            /**
1064             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1065             *
1066             * @param uuid the uuid
1067             * @param companyId the company ID
1068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1069             * @return the first matching message-boards message
1070             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1071             */
1072            @Override
1073            public MBMessage findByUuid_C_First(String uuid, long companyId,
1074                    OrderByComparator<MBMessage> orderByComparator)
1075                    throws NoSuchMessageException {
1076                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1077                                    orderByComparator);
1078    
1079                    if (mbMessage != null) {
1080                            return mbMessage;
1081                    }
1082    
1083                    StringBundler msg = new StringBundler(6);
1084    
1085                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1086    
1087                    msg.append("uuid=");
1088                    msg.append(uuid);
1089    
1090                    msg.append(", companyId=");
1091                    msg.append(companyId);
1092    
1093                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1094    
1095                    throw new NoSuchMessageException(msg.toString());
1096            }
1097    
1098            /**
1099             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1100             *
1101             * @param uuid the uuid
1102             * @param companyId the company ID
1103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1104             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1105             */
1106            @Override
1107            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1108                    OrderByComparator<MBMessage> orderByComparator) {
1109                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1110                                    orderByComparator);
1111    
1112                    if (!list.isEmpty()) {
1113                            return list.get(0);
1114                    }
1115    
1116                    return null;
1117            }
1118    
1119            /**
1120             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1121             *
1122             * @param uuid the uuid
1123             * @param companyId the company ID
1124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1125             * @return the last matching message-boards message
1126             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1127             */
1128            @Override
1129            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1130                    OrderByComparator<MBMessage> orderByComparator)
1131                    throws NoSuchMessageException {
1132                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1133                                    orderByComparator);
1134    
1135                    if (mbMessage != null) {
1136                            return mbMessage;
1137                    }
1138    
1139                    StringBundler msg = new StringBundler(6);
1140    
1141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1142    
1143                    msg.append("uuid=");
1144                    msg.append(uuid);
1145    
1146                    msg.append(", companyId=");
1147                    msg.append(companyId);
1148    
1149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1150    
1151                    throw new NoSuchMessageException(msg.toString());
1152            }
1153    
1154            /**
1155             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1156             *
1157             * @param uuid the uuid
1158             * @param companyId the company ID
1159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1160             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1161             */
1162            @Override
1163            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1164                    OrderByComparator<MBMessage> orderByComparator) {
1165                    int count = countByUuid_C(uuid, companyId);
1166    
1167                    if (count == 0) {
1168                            return null;
1169                    }
1170    
1171                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1172                                    orderByComparator);
1173    
1174                    if (!list.isEmpty()) {
1175                            return list.get(0);
1176                    }
1177    
1178                    return null;
1179            }
1180    
1181            /**
1182             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1183             *
1184             * @param messageId the primary key of the current message-boards message
1185             * @param uuid the uuid
1186             * @param companyId the company ID
1187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1188             * @return the previous, current, and next message-boards message
1189             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1190             */
1191            @Override
1192            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1193                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1194                    throws NoSuchMessageException {
1195                    MBMessage mbMessage = findByPrimaryKey(messageId);
1196    
1197                    Session session = null;
1198    
1199                    try {
1200                            session = openSession();
1201    
1202                            MBMessage[] array = new MBMessageImpl[3];
1203    
1204                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1205                                            companyId, orderByComparator, true);
1206    
1207                            array[1] = mbMessage;
1208    
1209                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1210                                            companyId, orderByComparator, false);
1211    
1212                            return array;
1213                    }
1214                    catch (Exception e) {
1215                            throw processException(e);
1216                    }
1217                    finally {
1218                            closeSession(session);
1219                    }
1220            }
1221    
1222            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1223                    MBMessage mbMessage, String uuid, long companyId,
1224                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1225                    StringBundler query = null;
1226    
1227                    if (orderByComparator != null) {
1228                            query = new StringBundler(6 +
1229                                            (orderByComparator.getOrderByFields().length * 6));
1230                    }
1231                    else {
1232                            query = new StringBundler(3);
1233                    }
1234    
1235                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1236    
1237                    boolean bindUuid = false;
1238    
1239                    if (uuid == null) {
1240                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1241                    }
1242                    else if (uuid.equals(StringPool.BLANK)) {
1243                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1244                    }
1245                    else {
1246                            bindUuid = true;
1247    
1248                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1249                    }
1250    
1251                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1252    
1253                    if (orderByComparator != null) {
1254                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1255    
1256                            if (orderByConditionFields.length > 0) {
1257                                    query.append(WHERE_AND);
1258                            }
1259    
1260                            for (int i = 0; i < orderByConditionFields.length; i++) {
1261                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1262                                    query.append(orderByConditionFields[i]);
1263    
1264                                    if ((i + 1) < orderByConditionFields.length) {
1265                                            if (orderByComparator.isAscending() ^ previous) {
1266                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1267                                            }
1268                                            else {
1269                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1270                                            }
1271                                    }
1272                                    else {
1273                                            if (orderByComparator.isAscending() ^ previous) {
1274                                                    query.append(WHERE_GREATER_THAN);
1275                                            }
1276                                            else {
1277                                                    query.append(WHERE_LESSER_THAN);
1278                                            }
1279                                    }
1280                            }
1281    
1282                            query.append(ORDER_BY_CLAUSE);
1283    
1284                            String[] orderByFields = orderByComparator.getOrderByFields();
1285    
1286                            for (int i = 0; i < orderByFields.length; i++) {
1287                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1288                                    query.append(orderByFields[i]);
1289    
1290                                    if ((i + 1) < orderByFields.length) {
1291                                            if (orderByComparator.isAscending() ^ previous) {
1292                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1293                                            }
1294                                            else {
1295                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1296                                            }
1297                                    }
1298                                    else {
1299                                            if (orderByComparator.isAscending() ^ previous) {
1300                                                    query.append(ORDER_BY_ASC);
1301                                            }
1302                                            else {
1303                                                    query.append(ORDER_BY_DESC);
1304                                            }
1305                                    }
1306                            }
1307                    }
1308                    else {
1309                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1310                    }
1311    
1312                    String sql = query.toString();
1313    
1314                    Query q = session.createQuery(sql);
1315    
1316                    q.setFirstResult(0);
1317                    q.setMaxResults(2);
1318    
1319                    QueryPos qPos = QueryPos.getInstance(q);
1320    
1321                    if (bindUuid) {
1322                            qPos.add(uuid);
1323                    }
1324    
1325                    qPos.add(companyId);
1326    
1327                    if (orderByComparator != null) {
1328                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1329    
1330                            for (Object value : values) {
1331                                    qPos.add(value);
1332                            }
1333                    }
1334    
1335                    List<MBMessage> list = q.list();
1336    
1337                    if (list.size() == 2) {
1338                            return list.get(1);
1339                    }
1340                    else {
1341                            return null;
1342                    }
1343            }
1344    
1345            /**
1346             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1347             *
1348             * @param uuid the uuid
1349             * @param companyId the company ID
1350             */
1351            @Override
1352            public void removeByUuid_C(String uuid, long companyId) {
1353                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1354                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1355                            remove(mbMessage);
1356                    }
1357            }
1358    
1359            /**
1360             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1361             *
1362             * @param uuid the uuid
1363             * @param companyId the company ID
1364             * @return the number of matching message-boards messages
1365             */
1366            @Override
1367            public int countByUuid_C(String uuid, long companyId) {
1368                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1369    
1370                    Object[] finderArgs = new Object[] { uuid, companyId };
1371    
1372                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1373                                    this);
1374    
1375                    if (count == null) {
1376                            StringBundler query = new StringBundler(3);
1377    
1378                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1379    
1380                            boolean bindUuid = false;
1381    
1382                            if (uuid == null) {
1383                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1384                            }
1385                            else if (uuid.equals(StringPool.BLANK)) {
1386                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1387                            }
1388                            else {
1389                                    bindUuid = true;
1390    
1391                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1392                            }
1393    
1394                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1395    
1396                            String sql = query.toString();
1397    
1398                            Session session = null;
1399    
1400                            try {
1401                                    session = openSession();
1402    
1403                                    Query q = session.createQuery(sql);
1404    
1405                                    QueryPos qPos = QueryPos.getInstance(q);
1406    
1407                                    if (bindUuid) {
1408                                            qPos.add(uuid);
1409                                    }
1410    
1411                                    qPos.add(companyId);
1412    
1413                                    count = (Long)q.uniqueResult();
1414    
1415                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1416                            }
1417                            catch (Exception e) {
1418                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1419    
1420                                    throw processException(e);
1421                            }
1422                            finally {
1423                                    closeSession(session);
1424                            }
1425                    }
1426    
1427                    return count.intValue();
1428            }
1429    
1430            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1431            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1432            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1433            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1434            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1435                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1436                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1437                            new String[] {
1438                                    Long.class.getName(),
1439                                    
1440                            Integer.class.getName(), Integer.class.getName(),
1441                                    OrderByComparator.class.getName()
1442                            });
1443            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1444                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1445                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1446                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1447                            new String[] { Long.class.getName() },
1448                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1449                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1450            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1451                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1452                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1453                            new String[] { Long.class.getName() });
1454    
1455            /**
1456             * Returns all the message-boards messages where groupId = &#63;.
1457             *
1458             * @param groupId the group ID
1459             * @return the matching message-boards messages
1460             */
1461            @Override
1462            public List<MBMessage> findByGroupId(long groupId) {
1463                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1464            }
1465    
1466            /**
1467             * Returns a range of all the message-boards messages where groupId = &#63;.
1468             *
1469             * <p>
1470             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1471             * </p>
1472             *
1473             * @param groupId the group ID
1474             * @param start the lower bound of the range of message-boards messages
1475             * @param end the upper bound of the range of message-boards messages (not inclusive)
1476             * @return the range of matching message-boards messages
1477             */
1478            @Override
1479            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1480                    return findByGroupId(groupId, start, end, null);
1481            }
1482    
1483            /**
1484             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1485             *
1486             * <p>
1487             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1488             * </p>
1489             *
1490             * @param groupId the group ID
1491             * @param start the lower bound of the range of message-boards messages
1492             * @param end the upper bound of the range of message-boards messages (not inclusive)
1493             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1494             * @return the ordered range of matching message-boards messages
1495             */
1496            @Override
1497            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1498                    OrderByComparator<MBMessage> orderByComparator) {
1499                    boolean pagination = true;
1500                    FinderPath finderPath = null;
1501                    Object[] finderArgs = null;
1502    
1503                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1504                                    (orderByComparator == null)) {
1505                            pagination = false;
1506                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1507                            finderArgs = new Object[] { groupId };
1508                    }
1509                    else {
1510                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1511                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1512                    }
1513    
1514                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1515                                    finderArgs, this);
1516    
1517                    if ((list != null) && !list.isEmpty()) {
1518                            for (MBMessage mbMessage : list) {
1519                                    if ((groupId != mbMessage.getGroupId())) {
1520                                            list = null;
1521    
1522                                            break;
1523                                    }
1524                            }
1525                    }
1526    
1527                    if (list == null) {
1528                            StringBundler query = null;
1529    
1530                            if (orderByComparator != null) {
1531                                    query = new StringBundler(3 +
1532                                                    (orderByComparator.getOrderByFields().length * 3));
1533                            }
1534                            else {
1535                                    query = new StringBundler(3);
1536                            }
1537    
1538                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1539    
1540                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1541    
1542                            if (orderByComparator != null) {
1543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1544                                            orderByComparator);
1545                            }
1546                            else
1547                             if (pagination) {
1548                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1549                            }
1550    
1551                            String sql = query.toString();
1552    
1553                            Session session = null;
1554    
1555                            try {
1556                                    session = openSession();
1557    
1558                                    Query q = session.createQuery(sql);
1559    
1560                                    QueryPos qPos = QueryPos.getInstance(q);
1561    
1562                                    qPos.add(groupId);
1563    
1564                                    if (!pagination) {
1565                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1566                                                            start, end, false);
1567    
1568                                            Collections.sort(list);
1569    
1570                                            list = Collections.unmodifiableList(list);
1571                                    }
1572                                    else {
1573                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1574                                                            start, end);
1575                                    }
1576    
1577                                    cacheResult(list);
1578    
1579                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1580                            }
1581                            catch (Exception e) {
1582                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1583    
1584                                    throw processException(e);
1585                            }
1586                            finally {
1587                                    closeSession(session);
1588                            }
1589                    }
1590    
1591                    return list;
1592            }
1593    
1594            /**
1595             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1596             *
1597             * @param groupId the group ID
1598             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1599             * @return the first matching message-boards message
1600             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1601             */
1602            @Override
1603            public MBMessage findByGroupId_First(long groupId,
1604                    OrderByComparator<MBMessage> orderByComparator)
1605                    throws NoSuchMessageException {
1606                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1607    
1608                    if (mbMessage != null) {
1609                            return mbMessage;
1610                    }
1611    
1612                    StringBundler msg = new StringBundler(4);
1613    
1614                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1615    
1616                    msg.append("groupId=");
1617                    msg.append(groupId);
1618    
1619                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1620    
1621                    throw new NoSuchMessageException(msg.toString());
1622            }
1623    
1624            /**
1625             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1626             *
1627             * @param groupId the group ID
1628             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1629             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1630             */
1631            @Override
1632            public MBMessage fetchByGroupId_First(long groupId,
1633                    OrderByComparator<MBMessage> orderByComparator) {
1634                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1635    
1636                    if (!list.isEmpty()) {
1637                            return list.get(0);
1638                    }
1639    
1640                    return null;
1641            }
1642    
1643            /**
1644             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1645             *
1646             * @param groupId the group ID
1647             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1648             * @return the last matching message-boards message
1649             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1650             */
1651            @Override
1652            public MBMessage findByGroupId_Last(long groupId,
1653                    OrderByComparator<MBMessage> orderByComparator)
1654                    throws NoSuchMessageException {
1655                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1656    
1657                    if (mbMessage != null) {
1658                            return mbMessage;
1659                    }
1660    
1661                    StringBundler msg = new StringBundler(4);
1662    
1663                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1664    
1665                    msg.append("groupId=");
1666                    msg.append(groupId);
1667    
1668                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1669    
1670                    throw new NoSuchMessageException(msg.toString());
1671            }
1672    
1673            /**
1674             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1675             *
1676             * @param groupId the group ID
1677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1678             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1679             */
1680            @Override
1681            public MBMessage fetchByGroupId_Last(long groupId,
1682                    OrderByComparator<MBMessage> orderByComparator) {
1683                    int count = countByGroupId(groupId);
1684    
1685                    if (count == 0) {
1686                            return null;
1687                    }
1688    
1689                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1690                                    orderByComparator);
1691    
1692                    if (!list.isEmpty()) {
1693                            return list.get(0);
1694                    }
1695    
1696                    return null;
1697            }
1698    
1699            /**
1700             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1701             *
1702             * @param messageId the primary key of the current message-boards message
1703             * @param groupId the group ID
1704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1705             * @return the previous, current, and next message-boards message
1706             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1707             */
1708            @Override
1709            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1710                    OrderByComparator<MBMessage> orderByComparator)
1711                    throws NoSuchMessageException {
1712                    MBMessage mbMessage = findByPrimaryKey(messageId);
1713    
1714                    Session session = null;
1715    
1716                    try {
1717                            session = openSession();
1718    
1719                            MBMessage[] array = new MBMessageImpl[3];
1720    
1721                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1722                                            orderByComparator, true);
1723    
1724                            array[1] = mbMessage;
1725    
1726                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1727                                            orderByComparator, false);
1728    
1729                            return array;
1730                    }
1731                    catch (Exception e) {
1732                            throw processException(e);
1733                    }
1734                    finally {
1735                            closeSession(session);
1736                    }
1737            }
1738    
1739            protected MBMessage getByGroupId_PrevAndNext(Session session,
1740                    MBMessage mbMessage, long groupId,
1741                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1742                    StringBundler query = null;
1743    
1744                    if (orderByComparator != null) {
1745                            query = new StringBundler(6 +
1746                                            (orderByComparator.getOrderByFields().length * 6));
1747                    }
1748                    else {
1749                            query = new StringBundler(3);
1750                    }
1751    
1752                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1753    
1754                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1755    
1756                    if (orderByComparator != null) {
1757                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1758    
1759                            if (orderByConditionFields.length > 0) {
1760                                    query.append(WHERE_AND);
1761                            }
1762    
1763                            for (int i = 0; i < orderByConditionFields.length; i++) {
1764                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1765                                    query.append(orderByConditionFields[i]);
1766    
1767                                    if ((i + 1) < orderByConditionFields.length) {
1768                                            if (orderByComparator.isAscending() ^ previous) {
1769                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1770                                            }
1771                                            else {
1772                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1773                                            }
1774                                    }
1775                                    else {
1776                                            if (orderByComparator.isAscending() ^ previous) {
1777                                                    query.append(WHERE_GREATER_THAN);
1778                                            }
1779                                            else {
1780                                                    query.append(WHERE_LESSER_THAN);
1781                                            }
1782                                    }
1783                            }
1784    
1785                            query.append(ORDER_BY_CLAUSE);
1786    
1787                            String[] orderByFields = orderByComparator.getOrderByFields();
1788    
1789                            for (int i = 0; i < orderByFields.length; i++) {
1790                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1791                                    query.append(orderByFields[i]);
1792    
1793                                    if ((i + 1) < orderByFields.length) {
1794                                            if (orderByComparator.isAscending() ^ previous) {
1795                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1796                                            }
1797                                            else {
1798                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1799                                            }
1800                                    }
1801                                    else {
1802                                            if (orderByComparator.isAscending() ^ previous) {
1803                                                    query.append(ORDER_BY_ASC);
1804                                            }
1805                                            else {
1806                                                    query.append(ORDER_BY_DESC);
1807                                            }
1808                                    }
1809                            }
1810                    }
1811                    else {
1812                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1813                    }
1814    
1815                    String sql = query.toString();
1816    
1817                    Query q = session.createQuery(sql);
1818    
1819                    q.setFirstResult(0);
1820                    q.setMaxResults(2);
1821    
1822                    QueryPos qPos = QueryPos.getInstance(q);
1823    
1824                    qPos.add(groupId);
1825    
1826                    if (orderByComparator != null) {
1827                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1828    
1829                            for (Object value : values) {
1830                                    qPos.add(value);
1831                            }
1832                    }
1833    
1834                    List<MBMessage> list = q.list();
1835    
1836                    if (list.size() == 2) {
1837                            return list.get(1);
1838                    }
1839                    else {
1840                            return null;
1841                    }
1842            }
1843    
1844            /**
1845             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1846             *
1847             * @param groupId the group ID
1848             * @return the matching message-boards messages that the user has permission to view
1849             */
1850            @Override
1851            public List<MBMessage> filterFindByGroupId(long groupId) {
1852                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1853                            QueryUtil.ALL_POS, null);
1854            }
1855    
1856            /**
1857             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1858             *
1859             * <p>
1860             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1861             * </p>
1862             *
1863             * @param groupId the group ID
1864             * @param start the lower bound of the range of message-boards messages
1865             * @param end the upper bound of the range of message-boards messages (not inclusive)
1866             * @return the range of matching message-boards messages that the user has permission to view
1867             */
1868            @Override
1869            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1870                    return filterFindByGroupId(groupId, start, end, null);
1871            }
1872    
1873            /**
1874             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1875             *
1876             * <p>
1877             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1878             * </p>
1879             *
1880             * @param groupId the group ID
1881             * @param start the lower bound of the range of message-boards messages
1882             * @param end the upper bound of the range of message-boards messages (not inclusive)
1883             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1884             * @return the ordered range of matching message-boards messages that the user has permission to view
1885             */
1886            @Override
1887            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1888                    int end, OrderByComparator<MBMessage> orderByComparator) {
1889                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1890                            return findByGroupId(groupId, start, end, orderByComparator);
1891                    }
1892    
1893                    StringBundler query = null;
1894    
1895                    if (orderByComparator != null) {
1896                            query = new StringBundler(3 +
1897                                            (orderByComparator.getOrderByFields().length * 3));
1898                    }
1899                    else {
1900                            query = new StringBundler(3);
1901                    }
1902    
1903                    if (getDB().isSupportsInlineDistinct()) {
1904                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1905                    }
1906                    else {
1907                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1908                    }
1909    
1910                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1911    
1912                    if (!getDB().isSupportsInlineDistinct()) {
1913                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1914                    }
1915    
1916                    if (orderByComparator != null) {
1917                            if (getDB().isSupportsInlineDistinct()) {
1918                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1919                                            orderByComparator, true);
1920                            }
1921                            else {
1922                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1923                                            orderByComparator, true);
1924                            }
1925                    }
1926                    else {
1927                            if (getDB().isSupportsInlineDistinct()) {
1928                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1929                            }
1930                            else {
1931                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
1932                            }
1933                    }
1934    
1935                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1936                                    MBMessage.class.getName(),
1937                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1938    
1939                    Session session = null;
1940    
1941                    try {
1942                            session = openSession();
1943    
1944                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1945    
1946                            if (getDB().isSupportsInlineDistinct()) {
1947                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1948                            }
1949                            else {
1950                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1951                            }
1952    
1953                            QueryPos qPos = QueryPos.getInstance(q);
1954    
1955                            qPos.add(groupId);
1956    
1957                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1958                    }
1959                    catch (Exception e) {
1960                            throw processException(e);
1961                    }
1962                    finally {
1963                            closeSession(session);
1964                    }
1965            }
1966    
1967            /**
1968             * 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;.
1969             *
1970             * @param messageId the primary key of the current message-boards message
1971             * @param groupId the group ID
1972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1973             * @return the previous, current, and next message-boards message
1974             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1975             */
1976            @Override
1977            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
1978                    long groupId, OrderByComparator<MBMessage> orderByComparator)
1979                    throws NoSuchMessageException {
1980                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1981                            return findByGroupId_PrevAndNext(messageId, groupId,
1982                                    orderByComparator);
1983                    }
1984    
1985                    MBMessage mbMessage = findByPrimaryKey(messageId);
1986    
1987                    Session session = null;
1988    
1989                    try {
1990                            session = openSession();
1991    
1992                            MBMessage[] array = new MBMessageImpl[3];
1993    
1994                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1995                                            groupId, orderByComparator, true);
1996    
1997                            array[1] = mbMessage;
1998    
1999                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2000                                            groupId, orderByComparator, false);
2001    
2002                            return array;
2003                    }
2004                    catch (Exception e) {
2005                            throw processException(e);
2006                    }
2007                    finally {
2008                            closeSession(session);
2009                    }
2010            }
2011    
2012            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2013                    MBMessage mbMessage, long groupId,
2014                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2015                    StringBundler query = null;
2016    
2017                    if (orderByComparator != null) {
2018                            query = new StringBundler(6 +
2019                                            (orderByComparator.getOrderByFields().length * 6));
2020                    }
2021                    else {
2022                            query = new StringBundler(3);
2023                    }
2024    
2025                    if (getDB().isSupportsInlineDistinct()) {
2026                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2027                    }
2028                    else {
2029                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2030                    }
2031    
2032                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2033    
2034                    if (!getDB().isSupportsInlineDistinct()) {
2035                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2036                    }
2037    
2038                    if (orderByComparator != null) {
2039                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2040    
2041                            if (orderByConditionFields.length > 0) {
2042                                    query.append(WHERE_AND);
2043                            }
2044    
2045                            for (int i = 0; i < orderByConditionFields.length; i++) {
2046                                    if (getDB().isSupportsInlineDistinct()) {
2047                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2048                                    }
2049                                    else {
2050                                            query.append(_ORDER_BY_ENTITY_TABLE);
2051                                    }
2052    
2053                                    query.append(orderByConditionFields[i]);
2054    
2055                                    if ((i + 1) < orderByConditionFields.length) {
2056                                            if (orderByComparator.isAscending() ^ previous) {
2057                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2058                                            }
2059                                            else {
2060                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2061                                            }
2062                                    }
2063                                    else {
2064                                            if (orderByComparator.isAscending() ^ previous) {
2065                                                    query.append(WHERE_GREATER_THAN);
2066                                            }
2067                                            else {
2068                                                    query.append(WHERE_LESSER_THAN);
2069                                            }
2070                                    }
2071                            }
2072    
2073                            query.append(ORDER_BY_CLAUSE);
2074    
2075                            String[] orderByFields = orderByComparator.getOrderByFields();
2076    
2077                            for (int i = 0; i < orderByFields.length; i++) {
2078                                    if (getDB().isSupportsInlineDistinct()) {
2079                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2080                                    }
2081                                    else {
2082                                            query.append(_ORDER_BY_ENTITY_TABLE);
2083                                    }
2084    
2085                                    query.append(orderByFields[i]);
2086    
2087                                    if ((i + 1) < orderByFields.length) {
2088                                            if (orderByComparator.isAscending() ^ previous) {
2089                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2090                                            }
2091                                            else {
2092                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2093                                            }
2094                                    }
2095                                    else {
2096                                            if (orderByComparator.isAscending() ^ previous) {
2097                                                    query.append(ORDER_BY_ASC);
2098                                            }
2099                                            else {
2100                                                    query.append(ORDER_BY_DESC);
2101                                            }
2102                                    }
2103                            }
2104                    }
2105                    else {
2106                            if (getDB().isSupportsInlineDistinct()) {
2107                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2108                            }
2109                            else {
2110                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2111                            }
2112                    }
2113    
2114                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2115                                    MBMessage.class.getName(),
2116                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2117    
2118                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2119    
2120                    q.setFirstResult(0);
2121                    q.setMaxResults(2);
2122    
2123                    if (getDB().isSupportsInlineDistinct()) {
2124                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2125                    }
2126                    else {
2127                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2128                    }
2129    
2130                    QueryPos qPos = QueryPos.getInstance(q);
2131    
2132                    qPos.add(groupId);
2133    
2134                    if (orderByComparator != null) {
2135                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2136    
2137                            for (Object value : values) {
2138                                    qPos.add(value);
2139                            }
2140                    }
2141    
2142                    List<MBMessage> list = q.list();
2143    
2144                    if (list.size() == 2) {
2145                            return list.get(1);
2146                    }
2147                    else {
2148                            return null;
2149                    }
2150            }
2151    
2152            /**
2153             * Removes all the message-boards messages where groupId = &#63; from the database.
2154             *
2155             * @param groupId the group ID
2156             */
2157            @Override
2158            public void removeByGroupId(long groupId) {
2159                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2160                                    QueryUtil.ALL_POS, null)) {
2161                            remove(mbMessage);
2162                    }
2163            }
2164    
2165            /**
2166             * Returns the number of message-boards messages where groupId = &#63;.
2167             *
2168             * @param groupId the group ID
2169             * @return the number of matching message-boards messages
2170             */
2171            @Override
2172            public int countByGroupId(long groupId) {
2173                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2174    
2175                    Object[] finderArgs = new Object[] { groupId };
2176    
2177                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2178                                    this);
2179    
2180                    if (count == null) {
2181                            StringBundler query = new StringBundler(2);
2182    
2183                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2184    
2185                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2186    
2187                            String sql = query.toString();
2188    
2189                            Session session = null;
2190    
2191                            try {
2192                                    session = openSession();
2193    
2194                                    Query q = session.createQuery(sql);
2195    
2196                                    QueryPos qPos = QueryPos.getInstance(q);
2197    
2198                                    qPos.add(groupId);
2199    
2200                                    count = (Long)q.uniqueResult();
2201    
2202                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2203                            }
2204                            catch (Exception e) {
2205                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2206    
2207                                    throw processException(e);
2208                            }
2209                            finally {
2210                                    closeSession(session);
2211                            }
2212                    }
2213    
2214                    return count.intValue();
2215            }
2216    
2217            /**
2218             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2219             *
2220             * @param groupId the group ID
2221             * @return the number of matching message-boards messages that the user has permission to view
2222             */
2223            @Override
2224            public int filterCountByGroupId(long groupId) {
2225                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2226                            return countByGroupId(groupId);
2227                    }
2228    
2229                    StringBundler query = new StringBundler(2);
2230    
2231                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2232    
2233                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2234    
2235                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2236                                    MBMessage.class.getName(),
2237                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2238    
2239                    Session session = null;
2240    
2241                    try {
2242                            session = openSession();
2243    
2244                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2245    
2246                            q.addScalar(COUNT_COLUMN_NAME,
2247                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2248    
2249                            QueryPos qPos = QueryPos.getInstance(q);
2250    
2251                            qPos.add(groupId);
2252    
2253                            Long count = (Long)q.uniqueResult();
2254    
2255                            return count.intValue();
2256                    }
2257                    catch (Exception e) {
2258                            throw processException(e);
2259                    }
2260                    finally {
2261                            closeSession(session);
2262                    }
2263            }
2264    
2265            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2266            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2267                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2268                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2269                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2270                            new String[] {
2271                                    Long.class.getName(),
2272                                    
2273                            Integer.class.getName(), Integer.class.getName(),
2274                                    OrderByComparator.class.getName()
2275                            });
2276            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2277                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2278                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2279                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2280                            new String[] { Long.class.getName() },
2281                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2282                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2283            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2284                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2285                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2286                            new String[] { Long.class.getName() });
2287    
2288            /**
2289             * Returns all the message-boards messages where companyId = &#63;.
2290             *
2291             * @param companyId the company ID
2292             * @return the matching message-boards messages
2293             */
2294            @Override
2295            public List<MBMessage> findByCompanyId(long companyId) {
2296                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2297                            null);
2298            }
2299    
2300            /**
2301             * Returns a range of all the message-boards messages where companyId = &#63;.
2302             *
2303             * <p>
2304             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2305             * </p>
2306             *
2307             * @param companyId the company ID
2308             * @param start the lower bound of the range of message-boards messages
2309             * @param end the upper bound of the range of message-boards messages (not inclusive)
2310             * @return the range of matching message-boards messages
2311             */
2312            @Override
2313            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2314                    return findByCompanyId(companyId, start, end, null);
2315            }
2316    
2317            /**
2318             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2319             *
2320             * <p>
2321             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2322             * </p>
2323             *
2324             * @param companyId the company ID
2325             * @param start the lower bound of the range of message-boards messages
2326             * @param end the upper bound of the range of message-boards messages (not inclusive)
2327             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2328             * @return the ordered range of matching message-boards messages
2329             */
2330            @Override
2331            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2332                    OrderByComparator<MBMessage> orderByComparator) {
2333                    boolean pagination = true;
2334                    FinderPath finderPath = null;
2335                    Object[] finderArgs = null;
2336    
2337                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2338                                    (orderByComparator == null)) {
2339                            pagination = false;
2340                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2341                            finderArgs = new Object[] { companyId };
2342                    }
2343                    else {
2344                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2345                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2346                    }
2347    
2348                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2349                                    finderArgs, this);
2350    
2351                    if ((list != null) && !list.isEmpty()) {
2352                            for (MBMessage mbMessage : list) {
2353                                    if ((companyId != mbMessage.getCompanyId())) {
2354                                            list = null;
2355    
2356                                            break;
2357                                    }
2358                            }
2359                    }
2360    
2361                    if (list == null) {
2362                            StringBundler query = null;
2363    
2364                            if (orderByComparator != null) {
2365                                    query = new StringBundler(3 +
2366                                                    (orderByComparator.getOrderByFields().length * 3));
2367                            }
2368                            else {
2369                                    query = new StringBundler(3);
2370                            }
2371    
2372                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2373    
2374                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2375    
2376                            if (orderByComparator != null) {
2377                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2378                                            orderByComparator);
2379                            }
2380                            else
2381                             if (pagination) {
2382                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2383                            }
2384    
2385                            String sql = query.toString();
2386    
2387                            Session session = null;
2388    
2389                            try {
2390                                    session = openSession();
2391    
2392                                    Query q = session.createQuery(sql);
2393    
2394                                    QueryPos qPos = QueryPos.getInstance(q);
2395    
2396                                    qPos.add(companyId);
2397    
2398                                    if (!pagination) {
2399                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2400                                                            start, end, false);
2401    
2402                                            Collections.sort(list);
2403    
2404                                            list = Collections.unmodifiableList(list);
2405                                    }
2406                                    else {
2407                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2408                                                            start, end);
2409                                    }
2410    
2411                                    cacheResult(list);
2412    
2413                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2414                            }
2415                            catch (Exception e) {
2416                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2417    
2418                                    throw processException(e);
2419                            }
2420                            finally {
2421                                    closeSession(session);
2422                            }
2423                    }
2424    
2425                    return list;
2426            }
2427    
2428            /**
2429             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2430             *
2431             * @param companyId the company ID
2432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2433             * @return the first matching message-boards message
2434             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2435             */
2436            @Override
2437            public MBMessage findByCompanyId_First(long companyId,
2438                    OrderByComparator<MBMessage> orderByComparator)
2439                    throws NoSuchMessageException {
2440                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2441                                    orderByComparator);
2442    
2443                    if (mbMessage != null) {
2444                            return mbMessage;
2445                    }
2446    
2447                    StringBundler msg = new StringBundler(4);
2448    
2449                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2450    
2451                    msg.append("companyId=");
2452                    msg.append(companyId);
2453    
2454                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2455    
2456                    throw new NoSuchMessageException(msg.toString());
2457            }
2458    
2459            /**
2460             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2461             *
2462             * @param companyId the company ID
2463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2464             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2465             */
2466            @Override
2467            public MBMessage fetchByCompanyId_First(long companyId,
2468                    OrderByComparator<MBMessage> orderByComparator) {
2469                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2470                                    orderByComparator);
2471    
2472                    if (!list.isEmpty()) {
2473                            return list.get(0);
2474                    }
2475    
2476                    return null;
2477            }
2478    
2479            /**
2480             * Returns the last 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 last matching message-boards message
2485             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2486             */
2487            @Override
2488            public MBMessage findByCompanyId_Last(long companyId,
2489                    OrderByComparator<MBMessage> orderByComparator)
2490                    throws NoSuchMessageException {
2491                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2492    
2493                    if (mbMessage != null) {
2494                            return mbMessage;
2495                    }
2496    
2497                    StringBundler msg = new StringBundler(4);
2498    
2499                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2500    
2501                    msg.append("companyId=");
2502                    msg.append(companyId);
2503    
2504                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2505    
2506                    throw new NoSuchMessageException(msg.toString());
2507            }
2508    
2509            /**
2510             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2511             *
2512             * @param companyId the company ID
2513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2514             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2515             */
2516            @Override
2517            public MBMessage fetchByCompanyId_Last(long companyId,
2518                    OrderByComparator<MBMessage> orderByComparator) {
2519                    int count = countByCompanyId(companyId);
2520    
2521                    if (count == 0) {
2522                            return null;
2523                    }
2524    
2525                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2526                                    orderByComparator);
2527    
2528                    if (!list.isEmpty()) {
2529                            return list.get(0);
2530                    }
2531    
2532                    return null;
2533            }
2534    
2535            /**
2536             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2537             *
2538             * @param messageId the primary key of the current message-boards message
2539             * @param companyId the company ID
2540             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2541             * @return the previous, current, and next message-boards message
2542             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2543             */
2544            @Override
2545            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2546                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2547                    throws NoSuchMessageException {
2548                    MBMessage mbMessage = findByPrimaryKey(messageId);
2549    
2550                    Session session = null;
2551    
2552                    try {
2553                            session = openSession();
2554    
2555                            MBMessage[] array = new MBMessageImpl[3];
2556    
2557                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2558                                            companyId, orderByComparator, true);
2559    
2560                            array[1] = mbMessage;
2561    
2562                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2563                                            companyId, orderByComparator, false);
2564    
2565                            return array;
2566                    }
2567                    catch (Exception e) {
2568                            throw processException(e);
2569                    }
2570                    finally {
2571                            closeSession(session);
2572                    }
2573            }
2574    
2575            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2576                    MBMessage mbMessage, long companyId,
2577                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2578                    StringBundler query = null;
2579    
2580                    if (orderByComparator != null) {
2581                            query = new StringBundler(6 +
2582                                            (orderByComparator.getOrderByFields().length * 6));
2583                    }
2584                    else {
2585                            query = new StringBundler(3);
2586                    }
2587    
2588                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2589    
2590                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2591    
2592                    if (orderByComparator != null) {
2593                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2594    
2595                            if (orderByConditionFields.length > 0) {
2596                                    query.append(WHERE_AND);
2597                            }
2598    
2599                            for (int i = 0; i < orderByConditionFields.length; i++) {
2600                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2601                                    query.append(orderByConditionFields[i]);
2602    
2603                                    if ((i + 1) < orderByConditionFields.length) {
2604                                            if (orderByComparator.isAscending() ^ previous) {
2605                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2606                                            }
2607                                            else {
2608                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2609                                            }
2610                                    }
2611                                    else {
2612                                            if (orderByComparator.isAscending() ^ previous) {
2613                                                    query.append(WHERE_GREATER_THAN);
2614                                            }
2615                                            else {
2616                                                    query.append(WHERE_LESSER_THAN);
2617                                            }
2618                                    }
2619                            }
2620    
2621                            query.append(ORDER_BY_CLAUSE);
2622    
2623                            String[] orderByFields = orderByComparator.getOrderByFields();
2624    
2625                            for (int i = 0; i < orderByFields.length; i++) {
2626                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2627                                    query.append(orderByFields[i]);
2628    
2629                                    if ((i + 1) < orderByFields.length) {
2630                                            if (orderByComparator.isAscending() ^ previous) {
2631                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2632                                            }
2633                                            else {
2634                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2635                                            }
2636                                    }
2637                                    else {
2638                                            if (orderByComparator.isAscending() ^ previous) {
2639                                                    query.append(ORDER_BY_ASC);
2640                                            }
2641                                            else {
2642                                                    query.append(ORDER_BY_DESC);
2643                                            }
2644                                    }
2645                            }
2646                    }
2647                    else {
2648                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2649                    }
2650    
2651                    String sql = query.toString();
2652    
2653                    Query q = session.createQuery(sql);
2654    
2655                    q.setFirstResult(0);
2656                    q.setMaxResults(2);
2657    
2658                    QueryPos qPos = QueryPos.getInstance(q);
2659    
2660                    qPos.add(companyId);
2661    
2662                    if (orderByComparator != null) {
2663                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2664    
2665                            for (Object value : values) {
2666                                    qPos.add(value);
2667                            }
2668                    }
2669    
2670                    List<MBMessage> list = q.list();
2671    
2672                    if (list.size() == 2) {
2673                            return list.get(1);
2674                    }
2675                    else {
2676                            return null;
2677                    }
2678            }
2679    
2680            /**
2681             * Removes all the message-boards messages where companyId = &#63; from the database.
2682             *
2683             * @param companyId the company ID
2684             */
2685            @Override
2686            public void removeByCompanyId(long companyId) {
2687                    for (MBMessage mbMessage : findByCompanyId(companyId,
2688                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2689                            remove(mbMessage);
2690                    }
2691            }
2692    
2693            /**
2694             * Returns the number of message-boards messages where companyId = &#63;.
2695             *
2696             * @param companyId the company ID
2697             * @return the number of matching message-boards messages
2698             */
2699            @Override
2700            public int countByCompanyId(long companyId) {
2701                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2702    
2703                    Object[] finderArgs = new Object[] { companyId };
2704    
2705                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2706                                    this);
2707    
2708                    if (count == null) {
2709                            StringBundler query = new StringBundler(2);
2710    
2711                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2712    
2713                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2714    
2715                            String sql = query.toString();
2716    
2717                            Session session = null;
2718    
2719                            try {
2720                                    session = openSession();
2721    
2722                                    Query q = session.createQuery(sql);
2723    
2724                                    QueryPos qPos = QueryPos.getInstance(q);
2725    
2726                                    qPos.add(companyId);
2727    
2728                                    count = (Long)q.uniqueResult();
2729    
2730                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2731                            }
2732                            catch (Exception e) {
2733                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2734    
2735                                    throw processException(e);
2736                            }
2737                            finally {
2738                                    closeSession(session);
2739                            }
2740                    }
2741    
2742                    return count.intValue();
2743            }
2744    
2745            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2746            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2747                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2748                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2749                            new String[] {
2750                                    Long.class.getName(),
2751                                    
2752                            Integer.class.getName(), Integer.class.getName(),
2753                                    OrderByComparator.class.getName()
2754                            });
2755            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2756                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2757                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2758                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2759                            new String[] { Long.class.getName() },
2760                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2761                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2762            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2763                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2764                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2765                            new String[] { Long.class.getName() });
2766    
2767            /**
2768             * Returns all the message-boards messages where userId = &#63;.
2769             *
2770             * @param userId the user ID
2771             * @return the matching message-boards messages
2772             */
2773            @Override
2774            public List<MBMessage> findByUserId(long userId) {
2775                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2776            }
2777    
2778            /**
2779             * Returns a range of all the message-boards messages where userId = &#63;.
2780             *
2781             * <p>
2782             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2783             * </p>
2784             *
2785             * @param userId the user ID
2786             * @param start the lower bound of the range of message-boards messages
2787             * @param end the upper bound of the range of message-boards messages (not inclusive)
2788             * @return the range of matching message-boards messages
2789             */
2790            @Override
2791            public List<MBMessage> findByUserId(long userId, int start, int end) {
2792                    return findByUserId(userId, start, end, null);
2793            }
2794    
2795            /**
2796             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2797             *
2798             * <p>
2799             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2800             * </p>
2801             *
2802             * @param userId the user ID
2803             * @param start the lower bound of the range of message-boards messages
2804             * @param end the upper bound of the range of message-boards messages (not inclusive)
2805             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2806             * @return the ordered range of matching message-boards messages
2807             */
2808            @Override
2809            public List<MBMessage> findByUserId(long userId, int start, int end,
2810                    OrderByComparator<MBMessage> orderByComparator) {
2811                    boolean pagination = true;
2812                    FinderPath finderPath = null;
2813                    Object[] finderArgs = null;
2814    
2815                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2816                                    (orderByComparator == null)) {
2817                            pagination = false;
2818                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2819                            finderArgs = new Object[] { userId };
2820                    }
2821                    else {
2822                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2823                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2824                    }
2825    
2826                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2827                                    finderArgs, this);
2828    
2829                    if ((list != null) && !list.isEmpty()) {
2830                            for (MBMessage mbMessage : list) {
2831                                    if ((userId != mbMessage.getUserId())) {
2832                                            list = null;
2833    
2834                                            break;
2835                                    }
2836                            }
2837                    }
2838    
2839                    if (list == null) {
2840                            StringBundler query = null;
2841    
2842                            if (orderByComparator != null) {
2843                                    query = new StringBundler(3 +
2844                                                    (orderByComparator.getOrderByFields().length * 3));
2845                            }
2846                            else {
2847                                    query = new StringBundler(3);
2848                            }
2849    
2850                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2851    
2852                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2853    
2854                            if (orderByComparator != null) {
2855                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2856                                            orderByComparator);
2857                            }
2858                            else
2859                             if (pagination) {
2860                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2861                            }
2862    
2863                            String sql = query.toString();
2864    
2865                            Session session = null;
2866    
2867                            try {
2868                                    session = openSession();
2869    
2870                                    Query q = session.createQuery(sql);
2871    
2872                                    QueryPos qPos = QueryPos.getInstance(q);
2873    
2874                                    qPos.add(userId);
2875    
2876                                    if (!pagination) {
2877                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2878                                                            start, end, false);
2879    
2880                                            Collections.sort(list);
2881    
2882                                            list = Collections.unmodifiableList(list);
2883                                    }
2884                                    else {
2885                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2886                                                            start, end);
2887                                    }
2888    
2889                                    cacheResult(list);
2890    
2891                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2892                            }
2893                            catch (Exception e) {
2894                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2895    
2896                                    throw processException(e);
2897                            }
2898                            finally {
2899                                    closeSession(session);
2900                            }
2901                    }
2902    
2903                    return list;
2904            }
2905    
2906            /**
2907             * Returns the first message-boards message in the ordered set where userId = &#63;.
2908             *
2909             * @param userId the user ID
2910             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2911             * @return the first matching message-boards message
2912             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2913             */
2914            @Override
2915            public MBMessage findByUserId_First(long userId,
2916                    OrderByComparator<MBMessage> orderByComparator)
2917                    throws NoSuchMessageException {
2918                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
2919    
2920                    if (mbMessage != null) {
2921                            return mbMessage;
2922                    }
2923    
2924                    StringBundler msg = new StringBundler(4);
2925    
2926                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2927    
2928                    msg.append("userId=");
2929                    msg.append(userId);
2930    
2931                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2932    
2933                    throw new NoSuchMessageException(msg.toString());
2934            }
2935    
2936            /**
2937             * Returns the first message-boards message in the ordered set where userId = &#63;.
2938             *
2939             * @param userId the user ID
2940             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2941             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2942             */
2943            @Override
2944            public MBMessage fetchByUserId_First(long userId,
2945                    OrderByComparator<MBMessage> orderByComparator) {
2946                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
2947    
2948                    if (!list.isEmpty()) {
2949                            return list.get(0);
2950                    }
2951    
2952                    return null;
2953            }
2954    
2955            /**
2956             * Returns the last message-boards message in the ordered set where userId = &#63;.
2957             *
2958             * @param userId the user ID
2959             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2960             * @return the last matching message-boards message
2961             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2962             */
2963            @Override
2964            public MBMessage findByUserId_Last(long userId,
2965                    OrderByComparator<MBMessage> orderByComparator)
2966                    throws NoSuchMessageException {
2967                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
2968    
2969                    if (mbMessage != null) {
2970                            return mbMessage;
2971                    }
2972    
2973                    StringBundler msg = new StringBundler(4);
2974    
2975                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2976    
2977                    msg.append("userId=");
2978                    msg.append(userId);
2979    
2980                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2981    
2982                    throw new NoSuchMessageException(msg.toString());
2983            }
2984    
2985            /**
2986             * Returns the last message-boards message in the ordered set where userId = &#63;.
2987             *
2988             * @param userId the user ID
2989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2990             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2991             */
2992            @Override
2993            public MBMessage fetchByUserId_Last(long userId,
2994                    OrderByComparator<MBMessage> orderByComparator) {
2995                    int count = countByUserId(userId);
2996    
2997                    if (count == 0) {
2998                            return null;
2999                    }
3000    
3001                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3002                                    orderByComparator);
3003    
3004                    if (!list.isEmpty()) {
3005                            return list.get(0);
3006                    }
3007    
3008                    return null;
3009            }
3010    
3011            /**
3012             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3013             *
3014             * @param messageId the primary key of the current message-boards message
3015             * @param userId the user ID
3016             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3017             * @return the previous, current, and next message-boards message
3018             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3019             */
3020            @Override
3021            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3022                    OrderByComparator<MBMessage> orderByComparator)
3023                    throws NoSuchMessageException {
3024                    MBMessage mbMessage = findByPrimaryKey(messageId);
3025    
3026                    Session session = null;
3027    
3028                    try {
3029                            session = openSession();
3030    
3031                            MBMessage[] array = new MBMessageImpl[3];
3032    
3033                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3034                                            orderByComparator, true);
3035    
3036                            array[1] = mbMessage;
3037    
3038                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3039                                            orderByComparator, false);
3040    
3041                            return array;
3042                    }
3043                    catch (Exception e) {
3044                            throw processException(e);
3045                    }
3046                    finally {
3047                            closeSession(session);
3048                    }
3049            }
3050    
3051            protected MBMessage getByUserId_PrevAndNext(Session session,
3052                    MBMessage mbMessage, long userId,
3053                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3054                    StringBundler query = null;
3055    
3056                    if (orderByComparator != null) {
3057                            query = new StringBundler(6 +
3058                                            (orderByComparator.getOrderByFields().length * 6));
3059                    }
3060                    else {
3061                            query = new StringBundler(3);
3062                    }
3063    
3064                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3065    
3066                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3067    
3068                    if (orderByComparator != null) {
3069                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3070    
3071                            if (orderByConditionFields.length > 0) {
3072                                    query.append(WHERE_AND);
3073                            }
3074    
3075                            for (int i = 0; i < orderByConditionFields.length; i++) {
3076                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3077                                    query.append(orderByConditionFields[i]);
3078    
3079                                    if ((i + 1) < orderByConditionFields.length) {
3080                                            if (orderByComparator.isAscending() ^ previous) {
3081                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3082                                            }
3083                                            else {
3084                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3085                                            }
3086                                    }
3087                                    else {
3088                                            if (orderByComparator.isAscending() ^ previous) {
3089                                                    query.append(WHERE_GREATER_THAN);
3090                                            }
3091                                            else {
3092                                                    query.append(WHERE_LESSER_THAN);
3093                                            }
3094                                    }
3095                            }
3096    
3097                            query.append(ORDER_BY_CLAUSE);
3098    
3099                            String[] orderByFields = orderByComparator.getOrderByFields();
3100    
3101                            for (int i = 0; i < orderByFields.length; i++) {
3102                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3103                                    query.append(orderByFields[i]);
3104    
3105                                    if ((i + 1) < orderByFields.length) {
3106                                            if (orderByComparator.isAscending() ^ previous) {
3107                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3108                                            }
3109                                            else {
3110                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3111                                            }
3112                                    }
3113                                    else {
3114                                            if (orderByComparator.isAscending() ^ previous) {
3115                                                    query.append(ORDER_BY_ASC);
3116                                            }
3117                                            else {
3118                                                    query.append(ORDER_BY_DESC);
3119                                            }
3120                                    }
3121                            }
3122                    }
3123                    else {
3124                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3125                    }
3126    
3127                    String sql = query.toString();
3128    
3129                    Query q = session.createQuery(sql);
3130    
3131                    q.setFirstResult(0);
3132                    q.setMaxResults(2);
3133    
3134                    QueryPos qPos = QueryPos.getInstance(q);
3135    
3136                    qPos.add(userId);
3137    
3138                    if (orderByComparator != null) {
3139                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3140    
3141                            for (Object value : values) {
3142                                    qPos.add(value);
3143                            }
3144                    }
3145    
3146                    List<MBMessage> list = q.list();
3147    
3148                    if (list.size() == 2) {
3149                            return list.get(1);
3150                    }
3151                    else {
3152                            return null;
3153                    }
3154            }
3155    
3156            /**
3157             * Removes all the message-boards messages where userId = &#63; from the database.
3158             *
3159             * @param userId the user ID
3160             */
3161            @Override
3162            public void removeByUserId(long userId) {
3163                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3164                                    QueryUtil.ALL_POS, null)) {
3165                            remove(mbMessage);
3166                    }
3167            }
3168    
3169            /**
3170             * Returns the number of message-boards messages where userId = &#63;.
3171             *
3172             * @param userId the user ID
3173             * @return the number of matching message-boards messages
3174             */
3175            @Override
3176            public int countByUserId(long userId) {
3177                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3178    
3179                    Object[] finderArgs = new Object[] { userId };
3180    
3181                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3182                                    this);
3183    
3184                    if (count == null) {
3185                            StringBundler query = new StringBundler(2);
3186    
3187                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3188    
3189                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3190    
3191                            String sql = query.toString();
3192    
3193                            Session session = null;
3194    
3195                            try {
3196                                    session = openSession();
3197    
3198                                    Query q = session.createQuery(sql);
3199    
3200                                    QueryPos qPos = QueryPos.getInstance(q);
3201    
3202                                    qPos.add(userId);
3203    
3204                                    count = (Long)q.uniqueResult();
3205    
3206                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3207                            }
3208                            catch (Exception e) {
3209                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3210    
3211                                    throw processException(e);
3212                            }
3213                            finally {
3214                                    closeSession(session);
3215                            }
3216                    }
3217    
3218                    return count.intValue();
3219            }
3220    
3221            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3222            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3223                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3224                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3225                            new String[] {
3226                                    Long.class.getName(),
3227                                    
3228                            Integer.class.getName(), Integer.class.getName(),
3229                                    OrderByComparator.class.getName()
3230                            });
3231            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3232                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3233                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3234                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3235                            new String[] { Long.class.getName() },
3236                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3237                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3238            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3239                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3240                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3241                            new String[] { Long.class.getName() });
3242    
3243            /**
3244             * Returns all the message-boards messages where threadId = &#63;.
3245             *
3246             * @param threadId the thread ID
3247             * @return the matching message-boards messages
3248             */
3249            @Override
3250            public List<MBMessage> findByThreadId(long threadId) {
3251                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3252                            null);
3253            }
3254    
3255            /**
3256             * Returns a range of all the message-boards messages where threadId = &#63;.
3257             *
3258             * <p>
3259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3260             * </p>
3261             *
3262             * @param threadId the thread ID
3263             * @param start the lower bound of the range of message-boards messages
3264             * @param end the upper bound of the range of message-boards messages (not inclusive)
3265             * @return the range of matching message-boards messages
3266             */
3267            @Override
3268            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3269                    return findByThreadId(threadId, start, end, null);
3270            }
3271    
3272            /**
3273             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3274             *
3275             * <p>
3276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3277             * </p>
3278             *
3279             * @param threadId the thread ID
3280             * @param start the lower bound of the range of message-boards messages
3281             * @param end the upper bound of the range of message-boards messages (not inclusive)
3282             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3283             * @return the ordered range of matching message-boards messages
3284             */
3285            @Override
3286            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3287                    OrderByComparator<MBMessage> orderByComparator) {
3288                    boolean pagination = true;
3289                    FinderPath finderPath = null;
3290                    Object[] finderArgs = null;
3291    
3292                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3293                                    (orderByComparator == null)) {
3294                            pagination = false;
3295                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3296                            finderArgs = new Object[] { threadId };
3297                    }
3298                    else {
3299                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3300                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3301                    }
3302    
3303                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3304                                    finderArgs, this);
3305    
3306                    if ((list != null) && !list.isEmpty()) {
3307                            for (MBMessage mbMessage : list) {
3308                                    if ((threadId != mbMessage.getThreadId())) {
3309                                            list = null;
3310    
3311                                            break;
3312                                    }
3313                            }
3314                    }
3315    
3316                    if (list == null) {
3317                            StringBundler query = null;
3318    
3319                            if (orderByComparator != null) {
3320                                    query = new StringBundler(3 +
3321                                                    (orderByComparator.getOrderByFields().length * 3));
3322                            }
3323                            else {
3324                                    query = new StringBundler(3);
3325                            }
3326    
3327                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3328    
3329                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3330    
3331                            if (orderByComparator != null) {
3332                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3333                                            orderByComparator);
3334                            }
3335                            else
3336                             if (pagination) {
3337                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3338                            }
3339    
3340                            String sql = query.toString();
3341    
3342                            Session session = null;
3343    
3344                            try {
3345                                    session = openSession();
3346    
3347                                    Query q = session.createQuery(sql);
3348    
3349                                    QueryPos qPos = QueryPos.getInstance(q);
3350    
3351                                    qPos.add(threadId);
3352    
3353                                    if (!pagination) {
3354                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3355                                                            start, end, false);
3356    
3357                                            Collections.sort(list);
3358    
3359                                            list = Collections.unmodifiableList(list);
3360                                    }
3361                                    else {
3362                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3363                                                            start, end);
3364                                    }
3365    
3366                                    cacheResult(list);
3367    
3368                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3369                            }
3370                            catch (Exception e) {
3371                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3372    
3373                                    throw processException(e);
3374                            }
3375                            finally {
3376                                    closeSession(session);
3377                            }
3378                    }
3379    
3380                    return list;
3381            }
3382    
3383            /**
3384             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3385             *
3386             * @param threadId the thread ID
3387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3388             * @return the first matching message-boards message
3389             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3390             */
3391            @Override
3392            public MBMessage findByThreadId_First(long threadId,
3393                    OrderByComparator<MBMessage> orderByComparator)
3394                    throws NoSuchMessageException {
3395                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3396    
3397                    if (mbMessage != null) {
3398                            return mbMessage;
3399                    }
3400    
3401                    StringBundler msg = new StringBundler(4);
3402    
3403                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3404    
3405                    msg.append("threadId=");
3406                    msg.append(threadId);
3407    
3408                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3409    
3410                    throw new NoSuchMessageException(msg.toString());
3411            }
3412    
3413            /**
3414             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3415             *
3416             * @param threadId the thread ID
3417             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3418             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3419             */
3420            @Override
3421            public MBMessage fetchByThreadId_First(long threadId,
3422                    OrderByComparator<MBMessage> orderByComparator) {
3423                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3424    
3425                    if (!list.isEmpty()) {
3426                            return list.get(0);
3427                    }
3428    
3429                    return null;
3430            }
3431    
3432            /**
3433             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3434             *
3435             * @param threadId the thread ID
3436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3437             * @return the last matching message-boards message
3438             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3439             */
3440            @Override
3441            public MBMessage findByThreadId_Last(long threadId,
3442                    OrderByComparator<MBMessage> orderByComparator)
3443                    throws NoSuchMessageException {
3444                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3445    
3446                    if (mbMessage != null) {
3447                            return mbMessage;
3448                    }
3449    
3450                    StringBundler msg = new StringBundler(4);
3451    
3452                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3453    
3454                    msg.append("threadId=");
3455                    msg.append(threadId);
3456    
3457                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3458    
3459                    throw new NoSuchMessageException(msg.toString());
3460            }
3461    
3462            /**
3463             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3464             *
3465             * @param threadId the thread ID
3466             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3467             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3468             */
3469            @Override
3470            public MBMessage fetchByThreadId_Last(long threadId,
3471                    OrderByComparator<MBMessage> orderByComparator) {
3472                    int count = countByThreadId(threadId);
3473    
3474                    if (count == 0) {
3475                            return null;
3476                    }
3477    
3478                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3479                                    orderByComparator);
3480    
3481                    if (!list.isEmpty()) {
3482                            return list.get(0);
3483                    }
3484    
3485                    return null;
3486            }
3487    
3488            /**
3489             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3490             *
3491             * @param messageId the primary key of the current message-boards message
3492             * @param threadId the thread ID
3493             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3494             * @return the previous, current, and next message-boards message
3495             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3496             */
3497            @Override
3498            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3499                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3500                    throws NoSuchMessageException {
3501                    MBMessage mbMessage = findByPrimaryKey(messageId);
3502    
3503                    Session session = null;
3504    
3505                    try {
3506                            session = openSession();
3507    
3508                            MBMessage[] array = new MBMessageImpl[3];
3509    
3510                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3511                                            orderByComparator, true);
3512    
3513                            array[1] = mbMessage;
3514    
3515                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3516                                            orderByComparator, false);
3517    
3518                            return array;
3519                    }
3520                    catch (Exception e) {
3521                            throw processException(e);
3522                    }
3523                    finally {
3524                            closeSession(session);
3525                    }
3526            }
3527    
3528            protected MBMessage getByThreadId_PrevAndNext(Session session,
3529                    MBMessage mbMessage, long threadId,
3530                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3531                    StringBundler query = null;
3532    
3533                    if (orderByComparator != null) {
3534                            query = new StringBundler(6 +
3535                                            (orderByComparator.getOrderByFields().length * 6));
3536                    }
3537                    else {
3538                            query = new StringBundler(3);
3539                    }
3540    
3541                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3542    
3543                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3544    
3545                    if (orderByComparator != null) {
3546                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3547    
3548                            if (orderByConditionFields.length > 0) {
3549                                    query.append(WHERE_AND);
3550                            }
3551    
3552                            for (int i = 0; i < orderByConditionFields.length; i++) {
3553                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3554                                    query.append(orderByConditionFields[i]);
3555    
3556                                    if ((i + 1) < orderByConditionFields.length) {
3557                                            if (orderByComparator.isAscending() ^ previous) {
3558                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3559                                            }
3560                                            else {
3561                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3562                                            }
3563                                    }
3564                                    else {
3565                                            if (orderByComparator.isAscending() ^ previous) {
3566                                                    query.append(WHERE_GREATER_THAN);
3567                                            }
3568                                            else {
3569                                                    query.append(WHERE_LESSER_THAN);
3570                                            }
3571                                    }
3572                            }
3573    
3574                            query.append(ORDER_BY_CLAUSE);
3575    
3576                            String[] orderByFields = orderByComparator.getOrderByFields();
3577    
3578                            for (int i = 0; i < orderByFields.length; i++) {
3579                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3580                                    query.append(orderByFields[i]);
3581    
3582                                    if ((i + 1) < orderByFields.length) {
3583                                            if (orderByComparator.isAscending() ^ previous) {
3584                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3585                                            }
3586                                            else {
3587                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3588                                            }
3589                                    }
3590                                    else {
3591                                            if (orderByComparator.isAscending() ^ previous) {
3592                                                    query.append(ORDER_BY_ASC);
3593                                            }
3594                                            else {
3595                                                    query.append(ORDER_BY_DESC);
3596                                            }
3597                                    }
3598                            }
3599                    }
3600                    else {
3601                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3602                    }
3603    
3604                    String sql = query.toString();
3605    
3606                    Query q = session.createQuery(sql);
3607    
3608                    q.setFirstResult(0);
3609                    q.setMaxResults(2);
3610    
3611                    QueryPos qPos = QueryPos.getInstance(q);
3612    
3613                    qPos.add(threadId);
3614    
3615                    if (orderByComparator != null) {
3616                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3617    
3618                            for (Object value : values) {
3619                                    qPos.add(value);
3620                            }
3621                    }
3622    
3623                    List<MBMessage> list = q.list();
3624    
3625                    if (list.size() == 2) {
3626                            return list.get(1);
3627                    }
3628                    else {
3629                            return null;
3630                    }
3631            }
3632    
3633            /**
3634             * Removes all the message-boards messages where threadId = &#63; from the database.
3635             *
3636             * @param threadId the thread ID
3637             */
3638            @Override
3639            public void removeByThreadId(long threadId) {
3640                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3641                                    QueryUtil.ALL_POS, null)) {
3642                            remove(mbMessage);
3643                    }
3644            }
3645    
3646            /**
3647             * Returns the number of message-boards messages where threadId = &#63;.
3648             *
3649             * @param threadId the thread ID
3650             * @return the number of matching message-boards messages
3651             */
3652            @Override
3653            public int countByThreadId(long threadId) {
3654                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3655    
3656                    Object[] finderArgs = new Object[] { threadId };
3657    
3658                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3659                                    this);
3660    
3661                    if (count == null) {
3662                            StringBundler query = new StringBundler(2);
3663    
3664                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3665    
3666                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3667    
3668                            String sql = query.toString();
3669    
3670                            Session session = null;
3671    
3672                            try {
3673                                    session = openSession();
3674    
3675                                    Query q = session.createQuery(sql);
3676    
3677                                    QueryPos qPos = QueryPos.getInstance(q);
3678    
3679                                    qPos.add(threadId);
3680    
3681                                    count = (Long)q.uniqueResult();
3682    
3683                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3684                            }
3685                            catch (Exception e) {
3686                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3687    
3688                                    throw processException(e);
3689                            }
3690                            finally {
3691                                    closeSession(session);
3692                            }
3693                    }
3694    
3695                    return count.intValue();
3696            }
3697    
3698            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3699            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3700                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3701                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3702                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3703                            new String[] {
3704                                    Long.class.getName(),
3705                                    
3706                            Integer.class.getName(), Integer.class.getName(),
3707                                    OrderByComparator.class.getName()
3708                            });
3709            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3710                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3711                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3712                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3713                            new String[] { Long.class.getName() },
3714                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3715                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3716            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3717                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3718                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3719                            new String[] { Long.class.getName() });
3720    
3721            /**
3722             * Returns all the message-boards messages where threadId = &#63;.
3723             *
3724             * @param threadId the thread ID
3725             * @return the matching message-boards messages
3726             */
3727            @Override
3728            public List<MBMessage> findByThreadReplies(long threadId) {
3729                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3730                            QueryUtil.ALL_POS, null);
3731            }
3732    
3733            /**
3734             * Returns a range of all the message-boards messages where threadId = &#63;.
3735             *
3736             * <p>
3737             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3738             * </p>
3739             *
3740             * @param threadId the thread ID
3741             * @param start the lower bound of the range of message-boards messages
3742             * @param end the upper bound of the range of message-boards messages (not inclusive)
3743             * @return the range of matching message-boards messages
3744             */
3745            @Override
3746            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3747                    return findByThreadReplies(threadId, start, end, null);
3748            }
3749    
3750            /**
3751             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3752             *
3753             * <p>
3754             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3755             * </p>
3756             *
3757             * @param threadId the thread ID
3758             * @param start the lower bound of the range of message-boards messages
3759             * @param end the upper bound of the range of message-boards messages (not inclusive)
3760             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3761             * @return the ordered range of matching message-boards messages
3762             */
3763            @Override
3764            public List<MBMessage> findByThreadReplies(long threadId, int start,
3765                    int end, OrderByComparator<MBMessage> orderByComparator) {
3766                    boolean pagination = true;
3767                    FinderPath finderPath = null;
3768                    Object[] finderArgs = null;
3769    
3770                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3771                                    (orderByComparator == null)) {
3772                            pagination = false;
3773                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3774                            finderArgs = new Object[] { threadId };
3775                    }
3776                    else {
3777                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3778                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3779                    }
3780    
3781                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3782                                    finderArgs, this);
3783    
3784                    if ((list != null) && !list.isEmpty()) {
3785                            for (MBMessage mbMessage : list) {
3786                                    if ((threadId != mbMessage.getThreadId())) {
3787                                            list = null;
3788    
3789                                            break;
3790                                    }
3791                            }
3792                    }
3793    
3794                    if (list == null) {
3795                            StringBundler query = null;
3796    
3797                            if (orderByComparator != null) {
3798                                    query = new StringBundler(3 +
3799                                                    (orderByComparator.getOrderByFields().length * 3));
3800                            }
3801                            else {
3802                                    query = new StringBundler(3);
3803                            }
3804    
3805                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3806    
3807                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3808    
3809                            if (orderByComparator != null) {
3810                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3811                                            orderByComparator);
3812                            }
3813                            else
3814                             if (pagination) {
3815                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3816                            }
3817    
3818                            String sql = query.toString();
3819    
3820                            Session session = null;
3821    
3822                            try {
3823                                    session = openSession();
3824    
3825                                    Query q = session.createQuery(sql);
3826    
3827                                    QueryPos qPos = QueryPos.getInstance(q);
3828    
3829                                    qPos.add(threadId);
3830    
3831                                    if (!pagination) {
3832                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3833                                                            start, end, false);
3834    
3835                                            Collections.sort(list);
3836    
3837                                            list = Collections.unmodifiableList(list);
3838                                    }
3839                                    else {
3840                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3841                                                            start, end);
3842                                    }
3843    
3844                                    cacheResult(list);
3845    
3846                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3847                            }
3848                            catch (Exception e) {
3849                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3850    
3851                                    throw processException(e);
3852                            }
3853                            finally {
3854                                    closeSession(session);
3855                            }
3856                    }
3857    
3858                    return list;
3859            }
3860    
3861            /**
3862             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3863             *
3864             * @param threadId the thread ID
3865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3866             * @return the first matching message-boards message
3867             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3868             */
3869            @Override
3870            public MBMessage findByThreadReplies_First(long threadId,
3871                    OrderByComparator<MBMessage> orderByComparator)
3872                    throws NoSuchMessageException {
3873                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3874                                    orderByComparator);
3875    
3876                    if (mbMessage != null) {
3877                            return mbMessage;
3878                    }
3879    
3880                    StringBundler msg = new StringBundler(4);
3881    
3882                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3883    
3884                    msg.append("threadId=");
3885                    msg.append(threadId);
3886    
3887                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3888    
3889                    throw new NoSuchMessageException(msg.toString());
3890            }
3891    
3892            /**
3893             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3894             *
3895             * @param threadId the thread ID
3896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3897             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3898             */
3899            @Override
3900            public MBMessage fetchByThreadReplies_First(long threadId,
3901                    OrderByComparator<MBMessage> orderByComparator) {
3902                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3903                                    orderByComparator);
3904    
3905                    if (!list.isEmpty()) {
3906                            return list.get(0);
3907                    }
3908    
3909                    return null;
3910            }
3911    
3912            /**
3913             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3914             *
3915             * @param threadId the thread ID
3916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3917             * @return the last matching message-boards message
3918             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3919             */
3920            @Override
3921            public MBMessage findByThreadReplies_Last(long threadId,
3922                    OrderByComparator<MBMessage> orderByComparator)
3923                    throws NoSuchMessageException {
3924                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3925                                    orderByComparator);
3926    
3927                    if (mbMessage != null) {
3928                            return mbMessage;
3929                    }
3930    
3931                    StringBundler msg = new StringBundler(4);
3932    
3933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3934    
3935                    msg.append("threadId=");
3936                    msg.append(threadId);
3937    
3938                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3939    
3940                    throw new NoSuchMessageException(msg.toString());
3941            }
3942    
3943            /**
3944             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3945             *
3946             * @param threadId the thread ID
3947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3948             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3949             */
3950            @Override
3951            public MBMessage fetchByThreadReplies_Last(long threadId,
3952                    OrderByComparator<MBMessage> orderByComparator) {
3953                    int count = countByThreadReplies(threadId);
3954    
3955                    if (count == 0) {
3956                            return null;
3957                    }
3958    
3959                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3960                                    orderByComparator);
3961    
3962                    if (!list.isEmpty()) {
3963                            return list.get(0);
3964                    }
3965    
3966                    return null;
3967            }
3968    
3969            /**
3970             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3971             *
3972             * @param messageId the primary key of the current message-boards message
3973             * @param threadId the thread ID
3974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3975             * @return the previous, current, and next message-boards message
3976             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3977             */
3978            @Override
3979            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3980                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3981                    throws NoSuchMessageException {
3982                    MBMessage mbMessage = findByPrimaryKey(messageId);
3983    
3984                    Session session = null;
3985    
3986                    try {
3987                            session = openSession();
3988    
3989                            MBMessage[] array = new MBMessageImpl[3];
3990    
3991                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3992                                            threadId, orderByComparator, true);
3993    
3994                            array[1] = mbMessage;
3995    
3996                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3997                                            threadId, orderByComparator, false);
3998    
3999                            return array;
4000                    }
4001                    catch (Exception e) {
4002                            throw processException(e);
4003                    }
4004                    finally {
4005                            closeSession(session);
4006                    }
4007            }
4008    
4009            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4010                    MBMessage mbMessage, long threadId,
4011                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4012                    StringBundler query = null;
4013    
4014                    if (orderByComparator != null) {
4015                            query = new StringBundler(6 +
4016                                            (orderByComparator.getOrderByFields().length * 6));
4017                    }
4018                    else {
4019                            query = new StringBundler(3);
4020                    }
4021    
4022                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4023    
4024                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4025    
4026                    if (orderByComparator != null) {
4027                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4028    
4029                            if (orderByConditionFields.length > 0) {
4030                                    query.append(WHERE_AND);
4031                            }
4032    
4033                            for (int i = 0; i < orderByConditionFields.length; i++) {
4034                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4035                                    query.append(orderByConditionFields[i]);
4036    
4037                                    if ((i + 1) < orderByConditionFields.length) {
4038                                            if (orderByComparator.isAscending() ^ previous) {
4039                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4040                                            }
4041                                            else {
4042                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4043                                            }
4044                                    }
4045                                    else {
4046                                            if (orderByComparator.isAscending() ^ previous) {
4047                                                    query.append(WHERE_GREATER_THAN);
4048                                            }
4049                                            else {
4050                                                    query.append(WHERE_LESSER_THAN);
4051                                            }
4052                                    }
4053                            }
4054    
4055                            query.append(ORDER_BY_CLAUSE);
4056    
4057                            String[] orderByFields = orderByComparator.getOrderByFields();
4058    
4059                            for (int i = 0; i < orderByFields.length; i++) {
4060                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4061                                    query.append(orderByFields[i]);
4062    
4063                                    if ((i + 1) < orderByFields.length) {
4064                                            if (orderByComparator.isAscending() ^ previous) {
4065                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4066                                            }
4067                                            else {
4068                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4069                                            }
4070                                    }
4071                                    else {
4072                                            if (orderByComparator.isAscending() ^ previous) {
4073                                                    query.append(ORDER_BY_ASC);
4074                                            }
4075                                            else {
4076                                                    query.append(ORDER_BY_DESC);
4077                                            }
4078                                    }
4079                            }
4080                    }
4081                    else {
4082                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4083                    }
4084    
4085                    String sql = query.toString();
4086    
4087                    Query q = session.createQuery(sql);
4088    
4089                    q.setFirstResult(0);
4090                    q.setMaxResults(2);
4091    
4092                    QueryPos qPos = QueryPos.getInstance(q);
4093    
4094                    qPos.add(threadId);
4095    
4096                    if (orderByComparator != null) {
4097                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4098    
4099                            for (Object value : values) {
4100                                    qPos.add(value);
4101                            }
4102                    }
4103    
4104                    List<MBMessage> list = q.list();
4105    
4106                    if (list.size() == 2) {
4107                            return list.get(1);
4108                    }
4109                    else {
4110                            return null;
4111                    }
4112            }
4113    
4114            /**
4115             * Removes all the message-boards messages where threadId = &#63; from the database.
4116             *
4117             * @param threadId the thread ID
4118             */
4119            @Override
4120            public void removeByThreadReplies(long threadId) {
4121                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4122                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4123                            remove(mbMessage);
4124                    }
4125            }
4126    
4127            /**
4128             * Returns the number of message-boards messages where threadId = &#63;.
4129             *
4130             * @param threadId the thread ID
4131             * @return the number of matching message-boards messages
4132             */
4133            @Override
4134            public int countByThreadReplies(long threadId) {
4135                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4136    
4137                    Object[] finderArgs = new Object[] { threadId };
4138    
4139                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4140                                    this);
4141    
4142                    if (count == null) {
4143                            StringBundler query = new StringBundler(2);
4144    
4145                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4146    
4147                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4148    
4149                            String sql = query.toString();
4150    
4151                            Session session = null;
4152    
4153                            try {
4154                                    session = openSession();
4155    
4156                                    Query q = session.createQuery(sql);
4157    
4158                                    QueryPos qPos = QueryPos.getInstance(q);
4159    
4160                                    qPos.add(threadId);
4161    
4162                                    count = (Long)q.uniqueResult();
4163    
4164                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4165                            }
4166                            catch (Exception e) {
4167                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4168    
4169                                    throw processException(e);
4170                            }
4171                            finally {
4172                                    closeSession(session);
4173                            }
4174                    }
4175    
4176                    return count.intValue();
4177            }
4178    
4179            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4180            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4181                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4182                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4183                            new String[] {
4184                                    Long.class.getName(), Long.class.getName(),
4185                                    
4186                            Integer.class.getName(), Integer.class.getName(),
4187                                    OrderByComparator.class.getName()
4188                            });
4189            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4190                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4191                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4192                            new String[] { Long.class.getName(), Long.class.getName() },
4193                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4194                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4195                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4196            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4197                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4198                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4199                            new String[] { Long.class.getName(), Long.class.getName() });
4200    
4201            /**
4202             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4203             *
4204             * @param groupId the group ID
4205             * @param userId the user ID
4206             * @return the matching message-boards messages
4207             */
4208            @Override
4209            public List<MBMessage> findByG_U(long groupId, long userId) {
4210                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4211                            null);
4212            }
4213    
4214            /**
4215             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4216             *
4217             * <p>
4218             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4219             * </p>
4220             *
4221             * @param groupId the group ID
4222             * @param userId the user ID
4223             * @param start the lower bound of the range of message-boards messages
4224             * @param end the upper bound of the range of message-boards messages (not inclusive)
4225             * @return the range of matching message-boards messages
4226             */
4227            @Override
4228            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4229                    int end) {
4230                    return findByG_U(groupId, userId, start, end, null);
4231            }
4232    
4233            /**
4234             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4235             *
4236             * <p>
4237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4238             * </p>
4239             *
4240             * @param groupId the group ID
4241             * @param userId the user ID
4242             * @param start the lower bound of the range of message-boards messages
4243             * @param end the upper bound of the range of message-boards messages (not inclusive)
4244             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4245             * @return the ordered range of matching message-boards messages
4246             */
4247            @Override
4248            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4249                    int end, OrderByComparator<MBMessage> orderByComparator) {
4250                    boolean pagination = true;
4251                    FinderPath finderPath = null;
4252                    Object[] finderArgs = null;
4253    
4254                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4255                                    (orderByComparator == null)) {
4256                            pagination = false;
4257                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4258                            finderArgs = new Object[] { groupId, userId };
4259                    }
4260                    else {
4261                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4262                            finderArgs = new Object[] {
4263                                            groupId, userId,
4264                                            
4265                                            start, end, orderByComparator
4266                                    };
4267                    }
4268    
4269                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4270                                    finderArgs, this);
4271    
4272                    if ((list != null) && !list.isEmpty()) {
4273                            for (MBMessage mbMessage : list) {
4274                                    if ((groupId != mbMessage.getGroupId()) ||
4275                                                    (userId != mbMessage.getUserId())) {
4276                                            list = null;
4277    
4278                                            break;
4279                                    }
4280                            }
4281                    }
4282    
4283                    if (list == null) {
4284                            StringBundler query = null;
4285    
4286                            if (orderByComparator != null) {
4287                                    query = new StringBundler(4 +
4288                                                    (orderByComparator.getOrderByFields().length * 3));
4289                            }
4290                            else {
4291                                    query = new StringBundler(4);
4292                            }
4293    
4294                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4295    
4296                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4297    
4298                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4299    
4300                            if (orderByComparator != null) {
4301                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4302                                            orderByComparator);
4303                            }
4304                            else
4305                             if (pagination) {
4306                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4307                            }
4308    
4309                            String sql = query.toString();
4310    
4311                            Session session = null;
4312    
4313                            try {
4314                                    session = openSession();
4315    
4316                                    Query q = session.createQuery(sql);
4317    
4318                                    QueryPos qPos = QueryPos.getInstance(q);
4319    
4320                                    qPos.add(groupId);
4321    
4322                                    qPos.add(userId);
4323    
4324                                    if (!pagination) {
4325                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4326                                                            start, end, false);
4327    
4328                                            Collections.sort(list);
4329    
4330                                            list = Collections.unmodifiableList(list);
4331                                    }
4332                                    else {
4333                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4334                                                            start, end);
4335                                    }
4336    
4337                                    cacheResult(list);
4338    
4339                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4340                            }
4341                            catch (Exception e) {
4342                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4343    
4344                                    throw processException(e);
4345                            }
4346                            finally {
4347                                    closeSession(session);
4348                            }
4349                    }
4350    
4351                    return list;
4352            }
4353    
4354            /**
4355             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4356             *
4357             * @param groupId the group ID
4358             * @param userId the user ID
4359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4360             * @return the first matching message-boards message
4361             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4362             */
4363            @Override
4364            public MBMessage findByG_U_First(long groupId, long userId,
4365                    OrderByComparator<MBMessage> orderByComparator)
4366                    throws NoSuchMessageException {
4367                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4368                                    orderByComparator);
4369    
4370                    if (mbMessage != null) {
4371                            return mbMessage;
4372                    }
4373    
4374                    StringBundler msg = new StringBundler(6);
4375    
4376                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4377    
4378                    msg.append("groupId=");
4379                    msg.append(groupId);
4380    
4381                    msg.append(", userId=");
4382                    msg.append(userId);
4383    
4384                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4385    
4386                    throw new NoSuchMessageException(msg.toString());
4387            }
4388    
4389            /**
4390             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4391             *
4392             * @param groupId the group ID
4393             * @param userId the user ID
4394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4395             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4396             */
4397            @Override
4398            public MBMessage fetchByG_U_First(long groupId, long userId,
4399                    OrderByComparator<MBMessage> orderByComparator) {
4400                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4401                                    orderByComparator);
4402    
4403                    if (!list.isEmpty()) {
4404                            return list.get(0);
4405                    }
4406    
4407                    return null;
4408            }
4409    
4410            /**
4411             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4412             *
4413             * @param groupId the group ID
4414             * @param userId the user ID
4415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4416             * @return the last matching message-boards message
4417             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4418             */
4419            @Override
4420            public MBMessage findByG_U_Last(long groupId, long userId,
4421                    OrderByComparator<MBMessage> orderByComparator)
4422                    throws NoSuchMessageException {
4423                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4424    
4425                    if (mbMessage != null) {
4426                            return mbMessage;
4427                    }
4428    
4429                    StringBundler msg = new StringBundler(6);
4430    
4431                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4432    
4433                    msg.append("groupId=");
4434                    msg.append(groupId);
4435    
4436                    msg.append(", userId=");
4437                    msg.append(userId);
4438    
4439                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4440    
4441                    throw new NoSuchMessageException(msg.toString());
4442            }
4443    
4444            /**
4445             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4446             *
4447             * @param groupId the group ID
4448             * @param userId the user ID
4449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4450             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4451             */
4452            @Override
4453            public MBMessage fetchByG_U_Last(long groupId, long userId,
4454                    OrderByComparator<MBMessage> orderByComparator) {
4455                    int count = countByG_U(groupId, userId);
4456    
4457                    if (count == 0) {
4458                            return null;
4459                    }
4460    
4461                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4462                                    orderByComparator);
4463    
4464                    if (!list.isEmpty()) {
4465                            return list.get(0);
4466                    }
4467    
4468                    return null;
4469            }
4470    
4471            /**
4472             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4473             *
4474             * @param messageId the primary key of the current message-boards message
4475             * @param groupId the group ID
4476             * @param userId the user ID
4477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4478             * @return the previous, current, and next message-boards message
4479             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4480             */
4481            @Override
4482            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4483                    long userId, OrderByComparator<MBMessage> orderByComparator)
4484                    throws NoSuchMessageException {
4485                    MBMessage mbMessage = findByPrimaryKey(messageId);
4486    
4487                    Session session = null;
4488    
4489                    try {
4490                            session = openSession();
4491    
4492                            MBMessage[] array = new MBMessageImpl[3];
4493    
4494                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4495                                            userId, orderByComparator, true);
4496    
4497                            array[1] = mbMessage;
4498    
4499                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4500                                            userId, orderByComparator, false);
4501    
4502                            return array;
4503                    }
4504                    catch (Exception e) {
4505                            throw processException(e);
4506                    }
4507                    finally {
4508                            closeSession(session);
4509                    }
4510            }
4511    
4512            protected MBMessage getByG_U_PrevAndNext(Session session,
4513                    MBMessage mbMessage, long groupId, long userId,
4514                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4515                    StringBundler query = null;
4516    
4517                    if (orderByComparator != null) {
4518                            query = new StringBundler(6 +
4519                                            (orderByComparator.getOrderByFields().length * 6));
4520                    }
4521                    else {
4522                            query = new StringBundler(3);
4523                    }
4524    
4525                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4526    
4527                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4528    
4529                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4530    
4531                    if (orderByComparator != null) {
4532                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4533    
4534                            if (orderByConditionFields.length > 0) {
4535                                    query.append(WHERE_AND);
4536                            }
4537    
4538                            for (int i = 0; i < orderByConditionFields.length; i++) {
4539                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4540                                    query.append(orderByConditionFields[i]);
4541    
4542                                    if ((i + 1) < orderByConditionFields.length) {
4543                                            if (orderByComparator.isAscending() ^ previous) {
4544                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4545                                            }
4546                                            else {
4547                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4548                                            }
4549                                    }
4550                                    else {
4551                                            if (orderByComparator.isAscending() ^ previous) {
4552                                                    query.append(WHERE_GREATER_THAN);
4553                                            }
4554                                            else {
4555                                                    query.append(WHERE_LESSER_THAN);
4556                                            }
4557                                    }
4558                            }
4559    
4560                            query.append(ORDER_BY_CLAUSE);
4561    
4562                            String[] orderByFields = orderByComparator.getOrderByFields();
4563    
4564                            for (int i = 0; i < orderByFields.length; i++) {
4565                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4566                                    query.append(orderByFields[i]);
4567    
4568                                    if ((i + 1) < orderByFields.length) {
4569                                            if (orderByComparator.isAscending() ^ previous) {
4570                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4571                                            }
4572                                            else {
4573                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4574                                            }
4575                                    }
4576                                    else {
4577                                            if (orderByComparator.isAscending() ^ previous) {
4578                                                    query.append(ORDER_BY_ASC);
4579                                            }
4580                                            else {
4581                                                    query.append(ORDER_BY_DESC);
4582                                            }
4583                                    }
4584                            }
4585                    }
4586                    else {
4587                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4588                    }
4589    
4590                    String sql = query.toString();
4591    
4592                    Query q = session.createQuery(sql);
4593    
4594                    q.setFirstResult(0);
4595                    q.setMaxResults(2);
4596    
4597                    QueryPos qPos = QueryPos.getInstance(q);
4598    
4599                    qPos.add(groupId);
4600    
4601                    qPos.add(userId);
4602    
4603                    if (orderByComparator != null) {
4604                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4605    
4606                            for (Object value : values) {
4607                                    qPos.add(value);
4608                            }
4609                    }
4610    
4611                    List<MBMessage> list = q.list();
4612    
4613                    if (list.size() == 2) {
4614                            return list.get(1);
4615                    }
4616                    else {
4617                            return null;
4618                    }
4619            }
4620    
4621            /**
4622             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4623             *
4624             * @param groupId the group ID
4625             * @param userId the user ID
4626             * @return the matching message-boards messages that the user has permission to view
4627             */
4628            @Override
4629            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4630                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4631                            QueryUtil.ALL_POS, null);
4632            }
4633    
4634            /**
4635             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4636             *
4637             * <p>
4638             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4639             * </p>
4640             *
4641             * @param groupId the group ID
4642             * @param userId the user ID
4643             * @param start the lower bound of the range of message-boards messages
4644             * @param end the upper bound of the range of message-boards messages (not inclusive)
4645             * @return the range of matching message-boards messages that the user has permission to view
4646             */
4647            @Override
4648            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4649                    int start, int end) {
4650                    return filterFindByG_U(groupId, userId, start, end, null);
4651            }
4652    
4653            /**
4654             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4655             *
4656             * <p>
4657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4658             * </p>
4659             *
4660             * @param groupId the group ID
4661             * @param userId the user ID
4662             * @param start the lower bound of the range of message-boards messages
4663             * @param end the upper bound of the range of message-boards messages (not inclusive)
4664             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4665             * @return the ordered range of matching message-boards messages that the user has permission to view
4666             */
4667            @Override
4668            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4669                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4670                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4671                            return findByG_U(groupId, userId, start, end, orderByComparator);
4672                    }
4673    
4674                    StringBundler query = null;
4675    
4676                    if (orderByComparator != null) {
4677                            query = new StringBundler(4 +
4678                                            (orderByComparator.getOrderByFields().length * 3));
4679                    }
4680                    else {
4681                            query = new StringBundler(4);
4682                    }
4683    
4684                    if (getDB().isSupportsInlineDistinct()) {
4685                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4686                    }
4687                    else {
4688                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4689                    }
4690    
4691                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4692    
4693                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4694    
4695                    if (!getDB().isSupportsInlineDistinct()) {
4696                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4697                    }
4698    
4699                    if (orderByComparator != null) {
4700                            if (getDB().isSupportsInlineDistinct()) {
4701                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4702                                            orderByComparator, true);
4703                            }
4704                            else {
4705                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4706                                            orderByComparator, true);
4707                            }
4708                    }
4709                    else {
4710                            if (getDB().isSupportsInlineDistinct()) {
4711                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4712                            }
4713                            else {
4714                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4715                            }
4716                    }
4717    
4718                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4719                                    MBMessage.class.getName(),
4720                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4721    
4722                    Session session = null;
4723    
4724                    try {
4725                            session = openSession();
4726    
4727                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4728    
4729                            if (getDB().isSupportsInlineDistinct()) {
4730                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4731                            }
4732                            else {
4733                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4734                            }
4735    
4736                            QueryPos qPos = QueryPos.getInstance(q);
4737    
4738                            qPos.add(groupId);
4739    
4740                            qPos.add(userId);
4741    
4742                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4743                    }
4744                    catch (Exception e) {
4745                            throw processException(e);
4746                    }
4747                    finally {
4748                            closeSession(session);
4749                    }
4750            }
4751    
4752            /**
4753             * 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;.
4754             *
4755             * @param messageId the primary key of the current message-boards message
4756             * @param groupId the group ID
4757             * @param userId the user ID
4758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4759             * @return the previous, current, and next message-boards message
4760             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4761             */
4762            @Override
4763            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4764                    long groupId, long userId,
4765                    OrderByComparator<MBMessage> orderByComparator)
4766                    throws NoSuchMessageException {
4767                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4768                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4769                                    orderByComparator);
4770                    }
4771    
4772                    MBMessage mbMessage = findByPrimaryKey(messageId);
4773    
4774                    Session session = null;
4775    
4776                    try {
4777                            session = openSession();
4778    
4779                            MBMessage[] array = new MBMessageImpl[3];
4780    
4781                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4782                                            userId, orderByComparator, true);
4783    
4784                            array[1] = mbMessage;
4785    
4786                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4787                                            userId, orderByComparator, false);
4788    
4789                            return array;
4790                    }
4791                    catch (Exception e) {
4792                            throw processException(e);
4793                    }
4794                    finally {
4795                            closeSession(session);
4796                    }
4797            }
4798    
4799            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4800                    MBMessage mbMessage, long groupId, long userId,
4801                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4802                    StringBundler query = null;
4803    
4804                    if (orderByComparator != null) {
4805                            query = new StringBundler(6 +
4806                                            (orderByComparator.getOrderByFields().length * 6));
4807                    }
4808                    else {
4809                            query = new StringBundler(3);
4810                    }
4811    
4812                    if (getDB().isSupportsInlineDistinct()) {
4813                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4814                    }
4815                    else {
4816                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4817                    }
4818    
4819                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4820    
4821                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4822    
4823                    if (!getDB().isSupportsInlineDistinct()) {
4824                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4825                    }
4826    
4827                    if (orderByComparator != null) {
4828                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4829    
4830                            if (orderByConditionFields.length > 0) {
4831                                    query.append(WHERE_AND);
4832                            }
4833    
4834                            for (int i = 0; i < orderByConditionFields.length; i++) {
4835                                    if (getDB().isSupportsInlineDistinct()) {
4836                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4837                                    }
4838                                    else {
4839                                            query.append(_ORDER_BY_ENTITY_TABLE);
4840                                    }
4841    
4842                                    query.append(orderByConditionFields[i]);
4843    
4844                                    if ((i + 1) < orderByConditionFields.length) {
4845                                            if (orderByComparator.isAscending() ^ previous) {
4846                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4847                                            }
4848                                            else {
4849                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4850                                            }
4851                                    }
4852                                    else {
4853                                            if (orderByComparator.isAscending() ^ previous) {
4854                                                    query.append(WHERE_GREATER_THAN);
4855                                            }
4856                                            else {
4857                                                    query.append(WHERE_LESSER_THAN);
4858                                            }
4859                                    }
4860                            }
4861    
4862                            query.append(ORDER_BY_CLAUSE);
4863    
4864                            String[] orderByFields = orderByComparator.getOrderByFields();
4865    
4866                            for (int i = 0; i < orderByFields.length; i++) {
4867                                    if (getDB().isSupportsInlineDistinct()) {
4868                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4869                                    }
4870                                    else {
4871                                            query.append(_ORDER_BY_ENTITY_TABLE);
4872                                    }
4873    
4874                                    query.append(orderByFields[i]);
4875    
4876                                    if ((i + 1) < orderByFields.length) {
4877                                            if (orderByComparator.isAscending() ^ previous) {
4878                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4879                                            }
4880                                            else {
4881                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4882                                            }
4883                                    }
4884                                    else {
4885                                            if (orderByComparator.isAscending() ^ previous) {
4886                                                    query.append(ORDER_BY_ASC);
4887                                            }
4888                                            else {
4889                                                    query.append(ORDER_BY_DESC);
4890                                            }
4891                                    }
4892                            }
4893                    }
4894                    else {
4895                            if (getDB().isSupportsInlineDistinct()) {
4896                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4897                            }
4898                            else {
4899                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4900                            }
4901                    }
4902    
4903                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4904                                    MBMessage.class.getName(),
4905                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4906    
4907                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4908    
4909                    q.setFirstResult(0);
4910                    q.setMaxResults(2);
4911    
4912                    if (getDB().isSupportsInlineDistinct()) {
4913                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4914                    }
4915                    else {
4916                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4917                    }
4918    
4919                    QueryPos qPos = QueryPos.getInstance(q);
4920    
4921                    qPos.add(groupId);
4922    
4923                    qPos.add(userId);
4924    
4925                    if (orderByComparator != null) {
4926                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4927    
4928                            for (Object value : values) {
4929                                    qPos.add(value);
4930                            }
4931                    }
4932    
4933                    List<MBMessage> list = q.list();
4934    
4935                    if (list.size() == 2) {
4936                            return list.get(1);
4937                    }
4938                    else {
4939                            return null;
4940                    }
4941            }
4942    
4943            /**
4944             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
4945             *
4946             * @param groupId the group ID
4947             * @param userId the user ID
4948             */
4949            @Override
4950            public void removeByG_U(long groupId, long userId) {
4951                    for (MBMessage mbMessage : findByG_U(groupId, userId,
4952                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4953                            remove(mbMessage);
4954                    }
4955            }
4956    
4957            /**
4958             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
4959             *
4960             * @param groupId the group ID
4961             * @param userId the user ID
4962             * @return the number of matching message-boards messages
4963             */
4964            @Override
4965            public int countByG_U(long groupId, long userId) {
4966                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
4967    
4968                    Object[] finderArgs = new Object[] { groupId, userId };
4969    
4970                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4971                                    this);
4972    
4973                    if (count == null) {
4974                            StringBundler query = new StringBundler(3);
4975    
4976                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4977    
4978                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4979    
4980                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4981    
4982                            String sql = query.toString();
4983    
4984                            Session session = null;
4985    
4986                            try {
4987                                    session = openSession();
4988    
4989                                    Query q = session.createQuery(sql);
4990    
4991                                    QueryPos qPos = QueryPos.getInstance(q);
4992    
4993                                    qPos.add(groupId);
4994    
4995                                    qPos.add(userId);
4996    
4997                                    count = (Long)q.uniqueResult();
4998    
4999                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5000                            }
5001                            catch (Exception e) {
5002                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5003    
5004                                    throw processException(e);
5005                            }
5006                            finally {
5007                                    closeSession(session);
5008                            }
5009                    }
5010    
5011                    return count.intValue();
5012            }
5013    
5014            /**
5015             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5016             *
5017             * @param groupId the group ID
5018             * @param userId the user ID
5019             * @return the number of matching message-boards messages that the user has permission to view
5020             */
5021            @Override
5022            public int filterCountByG_U(long groupId, long userId) {
5023                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5024                            return countByG_U(groupId, userId);
5025                    }
5026    
5027                    StringBundler query = new StringBundler(3);
5028    
5029                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5030    
5031                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5032    
5033                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5034    
5035                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5036                                    MBMessage.class.getName(),
5037                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5038    
5039                    Session session = null;
5040    
5041                    try {
5042                            session = openSession();
5043    
5044                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5045    
5046                            q.addScalar(COUNT_COLUMN_NAME,
5047                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5048    
5049                            QueryPos qPos = QueryPos.getInstance(q);
5050    
5051                            qPos.add(groupId);
5052    
5053                            qPos.add(userId);
5054    
5055                            Long count = (Long)q.uniqueResult();
5056    
5057                            return count.intValue();
5058                    }
5059                    catch (Exception e) {
5060                            throw processException(e);
5061                    }
5062                    finally {
5063                            closeSession(session);
5064                    }
5065            }
5066    
5067            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5068            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5069            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5070                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5071                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5072                            new String[] {
5073                                    Long.class.getName(), Long.class.getName(),
5074                                    
5075                            Integer.class.getName(), Integer.class.getName(),
5076                                    OrderByComparator.class.getName()
5077                            });
5078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5079                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5081                            new String[] { Long.class.getName(), Long.class.getName() },
5082                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5083                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5084                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5085            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5086                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5088                            new String[] { Long.class.getName(), Long.class.getName() });
5089    
5090            /**
5091             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5092             *
5093             * @param groupId the group ID
5094             * @param categoryId the category ID
5095             * @return the matching message-boards messages
5096             */
5097            @Override
5098            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5099                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5100                            QueryUtil.ALL_POS, null);
5101            }
5102    
5103            /**
5104             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5105             *
5106             * <p>
5107             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5108             * </p>
5109             *
5110             * @param groupId the group ID
5111             * @param categoryId the category ID
5112             * @param start the lower bound of the range of message-boards messages
5113             * @param end the upper bound of the range of message-boards messages (not inclusive)
5114             * @return the range of matching message-boards messages
5115             */
5116            @Override
5117            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5118                    int end) {
5119                    return findByG_C(groupId, categoryId, start, end, null);
5120            }
5121    
5122            /**
5123             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5124             *
5125             * <p>
5126             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5127             * </p>
5128             *
5129             * @param groupId the group ID
5130             * @param categoryId the category ID
5131             * @param start the lower bound of the range of message-boards messages
5132             * @param end the upper bound of the range of message-boards messages (not inclusive)
5133             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5134             * @return the ordered range of matching message-boards messages
5135             */
5136            @Override
5137            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5138                    int end, OrderByComparator<MBMessage> orderByComparator) {
5139                    boolean pagination = true;
5140                    FinderPath finderPath = null;
5141                    Object[] finderArgs = null;
5142    
5143                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5144                                    (orderByComparator == null)) {
5145                            pagination = false;
5146                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5147                            finderArgs = new Object[] { groupId, categoryId };
5148                    }
5149                    else {
5150                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5151                            finderArgs = new Object[] {
5152                                            groupId, categoryId,
5153                                            
5154                                            start, end, orderByComparator
5155                                    };
5156                    }
5157    
5158                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5159                                    finderArgs, this);
5160    
5161                    if ((list != null) && !list.isEmpty()) {
5162                            for (MBMessage mbMessage : list) {
5163                                    if ((groupId != mbMessage.getGroupId()) ||
5164                                                    (categoryId != mbMessage.getCategoryId())) {
5165                                            list = null;
5166    
5167                                            break;
5168                                    }
5169                            }
5170                    }
5171    
5172                    if (list == null) {
5173                            StringBundler query = null;
5174    
5175                            if (orderByComparator != null) {
5176                                    query = new StringBundler(4 +
5177                                                    (orderByComparator.getOrderByFields().length * 3));
5178                            }
5179                            else {
5180                                    query = new StringBundler(4);
5181                            }
5182    
5183                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5184    
5185                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5186    
5187                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5188    
5189                            if (orderByComparator != null) {
5190                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5191                                            orderByComparator);
5192                            }
5193                            else
5194                             if (pagination) {
5195                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5196                            }
5197    
5198                            String sql = query.toString();
5199    
5200                            Session session = null;
5201    
5202                            try {
5203                                    session = openSession();
5204    
5205                                    Query q = session.createQuery(sql);
5206    
5207                                    QueryPos qPos = QueryPos.getInstance(q);
5208    
5209                                    qPos.add(groupId);
5210    
5211                                    qPos.add(categoryId);
5212    
5213                                    if (!pagination) {
5214                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5215                                                            start, end, false);
5216    
5217                                            Collections.sort(list);
5218    
5219                                            list = Collections.unmodifiableList(list);
5220                                    }
5221                                    else {
5222                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5223                                                            start, end);
5224                                    }
5225    
5226                                    cacheResult(list);
5227    
5228                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5229                            }
5230                            catch (Exception e) {
5231                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5232    
5233                                    throw processException(e);
5234                            }
5235                            finally {
5236                                    closeSession(session);
5237                            }
5238                    }
5239    
5240                    return list;
5241            }
5242    
5243            /**
5244             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5245             *
5246             * @param groupId the group ID
5247             * @param categoryId the category ID
5248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5249             * @return the first matching message-boards message
5250             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5251             */
5252            @Override
5253            public MBMessage findByG_C_First(long groupId, long categoryId,
5254                    OrderByComparator<MBMessage> orderByComparator)
5255                    throws NoSuchMessageException {
5256                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5257                                    orderByComparator);
5258    
5259                    if (mbMessage != null) {
5260                            return mbMessage;
5261                    }
5262    
5263                    StringBundler msg = new StringBundler(6);
5264    
5265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5266    
5267                    msg.append("groupId=");
5268                    msg.append(groupId);
5269    
5270                    msg.append(", categoryId=");
5271                    msg.append(categoryId);
5272    
5273                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5274    
5275                    throw new NoSuchMessageException(msg.toString());
5276            }
5277    
5278            /**
5279             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5280             *
5281             * @param groupId the group ID
5282             * @param categoryId the category ID
5283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5284             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5285             */
5286            @Override
5287            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5288                    OrderByComparator<MBMessage> orderByComparator) {
5289                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5290                                    orderByComparator);
5291    
5292                    if (!list.isEmpty()) {
5293                            return list.get(0);
5294                    }
5295    
5296                    return null;
5297            }
5298    
5299            /**
5300             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5301             *
5302             * @param groupId the group ID
5303             * @param categoryId the category ID
5304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5305             * @return the last matching message-boards message
5306             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5307             */
5308            @Override
5309            public MBMessage findByG_C_Last(long groupId, long categoryId,
5310                    OrderByComparator<MBMessage> orderByComparator)
5311                    throws NoSuchMessageException {
5312                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5313                                    orderByComparator);
5314    
5315                    if (mbMessage != null) {
5316                            return mbMessage;
5317                    }
5318    
5319                    StringBundler msg = new StringBundler(6);
5320    
5321                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5322    
5323                    msg.append("groupId=");
5324                    msg.append(groupId);
5325    
5326                    msg.append(", categoryId=");
5327                    msg.append(categoryId);
5328    
5329                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5330    
5331                    throw new NoSuchMessageException(msg.toString());
5332            }
5333    
5334            /**
5335             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5336             *
5337             * @param groupId the group ID
5338             * @param categoryId the category ID
5339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5340             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5341             */
5342            @Override
5343            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5344                    OrderByComparator<MBMessage> orderByComparator) {
5345                    int count = countByG_C(groupId, categoryId);
5346    
5347                    if (count == 0) {
5348                            return null;
5349                    }
5350    
5351                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5352                                    orderByComparator);
5353    
5354                    if (!list.isEmpty()) {
5355                            return list.get(0);
5356                    }
5357    
5358                    return null;
5359            }
5360    
5361            /**
5362             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5363             *
5364             * @param messageId the primary key of the current message-boards message
5365             * @param groupId the group ID
5366             * @param categoryId the category ID
5367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5368             * @return the previous, current, and next message-boards message
5369             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5370             */
5371            @Override
5372            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5373                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5374                    throws NoSuchMessageException {
5375                    MBMessage mbMessage = findByPrimaryKey(messageId);
5376    
5377                    Session session = null;
5378    
5379                    try {
5380                            session = openSession();
5381    
5382                            MBMessage[] array = new MBMessageImpl[3];
5383    
5384                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5385                                            categoryId, orderByComparator, true);
5386    
5387                            array[1] = mbMessage;
5388    
5389                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5390                                            categoryId, orderByComparator, false);
5391    
5392                            return array;
5393                    }
5394                    catch (Exception e) {
5395                            throw processException(e);
5396                    }
5397                    finally {
5398                            closeSession(session);
5399                    }
5400            }
5401    
5402            protected MBMessage getByG_C_PrevAndNext(Session session,
5403                    MBMessage mbMessage, long groupId, long categoryId,
5404                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5405                    StringBundler query = null;
5406    
5407                    if (orderByComparator != null) {
5408                            query = new StringBundler(6 +
5409                                            (orderByComparator.getOrderByFields().length * 6));
5410                    }
5411                    else {
5412                            query = new StringBundler(3);
5413                    }
5414    
5415                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5416    
5417                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5418    
5419                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5420    
5421                    if (orderByComparator != null) {
5422                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5423    
5424                            if (orderByConditionFields.length > 0) {
5425                                    query.append(WHERE_AND);
5426                            }
5427    
5428                            for (int i = 0; i < orderByConditionFields.length; i++) {
5429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5430                                    query.append(orderByConditionFields[i]);
5431    
5432                                    if ((i + 1) < orderByConditionFields.length) {
5433                                            if (orderByComparator.isAscending() ^ previous) {
5434                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5435                                            }
5436                                            else {
5437                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5438                                            }
5439                                    }
5440                                    else {
5441                                            if (orderByComparator.isAscending() ^ previous) {
5442                                                    query.append(WHERE_GREATER_THAN);
5443                                            }
5444                                            else {
5445                                                    query.append(WHERE_LESSER_THAN);
5446                                            }
5447                                    }
5448                            }
5449    
5450                            query.append(ORDER_BY_CLAUSE);
5451    
5452                            String[] orderByFields = orderByComparator.getOrderByFields();
5453    
5454                            for (int i = 0; i < orderByFields.length; i++) {
5455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5456                                    query.append(orderByFields[i]);
5457    
5458                                    if ((i + 1) < orderByFields.length) {
5459                                            if (orderByComparator.isAscending() ^ previous) {
5460                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5461                                            }
5462                                            else {
5463                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5464                                            }
5465                                    }
5466                                    else {
5467                                            if (orderByComparator.isAscending() ^ previous) {
5468                                                    query.append(ORDER_BY_ASC);
5469                                            }
5470                                            else {
5471                                                    query.append(ORDER_BY_DESC);
5472                                            }
5473                                    }
5474                            }
5475                    }
5476                    else {
5477                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5478                    }
5479    
5480                    String sql = query.toString();
5481    
5482                    Query q = session.createQuery(sql);
5483    
5484                    q.setFirstResult(0);
5485                    q.setMaxResults(2);
5486    
5487                    QueryPos qPos = QueryPos.getInstance(q);
5488    
5489                    qPos.add(groupId);
5490    
5491                    qPos.add(categoryId);
5492    
5493                    if (orderByComparator != null) {
5494                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5495    
5496                            for (Object value : values) {
5497                                    qPos.add(value);
5498                            }
5499                    }
5500    
5501                    List<MBMessage> list = q.list();
5502    
5503                    if (list.size() == 2) {
5504                            return list.get(1);
5505                    }
5506                    else {
5507                            return null;
5508                    }
5509            }
5510    
5511            /**
5512             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5513             *
5514             * @param groupId the group ID
5515             * @param categoryId the category ID
5516             * @return the matching message-boards messages that the user has permission to view
5517             */
5518            @Override
5519            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5520                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5521                            QueryUtil.ALL_POS, null);
5522            }
5523    
5524            /**
5525             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5526             *
5527             * <p>
5528             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5529             * </p>
5530             *
5531             * @param groupId the group ID
5532             * @param categoryId the category ID
5533             * @param start the lower bound of the range of message-boards messages
5534             * @param end the upper bound of the range of message-boards messages (not inclusive)
5535             * @return the range of matching message-boards messages that the user has permission to view
5536             */
5537            @Override
5538            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5539                    int start, int end) {
5540                    return filterFindByG_C(groupId, categoryId, start, end, null);
5541            }
5542    
5543            /**
5544             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5545             *
5546             * <p>
5547             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5548             * </p>
5549             *
5550             * @param groupId the group ID
5551             * @param categoryId the category ID
5552             * @param start the lower bound of the range of message-boards messages
5553             * @param end the upper bound of the range of message-boards messages (not inclusive)
5554             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5555             * @return the ordered range of matching message-boards messages that the user has permission to view
5556             */
5557            @Override
5558            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5559                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5560                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5561                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5562                    }
5563    
5564                    StringBundler query = null;
5565    
5566                    if (orderByComparator != null) {
5567                            query = new StringBundler(4 +
5568                                            (orderByComparator.getOrderByFields().length * 3));
5569                    }
5570                    else {
5571                            query = new StringBundler(4);
5572                    }
5573    
5574                    if (getDB().isSupportsInlineDistinct()) {
5575                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5576                    }
5577                    else {
5578                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5579                    }
5580    
5581                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5582    
5583                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5584    
5585                    if (!getDB().isSupportsInlineDistinct()) {
5586                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5587                    }
5588    
5589                    if (orderByComparator != null) {
5590                            if (getDB().isSupportsInlineDistinct()) {
5591                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5592                                            orderByComparator, true);
5593                            }
5594                            else {
5595                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5596                                            orderByComparator, true);
5597                            }
5598                    }
5599                    else {
5600                            if (getDB().isSupportsInlineDistinct()) {
5601                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5602                            }
5603                            else {
5604                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5605                            }
5606                    }
5607    
5608                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5609                                    MBMessage.class.getName(),
5610                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5611    
5612                    Session session = null;
5613    
5614                    try {
5615                            session = openSession();
5616    
5617                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5618    
5619                            if (getDB().isSupportsInlineDistinct()) {
5620                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5621                            }
5622                            else {
5623                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5624                            }
5625    
5626                            QueryPos qPos = QueryPos.getInstance(q);
5627    
5628                            qPos.add(groupId);
5629    
5630                            qPos.add(categoryId);
5631    
5632                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5633                    }
5634                    catch (Exception e) {
5635                            throw processException(e);
5636                    }
5637                    finally {
5638                            closeSession(session);
5639                    }
5640            }
5641    
5642            /**
5643             * 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;.
5644             *
5645             * @param messageId the primary key of the current message-boards message
5646             * @param groupId the group ID
5647             * @param categoryId the category ID
5648             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5649             * @return the previous, current, and next message-boards message
5650             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5651             */
5652            @Override
5653            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5654                    long groupId, long categoryId,
5655                    OrderByComparator<MBMessage> orderByComparator)
5656                    throws NoSuchMessageException {
5657                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5658                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5659                                    orderByComparator);
5660                    }
5661    
5662                    MBMessage mbMessage = findByPrimaryKey(messageId);
5663    
5664                    Session session = null;
5665    
5666                    try {
5667                            session = openSession();
5668    
5669                            MBMessage[] array = new MBMessageImpl[3];
5670    
5671                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5672                                            categoryId, orderByComparator, true);
5673    
5674                            array[1] = mbMessage;
5675    
5676                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5677                                            categoryId, orderByComparator, false);
5678    
5679                            return array;
5680                    }
5681                    catch (Exception e) {
5682                            throw processException(e);
5683                    }
5684                    finally {
5685                            closeSession(session);
5686                    }
5687            }
5688    
5689            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5690                    MBMessage mbMessage, long groupId, long categoryId,
5691                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5692                    StringBundler query = null;
5693    
5694                    if (orderByComparator != null) {
5695                            query = new StringBundler(6 +
5696                                            (orderByComparator.getOrderByFields().length * 6));
5697                    }
5698                    else {
5699                            query = new StringBundler(3);
5700                    }
5701    
5702                    if (getDB().isSupportsInlineDistinct()) {
5703                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5704                    }
5705                    else {
5706                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5707                    }
5708    
5709                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5710    
5711                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5712    
5713                    if (!getDB().isSupportsInlineDistinct()) {
5714                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5715                    }
5716    
5717                    if (orderByComparator != null) {
5718                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5719    
5720                            if (orderByConditionFields.length > 0) {
5721                                    query.append(WHERE_AND);
5722                            }
5723    
5724                            for (int i = 0; i < orderByConditionFields.length; i++) {
5725                                    if (getDB().isSupportsInlineDistinct()) {
5726                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5727                                    }
5728                                    else {
5729                                            query.append(_ORDER_BY_ENTITY_TABLE);
5730                                    }
5731    
5732                                    query.append(orderByConditionFields[i]);
5733    
5734                                    if ((i + 1) < orderByConditionFields.length) {
5735                                            if (orderByComparator.isAscending() ^ previous) {
5736                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5737                                            }
5738                                            else {
5739                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5740                                            }
5741                                    }
5742                                    else {
5743                                            if (orderByComparator.isAscending() ^ previous) {
5744                                                    query.append(WHERE_GREATER_THAN);
5745                                            }
5746                                            else {
5747                                                    query.append(WHERE_LESSER_THAN);
5748                                            }
5749                                    }
5750                            }
5751    
5752                            query.append(ORDER_BY_CLAUSE);
5753    
5754                            String[] orderByFields = orderByComparator.getOrderByFields();
5755    
5756                            for (int i = 0; i < orderByFields.length; i++) {
5757                                    if (getDB().isSupportsInlineDistinct()) {
5758                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5759                                    }
5760                                    else {
5761                                            query.append(_ORDER_BY_ENTITY_TABLE);
5762                                    }
5763    
5764                                    query.append(orderByFields[i]);
5765    
5766                                    if ((i + 1) < orderByFields.length) {
5767                                            if (orderByComparator.isAscending() ^ previous) {
5768                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5769                                            }
5770                                            else {
5771                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5772                                            }
5773                                    }
5774                                    else {
5775                                            if (orderByComparator.isAscending() ^ previous) {
5776                                                    query.append(ORDER_BY_ASC);
5777                                            }
5778                                            else {
5779                                                    query.append(ORDER_BY_DESC);
5780                                            }
5781                                    }
5782                            }
5783                    }
5784                    else {
5785                            if (getDB().isSupportsInlineDistinct()) {
5786                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5787                            }
5788                            else {
5789                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5790                            }
5791                    }
5792    
5793                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5794                                    MBMessage.class.getName(),
5795                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5796    
5797                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5798    
5799                    q.setFirstResult(0);
5800                    q.setMaxResults(2);
5801    
5802                    if (getDB().isSupportsInlineDistinct()) {
5803                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5804                    }
5805                    else {
5806                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5807                    }
5808    
5809                    QueryPos qPos = QueryPos.getInstance(q);
5810    
5811                    qPos.add(groupId);
5812    
5813                    qPos.add(categoryId);
5814    
5815                    if (orderByComparator != null) {
5816                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5817    
5818                            for (Object value : values) {
5819                                    qPos.add(value);
5820                            }
5821                    }
5822    
5823                    List<MBMessage> list = q.list();
5824    
5825                    if (list.size() == 2) {
5826                            return list.get(1);
5827                    }
5828                    else {
5829                            return null;
5830                    }
5831            }
5832    
5833            /**
5834             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
5835             *
5836             * @param groupId the group ID
5837             * @param categoryId the category ID
5838             */
5839            @Override
5840            public void removeByG_C(long groupId, long categoryId) {
5841                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5842                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5843                            remove(mbMessage);
5844                    }
5845            }
5846    
5847            /**
5848             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
5849             *
5850             * @param groupId the group ID
5851             * @param categoryId the category ID
5852             * @return the number of matching message-boards messages
5853             */
5854            @Override
5855            public int countByG_C(long groupId, long categoryId) {
5856                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5857    
5858                    Object[] finderArgs = new Object[] { groupId, categoryId };
5859    
5860                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5861                                    this);
5862    
5863                    if (count == null) {
5864                            StringBundler query = new StringBundler(3);
5865    
5866                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5867    
5868                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5869    
5870                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5871    
5872                            String sql = query.toString();
5873    
5874                            Session session = null;
5875    
5876                            try {
5877                                    session = openSession();
5878    
5879                                    Query q = session.createQuery(sql);
5880    
5881                                    QueryPos qPos = QueryPos.getInstance(q);
5882    
5883                                    qPos.add(groupId);
5884    
5885                                    qPos.add(categoryId);
5886    
5887                                    count = (Long)q.uniqueResult();
5888    
5889                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5890                            }
5891                            catch (Exception e) {
5892                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5893    
5894                                    throw processException(e);
5895                            }
5896                            finally {
5897                                    closeSession(session);
5898                            }
5899                    }
5900    
5901                    return count.intValue();
5902            }
5903    
5904            /**
5905             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5906             *
5907             * @param groupId the group ID
5908             * @param categoryId the category ID
5909             * @return the number of matching message-boards messages that the user has permission to view
5910             */
5911            @Override
5912            public int filterCountByG_C(long groupId, long categoryId) {
5913                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5914                            return countByG_C(groupId, categoryId);
5915                    }
5916    
5917                    StringBundler query = new StringBundler(3);
5918    
5919                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5920    
5921                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5922    
5923                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5924    
5925                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5926                                    MBMessage.class.getName(),
5927                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5928    
5929                    Session session = null;
5930    
5931                    try {
5932                            session = openSession();
5933    
5934                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5935    
5936                            q.addScalar(COUNT_COLUMN_NAME,
5937                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5938    
5939                            QueryPos qPos = QueryPos.getInstance(q);
5940    
5941                            qPos.add(groupId);
5942    
5943                            qPos.add(categoryId);
5944    
5945                            Long count = (Long)q.uniqueResult();
5946    
5947                            return count.intValue();
5948                    }
5949                    catch (Exception e) {
5950                            throw processException(e);
5951                    }
5952                    finally {
5953                            closeSession(session);
5954                    }
5955            }
5956    
5957            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
5958            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
5959            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5960                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5961                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
5962                            new String[] {
5963                                    Long.class.getName(), Integer.class.getName(),
5964                                    
5965                            Integer.class.getName(), Integer.class.getName(),
5966                                    OrderByComparator.class.getName()
5967                            });
5968            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5969                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5970                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
5971                            new String[] { Long.class.getName(), Integer.class.getName() },
5972                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5973                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
5974                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5975            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5976                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5977                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
5978                            new String[] { Long.class.getName(), Integer.class.getName() });
5979    
5980            /**
5981             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5982             *
5983             * @param groupId the group ID
5984             * @param status the status
5985             * @return the matching message-boards messages
5986             */
5987            @Override
5988            public List<MBMessage> findByG_S(long groupId, int status) {
5989                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5990                            null);
5991            }
5992    
5993            /**
5994             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5995             *
5996             * <p>
5997             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5998             * </p>
5999             *
6000             * @param groupId the group ID
6001             * @param status the status
6002             * @param start the lower bound of the range of message-boards messages
6003             * @param end the upper bound of the range of message-boards messages (not inclusive)
6004             * @return the range of matching message-boards messages
6005             */
6006            @Override
6007            public List<MBMessage> findByG_S(long groupId, int status, int start,
6008                    int end) {
6009                    return findByG_S(groupId, status, start, end, null);
6010            }
6011    
6012            /**
6013             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6014             *
6015             * <p>
6016             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6017             * </p>
6018             *
6019             * @param groupId the group ID
6020             * @param status the status
6021             * @param start the lower bound of the range of message-boards messages
6022             * @param end the upper bound of the range of message-boards messages (not inclusive)
6023             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6024             * @return the ordered range of matching message-boards messages
6025             */
6026            @Override
6027            public List<MBMessage> findByG_S(long groupId, int status, int start,
6028                    int end, OrderByComparator<MBMessage> orderByComparator) {
6029                    boolean pagination = true;
6030                    FinderPath finderPath = null;
6031                    Object[] finderArgs = null;
6032    
6033                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6034                                    (orderByComparator == null)) {
6035                            pagination = false;
6036                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6037                            finderArgs = new Object[] { groupId, status };
6038                    }
6039                    else {
6040                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6041                            finderArgs = new Object[] {
6042                                            groupId, status,
6043                                            
6044                                            start, end, orderByComparator
6045                                    };
6046                    }
6047    
6048                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6049                                    finderArgs, this);
6050    
6051                    if ((list != null) && !list.isEmpty()) {
6052                            for (MBMessage mbMessage : list) {
6053                                    if ((groupId != mbMessage.getGroupId()) ||
6054                                                    (status != mbMessage.getStatus())) {
6055                                            list = null;
6056    
6057                                            break;
6058                                    }
6059                            }
6060                    }
6061    
6062                    if (list == null) {
6063                            StringBundler query = null;
6064    
6065                            if (orderByComparator != null) {
6066                                    query = new StringBundler(4 +
6067                                                    (orderByComparator.getOrderByFields().length * 3));
6068                            }
6069                            else {
6070                                    query = new StringBundler(4);
6071                            }
6072    
6073                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6074    
6075                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6076    
6077                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6078    
6079                            if (orderByComparator != null) {
6080                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6081                                            orderByComparator);
6082                            }
6083                            else
6084                             if (pagination) {
6085                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6086                            }
6087    
6088                            String sql = query.toString();
6089    
6090                            Session session = null;
6091    
6092                            try {
6093                                    session = openSession();
6094    
6095                                    Query q = session.createQuery(sql);
6096    
6097                                    QueryPos qPos = QueryPos.getInstance(q);
6098    
6099                                    qPos.add(groupId);
6100    
6101                                    qPos.add(status);
6102    
6103                                    if (!pagination) {
6104                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6105                                                            start, end, false);
6106    
6107                                            Collections.sort(list);
6108    
6109                                            list = Collections.unmodifiableList(list);
6110                                    }
6111                                    else {
6112                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6113                                                            start, end);
6114                                    }
6115    
6116                                    cacheResult(list);
6117    
6118                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6119                            }
6120                            catch (Exception e) {
6121                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6122    
6123                                    throw processException(e);
6124                            }
6125                            finally {
6126                                    closeSession(session);
6127                            }
6128                    }
6129    
6130                    return list;
6131            }
6132    
6133            /**
6134             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6135             *
6136             * @param groupId the group ID
6137             * @param status the status
6138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6139             * @return the first matching message-boards message
6140             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6141             */
6142            @Override
6143            public MBMessage findByG_S_First(long groupId, int status,
6144                    OrderByComparator<MBMessage> orderByComparator)
6145                    throws NoSuchMessageException {
6146                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6147                                    orderByComparator);
6148    
6149                    if (mbMessage != null) {
6150                            return mbMessage;
6151                    }
6152    
6153                    StringBundler msg = new StringBundler(6);
6154    
6155                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6156    
6157                    msg.append("groupId=");
6158                    msg.append(groupId);
6159    
6160                    msg.append(", status=");
6161                    msg.append(status);
6162    
6163                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6164    
6165                    throw new NoSuchMessageException(msg.toString());
6166            }
6167    
6168            /**
6169             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6170             *
6171             * @param groupId the group ID
6172             * @param status the status
6173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6174             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6175             */
6176            @Override
6177            public MBMessage fetchByG_S_First(long groupId, int status,
6178                    OrderByComparator<MBMessage> orderByComparator) {
6179                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6180                                    orderByComparator);
6181    
6182                    if (!list.isEmpty()) {
6183                            return list.get(0);
6184                    }
6185    
6186                    return null;
6187            }
6188    
6189            /**
6190             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6191             *
6192             * @param groupId the group ID
6193             * @param status the status
6194             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6195             * @return the last matching message-boards message
6196             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6197             */
6198            @Override
6199            public MBMessage findByG_S_Last(long groupId, int status,
6200                    OrderByComparator<MBMessage> orderByComparator)
6201                    throws NoSuchMessageException {
6202                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6203    
6204                    if (mbMessage != null) {
6205                            return mbMessage;
6206                    }
6207    
6208                    StringBundler msg = new StringBundler(6);
6209    
6210                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6211    
6212                    msg.append("groupId=");
6213                    msg.append(groupId);
6214    
6215                    msg.append(", status=");
6216                    msg.append(status);
6217    
6218                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6219    
6220                    throw new NoSuchMessageException(msg.toString());
6221            }
6222    
6223            /**
6224             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6225             *
6226             * @param groupId the group ID
6227             * @param status the status
6228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6229             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6230             */
6231            @Override
6232            public MBMessage fetchByG_S_Last(long groupId, int status,
6233                    OrderByComparator<MBMessage> orderByComparator) {
6234                    int count = countByG_S(groupId, status);
6235    
6236                    if (count == 0) {
6237                            return null;
6238                    }
6239    
6240                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6241                                    orderByComparator);
6242    
6243                    if (!list.isEmpty()) {
6244                            return list.get(0);
6245                    }
6246    
6247                    return null;
6248            }
6249    
6250            /**
6251             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6252             *
6253             * @param messageId the primary key of the current message-boards message
6254             * @param groupId the group ID
6255             * @param status the status
6256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6257             * @return the previous, current, and next message-boards message
6258             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6259             */
6260            @Override
6261            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6262                    int status, OrderByComparator<MBMessage> orderByComparator)
6263                    throws NoSuchMessageException {
6264                    MBMessage mbMessage = findByPrimaryKey(messageId);
6265    
6266                    Session session = null;
6267    
6268                    try {
6269                            session = openSession();
6270    
6271                            MBMessage[] array = new MBMessageImpl[3];
6272    
6273                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6274                                            status, orderByComparator, true);
6275    
6276                            array[1] = mbMessage;
6277    
6278                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6279                                            status, orderByComparator, false);
6280    
6281                            return array;
6282                    }
6283                    catch (Exception e) {
6284                            throw processException(e);
6285                    }
6286                    finally {
6287                            closeSession(session);
6288                    }
6289            }
6290    
6291            protected MBMessage getByG_S_PrevAndNext(Session session,
6292                    MBMessage mbMessage, long groupId, int status,
6293                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6294                    StringBundler query = null;
6295    
6296                    if (orderByComparator != null) {
6297                            query = new StringBundler(6 +
6298                                            (orderByComparator.getOrderByFields().length * 6));
6299                    }
6300                    else {
6301                            query = new StringBundler(3);
6302                    }
6303    
6304                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6305    
6306                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6307    
6308                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6309    
6310                    if (orderByComparator != null) {
6311                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6312    
6313                            if (orderByConditionFields.length > 0) {
6314                                    query.append(WHERE_AND);
6315                            }
6316    
6317                            for (int i = 0; i < orderByConditionFields.length; i++) {
6318                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6319                                    query.append(orderByConditionFields[i]);
6320    
6321                                    if ((i + 1) < orderByConditionFields.length) {
6322                                            if (orderByComparator.isAscending() ^ previous) {
6323                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6324                                            }
6325                                            else {
6326                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6327                                            }
6328                                    }
6329                                    else {
6330                                            if (orderByComparator.isAscending() ^ previous) {
6331                                                    query.append(WHERE_GREATER_THAN);
6332                                            }
6333                                            else {
6334                                                    query.append(WHERE_LESSER_THAN);
6335                                            }
6336                                    }
6337                            }
6338    
6339                            query.append(ORDER_BY_CLAUSE);
6340    
6341                            String[] orderByFields = orderByComparator.getOrderByFields();
6342    
6343                            for (int i = 0; i < orderByFields.length; i++) {
6344                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6345                                    query.append(orderByFields[i]);
6346    
6347                                    if ((i + 1) < orderByFields.length) {
6348                                            if (orderByComparator.isAscending() ^ previous) {
6349                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6350                                            }
6351                                            else {
6352                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6353                                            }
6354                                    }
6355                                    else {
6356                                            if (orderByComparator.isAscending() ^ previous) {
6357                                                    query.append(ORDER_BY_ASC);
6358                                            }
6359                                            else {
6360                                                    query.append(ORDER_BY_DESC);
6361                                            }
6362                                    }
6363                            }
6364                    }
6365                    else {
6366                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6367                    }
6368    
6369                    String sql = query.toString();
6370    
6371                    Query q = session.createQuery(sql);
6372    
6373                    q.setFirstResult(0);
6374                    q.setMaxResults(2);
6375    
6376                    QueryPos qPos = QueryPos.getInstance(q);
6377    
6378                    qPos.add(groupId);
6379    
6380                    qPos.add(status);
6381    
6382                    if (orderByComparator != null) {
6383                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6384    
6385                            for (Object value : values) {
6386                                    qPos.add(value);
6387                            }
6388                    }
6389    
6390                    List<MBMessage> list = q.list();
6391    
6392                    if (list.size() == 2) {
6393                            return list.get(1);
6394                    }
6395                    else {
6396                            return null;
6397                    }
6398            }
6399    
6400            /**
6401             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6402             *
6403             * @param groupId the group ID
6404             * @param status the status
6405             * @return the matching message-boards messages that the user has permission to view
6406             */
6407            @Override
6408            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6409                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6410                            QueryUtil.ALL_POS, null);
6411            }
6412    
6413            /**
6414             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6415             *
6416             * <p>
6417             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6418             * </p>
6419             *
6420             * @param groupId the group ID
6421             * @param status the status
6422             * @param start the lower bound of the range of message-boards messages
6423             * @param end the upper bound of the range of message-boards messages (not inclusive)
6424             * @return the range of matching message-boards messages that the user has permission to view
6425             */
6426            @Override
6427            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6428                    int end) {
6429                    return filterFindByG_S(groupId, status, start, end, null);
6430            }
6431    
6432            /**
6433             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6434             *
6435             * <p>
6436             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6437             * </p>
6438             *
6439             * @param groupId the group ID
6440             * @param status the status
6441             * @param start the lower bound of the range of message-boards messages
6442             * @param end the upper bound of the range of message-boards messages (not inclusive)
6443             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6444             * @return the ordered range of matching message-boards messages that the user has permission to view
6445             */
6446            @Override
6447            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6448                    int end, OrderByComparator<MBMessage> orderByComparator) {
6449                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6450                            return findByG_S(groupId, status, start, end, orderByComparator);
6451                    }
6452    
6453                    StringBundler query = null;
6454    
6455                    if (orderByComparator != null) {
6456                            query = new StringBundler(4 +
6457                                            (orderByComparator.getOrderByFields().length * 3));
6458                    }
6459                    else {
6460                            query = new StringBundler(4);
6461                    }
6462    
6463                    if (getDB().isSupportsInlineDistinct()) {
6464                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6465                    }
6466                    else {
6467                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6468                    }
6469    
6470                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6471    
6472                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6473    
6474                    if (!getDB().isSupportsInlineDistinct()) {
6475                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6476                    }
6477    
6478                    if (orderByComparator != null) {
6479                            if (getDB().isSupportsInlineDistinct()) {
6480                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6481                                            orderByComparator, true);
6482                            }
6483                            else {
6484                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6485                                            orderByComparator, true);
6486                            }
6487                    }
6488                    else {
6489                            if (getDB().isSupportsInlineDistinct()) {
6490                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6491                            }
6492                            else {
6493                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6494                            }
6495                    }
6496    
6497                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6498                                    MBMessage.class.getName(),
6499                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6500    
6501                    Session session = null;
6502    
6503                    try {
6504                            session = openSession();
6505    
6506                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6507    
6508                            if (getDB().isSupportsInlineDistinct()) {
6509                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6510                            }
6511                            else {
6512                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6513                            }
6514    
6515                            QueryPos qPos = QueryPos.getInstance(q);
6516    
6517                            qPos.add(groupId);
6518    
6519                            qPos.add(status);
6520    
6521                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6522                    }
6523                    catch (Exception e) {
6524                            throw processException(e);
6525                    }
6526                    finally {
6527                            closeSession(session);
6528                    }
6529            }
6530    
6531            /**
6532             * 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;.
6533             *
6534             * @param messageId the primary key of the current message-boards message
6535             * @param groupId the group ID
6536             * @param status the status
6537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6538             * @return the previous, current, and next message-boards message
6539             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6540             */
6541            @Override
6542            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6543                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6544                    throws NoSuchMessageException {
6545                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6546                            return findByG_S_PrevAndNext(messageId, groupId, status,
6547                                    orderByComparator);
6548                    }
6549    
6550                    MBMessage mbMessage = findByPrimaryKey(messageId);
6551    
6552                    Session session = null;
6553    
6554                    try {
6555                            session = openSession();
6556    
6557                            MBMessage[] array = new MBMessageImpl[3];
6558    
6559                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6560                                            status, orderByComparator, true);
6561    
6562                            array[1] = mbMessage;
6563    
6564                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6565                                            status, orderByComparator, false);
6566    
6567                            return array;
6568                    }
6569                    catch (Exception e) {
6570                            throw processException(e);
6571                    }
6572                    finally {
6573                            closeSession(session);
6574                    }
6575            }
6576    
6577            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6578                    MBMessage mbMessage, long groupId, int status,
6579                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6580                    StringBundler query = null;
6581    
6582                    if (orderByComparator != null) {
6583                            query = new StringBundler(6 +
6584                                            (orderByComparator.getOrderByFields().length * 6));
6585                    }
6586                    else {
6587                            query = new StringBundler(3);
6588                    }
6589    
6590                    if (getDB().isSupportsInlineDistinct()) {
6591                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6592                    }
6593                    else {
6594                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6595                    }
6596    
6597                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6598    
6599                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6600    
6601                    if (!getDB().isSupportsInlineDistinct()) {
6602                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6603                    }
6604    
6605                    if (orderByComparator != null) {
6606                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6607    
6608                            if (orderByConditionFields.length > 0) {
6609                                    query.append(WHERE_AND);
6610                            }
6611    
6612                            for (int i = 0; i < orderByConditionFields.length; i++) {
6613                                    if (getDB().isSupportsInlineDistinct()) {
6614                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6615                                    }
6616                                    else {
6617                                            query.append(_ORDER_BY_ENTITY_TABLE);
6618                                    }
6619    
6620                                    query.append(orderByConditionFields[i]);
6621    
6622                                    if ((i + 1) < orderByConditionFields.length) {
6623                                            if (orderByComparator.isAscending() ^ previous) {
6624                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6625                                            }
6626                                            else {
6627                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6628                                            }
6629                                    }
6630                                    else {
6631                                            if (orderByComparator.isAscending() ^ previous) {
6632                                                    query.append(WHERE_GREATER_THAN);
6633                                            }
6634                                            else {
6635                                                    query.append(WHERE_LESSER_THAN);
6636                                            }
6637                                    }
6638                            }
6639    
6640                            query.append(ORDER_BY_CLAUSE);
6641    
6642                            String[] orderByFields = orderByComparator.getOrderByFields();
6643    
6644                            for (int i = 0; i < orderByFields.length; i++) {
6645                                    if (getDB().isSupportsInlineDistinct()) {
6646                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6647                                    }
6648                                    else {
6649                                            query.append(_ORDER_BY_ENTITY_TABLE);
6650                                    }
6651    
6652                                    query.append(orderByFields[i]);
6653    
6654                                    if ((i + 1) < orderByFields.length) {
6655                                            if (orderByComparator.isAscending() ^ previous) {
6656                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6657                                            }
6658                                            else {
6659                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6660                                            }
6661                                    }
6662                                    else {
6663                                            if (orderByComparator.isAscending() ^ previous) {
6664                                                    query.append(ORDER_BY_ASC);
6665                                            }
6666                                            else {
6667                                                    query.append(ORDER_BY_DESC);
6668                                            }
6669                                    }
6670                            }
6671                    }
6672                    else {
6673                            if (getDB().isSupportsInlineDistinct()) {
6674                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6675                            }
6676                            else {
6677                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6678                            }
6679                    }
6680    
6681                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6682                                    MBMessage.class.getName(),
6683                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6684    
6685                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6686    
6687                    q.setFirstResult(0);
6688                    q.setMaxResults(2);
6689    
6690                    if (getDB().isSupportsInlineDistinct()) {
6691                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6692                    }
6693                    else {
6694                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6695                    }
6696    
6697                    QueryPos qPos = QueryPos.getInstance(q);
6698    
6699                    qPos.add(groupId);
6700    
6701                    qPos.add(status);
6702    
6703                    if (orderByComparator != null) {
6704                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6705    
6706                            for (Object value : values) {
6707                                    qPos.add(value);
6708                            }
6709                    }
6710    
6711                    List<MBMessage> list = q.list();
6712    
6713                    if (list.size() == 2) {
6714                            return list.get(1);
6715                    }
6716                    else {
6717                            return null;
6718                    }
6719            }
6720    
6721            /**
6722             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6723             *
6724             * @param groupId the group ID
6725             * @param status the status
6726             */
6727            @Override
6728            public void removeByG_S(long groupId, int status) {
6729                    for (MBMessage mbMessage : findByG_S(groupId, status,
6730                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6731                            remove(mbMessage);
6732                    }
6733            }
6734    
6735            /**
6736             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6737             *
6738             * @param groupId the group ID
6739             * @param status the status
6740             * @return the number of matching message-boards messages
6741             */
6742            @Override
6743            public int countByG_S(long groupId, int status) {
6744                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6745    
6746                    Object[] finderArgs = new Object[] { groupId, status };
6747    
6748                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6749                                    this);
6750    
6751                    if (count == null) {
6752                            StringBundler query = new StringBundler(3);
6753    
6754                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6755    
6756                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6757    
6758                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6759    
6760                            String sql = query.toString();
6761    
6762                            Session session = null;
6763    
6764                            try {
6765                                    session = openSession();
6766    
6767                                    Query q = session.createQuery(sql);
6768    
6769                                    QueryPos qPos = QueryPos.getInstance(q);
6770    
6771                                    qPos.add(groupId);
6772    
6773                                    qPos.add(status);
6774    
6775                                    count = (Long)q.uniqueResult();
6776    
6777                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6778                            }
6779                            catch (Exception e) {
6780                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6781    
6782                                    throw processException(e);
6783                            }
6784                            finally {
6785                                    closeSession(session);
6786                            }
6787                    }
6788    
6789                    return count.intValue();
6790            }
6791    
6792            /**
6793             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6794             *
6795             * @param groupId the group ID
6796             * @param status the status
6797             * @return the number of matching message-boards messages that the user has permission to view
6798             */
6799            @Override
6800            public int filterCountByG_S(long groupId, int status) {
6801                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6802                            return countByG_S(groupId, status);
6803                    }
6804    
6805                    StringBundler query = new StringBundler(3);
6806    
6807                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6808    
6809                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6810    
6811                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6812    
6813                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6814                                    MBMessage.class.getName(),
6815                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6816    
6817                    Session session = null;
6818    
6819                    try {
6820                            session = openSession();
6821    
6822                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6823    
6824                            q.addScalar(COUNT_COLUMN_NAME,
6825                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6826    
6827                            QueryPos qPos = QueryPos.getInstance(q);
6828    
6829                            qPos.add(groupId);
6830    
6831                            qPos.add(status);
6832    
6833                            Long count = (Long)q.uniqueResult();
6834    
6835                            return count.intValue();
6836                    }
6837                    catch (Exception e) {
6838                            throw processException(e);
6839                    }
6840                    finally {
6841                            closeSession(session);
6842                    }
6843            }
6844    
6845            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6846            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6847            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6848                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6849                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
6850                            new String[] {
6851                                    Long.class.getName(), Integer.class.getName(),
6852                                    
6853                            Integer.class.getName(), Integer.class.getName(),
6854                                    OrderByComparator.class.getName()
6855                            });
6856            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6857                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6858                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
6859                            new String[] { Long.class.getName(), Integer.class.getName() },
6860                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
6861                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6862                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6863            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6864                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6865                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
6866                            new String[] { Long.class.getName(), Integer.class.getName() });
6867    
6868            /**
6869             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6870             *
6871             * @param companyId the company ID
6872             * @param status the status
6873             * @return the matching message-boards messages
6874             */
6875            @Override
6876            public List<MBMessage> findByC_S(long companyId, int status) {
6877                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6878                            QueryUtil.ALL_POS, null);
6879            }
6880    
6881            /**
6882             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6883             *
6884             * <p>
6885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6886             * </p>
6887             *
6888             * @param companyId the company ID
6889             * @param status the status
6890             * @param start the lower bound of the range of message-boards messages
6891             * @param end the upper bound of the range of message-boards messages (not inclusive)
6892             * @return the range of matching message-boards messages
6893             */
6894            @Override
6895            public List<MBMessage> findByC_S(long companyId, int status, int start,
6896                    int end) {
6897                    return findByC_S(companyId, status, start, end, null);
6898            }
6899    
6900            /**
6901             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6902             *
6903             * <p>
6904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6905             * </p>
6906             *
6907             * @param companyId the company ID
6908             * @param status the status
6909             * @param start the lower bound of the range of message-boards messages
6910             * @param end the upper bound of the range of message-boards messages (not inclusive)
6911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6912             * @return the ordered range of matching message-boards messages
6913             */
6914            @Override
6915            public List<MBMessage> findByC_S(long companyId, int status, int start,
6916                    int end, OrderByComparator<MBMessage> orderByComparator) {
6917                    boolean pagination = true;
6918                    FinderPath finderPath = null;
6919                    Object[] finderArgs = null;
6920    
6921                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6922                                    (orderByComparator == null)) {
6923                            pagination = false;
6924                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6925                            finderArgs = new Object[] { companyId, status };
6926                    }
6927                    else {
6928                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6929                            finderArgs = new Object[] {
6930                                            companyId, status,
6931                                            
6932                                            start, end, orderByComparator
6933                                    };
6934                    }
6935    
6936                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6937                                    finderArgs, this);
6938    
6939                    if ((list != null) && !list.isEmpty()) {
6940                            for (MBMessage mbMessage : list) {
6941                                    if ((companyId != mbMessage.getCompanyId()) ||
6942                                                    (status != mbMessage.getStatus())) {
6943                                            list = null;
6944    
6945                                            break;
6946                                    }
6947                            }
6948                    }
6949    
6950                    if (list == null) {
6951                            StringBundler query = null;
6952    
6953                            if (orderByComparator != null) {
6954                                    query = new StringBundler(4 +
6955                                                    (orderByComparator.getOrderByFields().length * 3));
6956                            }
6957                            else {
6958                                    query = new StringBundler(4);
6959                            }
6960    
6961                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6962    
6963                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6964    
6965                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6966    
6967                            if (orderByComparator != null) {
6968                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6969                                            orderByComparator);
6970                            }
6971                            else
6972                             if (pagination) {
6973                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6974                            }
6975    
6976                            String sql = query.toString();
6977    
6978                            Session session = null;
6979    
6980                            try {
6981                                    session = openSession();
6982    
6983                                    Query q = session.createQuery(sql);
6984    
6985                                    QueryPos qPos = QueryPos.getInstance(q);
6986    
6987                                    qPos.add(companyId);
6988    
6989                                    qPos.add(status);
6990    
6991                                    if (!pagination) {
6992                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6993                                                            start, end, false);
6994    
6995                                            Collections.sort(list);
6996    
6997                                            list = Collections.unmodifiableList(list);
6998                                    }
6999                                    else {
7000                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7001                                                            start, end);
7002                                    }
7003    
7004                                    cacheResult(list);
7005    
7006                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7007                            }
7008                            catch (Exception e) {
7009                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7010    
7011                                    throw processException(e);
7012                            }
7013                            finally {
7014                                    closeSession(session);
7015                            }
7016                    }
7017    
7018                    return list;
7019            }
7020    
7021            /**
7022             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7023             *
7024             * @param companyId the company ID
7025             * @param status the status
7026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7027             * @return the first matching message-boards message
7028             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7029             */
7030            @Override
7031            public MBMessage findByC_S_First(long companyId, int status,
7032                    OrderByComparator<MBMessage> orderByComparator)
7033                    throws NoSuchMessageException {
7034                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7035                                    orderByComparator);
7036    
7037                    if (mbMessage != null) {
7038                            return mbMessage;
7039                    }
7040    
7041                    StringBundler msg = new StringBundler(6);
7042    
7043                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7044    
7045                    msg.append("companyId=");
7046                    msg.append(companyId);
7047    
7048                    msg.append(", status=");
7049                    msg.append(status);
7050    
7051                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7052    
7053                    throw new NoSuchMessageException(msg.toString());
7054            }
7055    
7056            /**
7057             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7058             *
7059             * @param companyId the company ID
7060             * @param status the status
7061             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7062             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7063             */
7064            @Override
7065            public MBMessage fetchByC_S_First(long companyId, int status,
7066                    OrderByComparator<MBMessage> orderByComparator) {
7067                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7068                                    orderByComparator);
7069    
7070                    if (!list.isEmpty()) {
7071                            return list.get(0);
7072                    }
7073    
7074                    return null;
7075            }
7076    
7077            /**
7078             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7079             *
7080             * @param companyId the company ID
7081             * @param status the status
7082             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7083             * @return the last matching message-boards message
7084             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7085             */
7086            @Override
7087            public MBMessage findByC_S_Last(long companyId, int status,
7088                    OrderByComparator<MBMessage> orderByComparator)
7089                    throws NoSuchMessageException {
7090                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7091                                    orderByComparator);
7092    
7093                    if (mbMessage != null) {
7094                            return mbMessage;
7095                    }
7096    
7097                    StringBundler msg = new StringBundler(6);
7098    
7099                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7100    
7101                    msg.append("companyId=");
7102                    msg.append(companyId);
7103    
7104                    msg.append(", status=");
7105                    msg.append(status);
7106    
7107                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7108    
7109                    throw new NoSuchMessageException(msg.toString());
7110            }
7111    
7112            /**
7113             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7114             *
7115             * @param companyId the company ID
7116             * @param status the status
7117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7118             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7119             */
7120            @Override
7121            public MBMessage fetchByC_S_Last(long companyId, int status,
7122                    OrderByComparator<MBMessage> orderByComparator) {
7123                    int count = countByC_S(companyId, status);
7124    
7125                    if (count == 0) {
7126                            return null;
7127                    }
7128    
7129                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7130                                    orderByComparator);
7131    
7132                    if (!list.isEmpty()) {
7133                            return list.get(0);
7134                    }
7135    
7136                    return null;
7137            }
7138    
7139            /**
7140             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7141             *
7142             * @param messageId the primary key of the current message-boards message
7143             * @param companyId the company ID
7144             * @param status the status
7145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7146             * @return the previous, current, and next message-boards message
7147             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7148             */
7149            @Override
7150            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7151                    int status, OrderByComparator<MBMessage> orderByComparator)
7152                    throws NoSuchMessageException {
7153                    MBMessage mbMessage = findByPrimaryKey(messageId);
7154    
7155                    Session session = null;
7156    
7157                    try {
7158                            session = openSession();
7159    
7160                            MBMessage[] array = new MBMessageImpl[3];
7161    
7162                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7163                                            status, orderByComparator, true);
7164    
7165                            array[1] = mbMessage;
7166    
7167                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7168                                            status, orderByComparator, false);
7169    
7170                            return array;
7171                    }
7172                    catch (Exception e) {
7173                            throw processException(e);
7174                    }
7175                    finally {
7176                            closeSession(session);
7177                    }
7178            }
7179    
7180            protected MBMessage getByC_S_PrevAndNext(Session session,
7181                    MBMessage mbMessage, long companyId, int status,
7182                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7183                    StringBundler query = null;
7184    
7185                    if (orderByComparator != null) {
7186                            query = new StringBundler(6 +
7187                                            (orderByComparator.getOrderByFields().length * 6));
7188                    }
7189                    else {
7190                            query = new StringBundler(3);
7191                    }
7192    
7193                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7194    
7195                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7196    
7197                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7198    
7199                    if (orderByComparator != null) {
7200                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7201    
7202                            if (orderByConditionFields.length > 0) {
7203                                    query.append(WHERE_AND);
7204                            }
7205    
7206                            for (int i = 0; i < orderByConditionFields.length; i++) {
7207                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7208                                    query.append(orderByConditionFields[i]);
7209    
7210                                    if ((i + 1) < orderByConditionFields.length) {
7211                                            if (orderByComparator.isAscending() ^ previous) {
7212                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7213                                            }
7214                                            else {
7215                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7216                                            }
7217                                    }
7218                                    else {
7219                                            if (orderByComparator.isAscending() ^ previous) {
7220                                                    query.append(WHERE_GREATER_THAN);
7221                                            }
7222                                            else {
7223                                                    query.append(WHERE_LESSER_THAN);
7224                                            }
7225                                    }
7226                            }
7227    
7228                            query.append(ORDER_BY_CLAUSE);
7229    
7230                            String[] orderByFields = orderByComparator.getOrderByFields();
7231    
7232                            for (int i = 0; i < orderByFields.length; i++) {
7233                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7234                                    query.append(orderByFields[i]);
7235    
7236                                    if ((i + 1) < orderByFields.length) {
7237                                            if (orderByComparator.isAscending() ^ previous) {
7238                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7239                                            }
7240                                            else {
7241                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7242                                            }
7243                                    }
7244                                    else {
7245                                            if (orderByComparator.isAscending() ^ previous) {
7246                                                    query.append(ORDER_BY_ASC);
7247                                            }
7248                                            else {
7249                                                    query.append(ORDER_BY_DESC);
7250                                            }
7251                                    }
7252                            }
7253                    }
7254                    else {
7255                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7256                    }
7257    
7258                    String sql = query.toString();
7259    
7260                    Query q = session.createQuery(sql);
7261    
7262                    q.setFirstResult(0);
7263                    q.setMaxResults(2);
7264    
7265                    QueryPos qPos = QueryPos.getInstance(q);
7266    
7267                    qPos.add(companyId);
7268    
7269                    qPos.add(status);
7270    
7271                    if (orderByComparator != null) {
7272                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7273    
7274                            for (Object value : values) {
7275                                    qPos.add(value);
7276                            }
7277                    }
7278    
7279                    List<MBMessage> list = q.list();
7280    
7281                    if (list.size() == 2) {
7282                            return list.get(1);
7283                    }
7284                    else {
7285                            return null;
7286                    }
7287            }
7288    
7289            /**
7290             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7291             *
7292             * @param companyId the company ID
7293             * @param status the status
7294             */
7295            @Override
7296            public void removeByC_S(long companyId, int status) {
7297                    for (MBMessage mbMessage : findByC_S(companyId, status,
7298                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7299                            remove(mbMessage);
7300                    }
7301            }
7302    
7303            /**
7304             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7305             *
7306             * @param companyId the company ID
7307             * @param status the status
7308             * @return the number of matching message-boards messages
7309             */
7310            @Override
7311            public int countByC_S(long companyId, int status) {
7312                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7313    
7314                    Object[] finderArgs = new Object[] { companyId, status };
7315    
7316                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7317                                    this);
7318    
7319                    if (count == null) {
7320                            StringBundler query = new StringBundler(3);
7321    
7322                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7323    
7324                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7325    
7326                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7327    
7328                            String sql = query.toString();
7329    
7330                            Session session = null;
7331    
7332                            try {
7333                                    session = openSession();
7334    
7335                                    Query q = session.createQuery(sql);
7336    
7337                                    QueryPos qPos = QueryPos.getInstance(q);
7338    
7339                                    qPos.add(companyId);
7340    
7341                                    qPos.add(status);
7342    
7343                                    count = (Long)q.uniqueResult();
7344    
7345                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7346                            }
7347                            catch (Exception e) {
7348                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7349    
7350                                    throw processException(e);
7351                            }
7352                            finally {
7353                                    closeSession(session);
7354                            }
7355                    }
7356    
7357                    return count.intValue();
7358            }
7359    
7360            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7361            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7362            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7363                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7364                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7365                            new String[] {
7366                                    Long.class.getName(), Long.class.getName(),
7367                                    
7368                            Integer.class.getName(), Integer.class.getName(),
7369                                    OrderByComparator.class.getName()
7370                            });
7371            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7372                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7373                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7374                            new String[] { Long.class.getName(), Long.class.getName() },
7375                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7376                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7377                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7378            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7379                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7380                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7381                            new String[] { Long.class.getName(), Long.class.getName() });
7382            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7383                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7384                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7385                            new String[] { Long.class.getName(), Long.class.getName() });
7386    
7387            /**
7388             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7389             *
7390             * @param userId the user ID
7391             * @param classNameId the class name ID
7392             * @return the matching message-boards messages
7393             */
7394            @Override
7395            public List<MBMessage> findByU_C(long userId, long classNameId) {
7396                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7397                            QueryUtil.ALL_POS, null);
7398            }
7399    
7400            /**
7401             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7402             *
7403             * <p>
7404             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7405             * </p>
7406             *
7407             * @param userId the user ID
7408             * @param classNameId the class name ID
7409             * @param start the lower bound of the range of message-boards messages
7410             * @param end the upper bound of the range of message-boards messages (not inclusive)
7411             * @return the range of matching message-boards messages
7412             */
7413            @Override
7414            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7415                    int end) {
7416                    return findByU_C(userId, classNameId, start, end, null);
7417            }
7418    
7419            /**
7420             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7421             *
7422             * <p>
7423             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7424             * </p>
7425             *
7426             * @param userId the user ID
7427             * @param classNameId the class name ID
7428             * @param start the lower bound of the range of message-boards messages
7429             * @param end the upper bound of the range of message-boards messages (not inclusive)
7430             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7431             * @return the ordered range of matching message-boards messages
7432             */
7433            @Override
7434            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7435                    int end, OrderByComparator<MBMessage> orderByComparator) {
7436                    boolean pagination = true;
7437                    FinderPath finderPath = null;
7438                    Object[] finderArgs = null;
7439    
7440                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7441                                    (orderByComparator == null)) {
7442                            pagination = false;
7443                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7444                            finderArgs = new Object[] { userId, classNameId };
7445                    }
7446                    else {
7447                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7448                            finderArgs = new Object[] {
7449                                            userId, classNameId,
7450                                            
7451                                            start, end, orderByComparator
7452                                    };
7453                    }
7454    
7455                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7456                                    finderArgs, this);
7457    
7458                    if ((list != null) && !list.isEmpty()) {
7459                            for (MBMessage mbMessage : list) {
7460                                    if ((userId != mbMessage.getUserId()) ||
7461                                                    (classNameId != mbMessage.getClassNameId())) {
7462                                            list = null;
7463    
7464                                            break;
7465                                    }
7466                            }
7467                    }
7468    
7469                    if (list == null) {
7470                            StringBundler query = null;
7471    
7472                            if (orderByComparator != null) {
7473                                    query = new StringBundler(4 +
7474                                                    (orderByComparator.getOrderByFields().length * 3));
7475                            }
7476                            else {
7477                                    query = new StringBundler(4);
7478                            }
7479    
7480                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7481    
7482                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7483    
7484                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7485    
7486                            if (orderByComparator != null) {
7487                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7488                                            orderByComparator);
7489                            }
7490                            else
7491                             if (pagination) {
7492                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7493                            }
7494    
7495                            String sql = query.toString();
7496    
7497                            Session session = null;
7498    
7499                            try {
7500                                    session = openSession();
7501    
7502                                    Query q = session.createQuery(sql);
7503    
7504                                    QueryPos qPos = QueryPos.getInstance(q);
7505    
7506                                    qPos.add(userId);
7507    
7508                                    qPos.add(classNameId);
7509    
7510                                    if (!pagination) {
7511                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7512                                                            start, end, false);
7513    
7514                                            Collections.sort(list);
7515    
7516                                            list = Collections.unmodifiableList(list);
7517                                    }
7518                                    else {
7519                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7520                                                            start, end);
7521                                    }
7522    
7523                                    cacheResult(list);
7524    
7525                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7526                            }
7527                            catch (Exception e) {
7528                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7529    
7530                                    throw processException(e);
7531                            }
7532                            finally {
7533                                    closeSession(session);
7534                            }
7535                    }
7536    
7537                    return list;
7538            }
7539    
7540            /**
7541             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7542             *
7543             * @param userId the user ID
7544             * @param classNameId the class name ID
7545             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7546             * @return the first matching message-boards message
7547             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7548             */
7549            @Override
7550            public MBMessage findByU_C_First(long userId, long classNameId,
7551                    OrderByComparator<MBMessage> orderByComparator)
7552                    throws NoSuchMessageException {
7553                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7554                                    orderByComparator);
7555    
7556                    if (mbMessage != null) {
7557                            return mbMessage;
7558                    }
7559    
7560                    StringBundler msg = new StringBundler(6);
7561    
7562                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7563    
7564                    msg.append("userId=");
7565                    msg.append(userId);
7566    
7567                    msg.append(", classNameId=");
7568                    msg.append(classNameId);
7569    
7570                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7571    
7572                    throw new NoSuchMessageException(msg.toString());
7573            }
7574    
7575            /**
7576             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7577             *
7578             * @param userId the user ID
7579             * @param classNameId the class name ID
7580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7581             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7582             */
7583            @Override
7584            public MBMessage fetchByU_C_First(long userId, long classNameId,
7585                    OrderByComparator<MBMessage> orderByComparator) {
7586                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7587                                    orderByComparator);
7588    
7589                    if (!list.isEmpty()) {
7590                            return list.get(0);
7591                    }
7592    
7593                    return null;
7594            }
7595    
7596            /**
7597             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7598             *
7599             * @param userId the user ID
7600             * @param classNameId the class name ID
7601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7602             * @return the last matching message-boards message
7603             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7604             */
7605            @Override
7606            public MBMessage findByU_C_Last(long userId, long classNameId,
7607                    OrderByComparator<MBMessage> orderByComparator)
7608                    throws NoSuchMessageException {
7609                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7610                                    orderByComparator);
7611    
7612                    if (mbMessage != null) {
7613                            return mbMessage;
7614                    }
7615    
7616                    StringBundler msg = new StringBundler(6);
7617    
7618                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7619    
7620                    msg.append("userId=");
7621                    msg.append(userId);
7622    
7623                    msg.append(", classNameId=");
7624                    msg.append(classNameId);
7625    
7626                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7627    
7628                    throw new NoSuchMessageException(msg.toString());
7629            }
7630    
7631            /**
7632             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7633             *
7634             * @param userId the user ID
7635             * @param classNameId the class name ID
7636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7637             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7638             */
7639            @Override
7640            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7641                    OrderByComparator<MBMessage> orderByComparator) {
7642                    int count = countByU_C(userId, classNameId);
7643    
7644                    if (count == 0) {
7645                            return null;
7646                    }
7647    
7648                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7649                                    orderByComparator);
7650    
7651                    if (!list.isEmpty()) {
7652                            return list.get(0);
7653                    }
7654    
7655                    return null;
7656            }
7657    
7658            /**
7659             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7660             *
7661             * @param messageId the primary key of the current message-boards message
7662             * @param userId the user ID
7663             * @param classNameId the class name ID
7664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7665             * @return the previous, current, and next message-boards message
7666             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7667             */
7668            @Override
7669            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7670                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7671                    throws NoSuchMessageException {
7672                    MBMessage mbMessage = findByPrimaryKey(messageId);
7673    
7674                    Session session = null;
7675    
7676                    try {
7677                            session = openSession();
7678    
7679                            MBMessage[] array = new MBMessageImpl[3];
7680    
7681                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7682                                            classNameId, orderByComparator, true);
7683    
7684                            array[1] = mbMessage;
7685    
7686                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7687                                            classNameId, orderByComparator, false);
7688    
7689                            return array;
7690                    }
7691                    catch (Exception e) {
7692                            throw processException(e);
7693                    }
7694                    finally {
7695                            closeSession(session);
7696                    }
7697            }
7698    
7699            protected MBMessage getByU_C_PrevAndNext(Session session,
7700                    MBMessage mbMessage, long userId, long classNameId,
7701                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7702                    StringBundler query = null;
7703    
7704                    if (orderByComparator != null) {
7705                            query = new StringBundler(6 +
7706                                            (orderByComparator.getOrderByFields().length * 6));
7707                    }
7708                    else {
7709                            query = new StringBundler(3);
7710                    }
7711    
7712                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7713    
7714                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7715    
7716                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7717    
7718                    if (orderByComparator != null) {
7719                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7720    
7721                            if (orderByConditionFields.length > 0) {
7722                                    query.append(WHERE_AND);
7723                            }
7724    
7725                            for (int i = 0; i < orderByConditionFields.length; i++) {
7726                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7727                                    query.append(orderByConditionFields[i]);
7728    
7729                                    if ((i + 1) < orderByConditionFields.length) {
7730                                            if (orderByComparator.isAscending() ^ previous) {
7731                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7732                                            }
7733                                            else {
7734                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7735                                            }
7736                                    }
7737                                    else {
7738                                            if (orderByComparator.isAscending() ^ previous) {
7739                                                    query.append(WHERE_GREATER_THAN);
7740                                            }
7741                                            else {
7742                                                    query.append(WHERE_LESSER_THAN);
7743                                            }
7744                                    }
7745                            }
7746    
7747                            query.append(ORDER_BY_CLAUSE);
7748    
7749                            String[] orderByFields = orderByComparator.getOrderByFields();
7750    
7751                            for (int i = 0; i < orderByFields.length; i++) {
7752                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7753                                    query.append(orderByFields[i]);
7754    
7755                                    if ((i + 1) < orderByFields.length) {
7756                                            if (orderByComparator.isAscending() ^ previous) {
7757                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7758                                            }
7759                                            else {
7760                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7761                                            }
7762                                    }
7763                                    else {
7764                                            if (orderByComparator.isAscending() ^ previous) {
7765                                                    query.append(ORDER_BY_ASC);
7766                                            }
7767                                            else {
7768                                                    query.append(ORDER_BY_DESC);
7769                                            }
7770                                    }
7771                            }
7772                    }
7773                    else {
7774                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7775                    }
7776    
7777                    String sql = query.toString();
7778    
7779                    Query q = session.createQuery(sql);
7780    
7781                    q.setFirstResult(0);
7782                    q.setMaxResults(2);
7783    
7784                    QueryPos qPos = QueryPos.getInstance(q);
7785    
7786                    qPos.add(userId);
7787    
7788                    qPos.add(classNameId);
7789    
7790                    if (orderByComparator != null) {
7791                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7792    
7793                            for (Object value : values) {
7794                                    qPos.add(value);
7795                            }
7796                    }
7797    
7798                    List<MBMessage> list = q.list();
7799    
7800                    if (list.size() == 2) {
7801                            return list.get(1);
7802                    }
7803                    else {
7804                            return null;
7805                    }
7806            }
7807    
7808            /**
7809             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7810             *
7811             * <p>
7812             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7813             * </p>
7814             *
7815             * @param userId the user ID
7816             * @param classNameIds the class name IDs
7817             * @return the matching message-boards messages
7818             */
7819            @Override
7820            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
7821                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7822                            QueryUtil.ALL_POS, null);
7823            }
7824    
7825            /**
7826             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7827             *
7828             * <p>
7829             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7830             * </p>
7831             *
7832             * @param userId the user ID
7833             * @param classNameIds the class name IDs
7834             * @param start the lower bound of the range of message-boards messages
7835             * @param end the upper bound of the range of message-boards messages (not inclusive)
7836             * @return the range of matching message-boards messages
7837             */
7838            @Override
7839            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7840                    int start, int end) {
7841                    return findByU_C(userId, classNameIds, start, end, null);
7842            }
7843    
7844            /**
7845             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7846             *
7847             * <p>
7848             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7849             * </p>
7850             *
7851             * @param userId the user ID
7852             * @param classNameIds the class name IDs
7853             * @param start the lower bound of the range of message-boards messages
7854             * @param end the upper bound of the range of message-boards messages (not inclusive)
7855             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7856             * @return the ordered range of matching message-boards messages
7857             */
7858            @Override
7859            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7860                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
7861                    if (classNameIds == null) {
7862                            classNameIds = new long[0];
7863                    }
7864                    else {
7865                            classNameIds = ArrayUtil.unique(classNameIds);
7866                    }
7867    
7868                    if (classNameIds.length == 1) {
7869                            return findByU_C(userId, classNameIds[0], start, end,
7870                                    orderByComparator);
7871                    }
7872    
7873                    boolean pagination = true;
7874                    Object[] finderArgs = null;
7875    
7876                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7877                                    (orderByComparator == null)) {
7878                            pagination = false;
7879                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7880                    }
7881                    else {
7882                            finderArgs = new Object[] {
7883                                            userId, StringUtil.merge(classNameIds),
7884                                            
7885                                            start, end, orderByComparator
7886                                    };
7887                    }
7888    
7889                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7890                                    finderArgs, this);
7891    
7892                    if ((list != null) && !list.isEmpty()) {
7893                            for (MBMessage mbMessage : list) {
7894                                    if ((userId != mbMessage.getUserId()) ||
7895                                                    !ArrayUtil.contains(classNameIds,
7896                                                            mbMessage.getClassNameId())) {
7897                                            list = null;
7898    
7899                                            break;
7900                                    }
7901                            }
7902                    }
7903    
7904                    if (list == null) {
7905                            StringBundler query = new StringBundler();
7906    
7907                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7908    
7909                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7910    
7911                            if (classNameIds.length > 0) {
7912                                    query.append(StringPool.OPEN_PARENTHESIS);
7913    
7914                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
7915    
7916                                    query.append(StringUtil.merge(classNameIds));
7917    
7918                                    query.append(StringPool.CLOSE_PARENTHESIS);
7919    
7920                                    query.append(StringPool.CLOSE_PARENTHESIS);
7921                            }
7922    
7923                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
7924                                                    1)), query.index() - 1);
7925    
7926                            if (orderByComparator != null) {
7927                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7928                                            orderByComparator);
7929                            }
7930                            else
7931                             if (pagination) {
7932                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7933                            }
7934    
7935                            String sql = query.toString();
7936    
7937                            Session session = null;
7938    
7939                            try {
7940                                    session = openSession();
7941    
7942                                    Query q = session.createQuery(sql);
7943    
7944                                    QueryPos qPos = QueryPos.getInstance(q);
7945    
7946                                    qPos.add(userId);
7947    
7948                                    if (!pagination) {
7949                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7950                                                            start, end, false);
7951    
7952                                            Collections.sort(list);
7953    
7954                                            list = Collections.unmodifiableList(list);
7955                                    }
7956                                    else {
7957                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7958                                                            start, end);
7959                                    }
7960    
7961                                    cacheResult(list);
7962    
7963                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7964                                            finderArgs, list);
7965                            }
7966                            catch (Exception e) {
7967                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7968                                            finderArgs);
7969    
7970                                    throw processException(e);
7971                            }
7972                            finally {
7973                                    closeSession(session);
7974                            }
7975                    }
7976    
7977                    return list;
7978            }
7979    
7980            /**
7981             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
7982             *
7983             * @param userId the user ID
7984             * @param classNameId the class name ID
7985             */
7986            @Override
7987            public void removeByU_C(long userId, long classNameId) {
7988                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
7989                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7990                            remove(mbMessage);
7991                    }
7992            }
7993    
7994            /**
7995             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
7996             *
7997             * @param userId the user ID
7998             * @param classNameId the class name ID
7999             * @return the number of matching message-boards messages
8000             */
8001            @Override
8002            public int countByU_C(long userId, long classNameId) {
8003                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8004    
8005                    Object[] finderArgs = new Object[] { userId, classNameId };
8006    
8007                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8008                                    this);
8009    
8010                    if (count == null) {
8011                            StringBundler query = new StringBundler(3);
8012    
8013                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8014    
8015                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8016    
8017                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8018    
8019                            String sql = query.toString();
8020    
8021                            Session session = null;
8022    
8023                            try {
8024                                    session = openSession();
8025    
8026                                    Query q = session.createQuery(sql);
8027    
8028                                    QueryPos qPos = QueryPos.getInstance(q);
8029    
8030                                    qPos.add(userId);
8031    
8032                                    qPos.add(classNameId);
8033    
8034                                    count = (Long)q.uniqueResult();
8035    
8036                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8037                            }
8038                            catch (Exception e) {
8039                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8040    
8041                                    throw processException(e);
8042                            }
8043                            finally {
8044                                    closeSession(session);
8045                            }
8046                    }
8047    
8048                    return count.intValue();
8049            }
8050    
8051            /**
8052             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8053             *
8054             * @param userId the user ID
8055             * @param classNameIds the class name IDs
8056             * @return the number of matching message-boards messages
8057             */
8058            @Override
8059            public int countByU_C(long userId, long[] classNameIds) {
8060                    if (classNameIds == null) {
8061                            classNameIds = new long[0];
8062                    }
8063                    else {
8064                            classNameIds = ArrayUtil.unique(classNameIds);
8065                    }
8066    
8067                    Object[] finderArgs = new Object[] {
8068                                    userId, StringUtil.merge(classNameIds)
8069                            };
8070    
8071                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8072                                    finderArgs, this);
8073    
8074                    if (count == null) {
8075                            StringBundler query = new StringBundler();
8076    
8077                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8078    
8079                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8080    
8081                            if (classNameIds.length > 0) {
8082                                    query.append(StringPool.OPEN_PARENTHESIS);
8083    
8084                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8085    
8086                                    query.append(StringUtil.merge(classNameIds));
8087    
8088                                    query.append(StringPool.CLOSE_PARENTHESIS);
8089    
8090                                    query.append(StringPool.CLOSE_PARENTHESIS);
8091                            }
8092    
8093                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8094                                                    1)), query.index() - 1);
8095    
8096                            String sql = query.toString();
8097    
8098                            Session session = null;
8099    
8100                            try {
8101                                    session = openSession();
8102    
8103                                    Query q = session.createQuery(sql);
8104    
8105                                    QueryPos qPos = QueryPos.getInstance(q);
8106    
8107                                    qPos.add(userId);
8108    
8109                                    count = (Long)q.uniqueResult();
8110    
8111                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8112                                            finderArgs, count);
8113                            }
8114                            catch (Exception e) {
8115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8116                                            finderArgs);
8117    
8118                                    throw processException(e);
8119                            }
8120                            finally {
8121                                    closeSession(session);
8122                            }
8123                    }
8124    
8125                    return count.intValue();
8126            }
8127    
8128            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8129            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8130            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8132                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8133                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8134                            new String[] {
8135                                    Long.class.getName(), Long.class.getName(),
8136                                    
8137                            Integer.class.getName(), Integer.class.getName(),
8138                                    OrderByComparator.class.getName()
8139                            });
8140            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8141                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8143                            new String[] { Long.class.getName(), Long.class.getName() },
8144                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8145                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8146                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8147            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8148                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8150                            new String[] { Long.class.getName(), Long.class.getName() });
8151    
8152            /**
8153             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8154             *
8155             * @param classNameId the class name ID
8156             * @param classPK the class p k
8157             * @return the matching message-boards messages
8158             */
8159            @Override
8160            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8161                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8162                            QueryUtil.ALL_POS, null);
8163            }
8164    
8165            /**
8166             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8167             *
8168             * <p>
8169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8170             * </p>
8171             *
8172             * @param classNameId the class name ID
8173             * @param classPK the class p k
8174             * @param start the lower bound of the range of message-boards messages
8175             * @param end the upper bound of the range of message-boards messages (not inclusive)
8176             * @return the range of matching message-boards messages
8177             */
8178            @Override
8179            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8180                    int end) {
8181                    return findByC_C(classNameId, classPK, start, end, null);
8182            }
8183    
8184            /**
8185             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8186             *
8187             * <p>
8188             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8189             * </p>
8190             *
8191             * @param classNameId the class name ID
8192             * @param classPK the class p k
8193             * @param start the lower bound of the range of message-boards messages
8194             * @param end the upper bound of the range of message-boards messages (not inclusive)
8195             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8196             * @return the ordered range of matching message-boards messages
8197             */
8198            @Override
8199            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8200                    int end, OrderByComparator<MBMessage> orderByComparator) {
8201                    boolean pagination = true;
8202                    FinderPath finderPath = null;
8203                    Object[] finderArgs = null;
8204    
8205                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8206                                    (orderByComparator == null)) {
8207                            pagination = false;
8208                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8209                            finderArgs = new Object[] { classNameId, classPK };
8210                    }
8211                    else {
8212                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8213                            finderArgs = new Object[] {
8214                                            classNameId, classPK,
8215                                            
8216                                            start, end, orderByComparator
8217                                    };
8218                    }
8219    
8220                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8221                                    finderArgs, this);
8222    
8223                    if ((list != null) && !list.isEmpty()) {
8224                            for (MBMessage mbMessage : list) {
8225                                    if ((classNameId != mbMessage.getClassNameId()) ||
8226                                                    (classPK != mbMessage.getClassPK())) {
8227                                            list = null;
8228    
8229                                            break;
8230                                    }
8231                            }
8232                    }
8233    
8234                    if (list == null) {
8235                            StringBundler query = null;
8236    
8237                            if (orderByComparator != null) {
8238                                    query = new StringBundler(4 +
8239                                                    (orderByComparator.getOrderByFields().length * 3));
8240                            }
8241                            else {
8242                                    query = new StringBundler(4);
8243                            }
8244    
8245                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8246    
8247                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8248    
8249                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8250    
8251                            if (orderByComparator != null) {
8252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8253                                            orderByComparator);
8254                            }
8255                            else
8256                             if (pagination) {
8257                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8258                            }
8259    
8260                            String sql = query.toString();
8261    
8262                            Session session = null;
8263    
8264                            try {
8265                                    session = openSession();
8266    
8267                                    Query q = session.createQuery(sql);
8268    
8269                                    QueryPos qPos = QueryPos.getInstance(q);
8270    
8271                                    qPos.add(classNameId);
8272    
8273                                    qPos.add(classPK);
8274    
8275                                    if (!pagination) {
8276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8277                                                            start, end, false);
8278    
8279                                            Collections.sort(list);
8280    
8281                                            list = Collections.unmodifiableList(list);
8282                                    }
8283                                    else {
8284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8285                                                            start, end);
8286                                    }
8287    
8288                                    cacheResult(list);
8289    
8290                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8291                            }
8292                            catch (Exception e) {
8293                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8294    
8295                                    throw processException(e);
8296                            }
8297                            finally {
8298                                    closeSession(session);
8299                            }
8300                    }
8301    
8302                    return list;
8303            }
8304    
8305            /**
8306             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8307             *
8308             * @param classNameId the class name ID
8309             * @param classPK the class p k
8310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8311             * @return the first matching message-boards message
8312             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8313             */
8314            @Override
8315            public MBMessage findByC_C_First(long classNameId, long classPK,
8316                    OrderByComparator<MBMessage> orderByComparator)
8317                    throws NoSuchMessageException {
8318                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8319                                    orderByComparator);
8320    
8321                    if (mbMessage != null) {
8322                            return mbMessage;
8323                    }
8324    
8325                    StringBundler msg = new StringBundler(6);
8326    
8327                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8328    
8329                    msg.append("classNameId=");
8330                    msg.append(classNameId);
8331    
8332                    msg.append(", classPK=");
8333                    msg.append(classPK);
8334    
8335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8336    
8337                    throw new NoSuchMessageException(msg.toString());
8338            }
8339    
8340            /**
8341             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8342             *
8343             * @param classNameId the class name ID
8344             * @param classPK the class p k
8345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8346             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8347             */
8348            @Override
8349            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8350                    OrderByComparator<MBMessage> orderByComparator) {
8351                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8352                                    orderByComparator);
8353    
8354                    if (!list.isEmpty()) {
8355                            return list.get(0);
8356                    }
8357    
8358                    return null;
8359            }
8360    
8361            /**
8362             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8363             *
8364             * @param classNameId the class name ID
8365             * @param classPK the class p k
8366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8367             * @return the last matching message-boards message
8368             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8369             */
8370            @Override
8371            public MBMessage findByC_C_Last(long classNameId, long classPK,
8372                    OrderByComparator<MBMessage> orderByComparator)
8373                    throws NoSuchMessageException {
8374                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8375                                    orderByComparator);
8376    
8377                    if (mbMessage != null) {
8378                            return mbMessage;
8379                    }
8380    
8381                    StringBundler msg = new StringBundler(6);
8382    
8383                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8384    
8385                    msg.append("classNameId=");
8386                    msg.append(classNameId);
8387    
8388                    msg.append(", classPK=");
8389                    msg.append(classPK);
8390    
8391                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8392    
8393                    throw new NoSuchMessageException(msg.toString());
8394            }
8395    
8396            /**
8397             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8398             *
8399             * @param classNameId the class name ID
8400             * @param classPK the class p k
8401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8402             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8403             */
8404            @Override
8405            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8406                    OrderByComparator<MBMessage> orderByComparator) {
8407                    int count = countByC_C(classNameId, classPK);
8408    
8409                    if (count == 0) {
8410                            return null;
8411                    }
8412    
8413                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8414                                    count, orderByComparator);
8415    
8416                    if (!list.isEmpty()) {
8417                            return list.get(0);
8418                    }
8419    
8420                    return null;
8421            }
8422    
8423            /**
8424             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8425             *
8426             * @param messageId the primary key of the current message-boards message
8427             * @param classNameId the class name ID
8428             * @param classPK the class p k
8429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8430             * @return the previous, current, and next message-boards message
8431             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8432             */
8433            @Override
8434            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8435                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8436                    throws NoSuchMessageException {
8437                    MBMessage mbMessage = findByPrimaryKey(messageId);
8438    
8439                    Session session = null;
8440    
8441                    try {
8442                            session = openSession();
8443    
8444                            MBMessage[] array = new MBMessageImpl[3];
8445    
8446                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8447                                            classPK, orderByComparator, true);
8448    
8449                            array[1] = mbMessage;
8450    
8451                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8452                                            classPK, orderByComparator, false);
8453    
8454                            return array;
8455                    }
8456                    catch (Exception e) {
8457                            throw processException(e);
8458                    }
8459                    finally {
8460                            closeSession(session);
8461                    }
8462            }
8463    
8464            protected MBMessage getByC_C_PrevAndNext(Session session,
8465                    MBMessage mbMessage, long classNameId, long classPK,
8466                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8467                    StringBundler query = null;
8468    
8469                    if (orderByComparator != null) {
8470                            query = new StringBundler(6 +
8471                                            (orderByComparator.getOrderByFields().length * 6));
8472                    }
8473                    else {
8474                            query = new StringBundler(3);
8475                    }
8476    
8477                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8478    
8479                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8480    
8481                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8482    
8483                    if (orderByComparator != null) {
8484                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8485    
8486                            if (orderByConditionFields.length > 0) {
8487                                    query.append(WHERE_AND);
8488                            }
8489    
8490                            for (int i = 0; i < orderByConditionFields.length; i++) {
8491                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8492                                    query.append(orderByConditionFields[i]);
8493    
8494                                    if ((i + 1) < orderByConditionFields.length) {
8495                                            if (orderByComparator.isAscending() ^ previous) {
8496                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8497                                            }
8498                                            else {
8499                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8500                                            }
8501                                    }
8502                                    else {
8503                                            if (orderByComparator.isAscending() ^ previous) {
8504                                                    query.append(WHERE_GREATER_THAN);
8505                                            }
8506                                            else {
8507                                                    query.append(WHERE_LESSER_THAN);
8508                                            }
8509                                    }
8510                            }
8511    
8512                            query.append(ORDER_BY_CLAUSE);
8513    
8514                            String[] orderByFields = orderByComparator.getOrderByFields();
8515    
8516                            for (int i = 0; i < orderByFields.length; i++) {
8517                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8518                                    query.append(orderByFields[i]);
8519    
8520                                    if ((i + 1) < orderByFields.length) {
8521                                            if (orderByComparator.isAscending() ^ previous) {
8522                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8523                                            }
8524                                            else {
8525                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8526                                            }
8527                                    }
8528                                    else {
8529                                            if (orderByComparator.isAscending() ^ previous) {
8530                                                    query.append(ORDER_BY_ASC);
8531                                            }
8532                                            else {
8533                                                    query.append(ORDER_BY_DESC);
8534                                            }
8535                                    }
8536                            }
8537                    }
8538                    else {
8539                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8540                    }
8541    
8542                    String sql = query.toString();
8543    
8544                    Query q = session.createQuery(sql);
8545    
8546                    q.setFirstResult(0);
8547                    q.setMaxResults(2);
8548    
8549                    QueryPos qPos = QueryPos.getInstance(q);
8550    
8551                    qPos.add(classNameId);
8552    
8553                    qPos.add(classPK);
8554    
8555                    if (orderByComparator != null) {
8556                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8557    
8558                            for (Object value : values) {
8559                                    qPos.add(value);
8560                            }
8561                    }
8562    
8563                    List<MBMessage> list = q.list();
8564    
8565                    if (list.size() == 2) {
8566                            return list.get(1);
8567                    }
8568                    else {
8569                            return null;
8570                    }
8571            }
8572    
8573            /**
8574             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8575             *
8576             * @param classNameId the class name ID
8577             * @param classPK the class p k
8578             */
8579            @Override
8580            public void removeByC_C(long classNameId, long classPK) {
8581                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8582                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8583                            remove(mbMessage);
8584                    }
8585            }
8586    
8587            /**
8588             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8589             *
8590             * @param classNameId the class name ID
8591             * @param classPK the class p k
8592             * @return the number of matching message-boards messages
8593             */
8594            @Override
8595            public int countByC_C(long classNameId, long classPK) {
8596                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8597    
8598                    Object[] finderArgs = new Object[] { classNameId, classPK };
8599    
8600                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8601                                    this);
8602    
8603                    if (count == null) {
8604                            StringBundler query = new StringBundler(3);
8605    
8606                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8607    
8608                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8609    
8610                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8611    
8612                            String sql = query.toString();
8613    
8614                            Session session = null;
8615    
8616                            try {
8617                                    session = openSession();
8618    
8619                                    Query q = session.createQuery(sql);
8620    
8621                                    QueryPos qPos = QueryPos.getInstance(q);
8622    
8623                                    qPos.add(classNameId);
8624    
8625                                    qPos.add(classPK);
8626    
8627                                    count = (Long)q.uniqueResult();
8628    
8629                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8630                            }
8631                            catch (Exception e) {
8632                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8633    
8634                                    throw processException(e);
8635                            }
8636                            finally {
8637                                    closeSession(session);
8638                            }
8639                    }
8640    
8641                    return count.intValue();
8642            }
8643    
8644            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8645            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8646            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8647                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8648                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8649                            new String[] {
8650                                    Long.class.getName(), Long.class.getName(),
8651                                    
8652                            Integer.class.getName(), Integer.class.getName(),
8653                                    OrderByComparator.class.getName()
8654                            });
8655            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8656                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8657                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8658                            new String[] { Long.class.getName(), Long.class.getName() },
8659                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8660                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8661                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8662            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8663                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8664                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8665                            new String[] { Long.class.getName(), Long.class.getName() });
8666    
8667            /**
8668             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8669             *
8670             * @param threadId the thread ID
8671             * @param parentMessageId the parent message ID
8672             * @return the matching message-boards messages
8673             */
8674            @Override
8675            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
8676                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8677                            QueryUtil.ALL_POS, null);
8678            }
8679    
8680            /**
8681             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8682             *
8683             * <p>
8684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8685             * </p>
8686             *
8687             * @param threadId the thread ID
8688             * @param parentMessageId the parent message ID
8689             * @param start the lower bound of the range of message-boards messages
8690             * @param end the upper bound of the range of message-boards messages (not inclusive)
8691             * @return the range of matching message-boards messages
8692             */
8693            @Override
8694            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8695                    int start, int end) {
8696                    return findByT_P(threadId, parentMessageId, start, end, null);
8697            }
8698    
8699            /**
8700             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8701             *
8702             * <p>
8703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8704             * </p>
8705             *
8706             * @param threadId the thread ID
8707             * @param parentMessageId the parent message ID
8708             * @param start the lower bound of the range of message-boards messages
8709             * @param end the upper bound of the range of message-boards messages (not inclusive)
8710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8711             * @return the ordered range of matching message-boards messages
8712             */
8713            @Override
8714            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8715                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8716                    boolean pagination = true;
8717                    FinderPath finderPath = null;
8718                    Object[] finderArgs = null;
8719    
8720                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8721                                    (orderByComparator == null)) {
8722                            pagination = false;
8723                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8724                            finderArgs = new Object[] { threadId, parentMessageId };
8725                    }
8726                    else {
8727                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8728                            finderArgs = new Object[] {
8729                                            threadId, parentMessageId,
8730                                            
8731                                            start, end, orderByComparator
8732                                    };
8733                    }
8734    
8735                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8736                                    finderArgs, this);
8737    
8738                    if ((list != null) && !list.isEmpty()) {
8739                            for (MBMessage mbMessage : list) {
8740                                    if ((threadId != mbMessage.getThreadId()) ||
8741                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8742                                            list = null;
8743    
8744                                            break;
8745                                    }
8746                            }
8747                    }
8748    
8749                    if (list == null) {
8750                            StringBundler query = null;
8751    
8752                            if (orderByComparator != null) {
8753                                    query = new StringBundler(4 +
8754                                                    (orderByComparator.getOrderByFields().length * 3));
8755                            }
8756                            else {
8757                                    query = new StringBundler(4);
8758                            }
8759    
8760                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8761    
8762                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8763    
8764                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8765    
8766                            if (orderByComparator != null) {
8767                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8768                                            orderByComparator);
8769                            }
8770                            else
8771                             if (pagination) {
8772                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8773                            }
8774    
8775                            String sql = query.toString();
8776    
8777                            Session session = null;
8778    
8779                            try {
8780                                    session = openSession();
8781    
8782                                    Query q = session.createQuery(sql);
8783    
8784                                    QueryPos qPos = QueryPos.getInstance(q);
8785    
8786                                    qPos.add(threadId);
8787    
8788                                    qPos.add(parentMessageId);
8789    
8790                                    if (!pagination) {
8791                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8792                                                            start, end, false);
8793    
8794                                            Collections.sort(list);
8795    
8796                                            list = Collections.unmodifiableList(list);
8797                                    }
8798                                    else {
8799                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8800                                                            start, end);
8801                                    }
8802    
8803                                    cacheResult(list);
8804    
8805                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8806                            }
8807                            catch (Exception e) {
8808                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8809    
8810                                    throw processException(e);
8811                            }
8812                            finally {
8813                                    closeSession(session);
8814                            }
8815                    }
8816    
8817                    return list;
8818            }
8819    
8820            /**
8821             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8822             *
8823             * @param threadId the thread ID
8824             * @param parentMessageId the parent message ID
8825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8826             * @return the first matching message-boards message
8827             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8828             */
8829            @Override
8830            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8831                    OrderByComparator<MBMessage> orderByComparator)
8832                    throws NoSuchMessageException {
8833                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8834                                    orderByComparator);
8835    
8836                    if (mbMessage != null) {
8837                            return mbMessage;
8838                    }
8839    
8840                    StringBundler msg = new StringBundler(6);
8841    
8842                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8843    
8844                    msg.append("threadId=");
8845                    msg.append(threadId);
8846    
8847                    msg.append(", parentMessageId=");
8848                    msg.append(parentMessageId);
8849    
8850                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8851    
8852                    throw new NoSuchMessageException(msg.toString());
8853            }
8854    
8855            /**
8856             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8857             *
8858             * @param threadId the thread ID
8859             * @param parentMessageId the parent message ID
8860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8861             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8862             */
8863            @Override
8864            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8865                    OrderByComparator<MBMessage> orderByComparator) {
8866                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8867                                    orderByComparator);
8868    
8869                    if (!list.isEmpty()) {
8870                            return list.get(0);
8871                    }
8872    
8873                    return null;
8874            }
8875    
8876            /**
8877             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8878             *
8879             * @param threadId the thread ID
8880             * @param parentMessageId the parent message ID
8881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8882             * @return the last matching message-boards message
8883             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8884             */
8885            @Override
8886            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8887                    OrderByComparator<MBMessage> orderByComparator)
8888                    throws NoSuchMessageException {
8889                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8890                                    orderByComparator);
8891    
8892                    if (mbMessage != null) {
8893                            return mbMessage;
8894                    }
8895    
8896                    StringBundler msg = new StringBundler(6);
8897    
8898                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8899    
8900                    msg.append("threadId=");
8901                    msg.append(threadId);
8902    
8903                    msg.append(", parentMessageId=");
8904                    msg.append(parentMessageId);
8905    
8906                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8907    
8908                    throw new NoSuchMessageException(msg.toString());
8909            }
8910    
8911            /**
8912             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8913             *
8914             * @param threadId the thread ID
8915             * @param parentMessageId the parent message ID
8916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8917             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8918             */
8919            @Override
8920            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8921                    OrderByComparator<MBMessage> orderByComparator) {
8922                    int count = countByT_P(threadId, parentMessageId);
8923    
8924                    if (count == 0) {
8925                            return null;
8926                    }
8927    
8928                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8929                                    count, orderByComparator);
8930    
8931                    if (!list.isEmpty()) {
8932                            return list.get(0);
8933                    }
8934    
8935                    return null;
8936            }
8937    
8938            /**
8939             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8940             *
8941             * @param messageId the primary key of the current message-boards message
8942             * @param threadId the thread ID
8943             * @param parentMessageId the parent message ID
8944             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8945             * @return the previous, current, and next message-boards message
8946             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8947             */
8948            @Override
8949            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8950                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
8951                    throws NoSuchMessageException {
8952                    MBMessage mbMessage = findByPrimaryKey(messageId);
8953    
8954                    Session session = null;
8955    
8956                    try {
8957                            session = openSession();
8958    
8959                            MBMessage[] array = new MBMessageImpl[3];
8960    
8961                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8962                                            parentMessageId, orderByComparator, true);
8963    
8964                            array[1] = mbMessage;
8965    
8966                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8967                                            parentMessageId, orderByComparator, false);
8968    
8969                            return array;
8970                    }
8971                    catch (Exception e) {
8972                            throw processException(e);
8973                    }
8974                    finally {
8975                            closeSession(session);
8976                    }
8977            }
8978    
8979            protected MBMessage getByT_P_PrevAndNext(Session session,
8980                    MBMessage mbMessage, long threadId, long parentMessageId,
8981                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8982                    StringBundler query = null;
8983    
8984                    if (orderByComparator != null) {
8985                            query = new StringBundler(6 +
8986                                            (orderByComparator.getOrderByFields().length * 6));
8987                    }
8988                    else {
8989                            query = new StringBundler(3);
8990                    }
8991    
8992                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8993    
8994                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8995    
8996                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8997    
8998                    if (orderByComparator != null) {
8999                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9000    
9001                            if (orderByConditionFields.length > 0) {
9002                                    query.append(WHERE_AND);
9003                            }
9004    
9005                            for (int i = 0; i < orderByConditionFields.length; i++) {
9006                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9007                                    query.append(orderByConditionFields[i]);
9008    
9009                                    if ((i + 1) < orderByConditionFields.length) {
9010                                            if (orderByComparator.isAscending() ^ previous) {
9011                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9012                                            }
9013                                            else {
9014                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9015                                            }
9016                                    }
9017                                    else {
9018                                            if (orderByComparator.isAscending() ^ previous) {
9019                                                    query.append(WHERE_GREATER_THAN);
9020                                            }
9021                                            else {
9022                                                    query.append(WHERE_LESSER_THAN);
9023                                            }
9024                                    }
9025                            }
9026    
9027                            query.append(ORDER_BY_CLAUSE);
9028    
9029                            String[] orderByFields = orderByComparator.getOrderByFields();
9030    
9031                            for (int i = 0; i < orderByFields.length; i++) {
9032                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9033                                    query.append(orderByFields[i]);
9034    
9035                                    if ((i + 1) < orderByFields.length) {
9036                                            if (orderByComparator.isAscending() ^ previous) {
9037                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9038                                            }
9039                                            else {
9040                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9041                                            }
9042                                    }
9043                                    else {
9044                                            if (orderByComparator.isAscending() ^ previous) {
9045                                                    query.append(ORDER_BY_ASC);
9046                                            }
9047                                            else {
9048                                                    query.append(ORDER_BY_DESC);
9049                                            }
9050                                    }
9051                            }
9052                    }
9053                    else {
9054                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9055                    }
9056    
9057                    String sql = query.toString();
9058    
9059                    Query q = session.createQuery(sql);
9060    
9061                    q.setFirstResult(0);
9062                    q.setMaxResults(2);
9063    
9064                    QueryPos qPos = QueryPos.getInstance(q);
9065    
9066                    qPos.add(threadId);
9067    
9068                    qPos.add(parentMessageId);
9069    
9070                    if (orderByComparator != null) {
9071                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9072    
9073                            for (Object value : values) {
9074                                    qPos.add(value);
9075                            }
9076                    }
9077    
9078                    List<MBMessage> list = q.list();
9079    
9080                    if (list.size() == 2) {
9081                            return list.get(1);
9082                    }
9083                    else {
9084                            return null;
9085                    }
9086            }
9087    
9088            /**
9089             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9090             *
9091             * @param threadId the thread ID
9092             * @param parentMessageId the parent message ID
9093             */
9094            @Override
9095            public void removeByT_P(long threadId, long parentMessageId) {
9096                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9097                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9098                            remove(mbMessage);
9099                    }
9100            }
9101    
9102            /**
9103             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9104             *
9105             * @param threadId the thread ID
9106             * @param parentMessageId the parent message ID
9107             * @return the number of matching message-boards messages
9108             */
9109            @Override
9110            public int countByT_P(long threadId, long parentMessageId) {
9111                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9112    
9113                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9114    
9115                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9116                                    this);
9117    
9118                    if (count == null) {
9119                            StringBundler query = new StringBundler(3);
9120    
9121                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9122    
9123                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9124    
9125                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9126    
9127                            String sql = query.toString();
9128    
9129                            Session session = null;
9130    
9131                            try {
9132                                    session = openSession();
9133    
9134                                    Query q = session.createQuery(sql);
9135    
9136                                    QueryPos qPos = QueryPos.getInstance(q);
9137    
9138                                    qPos.add(threadId);
9139    
9140                                    qPos.add(parentMessageId);
9141    
9142                                    count = (Long)q.uniqueResult();
9143    
9144                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9145                            }
9146                            catch (Exception e) {
9147                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9148    
9149                                    throw processException(e);
9150                            }
9151                            finally {
9152                                    closeSession(session);
9153                            }
9154                    }
9155    
9156                    return count.intValue();
9157            }
9158    
9159            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9160            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9161            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9162                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9163                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9164                            new String[] {
9165                                    Long.class.getName(), Boolean.class.getName(),
9166                                    
9167                            Integer.class.getName(), Integer.class.getName(),
9168                                    OrderByComparator.class.getName()
9169                            });
9170            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9171                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9172                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9173                            new String[] { Long.class.getName(), Boolean.class.getName() },
9174                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9175                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9176                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9177            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9178                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9179                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9180                            new String[] { Long.class.getName(), Boolean.class.getName() });
9181    
9182            /**
9183             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9184             *
9185             * @param threadId the thread ID
9186             * @param answer the answer
9187             * @return the matching message-boards messages
9188             */
9189            @Override
9190            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9191                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9192                            QueryUtil.ALL_POS, null);
9193            }
9194    
9195            /**
9196             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9197             *
9198             * <p>
9199             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9200             * </p>
9201             *
9202             * @param threadId the thread ID
9203             * @param answer the answer
9204             * @param start the lower bound of the range of message-boards messages
9205             * @param end the upper bound of the range of message-boards messages (not inclusive)
9206             * @return the range of matching message-boards messages
9207             */
9208            @Override
9209            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9210                    int end) {
9211                    return findByT_A(threadId, answer, start, end, null);
9212            }
9213    
9214            /**
9215             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9216             *
9217             * <p>
9218             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9219             * </p>
9220             *
9221             * @param threadId the thread ID
9222             * @param answer the answer
9223             * @param start the lower bound of the range of message-boards messages
9224             * @param end the upper bound of the range of message-boards messages (not inclusive)
9225             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9226             * @return the ordered range of matching message-boards messages
9227             */
9228            @Override
9229            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9230                    int end, OrderByComparator<MBMessage> orderByComparator) {
9231                    boolean pagination = true;
9232                    FinderPath finderPath = null;
9233                    Object[] finderArgs = null;
9234    
9235                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9236                                    (orderByComparator == null)) {
9237                            pagination = false;
9238                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9239                            finderArgs = new Object[] { threadId, answer };
9240                    }
9241                    else {
9242                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9243                            finderArgs = new Object[] {
9244                                            threadId, answer,
9245                                            
9246                                            start, end, orderByComparator
9247                                    };
9248                    }
9249    
9250                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9251                                    finderArgs, this);
9252    
9253                    if ((list != null) && !list.isEmpty()) {
9254                            for (MBMessage mbMessage : list) {
9255                                    if ((threadId != mbMessage.getThreadId()) ||
9256                                                    (answer != mbMessage.getAnswer())) {
9257                                            list = null;
9258    
9259                                            break;
9260                                    }
9261                            }
9262                    }
9263    
9264                    if (list == null) {
9265                            StringBundler query = null;
9266    
9267                            if (orderByComparator != null) {
9268                                    query = new StringBundler(4 +
9269                                                    (orderByComparator.getOrderByFields().length * 3));
9270                            }
9271                            else {
9272                                    query = new StringBundler(4);
9273                            }
9274    
9275                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9276    
9277                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9278    
9279                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9280    
9281                            if (orderByComparator != null) {
9282                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9283                                            orderByComparator);
9284                            }
9285                            else
9286                             if (pagination) {
9287                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9288                            }
9289    
9290                            String sql = query.toString();
9291    
9292                            Session session = null;
9293    
9294                            try {
9295                                    session = openSession();
9296    
9297                                    Query q = session.createQuery(sql);
9298    
9299                                    QueryPos qPos = QueryPos.getInstance(q);
9300    
9301                                    qPos.add(threadId);
9302    
9303                                    qPos.add(answer);
9304    
9305                                    if (!pagination) {
9306                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9307                                                            start, end, false);
9308    
9309                                            Collections.sort(list);
9310    
9311                                            list = Collections.unmodifiableList(list);
9312                                    }
9313                                    else {
9314                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9315                                                            start, end);
9316                                    }
9317    
9318                                    cacheResult(list);
9319    
9320                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9321                            }
9322                            catch (Exception e) {
9323                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9324    
9325                                    throw processException(e);
9326                            }
9327                            finally {
9328                                    closeSession(session);
9329                            }
9330                    }
9331    
9332                    return list;
9333            }
9334    
9335            /**
9336             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9337             *
9338             * @param threadId the thread ID
9339             * @param answer the answer
9340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9341             * @return the first matching message-boards message
9342             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9343             */
9344            @Override
9345            public MBMessage findByT_A_First(long threadId, boolean answer,
9346                    OrderByComparator<MBMessage> orderByComparator)
9347                    throws NoSuchMessageException {
9348                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9349                                    orderByComparator);
9350    
9351                    if (mbMessage != null) {
9352                            return mbMessage;
9353                    }
9354    
9355                    StringBundler msg = new StringBundler(6);
9356    
9357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9358    
9359                    msg.append("threadId=");
9360                    msg.append(threadId);
9361    
9362                    msg.append(", answer=");
9363                    msg.append(answer);
9364    
9365                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9366    
9367                    throw new NoSuchMessageException(msg.toString());
9368            }
9369    
9370            /**
9371             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9372             *
9373             * @param threadId the thread ID
9374             * @param answer the answer
9375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9376             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9377             */
9378            @Override
9379            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9380                    OrderByComparator<MBMessage> orderByComparator) {
9381                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9382                                    orderByComparator);
9383    
9384                    if (!list.isEmpty()) {
9385                            return list.get(0);
9386                    }
9387    
9388                    return null;
9389            }
9390    
9391            /**
9392             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9393             *
9394             * @param threadId the thread ID
9395             * @param answer the answer
9396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9397             * @return the last matching message-boards message
9398             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9399             */
9400            @Override
9401            public MBMessage findByT_A_Last(long threadId, boolean answer,
9402                    OrderByComparator<MBMessage> orderByComparator)
9403                    throws NoSuchMessageException {
9404                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9405                                    orderByComparator);
9406    
9407                    if (mbMessage != null) {
9408                            return mbMessage;
9409                    }
9410    
9411                    StringBundler msg = new StringBundler(6);
9412    
9413                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9414    
9415                    msg.append("threadId=");
9416                    msg.append(threadId);
9417    
9418                    msg.append(", answer=");
9419                    msg.append(answer);
9420    
9421                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9422    
9423                    throw new NoSuchMessageException(msg.toString());
9424            }
9425    
9426            /**
9427             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9428             *
9429             * @param threadId the thread ID
9430             * @param answer the answer
9431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9432             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9433             */
9434            @Override
9435            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9436                    OrderByComparator<MBMessage> orderByComparator) {
9437                    int count = countByT_A(threadId, answer);
9438    
9439                    if (count == 0) {
9440                            return null;
9441                    }
9442    
9443                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9444                                    orderByComparator);
9445    
9446                    if (!list.isEmpty()) {
9447                            return list.get(0);
9448                    }
9449    
9450                    return null;
9451            }
9452    
9453            /**
9454             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9455             *
9456             * @param messageId the primary key of the current message-boards message
9457             * @param threadId the thread ID
9458             * @param answer the answer
9459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9460             * @return the previous, current, and next message-boards message
9461             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9462             */
9463            @Override
9464            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9465                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9466                    throws NoSuchMessageException {
9467                    MBMessage mbMessage = findByPrimaryKey(messageId);
9468    
9469                    Session session = null;
9470    
9471                    try {
9472                            session = openSession();
9473    
9474                            MBMessage[] array = new MBMessageImpl[3];
9475    
9476                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9477                                            answer, orderByComparator, true);
9478    
9479                            array[1] = mbMessage;
9480    
9481                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9482                                            answer, orderByComparator, false);
9483    
9484                            return array;
9485                    }
9486                    catch (Exception e) {
9487                            throw processException(e);
9488                    }
9489                    finally {
9490                            closeSession(session);
9491                    }
9492            }
9493    
9494            protected MBMessage getByT_A_PrevAndNext(Session session,
9495                    MBMessage mbMessage, long threadId, boolean answer,
9496                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9497                    StringBundler query = null;
9498    
9499                    if (orderByComparator != null) {
9500                            query = new StringBundler(6 +
9501                                            (orderByComparator.getOrderByFields().length * 6));
9502                    }
9503                    else {
9504                            query = new StringBundler(3);
9505                    }
9506    
9507                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9508    
9509                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9510    
9511                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9512    
9513                    if (orderByComparator != null) {
9514                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9515    
9516                            if (orderByConditionFields.length > 0) {
9517                                    query.append(WHERE_AND);
9518                            }
9519    
9520                            for (int i = 0; i < orderByConditionFields.length; i++) {
9521                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9522                                    query.append(orderByConditionFields[i]);
9523    
9524                                    if ((i + 1) < orderByConditionFields.length) {
9525                                            if (orderByComparator.isAscending() ^ previous) {
9526                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9527                                            }
9528                                            else {
9529                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9530                                            }
9531                                    }
9532                                    else {
9533                                            if (orderByComparator.isAscending() ^ previous) {
9534                                                    query.append(WHERE_GREATER_THAN);
9535                                            }
9536                                            else {
9537                                                    query.append(WHERE_LESSER_THAN);
9538                                            }
9539                                    }
9540                            }
9541    
9542                            query.append(ORDER_BY_CLAUSE);
9543    
9544                            String[] orderByFields = orderByComparator.getOrderByFields();
9545    
9546                            for (int i = 0; i < orderByFields.length; i++) {
9547                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9548                                    query.append(orderByFields[i]);
9549    
9550                                    if ((i + 1) < orderByFields.length) {
9551                                            if (orderByComparator.isAscending() ^ previous) {
9552                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9553                                            }
9554                                            else {
9555                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9556                                            }
9557                                    }
9558                                    else {
9559                                            if (orderByComparator.isAscending() ^ previous) {
9560                                                    query.append(ORDER_BY_ASC);
9561                                            }
9562                                            else {
9563                                                    query.append(ORDER_BY_DESC);
9564                                            }
9565                                    }
9566                            }
9567                    }
9568                    else {
9569                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9570                    }
9571    
9572                    String sql = query.toString();
9573    
9574                    Query q = session.createQuery(sql);
9575    
9576                    q.setFirstResult(0);
9577                    q.setMaxResults(2);
9578    
9579                    QueryPos qPos = QueryPos.getInstance(q);
9580    
9581                    qPos.add(threadId);
9582    
9583                    qPos.add(answer);
9584    
9585                    if (orderByComparator != null) {
9586                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9587    
9588                            for (Object value : values) {
9589                                    qPos.add(value);
9590                            }
9591                    }
9592    
9593                    List<MBMessage> list = q.list();
9594    
9595                    if (list.size() == 2) {
9596                            return list.get(1);
9597                    }
9598                    else {
9599                            return null;
9600                    }
9601            }
9602    
9603            /**
9604             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
9605             *
9606             * @param threadId the thread ID
9607             * @param answer the answer
9608             */
9609            @Override
9610            public void removeByT_A(long threadId, boolean answer) {
9611                    for (MBMessage mbMessage : findByT_A(threadId, answer,
9612                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9613                            remove(mbMessage);
9614                    }
9615            }
9616    
9617            /**
9618             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
9619             *
9620             * @param threadId the thread ID
9621             * @param answer the answer
9622             * @return the number of matching message-boards messages
9623             */
9624            @Override
9625            public int countByT_A(long threadId, boolean answer) {
9626                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9627    
9628                    Object[] finderArgs = new Object[] { threadId, answer };
9629    
9630                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9631                                    this);
9632    
9633                    if (count == null) {
9634                            StringBundler query = new StringBundler(3);
9635    
9636                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9637    
9638                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9639    
9640                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9641    
9642                            String sql = query.toString();
9643    
9644                            Session session = null;
9645    
9646                            try {
9647                                    session = openSession();
9648    
9649                                    Query q = session.createQuery(sql);
9650    
9651                                    QueryPos qPos = QueryPos.getInstance(q);
9652    
9653                                    qPos.add(threadId);
9654    
9655                                    qPos.add(answer);
9656    
9657                                    count = (Long)q.uniqueResult();
9658    
9659                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9660                            }
9661                            catch (Exception e) {
9662                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9663    
9664                                    throw processException(e);
9665                            }
9666                            finally {
9667                                    closeSession(session);
9668                            }
9669                    }
9670    
9671                    return count.intValue();
9672            }
9673    
9674            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9675            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9676            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9677                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9678                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9679                            new String[] {
9680                                    Long.class.getName(), Integer.class.getName(),
9681                                    
9682                            Integer.class.getName(), Integer.class.getName(),
9683                                    OrderByComparator.class.getName()
9684                            });
9685            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9686                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9687                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9688                            new String[] { Long.class.getName(), Integer.class.getName() },
9689                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9690                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9691                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9692            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9693                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9694                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9695                            new String[] { Long.class.getName(), Integer.class.getName() });
9696    
9697            /**
9698             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9699             *
9700             * @param threadId the thread ID
9701             * @param status the status
9702             * @return the matching message-boards messages
9703             */
9704            @Override
9705            public List<MBMessage> findByT_S(long threadId, int status) {
9706                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9707                            QueryUtil.ALL_POS, null);
9708            }
9709    
9710            /**
9711             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9712             *
9713             * <p>
9714             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9715             * </p>
9716             *
9717             * @param threadId the thread ID
9718             * @param status the status
9719             * @param start the lower bound of the range of message-boards messages
9720             * @param end the upper bound of the range of message-boards messages (not inclusive)
9721             * @return the range of matching message-boards messages
9722             */
9723            @Override
9724            public List<MBMessage> findByT_S(long threadId, int status, int start,
9725                    int end) {
9726                    return findByT_S(threadId, status, start, end, null);
9727            }
9728    
9729            /**
9730             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9731             *
9732             * <p>
9733             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9734             * </p>
9735             *
9736             * @param threadId the thread ID
9737             * @param status the status
9738             * @param start the lower bound of the range of message-boards messages
9739             * @param end the upper bound of the range of message-boards messages (not inclusive)
9740             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9741             * @return the ordered range of matching message-boards messages
9742             */
9743            @Override
9744            public List<MBMessage> findByT_S(long threadId, int status, int start,
9745                    int end, OrderByComparator<MBMessage> orderByComparator) {
9746                    boolean pagination = true;
9747                    FinderPath finderPath = null;
9748                    Object[] finderArgs = null;
9749    
9750                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9751                                    (orderByComparator == null)) {
9752                            pagination = false;
9753                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9754                            finderArgs = new Object[] { threadId, status };
9755                    }
9756                    else {
9757                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9758                            finderArgs = new Object[] {
9759                                            threadId, status,
9760                                            
9761                                            start, end, orderByComparator
9762                                    };
9763                    }
9764    
9765                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9766                                    finderArgs, this);
9767    
9768                    if ((list != null) && !list.isEmpty()) {
9769                            for (MBMessage mbMessage : list) {
9770                                    if ((threadId != mbMessage.getThreadId()) ||
9771                                                    (status != mbMessage.getStatus())) {
9772                                            list = null;
9773    
9774                                            break;
9775                                    }
9776                            }
9777                    }
9778    
9779                    if (list == null) {
9780                            StringBundler query = null;
9781    
9782                            if (orderByComparator != null) {
9783                                    query = new StringBundler(4 +
9784                                                    (orderByComparator.getOrderByFields().length * 3));
9785                            }
9786                            else {
9787                                    query = new StringBundler(4);
9788                            }
9789    
9790                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9791    
9792                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
9793    
9794                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
9795    
9796                            if (orderByComparator != null) {
9797                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9798                                            orderByComparator);
9799                            }
9800                            else
9801                             if (pagination) {
9802                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9803                            }
9804    
9805                            String sql = query.toString();
9806    
9807                            Session session = null;
9808    
9809                            try {
9810                                    session = openSession();
9811    
9812                                    Query q = session.createQuery(sql);
9813    
9814                                    QueryPos qPos = QueryPos.getInstance(q);
9815    
9816                                    qPos.add(threadId);
9817    
9818                                    qPos.add(status);
9819    
9820                                    if (!pagination) {
9821                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9822                                                            start, end, false);
9823    
9824                                            Collections.sort(list);
9825    
9826                                            list = Collections.unmodifiableList(list);
9827                                    }
9828                                    else {
9829                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9830                                                            start, end);
9831                                    }
9832    
9833                                    cacheResult(list);
9834    
9835                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9836                            }
9837                            catch (Exception e) {
9838                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9839    
9840                                    throw processException(e);
9841                            }
9842                            finally {
9843                                    closeSession(session);
9844                            }
9845                    }
9846    
9847                    return list;
9848            }
9849    
9850            /**
9851             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9852             *
9853             * @param threadId the thread ID
9854             * @param status the status
9855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9856             * @return the first matching message-boards message
9857             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9858             */
9859            @Override
9860            public MBMessage findByT_S_First(long threadId, int status,
9861                    OrderByComparator<MBMessage> orderByComparator)
9862                    throws NoSuchMessageException {
9863                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9864                                    orderByComparator);
9865    
9866                    if (mbMessage != null) {
9867                            return mbMessage;
9868                    }
9869    
9870                    StringBundler msg = new StringBundler(6);
9871    
9872                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9873    
9874                    msg.append("threadId=");
9875                    msg.append(threadId);
9876    
9877                    msg.append(", status=");
9878                    msg.append(status);
9879    
9880                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9881    
9882                    throw new NoSuchMessageException(msg.toString());
9883            }
9884    
9885            /**
9886             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9887             *
9888             * @param threadId the thread ID
9889             * @param status the status
9890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9891             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9892             */
9893            @Override
9894            public MBMessage fetchByT_S_First(long threadId, int status,
9895                    OrderByComparator<MBMessage> orderByComparator) {
9896                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9897                                    orderByComparator);
9898    
9899                    if (!list.isEmpty()) {
9900                            return list.get(0);
9901                    }
9902    
9903                    return null;
9904            }
9905    
9906            /**
9907             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9908             *
9909             * @param threadId the thread ID
9910             * @param status the status
9911             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9912             * @return the last matching message-boards message
9913             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9914             */
9915            @Override
9916            public MBMessage findByT_S_Last(long threadId, int status,
9917                    OrderByComparator<MBMessage> orderByComparator)
9918                    throws NoSuchMessageException {
9919                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9920                                    orderByComparator);
9921    
9922                    if (mbMessage != null) {
9923                            return mbMessage;
9924                    }
9925    
9926                    StringBundler msg = new StringBundler(6);
9927    
9928                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9929    
9930                    msg.append("threadId=");
9931                    msg.append(threadId);
9932    
9933                    msg.append(", status=");
9934                    msg.append(status);
9935    
9936                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9937    
9938                    throw new NoSuchMessageException(msg.toString());
9939            }
9940    
9941            /**
9942             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9943             *
9944             * @param threadId the thread ID
9945             * @param status the status
9946             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9947             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9948             */
9949            @Override
9950            public MBMessage fetchByT_S_Last(long threadId, int status,
9951                    OrderByComparator<MBMessage> orderByComparator) {
9952                    int count = countByT_S(threadId, status);
9953    
9954                    if (count == 0) {
9955                            return null;
9956                    }
9957    
9958                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9959                                    orderByComparator);
9960    
9961                    if (!list.isEmpty()) {
9962                            return list.get(0);
9963                    }
9964    
9965                    return null;
9966            }
9967    
9968            /**
9969             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9970             *
9971             * @param messageId the primary key of the current message-boards message
9972             * @param threadId the thread ID
9973             * @param status the status
9974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9975             * @return the previous, current, and next message-boards message
9976             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9977             */
9978            @Override
9979            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9980                    int status, OrderByComparator<MBMessage> orderByComparator)
9981                    throws NoSuchMessageException {
9982                    MBMessage mbMessage = findByPrimaryKey(messageId);
9983    
9984                    Session session = null;
9985    
9986                    try {
9987                            session = openSession();
9988    
9989                            MBMessage[] array = new MBMessageImpl[3];
9990    
9991                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9992                                            status, orderByComparator, true);
9993    
9994                            array[1] = mbMessage;
9995    
9996                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9997                                            status, orderByComparator, false);
9998    
9999                            return array;
10000                    }
10001                    catch (Exception e) {
10002                            throw processException(e);
10003                    }
10004                    finally {
10005                            closeSession(session);
10006                    }
10007            }
10008    
10009            protected MBMessage getByT_S_PrevAndNext(Session session,
10010                    MBMessage mbMessage, long threadId, int status,
10011                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10012                    StringBundler query = null;
10013    
10014                    if (orderByComparator != null) {
10015                            query = new StringBundler(6 +
10016                                            (orderByComparator.getOrderByFields().length * 6));
10017                    }
10018                    else {
10019                            query = new StringBundler(3);
10020                    }
10021    
10022                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10023    
10024                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10025    
10026                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10027    
10028                    if (orderByComparator != null) {
10029                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10030    
10031                            if (orderByConditionFields.length > 0) {
10032                                    query.append(WHERE_AND);
10033                            }
10034    
10035                            for (int i = 0; i < orderByConditionFields.length; i++) {
10036                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10037                                    query.append(orderByConditionFields[i]);
10038    
10039                                    if ((i + 1) < orderByConditionFields.length) {
10040                                            if (orderByComparator.isAscending() ^ previous) {
10041                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10042                                            }
10043                                            else {
10044                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10045                                            }
10046                                    }
10047                                    else {
10048                                            if (orderByComparator.isAscending() ^ previous) {
10049                                                    query.append(WHERE_GREATER_THAN);
10050                                            }
10051                                            else {
10052                                                    query.append(WHERE_LESSER_THAN);
10053                                            }
10054                                    }
10055                            }
10056    
10057                            query.append(ORDER_BY_CLAUSE);
10058    
10059                            String[] orderByFields = orderByComparator.getOrderByFields();
10060    
10061                            for (int i = 0; i < orderByFields.length; i++) {
10062                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10063                                    query.append(orderByFields[i]);
10064    
10065                                    if ((i + 1) < orderByFields.length) {
10066                                            if (orderByComparator.isAscending() ^ previous) {
10067                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10068                                            }
10069                                            else {
10070                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10071                                            }
10072                                    }
10073                                    else {
10074                                            if (orderByComparator.isAscending() ^ previous) {
10075                                                    query.append(ORDER_BY_ASC);
10076                                            }
10077                                            else {
10078                                                    query.append(ORDER_BY_DESC);
10079                                            }
10080                                    }
10081                            }
10082                    }
10083                    else {
10084                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10085                    }
10086    
10087                    String sql = query.toString();
10088    
10089                    Query q = session.createQuery(sql);
10090    
10091                    q.setFirstResult(0);
10092                    q.setMaxResults(2);
10093    
10094                    QueryPos qPos = QueryPos.getInstance(q);
10095    
10096                    qPos.add(threadId);
10097    
10098                    qPos.add(status);
10099    
10100                    if (orderByComparator != null) {
10101                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10102    
10103                            for (Object value : values) {
10104                                    qPos.add(value);
10105                            }
10106                    }
10107    
10108                    List<MBMessage> list = q.list();
10109    
10110                    if (list.size() == 2) {
10111                            return list.get(1);
10112                    }
10113                    else {
10114                            return null;
10115                    }
10116            }
10117    
10118            /**
10119             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10120             *
10121             * @param threadId the thread ID
10122             * @param status the status
10123             */
10124            @Override
10125            public void removeByT_S(long threadId, int status) {
10126                    for (MBMessage mbMessage : findByT_S(threadId, status,
10127                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10128                            remove(mbMessage);
10129                    }
10130            }
10131    
10132            /**
10133             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10134             *
10135             * @param threadId the thread ID
10136             * @param status the status
10137             * @return the number of matching message-boards messages
10138             */
10139            @Override
10140            public int countByT_S(long threadId, int status) {
10141                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10142    
10143                    Object[] finderArgs = new Object[] { threadId, status };
10144    
10145                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10146                                    this);
10147    
10148                    if (count == null) {
10149                            StringBundler query = new StringBundler(3);
10150    
10151                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10152    
10153                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10154    
10155                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10156    
10157                            String sql = query.toString();
10158    
10159                            Session session = null;
10160    
10161                            try {
10162                                    session = openSession();
10163    
10164                                    Query q = session.createQuery(sql);
10165    
10166                                    QueryPos qPos = QueryPos.getInstance(q);
10167    
10168                                    qPos.add(threadId);
10169    
10170                                    qPos.add(status);
10171    
10172                                    count = (Long)q.uniqueResult();
10173    
10174                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10175                            }
10176                            catch (Exception e) {
10177                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10178    
10179                                    throw processException(e);
10180                            }
10181                            finally {
10182                                    closeSession(session);
10183                            }
10184                    }
10185    
10186                    return count.intValue();
10187            }
10188    
10189            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10190            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10191            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10192                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10193                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10194                            new String[] {
10195                                    Long.class.getName(), Integer.class.getName(),
10196                                    
10197                            Integer.class.getName(), Integer.class.getName(),
10198                                    OrderByComparator.class.getName()
10199                            });
10200            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10201                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10202                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10203                            new String[] { Long.class.getName(), Integer.class.getName() },
10204                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10205                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10206                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10207            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10210                            new String[] { Long.class.getName(), Integer.class.getName() });
10211    
10212            /**
10213             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10214             *
10215             * @param threadId the thread ID
10216             * @param status the status
10217             * @return the matching message-boards messages
10218             */
10219            @Override
10220            public List<MBMessage> findByTR_S(long threadId, int status) {
10221                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10222                            QueryUtil.ALL_POS, null);
10223            }
10224    
10225            /**
10226             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10227             *
10228             * <p>
10229             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10230             * </p>
10231             *
10232             * @param threadId the thread ID
10233             * @param status the status
10234             * @param start the lower bound of the range of message-boards messages
10235             * @param end the upper bound of the range of message-boards messages (not inclusive)
10236             * @return the range of matching message-boards messages
10237             */
10238            @Override
10239            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10240                    int end) {
10241                    return findByTR_S(threadId, status, start, end, null);
10242            }
10243    
10244            /**
10245             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10246             *
10247             * <p>
10248             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10249             * </p>
10250             *
10251             * @param threadId the thread ID
10252             * @param status the status
10253             * @param start the lower bound of the range of message-boards messages
10254             * @param end the upper bound of the range of message-boards messages (not inclusive)
10255             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10256             * @return the ordered range of matching message-boards messages
10257             */
10258            @Override
10259            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10260                    int end, OrderByComparator<MBMessage> orderByComparator) {
10261                    boolean pagination = true;
10262                    FinderPath finderPath = null;
10263                    Object[] finderArgs = null;
10264    
10265                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10266                                    (orderByComparator == null)) {
10267                            pagination = false;
10268                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10269                            finderArgs = new Object[] { threadId, status };
10270                    }
10271                    else {
10272                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10273                            finderArgs = new Object[] {
10274                                            threadId, status,
10275                                            
10276                                            start, end, orderByComparator
10277                                    };
10278                    }
10279    
10280                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10281                                    finderArgs, this);
10282    
10283                    if ((list != null) && !list.isEmpty()) {
10284                            for (MBMessage mbMessage : list) {
10285                                    if ((threadId != mbMessage.getThreadId()) ||
10286                                                    (status != mbMessage.getStatus())) {
10287                                            list = null;
10288    
10289                                            break;
10290                                    }
10291                            }
10292                    }
10293    
10294                    if (list == null) {
10295                            StringBundler query = null;
10296    
10297                            if (orderByComparator != null) {
10298                                    query = new StringBundler(4 +
10299                                                    (orderByComparator.getOrderByFields().length * 3));
10300                            }
10301                            else {
10302                                    query = new StringBundler(4);
10303                            }
10304    
10305                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10306    
10307                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10308    
10309                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10310    
10311                            if (orderByComparator != null) {
10312                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10313                                            orderByComparator);
10314                            }
10315                            else
10316                             if (pagination) {
10317                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10318                            }
10319    
10320                            String sql = query.toString();
10321    
10322                            Session session = null;
10323    
10324                            try {
10325                                    session = openSession();
10326    
10327                                    Query q = session.createQuery(sql);
10328    
10329                                    QueryPos qPos = QueryPos.getInstance(q);
10330    
10331                                    qPos.add(threadId);
10332    
10333                                    qPos.add(status);
10334    
10335                                    if (!pagination) {
10336                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10337                                                            start, end, false);
10338    
10339                                            Collections.sort(list);
10340    
10341                                            list = Collections.unmodifiableList(list);
10342                                    }
10343                                    else {
10344                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10345                                                            start, end);
10346                                    }
10347    
10348                                    cacheResult(list);
10349    
10350                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10351                            }
10352                            catch (Exception e) {
10353                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10354    
10355                                    throw processException(e);
10356                            }
10357                            finally {
10358                                    closeSession(session);
10359                            }
10360                    }
10361    
10362                    return list;
10363            }
10364    
10365            /**
10366             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10367             *
10368             * @param threadId the thread ID
10369             * @param status the status
10370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10371             * @return the first matching message-boards message
10372             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10373             */
10374            @Override
10375            public MBMessage findByTR_S_First(long threadId, int status,
10376                    OrderByComparator<MBMessage> orderByComparator)
10377                    throws NoSuchMessageException {
10378                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10379                                    orderByComparator);
10380    
10381                    if (mbMessage != null) {
10382                            return mbMessage;
10383                    }
10384    
10385                    StringBundler msg = new StringBundler(6);
10386    
10387                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10388    
10389                    msg.append("threadId=");
10390                    msg.append(threadId);
10391    
10392                    msg.append(", status=");
10393                    msg.append(status);
10394    
10395                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10396    
10397                    throw new NoSuchMessageException(msg.toString());
10398            }
10399    
10400            /**
10401             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10402             *
10403             * @param threadId the thread ID
10404             * @param status the status
10405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10406             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10407             */
10408            @Override
10409            public MBMessage fetchByTR_S_First(long threadId, int status,
10410                    OrderByComparator<MBMessage> orderByComparator) {
10411                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10412                                    orderByComparator);
10413    
10414                    if (!list.isEmpty()) {
10415                            return list.get(0);
10416                    }
10417    
10418                    return null;
10419            }
10420    
10421            /**
10422             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10423             *
10424             * @param threadId the thread ID
10425             * @param status the status
10426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10427             * @return the last matching message-boards message
10428             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10429             */
10430            @Override
10431            public MBMessage findByTR_S_Last(long threadId, int status,
10432                    OrderByComparator<MBMessage> orderByComparator)
10433                    throws NoSuchMessageException {
10434                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10435                                    orderByComparator);
10436    
10437                    if (mbMessage != null) {
10438                            return mbMessage;
10439                    }
10440    
10441                    StringBundler msg = new StringBundler(6);
10442    
10443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10444    
10445                    msg.append("threadId=");
10446                    msg.append(threadId);
10447    
10448                    msg.append(", status=");
10449                    msg.append(status);
10450    
10451                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10452    
10453                    throw new NoSuchMessageException(msg.toString());
10454            }
10455    
10456            /**
10457             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10458             *
10459             * @param threadId the thread ID
10460             * @param status the status
10461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10462             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10463             */
10464            @Override
10465            public MBMessage fetchByTR_S_Last(long threadId, int status,
10466                    OrderByComparator<MBMessage> orderByComparator) {
10467                    int count = countByTR_S(threadId, status);
10468    
10469                    if (count == 0) {
10470                            return null;
10471                    }
10472    
10473                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10474                                    orderByComparator);
10475    
10476                    if (!list.isEmpty()) {
10477                            return list.get(0);
10478                    }
10479    
10480                    return null;
10481            }
10482    
10483            /**
10484             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10485             *
10486             * @param messageId the primary key of the current message-boards message
10487             * @param threadId the thread ID
10488             * @param status the status
10489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10490             * @return the previous, current, and next message-boards message
10491             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10492             */
10493            @Override
10494            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10495                    int status, OrderByComparator<MBMessage> orderByComparator)
10496                    throws NoSuchMessageException {
10497                    MBMessage mbMessage = findByPrimaryKey(messageId);
10498    
10499                    Session session = null;
10500    
10501                    try {
10502                            session = openSession();
10503    
10504                            MBMessage[] array = new MBMessageImpl[3];
10505    
10506                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10507                                            status, orderByComparator, true);
10508    
10509                            array[1] = mbMessage;
10510    
10511                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10512                                            status, orderByComparator, false);
10513    
10514                            return array;
10515                    }
10516                    catch (Exception e) {
10517                            throw processException(e);
10518                    }
10519                    finally {
10520                            closeSession(session);
10521                    }
10522            }
10523    
10524            protected MBMessage getByTR_S_PrevAndNext(Session session,
10525                    MBMessage mbMessage, long threadId, int status,
10526                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10527                    StringBundler query = null;
10528    
10529                    if (orderByComparator != null) {
10530                            query = new StringBundler(6 +
10531                                            (orderByComparator.getOrderByFields().length * 6));
10532                    }
10533                    else {
10534                            query = new StringBundler(3);
10535                    }
10536    
10537                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10538    
10539                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10540    
10541                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10542    
10543                    if (orderByComparator != null) {
10544                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10545    
10546                            if (orderByConditionFields.length > 0) {
10547                                    query.append(WHERE_AND);
10548                            }
10549    
10550                            for (int i = 0; i < orderByConditionFields.length; i++) {
10551                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10552                                    query.append(orderByConditionFields[i]);
10553    
10554                                    if ((i + 1) < orderByConditionFields.length) {
10555                                            if (orderByComparator.isAscending() ^ previous) {
10556                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10557                                            }
10558                                            else {
10559                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10560                                            }
10561                                    }
10562                                    else {
10563                                            if (orderByComparator.isAscending() ^ previous) {
10564                                                    query.append(WHERE_GREATER_THAN);
10565                                            }
10566                                            else {
10567                                                    query.append(WHERE_LESSER_THAN);
10568                                            }
10569                                    }
10570                            }
10571    
10572                            query.append(ORDER_BY_CLAUSE);
10573    
10574                            String[] orderByFields = orderByComparator.getOrderByFields();
10575    
10576                            for (int i = 0; i < orderByFields.length; i++) {
10577                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10578                                    query.append(orderByFields[i]);
10579    
10580                                    if ((i + 1) < orderByFields.length) {
10581                                            if (orderByComparator.isAscending() ^ previous) {
10582                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10583                                            }
10584                                            else {
10585                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10586                                            }
10587                                    }
10588                                    else {
10589                                            if (orderByComparator.isAscending() ^ previous) {
10590                                                    query.append(ORDER_BY_ASC);
10591                                            }
10592                                            else {
10593                                                    query.append(ORDER_BY_DESC);
10594                                            }
10595                                    }
10596                            }
10597                    }
10598                    else {
10599                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10600                    }
10601    
10602                    String sql = query.toString();
10603    
10604                    Query q = session.createQuery(sql);
10605    
10606                    q.setFirstResult(0);
10607                    q.setMaxResults(2);
10608    
10609                    QueryPos qPos = QueryPos.getInstance(q);
10610    
10611                    qPos.add(threadId);
10612    
10613                    qPos.add(status);
10614    
10615                    if (orderByComparator != null) {
10616                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10617    
10618                            for (Object value : values) {
10619                                    qPos.add(value);
10620                            }
10621                    }
10622    
10623                    List<MBMessage> list = q.list();
10624    
10625                    if (list.size() == 2) {
10626                            return list.get(1);
10627                    }
10628                    else {
10629                            return null;
10630                    }
10631            }
10632    
10633            /**
10634             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10635             *
10636             * @param threadId the thread ID
10637             * @param status the status
10638             */
10639            @Override
10640            public void removeByTR_S(long threadId, int status) {
10641                    for (MBMessage mbMessage : findByTR_S(threadId, status,
10642                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10643                            remove(mbMessage);
10644                    }
10645            }
10646    
10647            /**
10648             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10649             *
10650             * @param threadId the thread ID
10651             * @param status the status
10652             * @return the number of matching message-boards messages
10653             */
10654            @Override
10655            public int countByTR_S(long threadId, int status) {
10656                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10657    
10658                    Object[] finderArgs = new Object[] { threadId, status };
10659    
10660                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10661                                    this);
10662    
10663                    if (count == null) {
10664                            StringBundler query = new StringBundler(3);
10665    
10666                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10667    
10668                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10669    
10670                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10671    
10672                            String sql = query.toString();
10673    
10674                            Session session = null;
10675    
10676                            try {
10677                                    session = openSession();
10678    
10679                                    Query q = session.createQuery(sql);
10680    
10681                                    QueryPos qPos = QueryPos.getInstance(q);
10682    
10683                                    qPos.add(threadId);
10684    
10685                                    qPos.add(status);
10686    
10687                                    count = (Long)q.uniqueResult();
10688    
10689                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10690                            }
10691                            catch (Exception e) {
10692                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10693    
10694                                    throw processException(e);
10695                            }
10696                            finally {
10697                                    closeSession(session);
10698                            }
10699                    }
10700    
10701                    return count.intValue();
10702            }
10703    
10704            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10705            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10706            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10707                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10708                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10709                            new String[] {
10710                                    Long.class.getName(), Long.class.getName(),
10711                                    Integer.class.getName(),
10712                                    
10713                            Integer.class.getName(), Integer.class.getName(),
10714                                    OrderByComparator.class.getName()
10715                            });
10716            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10717                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10718                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10719                            new String[] {
10720                                    Long.class.getName(), Long.class.getName(),
10721                                    Integer.class.getName()
10722                            },
10723                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10724                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
10725                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10726                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10727            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10728                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10729                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10730                            new String[] {
10731                                    Long.class.getName(), Long.class.getName(),
10732                                    Integer.class.getName()
10733                            });
10734    
10735            /**
10736             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10737             *
10738             * @param groupId the group ID
10739             * @param userId the user ID
10740             * @param status the status
10741             * @return the matching message-boards messages
10742             */
10743            @Override
10744            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
10745                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10746                            QueryUtil.ALL_POS, null);
10747            }
10748    
10749            /**
10750             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10751             *
10752             * <p>
10753             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10754             * </p>
10755             *
10756             * @param groupId the group ID
10757             * @param userId the user ID
10758             * @param status the status
10759             * @param start the lower bound of the range of message-boards messages
10760             * @param end the upper bound of the range of message-boards messages (not inclusive)
10761             * @return the range of matching message-boards messages
10762             */
10763            @Override
10764            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10765                    int start, int end) {
10766                    return findByG_U_S(groupId, userId, status, start, end, null);
10767            }
10768    
10769            /**
10770             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10771             *
10772             * <p>
10773             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10774             * </p>
10775             *
10776             * @param groupId the group ID
10777             * @param userId the user ID
10778             * @param status the status
10779             * @param start the lower bound of the range of message-boards messages
10780             * @param end the upper bound of the range of message-boards messages (not inclusive)
10781             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10782             * @return the ordered range of matching message-boards messages
10783             */
10784            @Override
10785            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10786                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
10787                    boolean pagination = true;
10788                    FinderPath finderPath = null;
10789                    Object[] finderArgs = null;
10790    
10791                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10792                                    (orderByComparator == null)) {
10793                            pagination = false;
10794                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10795                            finderArgs = new Object[] { groupId, userId, status };
10796                    }
10797                    else {
10798                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10799                            finderArgs = new Object[] {
10800                                            groupId, userId, status,
10801                                            
10802                                            start, end, orderByComparator
10803                                    };
10804                    }
10805    
10806                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10807                                    finderArgs, this);
10808    
10809                    if ((list != null) && !list.isEmpty()) {
10810                            for (MBMessage mbMessage : list) {
10811                                    if ((groupId != mbMessage.getGroupId()) ||
10812                                                    (userId != mbMessage.getUserId()) ||
10813                                                    (status != mbMessage.getStatus())) {
10814                                            list = null;
10815    
10816                                            break;
10817                                    }
10818                            }
10819                    }
10820    
10821                    if (list == null) {
10822                            StringBundler query = null;
10823    
10824                            if (orderByComparator != null) {
10825                                    query = new StringBundler(5 +
10826                                                    (orderByComparator.getOrderByFields().length * 3));
10827                            }
10828                            else {
10829                                    query = new StringBundler(5);
10830                            }
10831    
10832                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10833    
10834                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10835    
10836                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10837    
10838                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10839    
10840                            if (orderByComparator != null) {
10841                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10842                                            orderByComparator);
10843                            }
10844                            else
10845                             if (pagination) {
10846                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10847                            }
10848    
10849                            String sql = query.toString();
10850    
10851                            Session session = null;
10852    
10853                            try {
10854                                    session = openSession();
10855    
10856                                    Query q = session.createQuery(sql);
10857    
10858                                    QueryPos qPos = QueryPos.getInstance(q);
10859    
10860                                    qPos.add(groupId);
10861    
10862                                    qPos.add(userId);
10863    
10864                                    qPos.add(status);
10865    
10866                                    if (!pagination) {
10867                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10868                                                            start, end, false);
10869    
10870                                            Collections.sort(list);
10871    
10872                                            list = Collections.unmodifiableList(list);
10873                                    }
10874                                    else {
10875                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10876                                                            start, end);
10877                                    }
10878    
10879                                    cacheResult(list);
10880    
10881                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10882                            }
10883                            catch (Exception e) {
10884                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10885    
10886                                    throw processException(e);
10887                            }
10888                            finally {
10889                                    closeSession(session);
10890                            }
10891                    }
10892    
10893                    return list;
10894            }
10895    
10896            /**
10897             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10898             *
10899             * @param groupId the group ID
10900             * @param userId the user ID
10901             * @param status the status
10902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10903             * @return the first matching message-boards message
10904             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10905             */
10906            @Override
10907            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10908                    OrderByComparator<MBMessage> orderByComparator)
10909                    throws NoSuchMessageException {
10910                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10911                                    orderByComparator);
10912    
10913                    if (mbMessage != null) {
10914                            return mbMessage;
10915                    }
10916    
10917                    StringBundler msg = new StringBundler(8);
10918    
10919                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10920    
10921                    msg.append("groupId=");
10922                    msg.append(groupId);
10923    
10924                    msg.append(", userId=");
10925                    msg.append(userId);
10926    
10927                    msg.append(", status=");
10928                    msg.append(status);
10929    
10930                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10931    
10932                    throw new NoSuchMessageException(msg.toString());
10933            }
10934    
10935            /**
10936             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10937             *
10938             * @param groupId the group ID
10939             * @param userId the user ID
10940             * @param status the status
10941             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10942             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10943             */
10944            @Override
10945            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10946                    OrderByComparator<MBMessage> orderByComparator) {
10947                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10948                                    orderByComparator);
10949    
10950                    if (!list.isEmpty()) {
10951                            return list.get(0);
10952                    }
10953    
10954                    return null;
10955            }
10956    
10957            /**
10958             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10959             *
10960             * @param groupId the group ID
10961             * @param userId the user ID
10962             * @param status the status
10963             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10964             * @return the last matching message-boards message
10965             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10966             */
10967            @Override
10968            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10969                    OrderByComparator<MBMessage> orderByComparator)
10970                    throws NoSuchMessageException {
10971                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10972                                    orderByComparator);
10973    
10974                    if (mbMessage != null) {
10975                            return mbMessage;
10976                    }
10977    
10978                    StringBundler msg = new StringBundler(8);
10979    
10980                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10981    
10982                    msg.append("groupId=");
10983                    msg.append(groupId);
10984    
10985                    msg.append(", userId=");
10986                    msg.append(userId);
10987    
10988                    msg.append(", status=");
10989                    msg.append(status);
10990    
10991                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10992    
10993                    throw new NoSuchMessageException(msg.toString());
10994            }
10995    
10996            /**
10997             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10998             *
10999             * @param groupId the group ID
11000             * @param userId the user ID
11001             * @param status the status
11002             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11003             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11004             */
11005            @Override
11006            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11007                    OrderByComparator<MBMessage> orderByComparator) {
11008                    int count = countByG_U_S(groupId, userId, status);
11009    
11010                    if (count == 0) {
11011                            return null;
11012                    }
11013    
11014                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11015                                    count, orderByComparator);
11016    
11017                    if (!list.isEmpty()) {
11018                            return list.get(0);
11019                    }
11020    
11021                    return null;
11022            }
11023    
11024            /**
11025             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11026             *
11027             * @param messageId the primary key of the current message-boards message
11028             * @param groupId the group ID
11029             * @param userId the user ID
11030             * @param status the status
11031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11032             * @return the previous, current, and next message-boards message
11033             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11034             */
11035            @Override
11036            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11037                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11038                    throws NoSuchMessageException {
11039                    MBMessage mbMessage = findByPrimaryKey(messageId);
11040    
11041                    Session session = null;
11042    
11043                    try {
11044                            session = openSession();
11045    
11046                            MBMessage[] array = new MBMessageImpl[3];
11047    
11048                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11049                                            userId, status, orderByComparator, true);
11050    
11051                            array[1] = mbMessage;
11052    
11053                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11054                                            userId, status, orderByComparator, false);
11055    
11056                            return array;
11057                    }
11058                    catch (Exception e) {
11059                            throw processException(e);
11060                    }
11061                    finally {
11062                            closeSession(session);
11063                    }
11064            }
11065    
11066            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11067                    MBMessage mbMessage, long groupId, long userId, int status,
11068                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11069                    StringBundler query = null;
11070    
11071                    if (orderByComparator != null) {
11072                            query = new StringBundler(6 +
11073                                            (orderByComparator.getOrderByFields().length * 6));
11074                    }
11075                    else {
11076                            query = new StringBundler(3);
11077                    }
11078    
11079                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11080    
11081                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11082    
11083                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11084    
11085                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11086    
11087                    if (orderByComparator != null) {
11088                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11089    
11090                            if (orderByConditionFields.length > 0) {
11091                                    query.append(WHERE_AND);
11092                            }
11093    
11094                            for (int i = 0; i < orderByConditionFields.length; i++) {
11095                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11096                                    query.append(orderByConditionFields[i]);
11097    
11098                                    if ((i + 1) < orderByConditionFields.length) {
11099                                            if (orderByComparator.isAscending() ^ previous) {
11100                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11101                                            }
11102                                            else {
11103                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11104                                            }
11105                                    }
11106                                    else {
11107                                            if (orderByComparator.isAscending() ^ previous) {
11108                                                    query.append(WHERE_GREATER_THAN);
11109                                            }
11110                                            else {
11111                                                    query.append(WHERE_LESSER_THAN);
11112                                            }
11113                                    }
11114                            }
11115    
11116                            query.append(ORDER_BY_CLAUSE);
11117    
11118                            String[] orderByFields = orderByComparator.getOrderByFields();
11119    
11120                            for (int i = 0; i < orderByFields.length; i++) {
11121                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11122                                    query.append(orderByFields[i]);
11123    
11124                                    if ((i + 1) < orderByFields.length) {
11125                                            if (orderByComparator.isAscending() ^ previous) {
11126                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11127                                            }
11128                                            else {
11129                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11130                                            }
11131                                    }
11132                                    else {
11133                                            if (orderByComparator.isAscending() ^ previous) {
11134                                                    query.append(ORDER_BY_ASC);
11135                                            }
11136                                            else {
11137                                                    query.append(ORDER_BY_DESC);
11138                                            }
11139                                    }
11140                            }
11141                    }
11142                    else {
11143                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11144                    }
11145    
11146                    String sql = query.toString();
11147    
11148                    Query q = session.createQuery(sql);
11149    
11150                    q.setFirstResult(0);
11151                    q.setMaxResults(2);
11152    
11153                    QueryPos qPos = QueryPos.getInstance(q);
11154    
11155                    qPos.add(groupId);
11156    
11157                    qPos.add(userId);
11158    
11159                    qPos.add(status);
11160    
11161                    if (orderByComparator != null) {
11162                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11163    
11164                            for (Object value : values) {
11165                                    qPos.add(value);
11166                            }
11167                    }
11168    
11169                    List<MBMessage> list = q.list();
11170    
11171                    if (list.size() == 2) {
11172                            return list.get(1);
11173                    }
11174                    else {
11175                            return null;
11176                    }
11177            }
11178    
11179            /**
11180             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11181             *
11182             * @param groupId the group ID
11183             * @param userId the user ID
11184             * @param status the status
11185             * @return the matching message-boards messages that the user has permission to view
11186             */
11187            @Override
11188            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11189                    int status) {
11190                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11191                            QueryUtil.ALL_POS, null);
11192            }
11193    
11194            /**
11195             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11196             *
11197             * <p>
11198             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11199             * </p>
11200             *
11201             * @param groupId the group ID
11202             * @param userId the user ID
11203             * @param status the status
11204             * @param start the lower bound of the range of message-boards messages
11205             * @param end the upper bound of the range of message-boards messages (not inclusive)
11206             * @return the range of matching message-boards messages that the user has permission to view
11207             */
11208            @Override
11209            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11210                    int status, int start, int end) {
11211                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11212            }
11213    
11214            /**
11215             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63; and status = &#63;.
11216             *
11217             * <p>
11218             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11219             * </p>
11220             *
11221             * @param groupId the group ID
11222             * @param userId the user ID
11223             * @param status the status
11224             * @param start the lower bound of the range of message-boards messages
11225             * @param end the upper bound of the range of message-boards messages (not inclusive)
11226             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11227             * @return the ordered range of matching message-boards messages that the user has permission to view
11228             */
11229            @Override
11230            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11231                    int status, int start, int end,
11232                    OrderByComparator<MBMessage> orderByComparator) {
11233                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11234                            return findByG_U_S(groupId, userId, status, start, end,
11235                                    orderByComparator);
11236                    }
11237    
11238                    StringBundler query = null;
11239    
11240                    if (orderByComparator != null) {
11241                            query = new StringBundler(5 +
11242                                            (orderByComparator.getOrderByFields().length * 3));
11243                    }
11244                    else {
11245                            query = new StringBundler(5);
11246                    }
11247    
11248                    if (getDB().isSupportsInlineDistinct()) {
11249                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11250                    }
11251                    else {
11252                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11253                    }
11254    
11255                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11256    
11257                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11258    
11259                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11260    
11261                    if (!getDB().isSupportsInlineDistinct()) {
11262                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11263                    }
11264    
11265                    if (orderByComparator != null) {
11266                            if (getDB().isSupportsInlineDistinct()) {
11267                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11268                                            orderByComparator, true);
11269                            }
11270                            else {
11271                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11272                                            orderByComparator, true);
11273                            }
11274                    }
11275                    else {
11276                            if (getDB().isSupportsInlineDistinct()) {
11277                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11278                            }
11279                            else {
11280                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11281                            }
11282                    }
11283    
11284                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11285                                    MBMessage.class.getName(),
11286                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11287    
11288                    Session session = null;
11289    
11290                    try {
11291                            session = openSession();
11292    
11293                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11294    
11295                            if (getDB().isSupportsInlineDistinct()) {
11296                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11297                            }
11298                            else {
11299                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11300                            }
11301    
11302                            QueryPos qPos = QueryPos.getInstance(q);
11303    
11304                            qPos.add(groupId);
11305    
11306                            qPos.add(userId);
11307    
11308                            qPos.add(status);
11309    
11310                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11311                    }
11312                    catch (Exception e) {
11313                            throw processException(e);
11314                    }
11315                    finally {
11316                            closeSession(session);
11317                    }
11318            }
11319    
11320            /**
11321             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11322             *
11323             * @param messageId the primary key of the current message-boards message
11324             * @param groupId the group ID
11325             * @param userId the user ID
11326             * @param status the status
11327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11328             * @return the previous, current, and next message-boards message
11329             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11330             */
11331            @Override
11332            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11333                    long groupId, long userId, int status,
11334                    OrderByComparator<MBMessage> orderByComparator)
11335                    throws NoSuchMessageException {
11336                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11337                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11338                                    orderByComparator);
11339                    }
11340    
11341                    MBMessage mbMessage = findByPrimaryKey(messageId);
11342    
11343                    Session session = null;
11344    
11345                    try {
11346                            session = openSession();
11347    
11348                            MBMessage[] array = new MBMessageImpl[3];
11349    
11350                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11351                                            groupId, userId, status, orderByComparator, true);
11352    
11353                            array[1] = mbMessage;
11354    
11355                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11356                                            groupId, userId, status, orderByComparator, false);
11357    
11358                            return array;
11359                    }
11360                    catch (Exception e) {
11361                            throw processException(e);
11362                    }
11363                    finally {
11364                            closeSession(session);
11365                    }
11366            }
11367    
11368            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11369                    MBMessage mbMessage, long groupId, long userId, int status,
11370                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11371                    StringBundler query = null;
11372    
11373                    if (orderByComparator != null) {
11374                            query = new StringBundler(6 +
11375                                            (orderByComparator.getOrderByFields().length * 6));
11376                    }
11377                    else {
11378                            query = new StringBundler(3);
11379                    }
11380    
11381                    if (getDB().isSupportsInlineDistinct()) {
11382                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11383                    }
11384                    else {
11385                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11386                    }
11387    
11388                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11389    
11390                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11391    
11392                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11393    
11394                    if (!getDB().isSupportsInlineDistinct()) {
11395                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11396                    }
11397    
11398                    if (orderByComparator != null) {
11399                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11400    
11401                            if (orderByConditionFields.length > 0) {
11402                                    query.append(WHERE_AND);
11403                            }
11404    
11405                            for (int i = 0; i < orderByConditionFields.length; i++) {
11406                                    if (getDB().isSupportsInlineDistinct()) {
11407                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11408                                    }
11409                                    else {
11410                                            query.append(_ORDER_BY_ENTITY_TABLE);
11411                                    }
11412    
11413                                    query.append(orderByConditionFields[i]);
11414    
11415                                    if ((i + 1) < orderByConditionFields.length) {
11416                                            if (orderByComparator.isAscending() ^ previous) {
11417                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11418                                            }
11419                                            else {
11420                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11421                                            }
11422                                    }
11423                                    else {
11424                                            if (orderByComparator.isAscending() ^ previous) {
11425                                                    query.append(WHERE_GREATER_THAN);
11426                                            }
11427                                            else {
11428                                                    query.append(WHERE_LESSER_THAN);
11429                                            }
11430                                    }
11431                            }
11432    
11433                            query.append(ORDER_BY_CLAUSE);
11434    
11435                            String[] orderByFields = orderByComparator.getOrderByFields();
11436    
11437                            for (int i = 0; i < orderByFields.length; i++) {
11438                                    if (getDB().isSupportsInlineDistinct()) {
11439                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11440                                    }
11441                                    else {
11442                                            query.append(_ORDER_BY_ENTITY_TABLE);
11443                                    }
11444    
11445                                    query.append(orderByFields[i]);
11446    
11447                                    if ((i + 1) < orderByFields.length) {
11448                                            if (orderByComparator.isAscending() ^ previous) {
11449                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11450                                            }
11451                                            else {
11452                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11453                                            }
11454                                    }
11455                                    else {
11456                                            if (orderByComparator.isAscending() ^ previous) {
11457                                                    query.append(ORDER_BY_ASC);
11458                                            }
11459                                            else {
11460                                                    query.append(ORDER_BY_DESC);
11461                                            }
11462                                    }
11463                            }
11464                    }
11465                    else {
11466                            if (getDB().isSupportsInlineDistinct()) {
11467                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11468                            }
11469                            else {
11470                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11471                            }
11472                    }
11473    
11474                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11475                                    MBMessage.class.getName(),
11476                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11477    
11478                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11479    
11480                    q.setFirstResult(0);
11481                    q.setMaxResults(2);
11482    
11483                    if (getDB().isSupportsInlineDistinct()) {
11484                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11485                    }
11486                    else {
11487                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11488                    }
11489    
11490                    QueryPos qPos = QueryPos.getInstance(q);
11491    
11492                    qPos.add(groupId);
11493    
11494                    qPos.add(userId);
11495    
11496                    qPos.add(status);
11497    
11498                    if (orderByComparator != null) {
11499                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11500    
11501                            for (Object value : values) {
11502                                    qPos.add(value);
11503                            }
11504                    }
11505    
11506                    List<MBMessage> list = q.list();
11507    
11508                    if (list.size() == 2) {
11509                            return list.get(1);
11510                    }
11511                    else {
11512                            return null;
11513                    }
11514            }
11515    
11516            /**
11517             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
11518             *
11519             * @param groupId the group ID
11520             * @param userId the user ID
11521             * @param status the status
11522             */
11523            @Override
11524            public void removeByG_U_S(long groupId, long userId, int status) {
11525                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11526                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11527                            remove(mbMessage);
11528                    }
11529            }
11530    
11531            /**
11532             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11533             *
11534             * @param groupId the group ID
11535             * @param userId the user ID
11536             * @param status the status
11537             * @return the number of matching message-boards messages
11538             */
11539            @Override
11540            public int countByG_U_S(long groupId, long userId, int status) {
11541                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11542    
11543                    Object[] finderArgs = new Object[] { groupId, userId, status };
11544    
11545                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11546                                    this);
11547    
11548                    if (count == null) {
11549                            StringBundler query = new StringBundler(4);
11550    
11551                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11552    
11553                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11554    
11555                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11556    
11557                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11558    
11559                            String sql = query.toString();
11560    
11561                            Session session = null;
11562    
11563                            try {
11564                                    session = openSession();
11565    
11566                                    Query q = session.createQuery(sql);
11567    
11568                                    QueryPos qPos = QueryPos.getInstance(q);
11569    
11570                                    qPos.add(groupId);
11571    
11572                                    qPos.add(userId);
11573    
11574                                    qPos.add(status);
11575    
11576                                    count = (Long)q.uniqueResult();
11577    
11578                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11579                            }
11580                            catch (Exception e) {
11581                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11582    
11583                                    throw processException(e);
11584                            }
11585                            finally {
11586                                    closeSession(session);
11587                            }
11588                    }
11589    
11590                    return count.intValue();
11591            }
11592    
11593            /**
11594             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11595             *
11596             * @param groupId the group ID
11597             * @param userId the user ID
11598             * @param status the status
11599             * @return the number of matching message-boards messages that the user has permission to view
11600             */
11601            @Override
11602            public int filterCountByG_U_S(long groupId, long userId, int status) {
11603                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11604                            return countByG_U_S(groupId, userId, status);
11605                    }
11606    
11607                    StringBundler query = new StringBundler(4);
11608    
11609                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11610    
11611                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11612    
11613                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11614    
11615                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11616    
11617                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11618                                    MBMessage.class.getName(),
11619                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11620    
11621                    Session session = null;
11622    
11623                    try {
11624                            session = openSession();
11625    
11626                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11627    
11628                            q.addScalar(COUNT_COLUMN_NAME,
11629                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11630    
11631                            QueryPos qPos = QueryPos.getInstance(q);
11632    
11633                            qPos.add(groupId);
11634    
11635                            qPos.add(userId);
11636    
11637                            qPos.add(status);
11638    
11639                            Long count = (Long)q.uniqueResult();
11640    
11641                            return count.intValue();
11642                    }
11643                    catch (Exception e) {
11644                            throw processException(e);
11645                    }
11646                    finally {
11647                            closeSession(session);
11648                    }
11649            }
11650    
11651            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11652            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11653            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11654            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11655                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11656                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11657                            new String[] {
11658                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
11659                                    
11660                            Integer.class.getName(), Integer.class.getName(),
11661                                    OrderByComparator.class.getName()
11662                            });
11663            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11664                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11665                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11666                            new String[] {
11667                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11668                            },
11669                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11670                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11671                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11672                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11673            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11674                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11675                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11676                            new String[] {
11677                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11678                            });
11679    
11680            /**
11681             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11682             *
11683             * @param groupId the group ID
11684             * @param categoryId the category ID
11685             * @param threadId the thread ID
11686             * @return the matching message-boards messages
11687             */
11688            @Override
11689            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11690                    long threadId) {
11691                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11692                            QueryUtil.ALL_POS, null);
11693            }
11694    
11695            /**
11696             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11697             *
11698             * <p>
11699             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11700             * </p>
11701             *
11702             * @param groupId the group ID
11703             * @param categoryId the category ID
11704             * @param threadId the thread ID
11705             * @param start the lower bound of the range of message-boards messages
11706             * @param end the upper bound of the range of message-boards messages (not inclusive)
11707             * @return the range of matching message-boards messages
11708             */
11709            @Override
11710            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11711                    long threadId, int start, int end) {
11712                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
11713            }
11714    
11715            /**
11716             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11717             *
11718             * <p>
11719             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11720             * </p>
11721             *
11722             * @param groupId the group ID
11723             * @param categoryId the category ID
11724             * @param threadId the thread ID
11725             * @param start the lower bound of the range of message-boards messages
11726             * @param end the upper bound of the range of message-boards messages (not inclusive)
11727             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11728             * @return the ordered range of matching message-boards messages
11729             */
11730            @Override
11731            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11732                    long threadId, int start, int end,
11733                    OrderByComparator<MBMessage> orderByComparator) {
11734                    boolean pagination = true;
11735                    FinderPath finderPath = null;
11736                    Object[] finderArgs = null;
11737    
11738                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11739                                    (orderByComparator == null)) {
11740                            pagination = false;
11741                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
11742                            finderArgs = new Object[] { groupId, categoryId, threadId };
11743                    }
11744                    else {
11745                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
11746                            finderArgs = new Object[] {
11747                                            groupId, categoryId, threadId,
11748                                            
11749                                            start, end, orderByComparator
11750                                    };
11751                    }
11752    
11753                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11754                                    finderArgs, this);
11755    
11756                    if ((list != null) && !list.isEmpty()) {
11757                            for (MBMessage mbMessage : list) {
11758                                    if ((groupId != mbMessage.getGroupId()) ||
11759                                                    (categoryId != mbMessage.getCategoryId()) ||
11760                                                    (threadId != mbMessage.getThreadId())) {
11761                                            list = null;
11762    
11763                                            break;
11764                                    }
11765                            }
11766                    }
11767    
11768                    if (list == null) {
11769                            StringBundler query = null;
11770    
11771                            if (orderByComparator != null) {
11772                                    query = new StringBundler(5 +
11773                                                    (orderByComparator.getOrderByFields().length * 3));
11774                            }
11775                            else {
11776                                    query = new StringBundler(5);
11777                            }
11778    
11779                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11780    
11781                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11782    
11783                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11784    
11785                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11786    
11787                            if (orderByComparator != null) {
11788                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11789                                            orderByComparator);
11790                            }
11791                            else
11792                             if (pagination) {
11793                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11794                            }
11795    
11796                            String sql = query.toString();
11797    
11798                            Session session = null;
11799    
11800                            try {
11801                                    session = openSession();
11802    
11803                                    Query q = session.createQuery(sql);
11804    
11805                                    QueryPos qPos = QueryPos.getInstance(q);
11806    
11807                                    qPos.add(groupId);
11808    
11809                                    qPos.add(categoryId);
11810    
11811                                    qPos.add(threadId);
11812    
11813                                    if (!pagination) {
11814                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11815                                                            start, end, false);
11816    
11817                                            Collections.sort(list);
11818    
11819                                            list = Collections.unmodifiableList(list);
11820                                    }
11821                                    else {
11822                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11823                                                            start, end);
11824                                    }
11825    
11826                                    cacheResult(list);
11827    
11828                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11829                            }
11830                            catch (Exception e) {
11831                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11832    
11833                                    throw processException(e);
11834                            }
11835                            finally {
11836                                    closeSession(session);
11837                            }
11838                    }
11839    
11840                    return list;
11841            }
11842    
11843            /**
11844             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11845             *
11846             * @param groupId the group ID
11847             * @param categoryId the category ID
11848             * @param threadId the thread ID
11849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11850             * @return the first matching message-boards message
11851             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11852             */
11853            @Override
11854            public MBMessage findByG_C_T_First(long groupId, long categoryId,
11855                    long threadId, OrderByComparator<MBMessage> orderByComparator)
11856                    throws NoSuchMessageException {
11857                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11858                                    orderByComparator);
11859    
11860                    if (mbMessage != null) {
11861                            return mbMessage;
11862                    }
11863    
11864                    StringBundler msg = new StringBundler(8);
11865    
11866                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11867    
11868                    msg.append("groupId=");
11869                    msg.append(groupId);
11870    
11871                    msg.append(", categoryId=");
11872                    msg.append(categoryId);
11873    
11874                    msg.append(", threadId=");
11875                    msg.append(threadId);
11876    
11877                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11878    
11879                    throw new NoSuchMessageException(msg.toString());
11880            }
11881    
11882            /**
11883             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11884             *
11885             * @param groupId the group ID
11886             * @param categoryId the category ID
11887             * @param threadId the thread ID
11888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11889             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11890             */
11891            @Override
11892            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11893                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
11894                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11895                                    orderByComparator);
11896    
11897                    if (!list.isEmpty()) {
11898                            return list.get(0);
11899                    }
11900    
11901                    return null;
11902            }
11903    
11904            /**
11905             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11906             *
11907             * @param groupId the group ID
11908             * @param categoryId the category ID
11909             * @param threadId the thread ID
11910             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11911             * @return the last matching message-boards message
11912             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11913             */
11914            @Override
11915            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11916                    long threadId, OrderByComparator<MBMessage> orderByComparator)
11917                    throws NoSuchMessageException {
11918                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11919                                    orderByComparator);
11920    
11921                    if (mbMessage != null) {
11922                            return mbMessage;
11923                    }
11924    
11925                    StringBundler msg = new StringBundler(8);
11926    
11927                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11928    
11929                    msg.append("groupId=");
11930                    msg.append(groupId);
11931    
11932                    msg.append(", categoryId=");
11933                    msg.append(categoryId);
11934    
11935                    msg.append(", threadId=");
11936                    msg.append(threadId);
11937    
11938                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11939    
11940                    throw new NoSuchMessageException(msg.toString());
11941            }
11942    
11943            /**
11944             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11945             *
11946             * @param groupId the group ID
11947             * @param categoryId the category ID
11948             * @param threadId the thread ID
11949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11950             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11951             */
11952            @Override
11953            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11954                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
11955                    int count = countByG_C_T(groupId, categoryId, threadId);
11956    
11957                    if (count == 0) {
11958                            return null;
11959                    }
11960    
11961                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11962                                    count - 1, count, orderByComparator);
11963    
11964                    if (!list.isEmpty()) {
11965                            return list.get(0);
11966                    }
11967    
11968                    return null;
11969            }
11970    
11971            /**
11972             * 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;.
11973             *
11974             * @param messageId the primary key of the current message-boards message
11975             * @param groupId the group ID
11976             * @param categoryId the category ID
11977             * @param threadId the thread ID
11978             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11979             * @return the previous, current, and next message-boards message
11980             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11981             */
11982            @Override
11983            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11984                    long categoryId, long threadId,
11985                    OrderByComparator<MBMessage> orderByComparator)
11986                    throws NoSuchMessageException {
11987                    MBMessage mbMessage = findByPrimaryKey(messageId);
11988    
11989                    Session session = null;
11990    
11991                    try {
11992                            session = openSession();
11993    
11994                            MBMessage[] array = new MBMessageImpl[3];
11995    
11996                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11997                                            categoryId, threadId, orderByComparator, true);
11998    
11999                            array[1] = mbMessage;
12000    
12001                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12002                                            categoryId, threadId, orderByComparator, false);
12003    
12004                            return array;
12005                    }
12006                    catch (Exception e) {
12007                            throw processException(e);
12008                    }
12009                    finally {
12010                            closeSession(session);
12011                    }
12012            }
12013    
12014            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12015                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12016                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12017                    StringBundler query = null;
12018    
12019                    if (orderByComparator != null) {
12020                            query = new StringBundler(6 +
12021                                            (orderByComparator.getOrderByFields().length * 6));
12022                    }
12023                    else {
12024                            query = new StringBundler(3);
12025                    }
12026    
12027                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12028    
12029                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12030    
12031                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12032    
12033                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12034    
12035                    if (orderByComparator != null) {
12036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12037    
12038                            if (orderByConditionFields.length > 0) {
12039                                    query.append(WHERE_AND);
12040                            }
12041    
12042                            for (int i = 0; i < orderByConditionFields.length; i++) {
12043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12044                                    query.append(orderByConditionFields[i]);
12045    
12046                                    if ((i + 1) < orderByConditionFields.length) {
12047                                            if (orderByComparator.isAscending() ^ previous) {
12048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12049                                            }
12050                                            else {
12051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12052                                            }
12053                                    }
12054                                    else {
12055                                            if (orderByComparator.isAscending() ^ previous) {
12056                                                    query.append(WHERE_GREATER_THAN);
12057                                            }
12058                                            else {
12059                                                    query.append(WHERE_LESSER_THAN);
12060                                            }
12061                                    }
12062                            }
12063    
12064                            query.append(ORDER_BY_CLAUSE);
12065    
12066                            String[] orderByFields = orderByComparator.getOrderByFields();
12067    
12068                            for (int i = 0; i < orderByFields.length; i++) {
12069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12070                                    query.append(orderByFields[i]);
12071    
12072                                    if ((i + 1) < orderByFields.length) {
12073                                            if (orderByComparator.isAscending() ^ previous) {
12074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12075                                            }
12076                                            else {
12077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12078                                            }
12079                                    }
12080                                    else {
12081                                            if (orderByComparator.isAscending() ^ previous) {
12082                                                    query.append(ORDER_BY_ASC);
12083                                            }
12084                                            else {
12085                                                    query.append(ORDER_BY_DESC);
12086                                            }
12087                                    }
12088                            }
12089                    }
12090                    else {
12091                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12092                    }
12093    
12094                    String sql = query.toString();
12095    
12096                    Query q = session.createQuery(sql);
12097    
12098                    q.setFirstResult(0);
12099                    q.setMaxResults(2);
12100    
12101                    QueryPos qPos = QueryPos.getInstance(q);
12102    
12103                    qPos.add(groupId);
12104    
12105                    qPos.add(categoryId);
12106    
12107                    qPos.add(threadId);
12108    
12109                    if (orderByComparator != null) {
12110                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12111    
12112                            for (Object value : values) {
12113                                    qPos.add(value);
12114                            }
12115                    }
12116    
12117                    List<MBMessage> list = q.list();
12118    
12119                    if (list.size() == 2) {
12120                            return list.get(1);
12121                    }
12122                    else {
12123                            return null;
12124                    }
12125            }
12126    
12127            /**
12128             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12129             *
12130             * @param groupId the group ID
12131             * @param categoryId the category ID
12132             * @param threadId the thread ID
12133             * @return the matching message-boards messages that the user has permission to view
12134             */
12135            @Override
12136            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12137                    long threadId) {
12138                    return filterFindByG_C_T(groupId, categoryId, threadId,
12139                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12140            }
12141    
12142            /**
12143             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12144             *
12145             * <p>
12146             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12147             * </p>
12148             *
12149             * @param groupId the group ID
12150             * @param categoryId the category ID
12151             * @param threadId the thread ID
12152             * @param start the lower bound of the range of message-boards messages
12153             * @param end the upper bound of the range of message-boards messages (not inclusive)
12154             * @return the range of matching message-boards messages that the user has permission to view
12155             */
12156            @Override
12157            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12158                    long threadId, int start, int end) {
12159                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12160            }
12161    
12162            /**
12163             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12164             *
12165             * <p>
12166             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12167             * </p>
12168             *
12169             * @param groupId the group ID
12170             * @param categoryId the category ID
12171             * @param threadId the thread ID
12172             * @param start the lower bound of the range of message-boards messages
12173             * @param end the upper bound of the range of message-boards messages (not inclusive)
12174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12175             * @return the ordered range of matching message-boards messages that the user has permission to view
12176             */
12177            @Override
12178            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12179                    long threadId, int start, int end,
12180                    OrderByComparator<MBMessage> orderByComparator) {
12181                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12182                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12183                                    orderByComparator);
12184                    }
12185    
12186                    StringBundler query = null;
12187    
12188                    if (orderByComparator != null) {
12189                            query = new StringBundler(5 +
12190                                            (orderByComparator.getOrderByFields().length * 3));
12191                    }
12192                    else {
12193                            query = new StringBundler(5);
12194                    }
12195    
12196                    if (getDB().isSupportsInlineDistinct()) {
12197                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12198                    }
12199                    else {
12200                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12201                    }
12202    
12203                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12204    
12205                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12206    
12207                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12208    
12209                    if (!getDB().isSupportsInlineDistinct()) {
12210                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12211                    }
12212    
12213                    if (orderByComparator != null) {
12214                            if (getDB().isSupportsInlineDistinct()) {
12215                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12216                                            orderByComparator, true);
12217                            }
12218                            else {
12219                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12220                                            orderByComparator, true);
12221                            }
12222                    }
12223                    else {
12224                            if (getDB().isSupportsInlineDistinct()) {
12225                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12226                            }
12227                            else {
12228                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12229                            }
12230                    }
12231    
12232                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12233                                    MBMessage.class.getName(),
12234                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12235    
12236                    Session session = null;
12237    
12238                    try {
12239                            session = openSession();
12240    
12241                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12242    
12243                            if (getDB().isSupportsInlineDistinct()) {
12244                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12245                            }
12246                            else {
12247                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12248                            }
12249    
12250                            QueryPos qPos = QueryPos.getInstance(q);
12251    
12252                            qPos.add(groupId);
12253    
12254                            qPos.add(categoryId);
12255    
12256                            qPos.add(threadId);
12257    
12258                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12259                    }
12260                    catch (Exception e) {
12261                            throw processException(e);
12262                    }
12263                    finally {
12264                            closeSession(session);
12265                    }
12266            }
12267    
12268            /**
12269             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12270             *
12271             * @param messageId the primary key of the current message-boards message
12272             * @param groupId the group ID
12273             * @param categoryId the category ID
12274             * @param threadId the thread ID
12275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12276             * @return the previous, current, and next message-boards message
12277             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12278             */
12279            @Override
12280            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12281                    long groupId, long categoryId, long threadId,
12282                    OrderByComparator<MBMessage> orderByComparator)
12283                    throws NoSuchMessageException {
12284                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12285                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12286                                    threadId, orderByComparator);
12287                    }
12288    
12289                    MBMessage mbMessage = findByPrimaryKey(messageId);
12290    
12291                    Session session = null;
12292    
12293                    try {
12294                            session = openSession();
12295    
12296                            MBMessage[] array = new MBMessageImpl[3];
12297    
12298                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12299                                            groupId, categoryId, threadId, orderByComparator, true);
12300    
12301                            array[1] = mbMessage;
12302    
12303                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12304                                            groupId, categoryId, threadId, orderByComparator, false);
12305    
12306                            return array;
12307                    }
12308                    catch (Exception e) {
12309                            throw processException(e);
12310                    }
12311                    finally {
12312                            closeSession(session);
12313                    }
12314            }
12315    
12316            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12317                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12318                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12319                    StringBundler query = null;
12320    
12321                    if (orderByComparator != null) {
12322                            query = new StringBundler(6 +
12323                                            (orderByComparator.getOrderByFields().length * 6));
12324                    }
12325                    else {
12326                            query = new StringBundler(3);
12327                    }
12328    
12329                    if (getDB().isSupportsInlineDistinct()) {
12330                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12331                    }
12332                    else {
12333                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12334                    }
12335    
12336                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12337    
12338                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12339    
12340                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12341    
12342                    if (!getDB().isSupportsInlineDistinct()) {
12343                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12344                    }
12345    
12346                    if (orderByComparator != null) {
12347                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12348    
12349                            if (orderByConditionFields.length > 0) {
12350                                    query.append(WHERE_AND);
12351                            }
12352    
12353                            for (int i = 0; i < orderByConditionFields.length; i++) {
12354                                    if (getDB().isSupportsInlineDistinct()) {
12355                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12356                                    }
12357                                    else {
12358                                            query.append(_ORDER_BY_ENTITY_TABLE);
12359                                    }
12360    
12361                                    query.append(orderByConditionFields[i]);
12362    
12363                                    if ((i + 1) < orderByConditionFields.length) {
12364                                            if (orderByComparator.isAscending() ^ previous) {
12365                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12366                                            }
12367                                            else {
12368                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12369                                            }
12370                                    }
12371                                    else {
12372                                            if (orderByComparator.isAscending() ^ previous) {
12373                                                    query.append(WHERE_GREATER_THAN);
12374                                            }
12375                                            else {
12376                                                    query.append(WHERE_LESSER_THAN);
12377                                            }
12378                                    }
12379                            }
12380    
12381                            query.append(ORDER_BY_CLAUSE);
12382    
12383                            String[] orderByFields = orderByComparator.getOrderByFields();
12384    
12385                            for (int i = 0; i < orderByFields.length; i++) {
12386                                    if (getDB().isSupportsInlineDistinct()) {
12387                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12388                                    }
12389                                    else {
12390                                            query.append(_ORDER_BY_ENTITY_TABLE);
12391                                    }
12392    
12393                                    query.append(orderByFields[i]);
12394    
12395                                    if ((i + 1) < orderByFields.length) {
12396                                            if (orderByComparator.isAscending() ^ previous) {
12397                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12398                                            }
12399                                            else {
12400                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12401                                            }
12402                                    }
12403                                    else {
12404                                            if (orderByComparator.isAscending() ^ previous) {
12405                                                    query.append(ORDER_BY_ASC);
12406                                            }
12407                                            else {
12408                                                    query.append(ORDER_BY_DESC);
12409                                            }
12410                                    }
12411                            }
12412                    }
12413                    else {
12414                            if (getDB().isSupportsInlineDistinct()) {
12415                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12416                            }
12417                            else {
12418                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12419                            }
12420                    }
12421    
12422                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12423                                    MBMessage.class.getName(),
12424                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12425    
12426                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12427    
12428                    q.setFirstResult(0);
12429                    q.setMaxResults(2);
12430    
12431                    if (getDB().isSupportsInlineDistinct()) {
12432                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12433                    }
12434                    else {
12435                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12436                    }
12437    
12438                    QueryPos qPos = QueryPos.getInstance(q);
12439    
12440                    qPos.add(groupId);
12441    
12442                    qPos.add(categoryId);
12443    
12444                    qPos.add(threadId);
12445    
12446                    if (orderByComparator != null) {
12447                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12448    
12449                            for (Object value : values) {
12450                                    qPos.add(value);
12451                            }
12452                    }
12453    
12454                    List<MBMessage> list = q.list();
12455    
12456                    if (list.size() == 2) {
12457                            return list.get(1);
12458                    }
12459                    else {
12460                            return null;
12461                    }
12462            }
12463    
12464            /**
12465             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12466             *
12467             * @param groupId the group ID
12468             * @param categoryId the category ID
12469             * @param threadId the thread ID
12470             */
12471            @Override
12472            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
12473                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12474                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12475                            remove(mbMessage);
12476                    }
12477            }
12478    
12479            /**
12480             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12481             *
12482             * @param groupId the group ID
12483             * @param categoryId the category ID
12484             * @param threadId the thread ID
12485             * @return the number of matching message-boards messages
12486             */
12487            @Override
12488            public int countByG_C_T(long groupId, long categoryId, long threadId) {
12489                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12490    
12491                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12492    
12493                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12494                                    this);
12495    
12496                    if (count == null) {
12497                            StringBundler query = new StringBundler(4);
12498    
12499                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12500    
12501                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12502    
12503                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12504    
12505                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12506    
12507                            String sql = query.toString();
12508    
12509                            Session session = null;
12510    
12511                            try {
12512                                    session = openSession();
12513    
12514                                    Query q = session.createQuery(sql);
12515    
12516                                    QueryPos qPos = QueryPos.getInstance(q);
12517    
12518                                    qPos.add(groupId);
12519    
12520                                    qPos.add(categoryId);
12521    
12522                                    qPos.add(threadId);
12523    
12524                                    count = (Long)q.uniqueResult();
12525    
12526                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12527                            }
12528                            catch (Exception e) {
12529                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12530    
12531                                    throw processException(e);
12532                            }
12533                            finally {
12534                                    closeSession(session);
12535                            }
12536                    }
12537    
12538                    return count.intValue();
12539            }
12540    
12541            /**
12542             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12543             *
12544             * @param groupId the group ID
12545             * @param categoryId the category ID
12546             * @param threadId the thread ID
12547             * @return the number of matching message-boards messages that the user has permission to view
12548             */
12549            @Override
12550            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
12551                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12552                            return countByG_C_T(groupId, categoryId, threadId);
12553                    }
12554    
12555                    StringBundler query = new StringBundler(4);
12556    
12557                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12558    
12559                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12560    
12561                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12562    
12563                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12564    
12565                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12566                                    MBMessage.class.getName(),
12567                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12568    
12569                    Session session = null;
12570    
12571                    try {
12572                            session = openSession();
12573    
12574                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12575    
12576                            q.addScalar(COUNT_COLUMN_NAME,
12577                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12578    
12579                            QueryPos qPos = QueryPos.getInstance(q);
12580    
12581                            qPos.add(groupId);
12582    
12583                            qPos.add(categoryId);
12584    
12585                            qPos.add(threadId);
12586    
12587                            Long count = (Long)q.uniqueResult();
12588    
12589                            return count.intValue();
12590                    }
12591                    catch (Exception e) {
12592                            throw processException(e);
12593                    }
12594                    finally {
12595                            closeSession(session);
12596                    }
12597            }
12598    
12599            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12600            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12601            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12602            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12603                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12604                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12605                            new String[] {
12606                                    Long.class.getName(), Long.class.getName(),
12607                                    Integer.class.getName(),
12608                                    
12609                            Integer.class.getName(), Integer.class.getName(),
12610                                    OrderByComparator.class.getName()
12611                            });
12612            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12613                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12614                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12615                            new String[] {
12616                                    Long.class.getName(), Long.class.getName(),
12617                                    Integer.class.getName()
12618                            },
12619                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12620                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12621                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12622                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12623            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12624                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12625                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12626                            new String[] {
12627                                    Long.class.getName(), Long.class.getName(),
12628                                    Integer.class.getName()
12629                            });
12630    
12631            /**
12632             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12633             *
12634             * @param groupId the group ID
12635             * @param categoryId the category ID
12636             * @param status the status
12637             * @return the matching message-boards messages
12638             */
12639            @Override
12640            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
12641                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12642                            QueryUtil.ALL_POS, null);
12643            }
12644    
12645            /**
12646             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12647             *
12648             * <p>
12649             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12650             * </p>
12651             *
12652             * @param groupId the group ID
12653             * @param categoryId the category ID
12654             * @param status the status
12655             * @param start the lower bound of the range of message-boards messages
12656             * @param end the upper bound of the range of message-boards messages (not inclusive)
12657             * @return the range of matching message-boards messages
12658             */
12659            @Override
12660            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12661                    int status, int start, int end) {
12662                    return findByG_C_S(groupId, categoryId, status, start, end, null);
12663            }
12664    
12665            /**
12666             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12667             *
12668             * <p>
12669             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12670             * </p>
12671             *
12672             * @param groupId the group ID
12673             * @param categoryId the category ID
12674             * @param status the status
12675             * @param start the lower bound of the range of message-boards messages
12676             * @param end the upper bound of the range of message-boards messages (not inclusive)
12677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12678             * @return the ordered range of matching message-boards messages
12679             */
12680            @Override
12681            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12682                    int status, int start, int end,
12683                    OrderByComparator<MBMessage> orderByComparator) {
12684                    boolean pagination = true;
12685                    FinderPath finderPath = null;
12686                    Object[] finderArgs = null;
12687    
12688                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12689                                    (orderByComparator == null)) {
12690                            pagination = false;
12691                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
12692                            finderArgs = new Object[] { groupId, categoryId, status };
12693                    }
12694                    else {
12695                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
12696                            finderArgs = new Object[] {
12697                                            groupId, categoryId, status,
12698                                            
12699                                            start, end, orderByComparator
12700                                    };
12701                    }
12702    
12703                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12704                                    finderArgs, this);
12705    
12706                    if ((list != null) && !list.isEmpty()) {
12707                            for (MBMessage mbMessage : list) {
12708                                    if ((groupId != mbMessage.getGroupId()) ||
12709                                                    (categoryId != mbMessage.getCategoryId()) ||
12710                                                    (status != mbMessage.getStatus())) {
12711                                            list = null;
12712    
12713                                            break;
12714                                    }
12715                            }
12716                    }
12717    
12718                    if (list == null) {
12719                            StringBundler query = null;
12720    
12721                            if (orderByComparator != null) {
12722                                    query = new StringBundler(5 +
12723                                                    (orderByComparator.getOrderByFields().length * 3));
12724                            }
12725                            else {
12726                                    query = new StringBundler(5);
12727                            }
12728    
12729                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12730    
12731                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12732    
12733                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12734    
12735                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12736    
12737                            if (orderByComparator != null) {
12738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12739                                            orderByComparator);
12740                            }
12741                            else
12742                             if (pagination) {
12743                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12744                            }
12745    
12746                            String sql = query.toString();
12747    
12748                            Session session = null;
12749    
12750                            try {
12751                                    session = openSession();
12752    
12753                                    Query q = session.createQuery(sql);
12754    
12755                                    QueryPos qPos = QueryPos.getInstance(q);
12756    
12757                                    qPos.add(groupId);
12758    
12759                                    qPos.add(categoryId);
12760    
12761                                    qPos.add(status);
12762    
12763                                    if (!pagination) {
12764                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12765                                                            start, end, false);
12766    
12767                                            Collections.sort(list);
12768    
12769                                            list = Collections.unmodifiableList(list);
12770                                    }
12771                                    else {
12772                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12773                                                            start, end);
12774                                    }
12775    
12776                                    cacheResult(list);
12777    
12778                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12779                            }
12780                            catch (Exception e) {
12781                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12782    
12783                                    throw processException(e);
12784                            }
12785                            finally {
12786                                    closeSession(session);
12787                            }
12788                    }
12789    
12790                    return list;
12791            }
12792    
12793            /**
12794             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12795             *
12796             * @param groupId the group ID
12797             * @param categoryId the category ID
12798             * @param status the status
12799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12800             * @return the first matching message-boards message
12801             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12802             */
12803            @Override
12804            public MBMessage findByG_C_S_First(long groupId, long categoryId,
12805                    int status, OrderByComparator<MBMessage> orderByComparator)
12806                    throws NoSuchMessageException {
12807                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
12808                                    orderByComparator);
12809    
12810                    if (mbMessage != null) {
12811                            return mbMessage;
12812                    }
12813    
12814                    StringBundler msg = new StringBundler(8);
12815    
12816                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12817    
12818                    msg.append("groupId=");
12819                    msg.append(groupId);
12820    
12821                    msg.append(", categoryId=");
12822                    msg.append(categoryId);
12823    
12824                    msg.append(", status=");
12825                    msg.append(status);
12826    
12827                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12828    
12829                    throw new NoSuchMessageException(msg.toString());
12830            }
12831    
12832            /**
12833             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12834             *
12835             * @param groupId the group ID
12836             * @param categoryId the category ID
12837             * @param status the status
12838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12839             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12840             */
12841            @Override
12842            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
12843                    int status, OrderByComparator<MBMessage> orderByComparator) {
12844                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
12845                                    orderByComparator);
12846    
12847                    if (!list.isEmpty()) {
12848                            return list.get(0);
12849                    }
12850    
12851                    return null;
12852            }
12853    
12854            /**
12855             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12856             *
12857             * @param groupId the group ID
12858             * @param categoryId the category ID
12859             * @param status the status
12860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12861             * @return the last matching message-boards message
12862             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12863             */
12864            @Override
12865            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
12866                    int status, OrderByComparator<MBMessage> orderByComparator)
12867                    throws NoSuchMessageException {
12868                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
12869                                    orderByComparator);
12870    
12871                    if (mbMessage != null) {
12872                            return mbMessage;
12873                    }
12874    
12875                    StringBundler msg = new StringBundler(8);
12876    
12877                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12878    
12879                    msg.append("groupId=");
12880                    msg.append(groupId);
12881    
12882                    msg.append(", categoryId=");
12883                    msg.append(categoryId);
12884    
12885                    msg.append(", status=");
12886                    msg.append(status);
12887    
12888                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12889    
12890                    throw new NoSuchMessageException(msg.toString());
12891            }
12892    
12893            /**
12894             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12895             *
12896             * @param groupId the group ID
12897             * @param categoryId the category ID
12898             * @param status the status
12899             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12900             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12901             */
12902            @Override
12903            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
12904                    int status, OrderByComparator<MBMessage> orderByComparator) {
12905                    int count = countByG_C_S(groupId, categoryId, status);
12906    
12907                    if (count == 0) {
12908                            return null;
12909                    }
12910    
12911                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
12912                                    count - 1, count, orderByComparator);
12913    
12914                    if (!list.isEmpty()) {
12915                            return list.get(0);
12916                    }
12917    
12918                    return null;
12919            }
12920    
12921            /**
12922             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12923             *
12924             * @param messageId the primary key of the current message-boards message
12925             * @param groupId the group ID
12926             * @param categoryId the category ID
12927             * @param status the status
12928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12929             * @return the previous, current, and next message-boards message
12930             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12931             */
12932            @Override
12933            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
12934                    long categoryId, int status,
12935                    OrderByComparator<MBMessage> orderByComparator)
12936                    throws NoSuchMessageException {
12937                    MBMessage mbMessage = findByPrimaryKey(messageId);
12938    
12939                    Session session = null;
12940    
12941                    try {
12942                            session = openSession();
12943    
12944                            MBMessage[] array = new MBMessageImpl[3];
12945    
12946                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12947                                            categoryId, status, orderByComparator, true);
12948    
12949                            array[1] = mbMessage;
12950    
12951                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12952                                            categoryId, status, orderByComparator, false);
12953    
12954                            return array;
12955                    }
12956                    catch (Exception e) {
12957                            throw processException(e);
12958                    }
12959                    finally {
12960                            closeSession(session);
12961                    }
12962            }
12963    
12964            protected MBMessage getByG_C_S_PrevAndNext(Session session,
12965                    MBMessage mbMessage, long groupId, long categoryId, int status,
12966                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12967                    StringBundler query = null;
12968    
12969                    if (orderByComparator != null) {
12970                            query = new StringBundler(6 +
12971                                            (orderByComparator.getOrderByFields().length * 6));
12972                    }
12973                    else {
12974                            query = new StringBundler(3);
12975                    }
12976    
12977                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12978    
12979                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12980    
12981                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12982    
12983                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12984    
12985                    if (orderByComparator != null) {
12986                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12987    
12988                            if (orderByConditionFields.length > 0) {
12989                                    query.append(WHERE_AND);
12990                            }
12991    
12992                            for (int i = 0; i < orderByConditionFields.length; i++) {
12993                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12994                                    query.append(orderByConditionFields[i]);
12995    
12996                                    if ((i + 1) < orderByConditionFields.length) {
12997                                            if (orderByComparator.isAscending() ^ previous) {
12998                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12999                                            }
13000                                            else {
13001                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13002                                            }
13003                                    }
13004                                    else {
13005                                            if (orderByComparator.isAscending() ^ previous) {
13006                                                    query.append(WHERE_GREATER_THAN);
13007                                            }
13008                                            else {
13009                                                    query.append(WHERE_LESSER_THAN);
13010                                            }
13011                                    }
13012                            }
13013    
13014                            query.append(ORDER_BY_CLAUSE);
13015    
13016                            String[] orderByFields = orderByComparator.getOrderByFields();
13017    
13018                            for (int i = 0; i < orderByFields.length; i++) {
13019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13020                                    query.append(orderByFields[i]);
13021    
13022                                    if ((i + 1) < orderByFields.length) {
13023                                            if (orderByComparator.isAscending() ^ previous) {
13024                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13025                                            }
13026                                            else {
13027                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13028                                            }
13029                                    }
13030                                    else {
13031                                            if (orderByComparator.isAscending() ^ previous) {
13032                                                    query.append(ORDER_BY_ASC);
13033                                            }
13034                                            else {
13035                                                    query.append(ORDER_BY_DESC);
13036                                            }
13037                                    }
13038                            }
13039                    }
13040                    else {
13041                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13042                    }
13043    
13044                    String sql = query.toString();
13045    
13046                    Query q = session.createQuery(sql);
13047    
13048                    q.setFirstResult(0);
13049                    q.setMaxResults(2);
13050    
13051                    QueryPos qPos = QueryPos.getInstance(q);
13052    
13053                    qPos.add(groupId);
13054    
13055                    qPos.add(categoryId);
13056    
13057                    qPos.add(status);
13058    
13059                    if (orderByComparator != null) {
13060                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13061    
13062                            for (Object value : values) {
13063                                    qPos.add(value);
13064                            }
13065                    }
13066    
13067                    List<MBMessage> list = q.list();
13068    
13069                    if (list.size() == 2) {
13070                            return list.get(1);
13071                    }
13072                    else {
13073                            return null;
13074                    }
13075            }
13076    
13077            /**
13078             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13079             *
13080             * @param groupId the group ID
13081             * @param categoryId the category ID
13082             * @param status the status
13083             * @return the matching message-boards messages that the user has permission to view
13084             */
13085            @Override
13086            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13087                    int status) {
13088                    return filterFindByG_C_S(groupId, categoryId, status,
13089                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13090            }
13091    
13092            /**
13093             * 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;.
13094             *
13095             * <p>
13096             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13097             * </p>
13098             *
13099             * @param groupId the group ID
13100             * @param categoryId the category ID
13101             * @param status the status
13102             * @param start the lower bound of the range of message-boards messages
13103             * @param end the upper bound of the range of message-boards messages (not inclusive)
13104             * @return the range of matching message-boards messages that the user has permission to view
13105             */
13106            @Override
13107            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13108                    int status, int start, int end) {
13109                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13110            }
13111    
13112            /**
13113             * 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;.
13114             *
13115             * <p>
13116             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13117             * </p>
13118             *
13119             * @param groupId the group ID
13120             * @param categoryId the category ID
13121             * @param status the status
13122             * @param start the lower bound of the range of message-boards messages
13123             * @param end the upper bound of the range of message-boards messages (not inclusive)
13124             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13125             * @return the ordered range of matching message-boards messages that the user has permission to view
13126             */
13127            @Override
13128            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13129                    int status, int start, int end,
13130                    OrderByComparator<MBMessage> orderByComparator) {
13131                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13132                            return findByG_C_S(groupId, categoryId, status, start, end,
13133                                    orderByComparator);
13134                    }
13135    
13136                    StringBundler query = null;
13137    
13138                    if (orderByComparator != null) {
13139                            query = new StringBundler(5 +
13140                                            (orderByComparator.getOrderByFields().length * 3));
13141                    }
13142                    else {
13143                            query = new StringBundler(5);
13144                    }
13145    
13146                    if (getDB().isSupportsInlineDistinct()) {
13147                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13148                    }
13149                    else {
13150                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13151                    }
13152    
13153                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13154    
13155                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13156    
13157                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13158    
13159                    if (!getDB().isSupportsInlineDistinct()) {
13160                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13161                    }
13162    
13163                    if (orderByComparator != null) {
13164                            if (getDB().isSupportsInlineDistinct()) {
13165                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13166                                            orderByComparator, true);
13167                            }
13168                            else {
13169                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13170                                            orderByComparator, true);
13171                            }
13172                    }
13173                    else {
13174                            if (getDB().isSupportsInlineDistinct()) {
13175                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13176                            }
13177                            else {
13178                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13179                            }
13180                    }
13181    
13182                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13183                                    MBMessage.class.getName(),
13184                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13185    
13186                    Session session = null;
13187    
13188                    try {
13189                            session = openSession();
13190    
13191                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13192    
13193                            if (getDB().isSupportsInlineDistinct()) {
13194                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13195                            }
13196                            else {
13197                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13198                            }
13199    
13200                            QueryPos qPos = QueryPos.getInstance(q);
13201    
13202                            qPos.add(groupId);
13203    
13204                            qPos.add(categoryId);
13205    
13206                            qPos.add(status);
13207    
13208                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13209                    }
13210                    catch (Exception e) {
13211                            throw processException(e);
13212                    }
13213                    finally {
13214                            closeSession(session);
13215                    }
13216            }
13217    
13218            /**
13219             * 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;.
13220             *
13221             * @param messageId the primary key of the current message-boards message
13222             * @param groupId the group ID
13223             * @param categoryId the category ID
13224             * @param status the status
13225             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13226             * @return the previous, current, and next message-boards message
13227             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13228             */
13229            @Override
13230            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13231                    long groupId, long categoryId, int status,
13232                    OrderByComparator<MBMessage> orderByComparator)
13233                    throws NoSuchMessageException {
13234                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13235                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13236                                    status, orderByComparator);
13237                    }
13238    
13239                    MBMessage mbMessage = findByPrimaryKey(messageId);
13240    
13241                    Session session = null;
13242    
13243                    try {
13244                            session = openSession();
13245    
13246                            MBMessage[] array = new MBMessageImpl[3];
13247    
13248                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13249                                            groupId, categoryId, status, orderByComparator, true);
13250    
13251                            array[1] = mbMessage;
13252    
13253                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13254                                            groupId, categoryId, status, orderByComparator, false);
13255    
13256                            return array;
13257                    }
13258                    catch (Exception e) {
13259                            throw processException(e);
13260                    }
13261                    finally {
13262                            closeSession(session);
13263                    }
13264            }
13265    
13266            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13267                    MBMessage mbMessage, long groupId, long categoryId, int status,
13268                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13269                    StringBundler query = null;
13270    
13271                    if (orderByComparator != null) {
13272                            query = new StringBundler(6 +
13273                                            (orderByComparator.getOrderByFields().length * 6));
13274                    }
13275                    else {
13276                            query = new StringBundler(3);
13277                    }
13278    
13279                    if (getDB().isSupportsInlineDistinct()) {
13280                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13281                    }
13282                    else {
13283                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13284                    }
13285    
13286                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13287    
13288                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13289    
13290                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13291    
13292                    if (!getDB().isSupportsInlineDistinct()) {
13293                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13294                    }
13295    
13296                    if (orderByComparator != null) {
13297                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13298    
13299                            if (orderByConditionFields.length > 0) {
13300                                    query.append(WHERE_AND);
13301                            }
13302    
13303                            for (int i = 0; i < orderByConditionFields.length; i++) {
13304                                    if (getDB().isSupportsInlineDistinct()) {
13305                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13306                                    }
13307                                    else {
13308                                            query.append(_ORDER_BY_ENTITY_TABLE);
13309                                    }
13310    
13311                                    query.append(orderByConditionFields[i]);
13312    
13313                                    if ((i + 1) < orderByConditionFields.length) {
13314                                            if (orderByComparator.isAscending() ^ previous) {
13315                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13316                                            }
13317                                            else {
13318                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13319                                            }
13320                                    }
13321                                    else {
13322                                            if (orderByComparator.isAscending() ^ previous) {
13323                                                    query.append(WHERE_GREATER_THAN);
13324                                            }
13325                                            else {
13326                                                    query.append(WHERE_LESSER_THAN);
13327                                            }
13328                                    }
13329                            }
13330    
13331                            query.append(ORDER_BY_CLAUSE);
13332    
13333                            String[] orderByFields = orderByComparator.getOrderByFields();
13334    
13335                            for (int i = 0; i < orderByFields.length; i++) {
13336                                    if (getDB().isSupportsInlineDistinct()) {
13337                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13338                                    }
13339                                    else {
13340                                            query.append(_ORDER_BY_ENTITY_TABLE);
13341                                    }
13342    
13343                                    query.append(orderByFields[i]);
13344    
13345                                    if ((i + 1) < orderByFields.length) {
13346                                            if (orderByComparator.isAscending() ^ previous) {
13347                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13348                                            }
13349                                            else {
13350                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13351                                            }
13352                                    }
13353                                    else {
13354                                            if (orderByComparator.isAscending() ^ previous) {
13355                                                    query.append(ORDER_BY_ASC);
13356                                            }
13357                                            else {
13358                                                    query.append(ORDER_BY_DESC);
13359                                            }
13360                                    }
13361                            }
13362                    }
13363                    else {
13364                            if (getDB().isSupportsInlineDistinct()) {
13365                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13366                            }
13367                            else {
13368                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13369                            }
13370                    }
13371    
13372                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13373                                    MBMessage.class.getName(),
13374                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13375    
13376                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13377    
13378                    q.setFirstResult(0);
13379                    q.setMaxResults(2);
13380    
13381                    if (getDB().isSupportsInlineDistinct()) {
13382                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13383                    }
13384                    else {
13385                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13386                    }
13387    
13388                    QueryPos qPos = QueryPos.getInstance(q);
13389    
13390                    qPos.add(groupId);
13391    
13392                    qPos.add(categoryId);
13393    
13394                    qPos.add(status);
13395    
13396                    if (orderByComparator != null) {
13397                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13398    
13399                            for (Object value : values) {
13400                                    qPos.add(value);
13401                            }
13402                    }
13403    
13404                    List<MBMessage> list = q.list();
13405    
13406                    if (list.size() == 2) {
13407                            return list.get(1);
13408                    }
13409                    else {
13410                            return null;
13411                    }
13412            }
13413    
13414            /**
13415             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13416             *
13417             * @param groupId the group ID
13418             * @param categoryId the category ID
13419             * @param status the status
13420             */
13421            @Override
13422            public void removeByG_C_S(long groupId, long categoryId, int status) {
13423                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13424                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13425                            remove(mbMessage);
13426                    }
13427            }
13428    
13429            /**
13430             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13431             *
13432             * @param groupId the group ID
13433             * @param categoryId the category ID
13434             * @param status the status
13435             * @return the number of matching message-boards messages
13436             */
13437            @Override
13438            public int countByG_C_S(long groupId, long categoryId, int status) {
13439                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13440    
13441                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13442    
13443                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13444                                    this);
13445    
13446                    if (count == null) {
13447                            StringBundler query = new StringBundler(4);
13448    
13449                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13450    
13451                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13452    
13453                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13454    
13455                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13456    
13457                            String sql = query.toString();
13458    
13459                            Session session = null;
13460    
13461                            try {
13462                                    session = openSession();
13463    
13464                                    Query q = session.createQuery(sql);
13465    
13466                                    QueryPos qPos = QueryPos.getInstance(q);
13467    
13468                                    qPos.add(groupId);
13469    
13470                                    qPos.add(categoryId);
13471    
13472                                    qPos.add(status);
13473    
13474                                    count = (Long)q.uniqueResult();
13475    
13476                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13477                            }
13478                            catch (Exception e) {
13479                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13480    
13481                                    throw processException(e);
13482                            }
13483                            finally {
13484                                    closeSession(session);
13485                            }
13486                    }
13487    
13488                    return count.intValue();
13489            }
13490    
13491            /**
13492             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13493             *
13494             * @param groupId the group ID
13495             * @param categoryId the category ID
13496             * @param status the status
13497             * @return the number of matching message-boards messages that the user has permission to view
13498             */
13499            @Override
13500            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
13501                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13502                            return countByG_C_S(groupId, categoryId, status);
13503                    }
13504    
13505                    StringBundler query = new StringBundler(4);
13506    
13507                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13508    
13509                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13510    
13511                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13512    
13513                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13514    
13515                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13516                                    MBMessage.class.getName(),
13517                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13518    
13519                    Session session = null;
13520    
13521                    try {
13522                            session = openSession();
13523    
13524                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13525    
13526                            q.addScalar(COUNT_COLUMN_NAME,
13527                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13528    
13529                            QueryPos qPos = QueryPos.getInstance(q);
13530    
13531                            qPos.add(groupId);
13532    
13533                            qPos.add(categoryId);
13534    
13535                            qPos.add(status);
13536    
13537                            Long count = (Long)q.uniqueResult();
13538    
13539                            return count.intValue();
13540                    }
13541                    catch (Exception e) {
13542                            throw processException(e);
13543                    }
13544                    finally {
13545                            closeSession(session);
13546                    }
13547            }
13548    
13549            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13550            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13551            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13552            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13553                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13554                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13555                            new String[] {
13556                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13557                                    
13558                            Integer.class.getName(), Integer.class.getName(),
13559                                    OrderByComparator.class.getName()
13560                            });
13561            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13562                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13563                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13564                            new String[] {
13565                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13566                            },
13567                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
13568                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13569                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13570                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13571            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13572                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13573                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13574                            new String[] {
13575                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13576                            });
13577    
13578            /**
13579             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13580             *
13581             * @param userId the user ID
13582             * @param classNameId the class name ID
13583             * @param classPK the class p k
13584             * @return the matching message-boards messages
13585             */
13586            @Override
13587            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13588                    long classPK) {
13589                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13590                            QueryUtil.ALL_POS, null);
13591            }
13592    
13593            /**
13594             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13595             *
13596             * <p>
13597             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13598             * </p>
13599             *
13600             * @param userId the user ID
13601             * @param classNameId the class name ID
13602             * @param classPK the class p k
13603             * @param start the lower bound of the range of message-boards messages
13604             * @param end the upper bound of the range of message-boards messages (not inclusive)
13605             * @return the range of matching message-boards messages
13606             */
13607            @Override
13608            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13609                    long classPK, int start, int end) {
13610                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
13611            }
13612    
13613            /**
13614             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13615             *
13616             * <p>
13617             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13618             * </p>
13619             *
13620             * @param userId the user ID
13621             * @param classNameId the class name ID
13622             * @param classPK the class p k
13623             * @param start the lower bound of the range of message-boards messages
13624             * @param end the upper bound of the range of message-boards messages (not inclusive)
13625             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13626             * @return the ordered range of matching message-boards messages
13627             */
13628            @Override
13629            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13630                    long classPK, int start, int end,
13631                    OrderByComparator<MBMessage> orderByComparator) {
13632                    boolean pagination = true;
13633                    FinderPath finderPath = null;
13634                    Object[] finderArgs = null;
13635    
13636                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13637                                    (orderByComparator == null)) {
13638                            pagination = false;
13639                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13640                            finderArgs = new Object[] { userId, classNameId, classPK };
13641                    }
13642                    else {
13643                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13644                            finderArgs = new Object[] {
13645                                            userId, classNameId, classPK,
13646                                            
13647                                            start, end, orderByComparator
13648                                    };
13649                    }
13650    
13651                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13652                                    finderArgs, this);
13653    
13654                    if ((list != null) && !list.isEmpty()) {
13655                            for (MBMessage mbMessage : list) {
13656                                    if ((userId != mbMessage.getUserId()) ||
13657                                                    (classNameId != mbMessage.getClassNameId()) ||
13658                                                    (classPK != mbMessage.getClassPK())) {
13659                                            list = null;
13660    
13661                                            break;
13662                                    }
13663                            }
13664                    }
13665    
13666                    if (list == null) {
13667                            StringBundler query = null;
13668    
13669                            if (orderByComparator != null) {
13670                                    query = new StringBundler(5 +
13671                                                    (orderByComparator.getOrderByFields().length * 3));
13672                            }
13673                            else {
13674                                    query = new StringBundler(5);
13675                            }
13676    
13677                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13678    
13679                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13680    
13681                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13682    
13683                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13684    
13685                            if (orderByComparator != null) {
13686                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13687                                            orderByComparator);
13688                            }
13689                            else
13690                             if (pagination) {
13691                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13692                            }
13693    
13694                            String sql = query.toString();
13695    
13696                            Session session = null;
13697    
13698                            try {
13699                                    session = openSession();
13700    
13701                                    Query q = session.createQuery(sql);
13702    
13703                                    QueryPos qPos = QueryPos.getInstance(q);
13704    
13705                                    qPos.add(userId);
13706    
13707                                    qPos.add(classNameId);
13708    
13709                                    qPos.add(classPK);
13710    
13711                                    if (!pagination) {
13712                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13713                                                            start, end, false);
13714    
13715                                            Collections.sort(list);
13716    
13717                                            list = Collections.unmodifiableList(list);
13718                                    }
13719                                    else {
13720                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13721                                                            start, end);
13722                                    }
13723    
13724                                    cacheResult(list);
13725    
13726                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13727                            }
13728                            catch (Exception e) {
13729                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13730    
13731                                    throw processException(e);
13732                            }
13733                            finally {
13734                                    closeSession(session);
13735                            }
13736                    }
13737    
13738                    return list;
13739            }
13740    
13741            /**
13742             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13743             *
13744             * @param userId the user ID
13745             * @param classNameId the class name ID
13746             * @param classPK the class p k
13747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13748             * @return the first matching message-boards message
13749             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13750             */
13751            @Override
13752            public MBMessage findByU_C_C_First(long userId, long classNameId,
13753                    long classPK, OrderByComparator<MBMessage> orderByComparator)
13754                    throws NoSuchMessageException {
13755                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
13756                                    orderByComparator);
13757    
13758                    if (mbMessage != null) {
13759                            return mbMessage;
13760                    }
13761    
13762                    StringBundler msg = new StringBundler(8);
13763    
13764                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13765    
13766                    msg.append("userId=");
13767                    msg.append(userId);
13768    
13769                    msg.append(", classNameId=");
13770                    msg.append(classNameId);
13771    
13772                    msg.append(", classPK=");
13773                    msg.append(classPK);
13774    
13775                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13776    
13777                    throw new NoSuchMessageException(msg.toString());
13778            }
13779    
13780            /**
13781             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13782             *
13783             * @param userId the user ID
13784             * @param classNameId the class name ID
13785             * @param classPK the class p k
13786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13787             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13788             */
13789            @Override
13790            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
13791                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
13792                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
13793                                    orderByComparator);
13794    
13795                    if (!list.isEmpty()) {
13796                            return list.get(0);
13797                    }
13798    
13799                    return null;
13800            }
13801    
13802            /**
13803             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13804             *
13805             * @param userId the user ID
13806             * @param classNameId the class name ID
13807             * @param classPK the class p k
13808             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13809             * @return the last matching message-boards message
13810             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13811             */
13812            @Override
13813            public MBMessage findByU_C_C_Last(long userId, long classNameId,
13814                    long classPK, OrderByComparator<MBMessage> orderByComparator)
13815                    throws NoSuchMessageException {
13816                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
13817                                    orderByComparator);
13818    
13819                    if (mbMessage != null) {
13820                            return mbMessage;
13821                    }
13822    
13823                    StringBundler msg = new StringBundler(8);
13824    
13825                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13826    
13827                    msg.append("userId=");
13828                    msg.append(userId);
13829    
13830                    msg.append(", classNameId=");
13831                    msg.append(classNameId);
13832    
13833                    msg.append(", classPK=");
13834                    msg.append(classPK);
13835    
13836                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13837    
13838                    throw new NoSuchMessageException(msg.toString());
13839            }
13840    
13841            /**
13842             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13843             *
13844             * @param userId the user ID
13845             * @param classNameId the class name ID
13846             * @param classPK the class p k
13847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13848             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13849             */
13850            @Override
13851            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
13852                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
13853                    int count = countByU_C_C(userId, classNameId, classPK);
13854    
13855                    if (count == 0) {
13856                            return null;
13857                    }
13858    
13859                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
13860                                    count - 1, count, orderByComparator);
13861    
13862                    if (!list.isEmpty()) {
13863                            return list.get(0);
13864                    }
13865    
13866                    return null;
13867            }
13868    
13869            /**
13870             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13871             *
13872             * @param messageId the primary key of the current message-boards message
13873             * @param userId the user ID
13874             * @param classNameId the class name ID
13875             * @param classPK the class p k
13876             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13877             * @return the previous, current, and next message-boards message
13878             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13879             */
13880            @Override
13881            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
13882                    long classNameId, long classPK,
13883                    OrderByComparator<MBMessage> orderByComparator)
13884                    throws NoSuchMessageException {
13885                    MBMessage mbMessage = findByPrimaryKey(messageId);
13886    
13887                    Session session = null;
13888    
13889                    try {
13890                            session = openSession();
13891    
13892                            MBMessage[] array = new MBMessageImpl[3];
13893    
13894                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13895                                            classNameId, classPK, orderByComparator, true);
13896    
13897                            array[1] = mbMessage;
13898    
13899                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13900                                            classNameId, classPK, orderByComparator, false);
13901    
13902                            return array;
13903                    }
13904                    catch (Exception e) {
13905                            throw processException(e);
13906                    }
13907                    finally {
13908                            closeSession(session);
13909                    }
13910            }
13911    
13912            protected MBMessage getByU_C_C_PrevAndNext(Session session,
13913                    MBMessage mbMessage, long userId, long classNameId, long classPK,
13914                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13915                    StringBundler query = null;
13916    
13917                    if (orderByComparator != null) {
13918                            query = new StringBundler(6 +
13919                                            (orderByComparator.getOrderByFields().length * 6));
13920                    }
13921                    else {
13922                            query = new StringBundler(3);
13923                    }
13924    
13925                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13926    
13927                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13928    
13929                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13930    
13931                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13932    
13933                    if (orderByComparator != null) {
13934                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13935    
13936                            if (orderByConditionFields.length > 0) {
13937                                    query.append(WHERE_AND);
13938                            }
13939    
13940                            for (int i = 0; i < orderByConditionFields.length; i++) {
13941                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13942                                    query.append(orderByConditionFields[i]);
13943    
13944                                    if ((i + 1) < orderByConditionFields.length) {
13945                                            if (orderByComparator.isAscending() ^ previous) {
13946                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13947                                            }
13948                                            else {
13949                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13950                                            }
13951                                    }
13952                                    else {
13953                                            if (orderByComparator.isAscending() ^ previous) {
13954                                                    query.append(WHERE_GREATER_THAN);
13955                                            }
13956                                            else {
13957                                                    query.append(WHERE_LESSER_THAN);
13958                                            }
13959                                    }
13960                            }
13961    
13962                            query.append(ORDER_BY_CLAUSE);
13963    
13964                            String[] orderByFields = orderByComparator.getOrderByFields();
13965    
13966                            for (int i = 0; i < orderByFields.length; i++) {
13967                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13968                                    query.append(orderByFields[i]);
13969    
13970                                    if ((i + 1) < orderByFields.length) {
13971                                            if (orderByComparator.isAscending() ^ previous) {
13972                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13973                                            }
13974                                            else {
13975                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13976                                            }
13977                                    }
13978                                    else {
13979                                            if (orderByComparator.isAscending() ^ previous) {
13980                                                    query.append(ORDER_BY_ASC);
13981                                            }
13982                                            else {
13983                                                    query.append(ORDER_BY_DESC);
13984                                            }
13985                                    }
13986                            }
13987                    }
13988                    else {
13989                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13990                    }
13991    
13992                    String sql = query.toString();
13993    
13994                    Query q = session.createQuery(sql);
13995    
13996                    q.setFirstResult(0);
13997                    q.setMaxResults(2);
13998    
13999                    QueryPos qPos = QueryPos.getInstance(q);
14000    
14001                    qPos.add(userId);
14002    
14003                    qPos.add(classNameId);
14004    
14005                    qPos.add(classPK);
14006    
14007                    if (orderByComparator != null) {
14008                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14009    
14010                            for (Object value : values) {
14011                                    qPos.add(value);
14012                            }
14013                    }
14014    
14015                    List<MBMessage> list = q.list();
14016    
14017                    if (list.size() == 2) {
14018                            return list.get(1);
14019                    }
14020                    else {
14021                            return null;
14022                    }
14023            }
14024    
14025            /**
14026             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14027             *
14028             * @param userId the user ID
14029             * @param classNameId the class name ID
14030             * @param classPK the class p k
14031             */
14032            @Override
14033            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14034                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14035                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14036                            remove(mbMessage);
14037                    }
14038            }
14039    
14040            /**
14041             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14042             *
14043             * @param userId the user ID
14044             * @param classNameId the class name ID
14045             * @param classPK the class p k
14046             * @return the number of matching message-boards messages
14047             */
14048            @Override
14049            public int countByU_C_C(long userId, long classNameId, long classPK) {
14050                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14051    
14052                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14053    
14054                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14055                                    this);
14056    
14057                    if (count == null) {
14058                            StringBundler query = new StringBundler(4);
14059    
14060                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14061    
14062                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14063    
14064                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14065    
14066                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14067    
14068                            String sql = query.toString();
14069    
14070                            Session session = null;
14071    
14072                            try {
14073                                    session = openSession();
14074    
14075                                    Query q = session.createQuery(sql);
14076    
14077                                    QueryPos qPos = QueryPos.getInstance(q);
14078    
14079                                    qPos.add(userId);
14080    
14081                                    qPos.add(classNameId);
14082    
14083                                    qPos.add(classPK);
14084    
14085                                    count = (Long)q.uniqueResult();
14086    
14087                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14088                            }
14089                            catch (Exception e) {
14090                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14091    
14092                                    throw processException(e);
14093                            }
14094                            finally {
14095                                    closeSession(session);
14096                            }
14097                    }
14098    
14099                    return count.intValue();
14100            }
14101    
14102            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14103            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14104            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14105            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14106                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14107                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14108                            new String[] {
14109                                    Long.class.getName(), Long.class.getName(),
14110                                    Integer.class.getName(),
14111                                    
14112                            Integer.class.getName(), Integer.class.getName(),
14113                                    OrderByComparator.class.getName()
14114                            });
14115            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14116                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14118                            new String[] {
14119                                    Long.class.getName(), Long.class.getName(),
14120                                    Integer.class.getName()
14121                            },
14122                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14123                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14124                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14125                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14126            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14127                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14129                            new String[] {
14130                                    Long.class.getName(), Long.class.getName(),
14131                                    Integer.class.getName()
14132                            });
14133            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14134                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14135                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14136                            new String[] {
14137                                    Long.class.getName(), Long.class.getName(),
14138                                    Integer.class.getName()
14139                            });
14140    
14141            /**
14142             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14143             *
14144             * @param userId the user ID
14145             * @param classNameId the class name ID
14146             * @param status the status
14147             * @return the matching message-boards messages
14148             */
14149            @Override
14150            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14151                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14152                            QueryUtil.ALL_POS, null);
14153            }
14154    
14155            /**
14156             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14157             *
14158             * <p>
14159             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14160             * </p>
14161             *
14162             * @param userId the user ID
14163             * @param classNameId the class name ID
14164             * @param status the status
14165             * @param start the lower bound of the range of message-boards messages
14166             * @param end the upper bound of the range of message-boards messages (not inclusive)
14167             * @return the range of matching message-boards messages
14168             */
14169            @Override
14170            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14171                    int status, int start, int end) {
14172                    return findByU_C_S(userId, classNameId, status, start, end, null);
14173            }
14174    
14175            /**
14176             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14177             *
14178             * <p>
14179             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14180             * </p>
14181             *
14182             * @param userId the user ID
14183             * @param classNameId the class name ID
14184             * @param status the status
14185             * @param start the lower bound of the range of message-boards messages
14186             * @param end the upper bound of the range of message-boards messages (not inclusive)
14187             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14188             * @return the ordered range of matching message-boards messages
14189             */
14190            @Override
14191            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14192                    int status, int start, int end,
14193                    OrderByComparator<MBMessage> orderByComparator) {
14194                    boolean pagination = true;
14195                    FinderPath finderPath = null;
14196                    Object[] finderArgs = null;
14197    
14198                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14199                                    (orderByComparator == null)) {
14200                            pagination = false;
14201                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14202                            finderArgs = new Object[] { userId, classNameId, status };
14203                    }
14204                    else {
14205                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14206                            finderArgs = new Object[] {
14207                                            userId, classNameId, status,
14208                                            
14209                                            start, end, orderByComparator
14210                                    };
14211                    }
14212    
14213                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14214                                    finderArgs, this);
14215    
14216                    if ((list != null) && !list.isEmpty()) {
14217                            for (MBMessage mbMessage : list) {
14218                                    if ((userId != mbMessage.getUserId()) ||
14219                                                    (classNameId != mbMessage.getClassNameId()) ||
14220                                                    (status != mbMessage.getStatus())) {
14221                                            list = null;
14222    
14223                                            break;
14224                                    }
14225                            }
14226                    }
14227    
14228                    if (list == null) {
14229                            StringBundler query = null;
14230    
14231                            if (orderByComparator != null) {
14232                                    query = new StringBundler(5 +
14233                                                    (orderByComparator.getOrderByFields().length * 3));
14234                            }
14235                            else {
14236                                    query = new StringBundler(5);
14237                            }
14238    
14239                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14240    
14241                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14242    
14243                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14244    
14245                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14246    
14247                            if (orderByComparator != null) {
14248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14249                                            orderByComparator);
14250                            }
14251                            else
14252                             if (pagination) {
14253                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14254                            }
14255    
14256                            String sql = query.toString();
14257    
14258                            Session session = null;
14259    
14260                            try {
14261                                    session = openSession();
14262    
14263                                    Query q = session.createQuery(sql);
14264    
14265                                    QueryPos qPos = QueryPos.getInstance(q);
14266    
14267                                    qPos.add(userId);
14268    
14269                                    qPos.add(classNameId);
14270    
14271                                    qPos.add(status);
14272    
14273                                    if (!pagination) {
14274                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14275                                                            start, end, false);
14276    
14277                                            Collections.sort(list);
14278    
14279                                            list = Collections.unmodifiableList(list);
14280                                    }
14281                                    else {
14282                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14283                                                            start, end);
14284                                    }
14285    
14286                                    cacheResult(list);
14287    
14288                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14289                            }
14290                            catch (Exception e) {
14291                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14292    
14293                                    throw processException(e);
14294                            }
14295                            finally {
14296                                    closeSession(session);
14297                            }
14298                    }
14299    
14300                    return list;
14301            }
14302    
14303            /**
14304             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14305             *
14306             * @param userId the user ID
14307             * @param classNameId the class name ID
14308             * @param status the status
14309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14310             * @return the first matching message-boards message
14311             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14312             */
14313            @Override
14314            public MBMessage findByU_C_S_First(long userId, long classNameId,
14315                    int status, OrderByComparator<MBMessage> orderByComparator)
14316                    throws NoSuchMessageException {
14317                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14318                                    orderByComparator);
14319    
14320                    if (mbMessage != null) {
14321                            return mbMessage;
14322                    }
14323    
14324                    StringBundler msg = new StringBundler(8);
14325    
14326                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14327    
14328                    msg.append("userId=");
14329                    msg.append(userId);
14330    
14331                    msg.append(", classNameId=");
14332                    msg.append(classNameId);
14333    
14334                    msg.append(", status=");
14335                    msg.append(status);
14336    
14337                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14338    
14339                    throw new NoSuchMessageException(msg.toString());
14340            }
14341    
14342            /**
14343             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14344             *
14345             * @param userId the user ID
14346             * @param classNameId the class name ID
14347             * @param status the status
14348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14349             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14350             */
14351            @Override
14352            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14353                    int status, OrderByComparator<MBMessage> orderByComparator) {
14354                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14355                                    orderByComparator);
14356    
14357                    if (!list.isEmpty()) {
14358                            return list.get(0);
14359                    }
14360    
14361                    return null;
14362            }
14363    
14364            /**
14365             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14366             *
14367             * @param userId the user ID
14368             * @param classNameId the class name ID
14369             * @param status the status
14370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14371             * @return the last matching message-boards message
14372             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14373             */
14374            @Override
14375            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14376                    int status, OrderByComparator<MBMessage> orderByComparator)
14377                    throws NoSuchMessageException {
14378                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14379                                    orderByComparator);
14380    
14381                    if (mbMessage != null) {
14382                            return mbMessage;
14383                    }
14384    
14385                    StringBundler msg = new StringBundler(8);
14386    
14387                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14388    
14389                    msg.append("userId=");
14390                    msg.append(userId);
14391    
14392                    msg.append(", classNameId=");
14393                    msg.append(classNameId);
14394    
14395                    msg.append(", status=");
14396                    msg.append(status);
14397    
14398                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14399    
14400                    throw new NoSuchMessageException(msg.toString());
14401            }
14402    
14403            /**
14404             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14405             *
14406             * @param userId the user ID
14407             * @param classNameId the class name ID
14408             * @param status the status
14409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14410             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14411             */
14412            @Override
14413            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14414                    int status, OrderByComparator<MBMessage> orderByComparator) {
14415                    int count = countByU_C_S(userId, classNameId, status);
14416    
14417                    if (count == 0) {
14418                            return null;
14419                    }
14420    
14421                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14422                                    count - 1, count, orderByComparator);
14423    
14424                    if (!list.isEmpty()) {
14425                            return list.get(0);
14426                    }
14427    
14428                    return null;
14429            }
14430    
14431            /**
14432             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14433             *
14434             * @param messageId the primary key of the current message-boards message
14435             * @param userId the user ID
14436             * @param classNameId the class name ID
14437             * @param status the status
14438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14439             * @return the previous, current, and next message-boards message
14440             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14441             */
14442            @Override
14443            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14444                    long classNameId, int status,
14445                    OrderByComparator<MBMessage> orderByComparator)
14446                    throws NoSuchMessageException {
14447                    MBMessage mbMessage = findByPrimaryKey(messageId);
14448    
14449                    Session session = null;
14450    
14451                    try {
14452                            session = openSession();
14453    
14454                            MBMessage[] array = new MBMessageImpl[3];
14455    
14456                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14457                                            classNameId, status, orderByComparator, true);
14458    
14459                            array[1] = mbMessage;
14460    
14461                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14462                                            classNameId, status, orderByComparator, false);
14463    
14464                            return array;
14465                    }
14466                    catch (Exception e) {
14467                            throw processException(e);
14468                    }
14469                    finally {
14470                            closeSession(session);
14471                    }
14472            }
14473    
14474            protected MBMessage getByU_C_S_PrevAndNext(Session session,
14475                    MBMessage mbMessage, long userId, long classNameId, int status,
14476                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14477                    StringBundler query = null;
14478    
14479                    if (orderByComparator != null) {
14480                            query = new StringBundler(6 +
14481                                            (orderByComparator.getOrderByFields().length * 6));
14482                    }
14483                    else {
14484                            query = new StringBundler(3);
14485                    }
14486    
14487                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14488    
14489                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14490    
14491                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14492    
14493                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14494    
14495                    if (orderByComparator != null) {
14496                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14497    
14498                            if (orderByConditionFields.length > 0) {
14499                                    query.append(WHERE_AND);
14500                            }
14501    
14502                            for (int i = 0; i < orderByConditionFields.length; i++) {
14503                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14504                                    query.append(orderByConditionFields[i]);
14505    
14506                                    if ((i + 1) < orderByConditionFields.length) {
14507                                            if (orderByComparator.isAscending() ^ previous) {
14508                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14509                                            }
14510                                            else {
14511                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14512                                            }
14513                                    }
14514                                    else {
14515                                            if (orderByComparator.isAscending() ^ previous) {
14516                                                    query.append(WHERE_GREATER_THAN);
14517                                            }
14518                                            else {
14519                                                    query.append(WHERE_LESSER_THAN);
14520                                            }
14521                                    }
14522                            }
14523    
14524                            query.append(ORDER_BY_CLAUSE);
14525    
14526                            String[] orderByFields = orderByComparator.getOrderByFields();
14527    
14528                            for (int i = 0; i < orderByFields.length; i++) {
14529                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14530                                    query.append(orderByFields[i]);
14531    
14532                                    if ((i + 1) < orderByFields.length) {
14533                                            if (orderByComparator.isAscending() ^ previous) {
14534                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14535                                            }
14536                                            else {
14537                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14538                                            }
14539                                    }
14540                                    else {
14541                                            if (orderByComparator.isAscending() ^ previous) {
14542                                                    query.append(ORDER_BY_ASC);
14543                                            }
14544                                            else {
14545                                                    query.append(ORDER_BY_DESC);
14546                                            }
14547                                    }
14548                            }
14549                    }
14550                    else {
14551                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14552                    }
14553    
14554                    String sql = query.toString();
14555    
14556                    Query q = session.createQuery(sql);
14557    
14558                    q.setFirstResult(0);
14559                    q.setMaxResults(2);
14560    
14561                    QueryPos qPos = QueryPos.getInstance(q);
14562    
14563                    qPos.add(userId);
14564    
14565                    qPos.add(classNameId);
14566    
14567                    qPos.add(status);
14568    
14569                    if (orderByComparator != null) {
14570                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14571    
14572                            for (Object value : values) {
14573                                    qPos.add(value);
14574                            }
14575                    }
14576    
14577                    List<MBMessage> list = q.list();
14578    
14579                    if (list.size() == 2) {
14580                            return list.get(1);
14581                    }
14582                    else {
14583                            return null;
14584                    }
14585            }
14586    
14587            /**
14588             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14589             *
14590             * <p>
14591             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14592             * </p>
14593             *
14594             * @param userId the user ID
14595             * @param classNameIds the class name IDs
14596             * @param status the status
14597             * @return the matching message-boards messages
14598             */
14599            @Override
14600            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14601                    int status) {
14602                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14603                            QueryUtil.ALL_POS, null);
14604            }
14605    
14606            /**
14607             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14608             *
14609             * <p>
14610             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14611             * </p>
14612             *
14613             * @param userId the user ID
14614             * @param classNameIds the class name IDs
14615             * @param status the status
14616             * @param start the lower bound of the range of message-boards messages
14617             * @param end the upper bound of the range of message-boards messages (not inclusive)
14618             * @return the range of matching message-boards messages
14619             */
14620            @Override
14621            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14622                    int status, int start, int end) {
14623                    return findByU_C_S(userId, classNameIds, status, start, end, null);
14624            }
14625    
14626            /**
14627             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14628             *
14629             * <p>
14630             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14631             * </p>
14632             *
14633             * @param userId the user ID
14634             * @param classNameIds the class name IDs
14635             * @param status the status
14636             * @param start the lower bound of the range of message-boards messages
14637             * @param end the upper bound of the range of message-boards messages (not inclusive)
14638             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14639             * @return the ordered range of matching message-boards messages
14640             */
14641            @Override
14642            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14643                    int status, int start, int end,
14644                    OrderByComparator<MBMessage> orderByComparator) {
14645                    if (classNameIds == null) {
14646                            classNameIds = new long[0];
14647                    }
14648                    else {
14649                            classNameIds = ArrayUtil.unique(classNameIds);
14650                    }
14651    
14652                    if (classNameIds.length == 1) {
14653                            return findByU_C_S(userId, classNameIds[0], status, start, end,
14654                                    orderByComparator);
14655                    }
14656    
14657                    boolean pagination = true;
14658                    Object[] finderArgs = null;
14659    
14660                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14661                                    (orderByComparator == null)) {
14662                            pagination = false;
14663                            finderArgs = new Object[] {
14664                                            userId, StringUtil.merge(classNameIds), status
14665                                    };
14666                    }
14667                    else {
14668                            finderArgs = new Object[] {
14669                                            userId, StringUtil.merge(classNameIds), status,
14670                                            
14671                                            start, end, orderByComparator
14672                                    };
14673                    }
14674    
14675                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14676                                    finderArgs, this);
14677    
14678                    if ((list != null) && !list.isEmpty()) {
14679                            for (MBMessage mbMessage : list) {
14680                                    if ((userId != mbMessage.getUserId()) ||
14681                                                    !ArrayUtil.contains(classNameIds,
14682                                                            mbMessage.getClassNameId()) ||
14683                                                    (status != mbMessage.getStatus())) {
14684                                            list = null;
14685    
14686                                            break;
14687                                    }
14688                            }
14689                    }
14690    
14691                    if (list == null) {
14692                            StringBundler query = new StringBundler();
14693    
14694                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14695    
14696                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14697    
14698                            if (classNameIds.length > 0) {
14699                                    query.append(StringPool.OPEN_PARENTHESIS);
14700    
14701                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
14702    
14703                                    query.append(StringUtil.merge(classNameIds));
14704    
14705                                    query.append(StringPool.CLOSE_PARENTHESIS);
14706    
14707                                    query.append(StringPool.CLOSE_PARENTHESIS);
14708    
14709                                    query.append(WHERE_AND);
14710                            }
14711    
14712                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14713    
14714                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
14715                                                    1)), query.index() - 1);
14716    
14717                            if (orderByComparator != null) {
14718                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14719                                            orderByComparator);
14720                            }
14721                            else
14722                             if (pagination) {
14723                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14724                            }
14725    
14726                            String sql = query.toString();
14727    
14728                            Session session = null;
14729    
14730                            try {
14731                                    session = openSession();
14732    
14733                                    Query q = session.createQuery(sql);
14734    
14735                                    QueryPos qPos = QueryPos.getInstance(q);
14736    
14737                                    qPos.add(userId);
14738    
14739                                    qPos.add(status);
14740    
14741                                    if (!pagination) {
14742                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14743                                                            start, end, false);
14744    
14745                                            Collections.sort(list);
14746    
14747                                            list = Collections.unmodifiableList(list);
14748                                    }
14749                                    else {
14750                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14751                                                            start, end);
14752                                    }
14753    
14754                                    cacheResult(list);
14755    
14756                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14757                                            finderArgs, list);
14758                            }
14759                            catch (Exception e) {
14760                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14761                                            finderArgs);
14762    
14763                                    throw processException(e);
14764                            }
14765                            finally {
14766                                    closeSession(session);
14767                            }
14768                    }
14769    
14770                    return list;
14771            }
14772    
14773            /**
14774             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
14775             *
14776             * @param userId the user ID
14777             * @param classNameId the class name ID
14778             * @param status the status
14779             */
14780            @Override
14781            public void removeByU_C_S(long userId, long classNameId, int status) {
14782                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
14783                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14784                            remove(mbMessage);
14785                    }
14786            }
14787    
14788            /**
14789             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14790             *
14791             * @param userId the user ID
14792             * @param classNameId the class name ID
14793             * @param status the status
14794             * @return the number of matching message-boards messages
14795             */
14796            @Override
14797            public int countByU_C_S(long userId, long classNameId, int status) {
14798                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
14799    
14800                    Object[] finderArgs = new Object[] { userId, classNameId, status };
14801    
14802                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14803                                    this);
14804    
14805                    if (count == null) {
14806                            StringBundler query = new StringBundler(4);
14807    
14808                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14809    
14810                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14811    
14812                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14813    
14814                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14815    
14816                            String sql = query.toString();
14817    
14818                            Session session = null;
14819    
14820                            try {
14821                                    session = openSession();
14822    
14823                                    Query q = session.createQuery(sql);
14824    
14825                                    QueryPos qPos = QueryPos.getInstance(q);
14826    
14827                                    qPos.add(userId);
14828    
14829                                    qPos.add(classNameId);
14830    
14831                                    qPos.add(status);
14832    
14833                                    count = (Long)q.uniqueResult();
14834    
14835                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14836                            }
14837                            catch (Exception e) {
14838                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14839    
14840                                    throw processException(e);
14841                            }
14842                            finally {
14843                                    closeSession(session);
14844                            }
14845                    }
14846    
14847                    return count.intValue();
14848            }
14849    
14850            /**
14851             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14852             *
14853             * @param userId the user ID
14854             * @param classNameIds the class name IDs
14855             * @param status the status
14856             * @return the number of matching message-boards messages
14857             */
14858            @Override
14859            public int countByU_C_S(long userId, long[] classNameIds, int status) {
14860                    if (classNameIds == null) {
14861                            classNameIds = new long[0];
14862                    }
14863                    else {
14864                            classNameIds = ArrayUtil.unique(classNameIds);
14865                    }
14866    
14867                    Object[] finderArgs = new Object[] {
14868                                    userId, StringUtil.merge(classNameIds), status
14869                            };
14870    
14871                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14872                                    finderArgs, this);
14873    
14874                    if (count == null) {
14875                            StringBundler query = new StringBundler();
14876    
14877                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14878    
14879                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14880    
14881                            if (classNameIds.length > 0) {
14882                                    query.append(StringPool.OPEN_PARENTHESIS);
14883    
14884                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
14885    
14886                                    query.append(StringUtil.merge(classNameIds));
14887    
14888                                    query.append(StringPool.CLOSE_PARENTHESIS);
14889    
14890                                    query.append(StringPool.CLOSE_PARENTHESIS);
14891    
14892                                    query.append(WHERE_AND);
14893                            }
14894    
14895                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14896    
14897                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
14898                                                    1)), query.index() - 1);
14899    
14900                            String sql = query.toString();
14901    
14902                            Session session = null;
14903    
14904                            try {
14905                                    session = openSession();
14906    
14907                                    Query q = session.createQuery(sql);
14908    
14909                                    QueryPos qPos = QueryPos.getInstance(q);
14910    
14911                                    qPos.add(userId);
14912    
14913                                    qPos.add(status);
14914    
14915                                    count = (Long)q.uniqueResult();
14916    
14917                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14918                                            finderArgs, count);
14919                            }
14920                            catch (Exception e) {
14921                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14922                                            finderArgs);
14923    
14924                                    throw processException(e);
14925                            }
14926                            finally {
14927                                    closeSession(session);
14928                            }
14929                    }
14930    
14931                    return count.intValue();
14932            }
14933    
14934            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
14935            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14936            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
14937            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
14938            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14939                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14940                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
14941                            new String[] {
14942                                    Long.class.getName(), Long.class.getName(),
14943                                    Integer.class.getName(),
14944                                    
14945                            Integer.class.getName(), Integer.class.getName(),
14946                                    OrderByComparator.class.getName()
14947                            });
14948            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14949                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14950                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
14951                            new String[] {
14952                                    Long.class.getName(), Long.class.getName(),
14953                                    Integer.class.getName()
14954                            },
14955                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14956                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14957                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14958                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14959            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14960                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14961                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
14962                            new String[] {
14963                                    Long.class.getName(), Long.class.getName(),
14964                                    Integer.class.getName()
14965                            });
14966    
14967            /**
14968             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
14969             *
14970             * @param classNameId the class name ID
14971             * @param classPK the class p k
14972             * @param status the status
14973             * @return the matching message-boards messages
14974             */
14975            @Override
14976            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
14977                    int status) {
14978                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
14979                            QueryUtil.ALL_POS, null);
14980            }
14981    
14982            /**
14983             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
14984             *
14985             * <p>
14986             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14987             * </p>
14988             *
14989             * @param classNameId the class name ID
14990             * @param classPK the class p k
14991             * @param status the status
14992             * @param start the lower bound of the range of message-boards messages
14993             * @param end the upper bound of the range of message-boards messages (not inclusive)
14994             * @return the range of matching message-boards messages
14995             */
14996            @Override
14997            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
14998                    int status, int start, int end) {
14999                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15000            }
15001    
15002            /**
15003             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15004             *
15005             * <p>
15006             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15007             * </p>
15008             *
15009             * @param classNameId the class name ID
15010             * @param classPK the class p k
15011             * @param status the status
15012             * @param start the lower bound of the range of message-boards messages
15013             * @param end the upper bound of the range of message-boards messages (not inclusive)
15014             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15015             * @return the ordered range of matching message-boards messages
15016             */
15017            @Override
15018            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15019                    int status, int start, int end,
15020                    OrderByComparator<MBMessage> orderByComparator) {
15021                    boolean pagination = true;
15022                    FinderPath finderPath = null;
15023                    Object[] finderArgs = null;
15024    
15025                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15026                                    (orderByComparator == null)) {
15027                            pagination = false;
15028                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15029                            finderArgs = new Object[] { classNameId, classPK, status };
15030                    }
15031                    else {
15032                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15033                            finderArgs = new Object[] {
15034                                            classNameId, classPK, status,
15035                                            
15036                                            start, end, orderByComparator
15037                                    };
15038                    }
15039    
15040                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15041                                    finderArgs, this);
15042    
15043                    if ((list != null) && !list.isEmpty()) {
15044                            for (MBMessage mbMessage : list) {
15045                                    if ((classNameId != mbMessage.getClassNameId()) ||
15046                                                    (classPK != mbMessage.getClassPK()) ||
15047                                                    (status != mbMessage.getStatus())) {
15048                                            list = null;
15049    
15050                                            break;
15051                                    }
15052                            }
15053                    }
15054    
15055                    if (list == null) {
15056                            StringBundler query = null;
15057    
15058                            if (orderByComparator != null) {
15059                                    query = new StringBundler(5 +
15060                                                    (orderByComparator.getOrderByFields().length * 3));
15061                            }
15062                            else {
15063                                    query = new StringBundler(5);
15064                            }
15065    
15066                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15067    
15068                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15069    
15070                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15071    
15072                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15073    
15074                            if (orderByComparator != null) {
15075                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15076                                            orderByComparator);
15077                            }
15078                            else
15079                             if (pagination) {
15080                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15081                            }
15082    
15083                            String sql = query.toString();
15084    
15085                            Session session = null;
15086    
15087                            try {
15088                                    session = openSession();
15089    
15090                                    Query q = session.createQuery(sql);
15091    
15092                                    QueryPos qPos = QueryPos.getInstance(q);
15093    
15094                                    qPos.add(classNameId);
15095    
15096                                    qPos.add(classPK);
15097    
15098                                    qPos.add(status);
15099    
15100                                    if (!pagination) {
15101                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15102                                                            start, end, false);
15103    
15104                                            Collections.sort(list);
15105    
15106                                            list = Collections.unmodifiableList(list);
15107                                    }
15108                                    else {
15109                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15110                                                            start, end);
15111                                    }
15112    
15113                                    cacheResult(list);
15114    
15115                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15116                            }
15117                            catch (Exception e) {
15118                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15119    
15120                                    throw processException(e);
15121                            }
15122                            finally {
15123                                    closeSession(session);
15124                            }
15125                    }
15126    
15127                    return list;
15128            }
15129    
15130            /**
15131             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15132             *
15133             * @param classNameId the class name ID
15134             * @param classPK the class p k
15135             * @param status the status
15136             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15137             * @return the first matching message-boards message
15138             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15139             */
15140            @Override
15141            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15142                    int status, OrderByComparator<MBMessage> orderByComparator)
15143                    throws NoSuchMessageException {
15144                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15145                                    orderByComparator);
15146    
15147                    if (mbMessage != null) {
15148                            return mbMessage;
15149                    }
15150    
15151                    StringBundler msg = new StringBundler(8);
15152    
15153                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15154    
15155                    msg.append("classNameId=");
15156                    msg.append(classNameId);
15157    
15158                    msg.append(", classPK=");
15159                    msg.append(classPK);
15160    
15161                    msg.append(", status=");
15162                    msg.append(status);
15163    
15164                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15165    
15166                    throw new NoSuchMessageException(msg.toString());
15167            }
15168    
15169            /**
15170             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15171             *
15172             * @param classNameId the class name ID
15173             * @param classPK the class p k
15174             * @param status the status
15175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15176             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15177             */
15178            @Override
15179            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15180                    int status, OrderByComparator<MBMessage> orderByComparator) {
15181                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15182                                    orderByComparator);
15183    
15184                    if (!list.isEmpty()) {
15185                            return list.get(0);
15186                    }
15187    
15188                    return null;
15189            }
15190    
15191            /**
15192             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15193             *
15194             * @param classNameId the class name ID
15195             * @param classPK the class p k
15196             * @param status the status
15197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15198             * @return the last matching message-boards message
15199             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15200             */
15201            @Override
15202            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15203                    int status, OrderByComparator<MBMessage> orderByComparator)
15204                    throws NoSuchMessageException {
15205                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15206                                    orderByComparator);
15207    
15208                    if (mbMessage != null) {
15209                            return mbMessage;
15210                    }
15211    
15212                    StringBundler msg = new StringBundler(8);
15213    
15214                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15215    
15216                    msg.append("classNameId=");
15217                    msg.append(classNameId);
15218    
15219                    msg.append(", classPK=");
15220                    msg.append(classPK);
15221    
15222                    msg.append(", status=");
15223                    msg.append(status);
15224    
15225                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15226    
15227                    throw new NoSuchMessageException(msg.toString());
15228            }
15229    
15230            /**
15231             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15232             *
15233             * @param classNameId the class name ID
15234             * @param classPK the class p k
15235             * @param status the status
15236             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15237             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15238             */
15239            @Override
15240            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15241                    int status, OrderByComparator<MBMessage> orderByComparator) {
15242                    int count = countByC_C_S(classNameId, classPK, status);
15243    
15244                    if (count == 0) {
15245                            return null;
15246                    }
15247    
15248                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15249                                    count - 1, count, orderByComparator);
15250    
15251                    if (!list.isEmpty()) {
15252                            return list.get(0);
15253                    }
15254    
15255                    return null;
15256            }
15257    
15258            /**
15259             * 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;.
15260             *
15261             * @param messageId the primary key of the current message-boards message
15262             * @param classNameId the class name ID
15263             * @param classPK the class p k
15264             * @param status the status
15265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15266             * @return the previous, current, and next message-boards message
15267             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15268             */
15269            @Override
15270            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15271                    long classNameId, long classPK, int status,
15272                    OrderByComparator<MBMessage> orderByComparator)
15273                    throws NoSuchMessageException {
15274                    MBMessage mbMessage = findByPrimaryKey(messageId);
15275    
15276                    Session session = null;
15277    
15278                    try {
15279                            session = openSession();
15280    
15281                            MBMessage[] array = new MBMessageImpl[3];
15282    
15283                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15284                                            classPK, status, orderByComparator, true);
15285    
15286                            array[1] = mbMessage;
15287    
15288                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15289                                            classPK, status, orderByComparator, false);
15290    
15291                            return array;
15292                    }
15293                    catch (Exception e) {
15294                            throw processException(e);
15295                    }
15296                    finally {
15297                            closeSession(session);
15298                    }
15299            }
15300    
15301            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15302                    MBMessage mbMessage, long classNameId, long classPK, int status,
15303                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15304                    StringBundler query = null;
15305    
15306                    if (orderByComparator != null) {
15307                            query = new StringBundler(6 +
15308                                            (orderByComparator.getOrderByFields().length * 6));
15309                    }
15310                    else {
15311                            query = new StringBundler(3);
15312                    }
15313    
15314                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15315    
15316                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15317    
15318                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15319    
15320                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15321    
15322                    if (orderByComparator != null) {
15323                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15324    
15325                            if (orderByConditionFields.length > 0) {
15326                                    query.append(WHERE_AND);
15327                            }
15328    
15329                            for (int i = 0; i < orderByConditionFields.length; i++) {
15330                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15331                                    query.append(orderByConditionFields[i]);
15332    
15333                                    if ((i + 1) < orderByConditionFields.length) {
15334                                            if (orderByComparator.isAscending() ^ previous) {
15335                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15336                                            }
15337                                            else {
15338                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15339                                            }
15340                                    }
15341                                    else {
15342                                            if (orderByComparator.isAscending() ^ previous) {
15343                                                    query.append(WHERE_GREATER_THAN);
15344                                            }
15345                                            else {
15346                                                    query.append(WHERE_LESSER_THAN);
15347                                            }
15348                                    }
15349                            }
15350    
15351                            query.append(ORDER_BY_CLAUSE);
15352    
15353                            String[] orderByFields = orderByComparator.getOrderByFields();
15354    
15355                            for (int i = 0; i < orderByFields.length; i++) {
15356                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15357                                    query.append(orderByFields[i]);
15358    
15359                                    if ((i + 1) < orderByFields.length) {
15360                                            if (orderByComparator.isAscending() ^ previous) {
15361                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15362                                            }
15363                                            else {
15364                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15365                                            }
15366                                    }
15367                                    else {
15368                                            if (orderByComparator.isAscending() ^ previous) {
15369                                                    query.append(ORDER_BY_ASC);
15370                                            }
15371                                            else {
15372                                                    query.append(ORDER_BY_DESC);
15373                                            }
15374                                    }
15375                            }
15376                    }
15377                    else {
15378                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15379                    }
15380    
15381                    String sql = query.toString();
15382    
15383                    Query q = session.createQuery(sql);
15384    
15385                    q.setFirstResult(0);
15386                    q.setMaxResults(2);
15387    
15388                    QueryPos qPos = QueryPos.getInstance(q);
15389    
15390                    qPos.add(classNameId);
15391    
15392                    qPos.add(classPK);
15393    
15394                    qPos.add(status);
15395    
15396                    if (orderByComparator != null) {
15397                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15398    
15399                            for (Object value : values) {
15400                                    qPos.add(value);
15401                            }
15402                    }
15403    
15404                    List<MBMessage> list = q.list();
15405    
15406                    if (list.size() == 2) {
15407                            return list.get(1);
15408                    }
15409                    else {
15410                            return null;
15411                    }
15412            }
15413    
15414            /**
15415             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15416             *
15417             * @param classNameId the class name ID
15418             * @param classPK the class p k
15419             * @param status the status
15420             */
15421            @Override
15422            public void removeByC_C_S(long classNameId, long classPK, int status) {
15423                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15424                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15425                            remove(mbMessage);
15426                    }
15427            }
15428    
15429            /**
15430             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15431             *
15432             * @param classNameId the class name ID
15433             * @param classPK the class p k
15434             * @param status the status
15435             * @return the number of matching message-boards messages
15436             */
15437            @Override
15438            public int countByC_C_S(long classNameId, long classPK, int status) {
15439                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15440    
15441                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
15442    
15443                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15444                                    this);
15445    
15446                    if (count == null) {
15447                            StringBundler query = new StringBundler(4);
15448    
15449                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15450    
15451                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15452    
15453                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15454    
15455                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15456    
15457                            String sql = query.toString();
15458    
15459                            Session session = null;
15460    
15461                            try {
15462                                    session = openSession();
15463    
15464                                    Query q = session.createQuery(sql);
15465    
15466                                    QueryPos qPos = QueryPos.getInstance(q);
15467    
15468                                    qPos.add(classNameId);
15469    
15470                                    qPos.add(classPK);
15471    
15472                                    qPos.add(status);
15473    
15474                                    count = (Long)q.uniqueResult();
15475    
15476                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15477                            }
15478                            catch (Exception e) {
15479                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15480    
15481                                    throw processException(e);
15482                            }
15483                            finally {
15484                                    closeSession(session);
15485                            }
15486                    }
15487    
15488                    return count.intValue();
15489            }
15490    
15491            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15492            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15493            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15494            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15495                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15496                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
15497                            new String[] {
15498                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15499                                    Boolean.class.getName(),
15500                                    
15501                            Integer.class.getName(), Integer.class.getName(),
15502                                    OrderByComparator.class.getName()
15503                            });
15504            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
15505                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15506                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15507                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
15508                            new String[] {
15509                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15510                                    Boolean.class.getName()
15511                            },
15512                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15513                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15514                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
15515                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
15516                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15517            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15518                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15519                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
15520                            new String[] {
15521                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15522                                    Boolean.class.getName()
15523                            });
15524    
15525            /**
15526             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15527             *
15528             * @param groupId the group ID
15529             * @param categoryId the category ID
15530             * @param threadId the thread ID
15531             * @param answer the answer
15532             * @return the matching message-boards messages
15533             */
15534            @Override
15535            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15536                    long threadId, boolean answer) {
15537                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
15538                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15539            }
15540    
15541            /**
15542             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15543             *
15544             * <p>
15545             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15546             * </p>
15547             *
15548             * @param groupId the group ID
15549             * @param categoryId the category ID
15550             * @param threadId the thread ID
15551             * @param answer the answer
15552             * @param start the lower bound of the range of message-boards messages
15553             * @param end the upper bound of the range of message-boards messages (not inclusive)
15554             * @return the range of matching message-boards messages
15555             */
15556            @Override
15557            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15558                    long threadId, boolean answer, int start, int end) {
15559                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
15560                            null);
15561            }
15562    
15563            /**
15564             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15565             *
15566             * <p>
15567             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15568             * </p>
15569             *
15570             * @param groupId the group ID
15571             * @param categoryId the category ID
15572             * @param threadId the thread ID
15573             * @param answer the answer
15574             * @param start the lower bound of the range of message-boards messages
15575             * @param end the upper bound of the range of message-boards messages (not inclusive)
15576             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15577             * @return the ordered range of matching message-boards messages
15578             */
15579            @Override
15580            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15581                    long threadId, boolean answer, int start, int end,
15582                    OrderByComparator<MBMessage> orderByComparator) {
15583                    boolean pagination = true;
15584                    FinderPath finderPath = null;
15585                    Object[] finderArgs = null;
15586    
15587                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15588                                    (orderByComparator == null)) {
15589                            pagination = false;
15590                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
15591                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
15592                    }
15593                    else {
15594                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
15595                            finderArgs = new Object[] {
15596                                            groupId, categoryId, threadId, answer,
15597                                            
15598                                            start, end, orderByComparator
15599                                    };
15600                    }
15601    
15602                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15603                                    finderArgs, this);
15604    
15605                    if ((list != null) && !list.isEmpty()) {
15606                            for (MBMessage mbMessage : list) {
15607                                    if ((groupId != mbMessage.getGroupId()) ||
15608                                                    (categoryId != mbMessage.getCategoryId()) ||
15609                                                    (threadId != mbMessage.getThreadId()) ||
15610                                                    (answer != mbMessage.getAnswer())) {
15611                                            list = null;
15612    
15613                                            break;
15614                                    }
15615                            }
15616                    }
15617    
15618                    if (list == null) {
15619                            StringBundler query = null;
15620    
15621                            if (orderByComparator != null) {
15622                                    query = new StringBundler(6 +
15623                                                    (orderByComparator.getOrderByFields().length * 3));
15624                            }
15625                            else {
15626                                    query = new StringBundler(6);
15627                            }
15628    
15629                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15630    
15631                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15632    
15633                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15634    
15635                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15636    
15637                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15638    
15639                            if (orderByComparator != null) {
15640                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15641                                            orderByComparator);
15642                            }
15643                            else
15644                             if (pagination) {
15645                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15646                            }
15647    
15648                            String sql = query.toString();
15649    
15650                            Session session = null;
15651    
15652                            try {
15653                                    session = openSession();
15654    
15655                                    Query q = session.createQuery(sql);
15656    
15657                                    QueryPos qPos = QueryPos.getInstance(q);
15658    
15659                                    qPos.add(groupId);
15660    
15661                                    qPos.add(categoryId);
15662    
15663                                    qPos.add(threadId);
15664    
15665                                    qPos.add(answer);
15666    
15667                                    if (!pagination) {
15668                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15669                                                            start, end, false);
15670    
15671                                            Collections.sort(list);
15672    
15673                                            list = Collections.unmodifiableList(list);
15674                                    }
15675                                    else {
15676                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15677                                                            start, end);
15678                                    }
15679    
15680                                    cacheResult(list);
15681    
15682                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15683                            }
15684                            catch (Exception e) {
15685                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15686    
15687                                    throw processException(e);
15688                            }
15689                            finally {
15690                                    closeSession(session);
15691                            }
15692                    }
15693    
15694                    return list;
15695            }
15696    
15697            /**
15698             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15699             *
15700             * @param groupId the group ID
15701             * @param categoryId the category ID
15702             * @param threadId the thread ID
15703             * @param answer the answer
15704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15705             * @return the first matching message-boards message
15706             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15707             */
15708            @Override
15709            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
15710                    long threadId, boolean answer,
15711                    OrderByComparator<MBMessage> orderByComparator)
15712                    throws NoSuchMessageException {
15713                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
15714                                    threadId, answer, orderByComparator);
15715    
15716                    if (mbMessage != null) {
15717                            return mbMessage;
15718                    }
15719    
15720                    StringBundler msg = new StringBundler(10);
15721    
15722                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15723    
15724                    msg.append("groupId=");
15725                    msg.append(groupId);
15726    
15727                    msg.append(", categoryId=");
15728                    msg.append(categoryId);
15729    
15730                    msg.append(", threadId=");
15731                    msg.append(threadId);
15732    
15733                    msg.append(", answer=");
15734                    msg.append(answer);
15735    
15736                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15737    
15738                    throw new NoSuchMessageException(msg.toString());
15739            }
15740    
15741            /**
15742             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15743             *
15744             * @param groupId the group ID
15745             * @param categoryId the category ID
15746             * @param threadId the thread ID
15747             * @param answer the answer
15748             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15749             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15750             */
15751            @Override
15752            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
15753                    long threadId, boolean answer,
15754                    OrderByComparator<MBMessage> orderByComparator) {
15755                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15756                                    answer, 0, 1, orderByComparator);
15757    
15758                    if (!list.isEmpty()) {
15759                            return list.get(0);
15760                    }
15761    
15762                    return null;
15763            }
15764    
15765            /**
15766             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15767             *
15768             * @param groupId the group ID
15769             * @param categoryId the category ID
15770             * @param threadId the thread ID
15771             * @param answer the answer
15772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15773             * @return the last matching message-boards message
15774             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15775             */
15776            @Override
15777            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
15778                    long threadId, boolean answer,
15779                    OrderByComparator<MBMessage> orderByComparator)
15780                    throws NoSuchMessageException {
15781                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
15782                                    threadId, answer, orderByComparator);
15783    
15784                    if (mbMessage != null) {
15785                            return mbMessage;
15786                    }
15787    
15788                    StringBundler msg = new StringBundler(10);
15789    
15790                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15791    
15792                    msg.append("groupId=");
15793                    msg.append(groupId);
15794    
15795                    msg.append(", categoryId=");
15796                    msg.append(categoryId);
15797    
15798                    msg.append(", threadId=");
15799                    msg.append(threadId);
15800    
15801                    msg.append(", answer=");
15802                    msg.append(answer);
15803    
15804                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15805    
15806                    throw new NoSuchMessageException(msg.toString());
15807            }
15808    
15809            /**
15810             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15811             *
15812             * @param groupId the group ID
15813             * @param categoryId the category ID
15814             * @param threadId the thread ID
15815             * @param answer the answer
15816             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15817             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15818             */
15819            @Override
15820            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
15821                    long threadId, boolean answer,
15822                    OrderByComparator<MBMessage> orderByComparator) {
15823                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
15824    
15825                    if (count == 0) {
15826                            return null;
15827                    }
15828    
15829                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15830                                    answer, count - 1, count, orderByComparator);
15831    
15832                    if (!list.isEmpty()) {
15833                            return list.get(0);
15834                    }
15835    
15836                    return null;
15837            }
15838    
15839            /**
15840             * 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;.
15841             *
15842             * @param messageId the primary key of the current message-boards message
15843             * @param groupId the group ID
15844             * @param categoryId the category ID
15845             * @param threadId the thread ID
15846             * @param answer the answer
15847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15848             * @return the previous, current, and next message-boards message
15849             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15850             */
15851            @Override
15852            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
15853                    long categoryId, long threadId, boolean answer,
15854                    OrderByComparator<MBMessage> orderByComparator)
15855                    throws NoSuchMessageException {
15856                    MBMessage mbMessage = findByPrimaryKey(messageId);
15857    
15858                    Session session = null;
15859    
15860                    try {
15861                            session = openSession();
15862    
15863                            MBMessage[] array = new MBMessageImpl[3];
15864    
15865                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15866                                            categoryId, threadId, answer, orderByComparator, true);
15867    
15868                            array[1] = mbMessage;
15869    
15870                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15871                                            categoryId, threadId, answer, orderByComparator, false);
15872    
15873                            return array;
15874                    }
15875                    catch (Exception e) {
15876                            throw processException(e);
15877                    }
15878                    finally {
15879                            closeSession(session);
15880                    }
15881            }
15882    
15883            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
15884                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
15885                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
15886                    boolean previous) {
15887                    StringBundler query = null;
15888    
15889                    if (orderByComparator != null) {
15890                            query = new StringBundler(6 +
15891                                            (orderByComparator.getOrderByFields().length * 6));
15892                    }
15893                    else {
15894                            query = new StringBundler(3);
15895                    }
15896    
15897                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15898    
15899                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15900    
15901                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15902    
15903                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15904    
15905                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15906    
15907                    if (orderByComparator != null) {
15908                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15909    
15910                            if (orderByConditionFields.length > 0) {
15911                                    query.append(WHERE_AND);
15912                            }
15913    
15914                            for (int i = 0; i < orderByConditionFields.length; i++) {
15915                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15916                                    query.append(orderByConditionFields[i]);
15917    
15918                                    if ((i + 1) < orderByConditionFields.length) {
15919                                            if (orderByComparator.isAscending() ^ previous) {
15920                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15921                                            }
15922                                            else {
15923                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15924                                            }
15925                                    }
15926                                    else {
15927                                            if (orderByComparator.isAscending() ^ previous) {
15928                                                    query.append(WHERE_GREATER_THAN);
15929                                            }
15930                                            else {
15931                                                    query.append(WHERE_LESSER_THAN);
15932                                            }
15933                                    }
15934                            }
15935    
15936                            query.append(ORDER_BY_CLAUSE);
15937    
15938                            String[] orderByFields = orderByComparator.getOrderByFields();
15939    
15940                            for (int i = 0; i < orderByFields.length; i++) {
15941                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15942                                    query.append(orderByFields[i]);
15943    
15944                                    if ((i + 1) < orderByFields.length) {
15945                                            if (orderByComparator.isAscending() ^ previous) {
15946                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15947                                            }
15948                                            else {
15949                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15950                                            }
15951                                    }
15952                                    else {
15953                                            if (orderByComparator.isAscending() ^ previous) {
15954                                                    query.append(ORDER_BY_ASC);
15955                                            }
15956                                            else {
15957                                                    query.append(ORDER_BY_DESC);
15958                                            }
15959                                    }
15960                            }
15961                    }
15962                    else {
15963                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15964                    }
15965    
15966                    String sql = query.toString();
15967    
15968                    Query q = session.createQuery(sql);
15969    
15970                    q.setFirstResult(0);
15971                    q.setMaxResults(2);
15972    
15973                    QueryPos qPos = QueryPos.getInstance(q);
15974    
15975                    qPos.add(groupId);
15976    
15977                    qPos.add(categoryId);
15978    
15979                    qPos.add(threadId);
15980    
15981                    qPos.add(answer);
15982    
15983                    if (orderByComparator != null) {
15984                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15985    
15986                            for (Object value : values) {
15987                                    qPos.add(value);
15988                            }
15989                    }
15990    
15991                    List<MBMessage> list = q.list();
15992    
15993                    if (list.size() == 2) {
15994                            return list.get(1);
15995                    }
15996                    else {
15997                            return null;
15998                    }
15999            }
16000    
16001            /**
16002             * 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;.
16003             *
16004             * @param groupId the group ID
16005             * @param categoryId the category ID
16006             * @param threadId the thread ID
16007             * @param answer the answer
16008             * @return the matching message-boards messages that the user has permission to view
16009             */
16010            @Override
16011            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16012                    long threadId, boolean answer) {
16013                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16014                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16015            }
16016    
16017            /**
16018             * 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;.
16019             *
16020             * <p>
16021             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16022             * </p>
16023             *
16024             * @param groupId the group ID
16025             * @param categoryId the category ID
16026             * @param threadId the thread ID
16027             * @param answer the answer
16028             * @param start the lower bound of the range of message-boards messages
16029             * @param end the upper bound of the range of message-boards messages (not inclusive)
16030             * @return the range of matching message-boards messages that the user has permission to view
16031             */
16032            @Override
16033            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16034                    long threadId, boolean answer, int start, int end) {
16035                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16036                            start, end, null);
16037            }
16038    
16039            /**
16040             * 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;.
16041             *
16042             * <p>
16043             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16044             * </p>
16045             *
16046             * @param groupId the group ID
16047             * @param categoryId the category ID
16048             * @param threadId the thread ID
16049             * @param answer the answer
16050             * @param start the lower bound of the range of message-boards messages
16051             * @param end the upper bound of the range of message-boards messages (not inclusive)
16052             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16053             * @return the ordered range of matching message-boards messages that the user has permission to view
16054             */
16055            @Override
16056            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16057                    long threadId, boolean answer, int start, int end,
16058                    OrderByComparator<MBMessage> orderByComparator) {
16059                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16060                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16061                                    end, orderByComparator);
16062                    }
16063    
16064                    StringBundler query = null;
16065    
16066                    if (orderByComparator != null) {
16067                            query = new StringBundler(6 +
16068                                            (orderByComparator.getOrderByFields().length * 3));
16069                    }
16070                    else {
16071                            query = new StringBundler(6);
16072                    }
16073    
16074                    if (getDB().isSupportsInlineDistinct()) {
16075                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16076                    }
16077                    else {
16078                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16079                    }
16080    
16081                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16082    
16083                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16084    
16085                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16086    
16087                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16088    
16089                    if (!getDB().isSupportsInlineDistinct()) {
16090                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16091                    }
16092    
16093                    if (orderByComparator != null) {
16094                            if (getDB().isSupportsInlineDistinct()) {
16095                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16096                                            orderByComparator, true);
16097                            }
16098                            else {
16099                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16100                                            orderByComparator, true);
16101                            }
16102                    }
16103                    else {
16104                            if (getDB().isSupportsInlineDistinct()) {
16105                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16106                            }
16107                            else {
16108                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16109                            }
16110                    }
16111    
16112                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16113                                    MBMessage.class.getName(),
16114                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16115    
16116                    Session session = null;
16117    
16118                    try {
16119                            session = openSession();
16120    
16121                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16122    
16123                            if (getDB().isSupportsInlineDistinct()) {
16124                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16125                            }
16126                            else {
16127                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16128                            }
16129    
16130                            QueryPos qPos = QueryPos.getInstance(q);
16131    
16132                            qPos.add(groupId);
16133    
16134                            qPos.add(categoryId);
16135    
16136                            qPos.add(threadId);
16137    
16138                            qPos.add(answer);
16139    
16140                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16141                    }
16142                    catch (Exception e) {
16143                            throw processException(e);
16144                    }
16145                    finally {
16146                            closeSession(session);
16147                    }
16148            }
16149    
16150            /**
16151             * 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;.
16152             *
16153             * @param messageId the primary key of the current message-boards message
16154             * @param groupId the group ID
16155             * @param categoryId the category ID
16156             * @param threadId the thread ID
16157             * @param answer the answer
16158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16159             * @return the previous, current, and next message-boards message
16160             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16161             */
16162            @Override
16163            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16164                    long groupId, long categoryId, long threadId, boolean answer,
16165                    OrderByComparator<MBMessage> orderByComparator)
16166                    throws NoSuchMessageException {
16167                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16168                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16169                                    threadId, answer, orderByComparator);
16170                    }
16171    
16172                    MBMessage mbMessage = findByPrimaryKey(messageId);
16173    
16174                    Session session = null;
16175    
16176                    try {
16177                            session = openSession();
16178    
16179                            MBMessage[] array = new MBMessageImpl[3];
16180    
16181                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16182                                            groupId, categoryId, threadId, answer, orderByComparator,
16183                                            true);
16184    
16185                            array[1] = mbMessage;
16186    
16187                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16188                                            groupId, categoryId, threadId, answer, orderByComparator,
16189                                            false);
16190    
16191                            return array;
16192                    }
16193                    catch (Exception e) {
16194                            throw processException(e);
16195                    }
16196                    finally {
16197                            closeSession(session);
16198                    }
16199            }
16200    
16201            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16202                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16203                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16204                    boolean previous) {
16205                    StringBundler query = null;
16206    
16207                    if (orderByComparator != null) {
16208                            query = new StringBundler(6 +
16209                                            (orderByComparator.getOrderByFields().length * 6));
16210                    }
16211                    else {
16212                            query = new StringBundler(3);
16213                    }
16214    
16215                    if (getDB().isSupportsInlineDistinct()) {
16216                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16217                    }
16218                    else {
16219                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16220                    }
16221    
16222                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16223    
16224                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16225    
16226                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16227    
16228                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16229    
16230                    if (!getDB().isSupportsInlineDistinct()) {
16231                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16232                    }
16233    
16234                    if (orderByComparator != null) {
16235                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16236    
16237                            if (orderByConditionFields.length > 0) {
16238                                    query.append(WHERE_AND);
16239                            }
16240    
16241                            for (int i = 0; i < orderByConditionFields.length; i++) {
16242                                    if (getDB().isSupportsInlineDistinct()) {
16243                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16244                                    }
16245                                    else {
16246                                            query.append(_ORDER_BY_ENTITY_TABLE);
16247                                    }
16248    
16249                                    query.append(orderByConditionFields[i]);
16250    
16251                                    if ((i + 1) < orderByConditionFields.length) {
16252                                            if (orderByComparator.isAscending() ^ previous) {
16253                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16254                                            }
16255                                            else {
16256                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16257                                            }
16258                                    }
16259                                    else {
16260                                            if (orderByComparator.isAscending() ^ previous) {
16261                                                    query.append(WHERE_GREATER_THAN);
16262                                            }
16263                                            else {
16264                                                    query.append(WHERE_LESSER_THAN);
16265                                            }
16266                                    }
16267                            }
16268    
16269                            query.append(ORDER_BY_CLAUSE);
16270    
16271                            String[] orderByFields = orderByComparator.getOrderByFields();
16272    
16273                            for (int i = 0; i < orderByFields.length; i++) {
16274                                    if (getDB().isSupportsInlineDistinct()) {
16275                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16276                                    }
16277                                    else {
16278                                            query.append(_ORDER_BY_ENTITY_TABLE);
16279                                    }
16280    
16281                                    query.append(orderByFields[i]);
16282    
16283                                    if ((i + 1) < orderByFields.length) {
16284                                            if (orderByComparator.isAscending() ^ previous) {
16285                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16286                                            }
16287                                            else {
16288                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16289                                            }
16290                                    }
16291                                    else {
16292                                            if (orderByComparator.isAscending() ^ previous) {
16293                                                    query.append(ORDER_BY_ASC);
16294                                            }
16295                                            else {
16296                                                    query.append(ORDER_BY_DESC);
16297                                            }
16298                                    }
16299                            }
16300                    }
16301                    else {
16302                            if (getDB().isSupportsInlineDistinct()) {
16303                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16304                            }
16305                            else {
16306                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16307                            }
16308                    }
16309    
16310                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16311                                    MBMessage.class.getName(),
16312                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16313    
16314                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
16315    
16316                    q.setFirstResult(0);
16317                    q.setMaxResults(2);
16318    
16319                    if (getDB().isSupportsInlineDistinct()) {
16320                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16321                    }
16322                    else {
16323                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16324                    }
16325    
16326                    QueryPos qPos = QueryPos.getInstance(q);
16327    
16328                    qPos.add(groupId);
16329    
16330                    qPos.add(categoryId);
16331    
16332                    qPos.add(threadId);
16333    
16334                    qPos.add(answer);
16335    
16336                    if (orderByComparator != null) {
16337                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16338    
16339                            for (Object value : values) {
16340                                    qPos.add(value);
16341                            }
16342                    }
16343    
16344                    List<MBMessage> list = q.list();
16345    
16346                    if (list.size() == 2) {
16347                            return list.get(1);
16348                    }
16349                    else {
16350                            return null;
16351                    }
16352            }
16353    
16354            /**
16355             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16356             *
16357             * @param groupId the group ID
16358             * @param categoryId the category ID
16359             * @param threadId the thread ID
16360             * @param answer the answer
16361             */
16362            @Override
16363            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16364                    boolean answer) {
16365                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16366                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16367                            remove(mbMessage);
16368                    }
16369            }
16370    
16371            /**
16372             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16373             *
16374             * @param groupId the group ID
16375             * @param categoryId the category ID
16376             * @param threadId the thread ID
16377             * @param answer the answer
16378             * @return the number of matching message-boards messages
16379             */
16380            @Override
16381            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16382                    boolean answer) {
16383                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
16384    
16385                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16386    
16387                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16388                                    this);
16389    
16390                    if (count == null) {
16391                            StringBundler query = new StringBundler(5);
16392    
16393                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16394    
16395                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16396    
16397                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16398    
16399                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16400    
16401                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16402    
16403                            String sql = query.toString();
16404    
16405                            Session session = null;
16406    
16407                            try {
16408                                    session = openSession();
16409    
16410                                    Query q = session.createQuery(sql);
16411    
16412                                    QueryPos qPos = QueryPos.getInstance(q);
16413    
16414                                    qPos.add(groupId);
16415    
16416                                    qPos.add(categoryId);
16417    
16418                                    qPos.add(threadId);
16419    
16420                                    qPos.add(answer);
16421    
16422                                    count = (Long)q.uniqueResult();
16423    
16424                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16425                            }
16426                            catch (Exception e) {
16427                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16428    
16429                                    throw processException(e);
16430                            }
16431                            finally {
16432                                    closeSession(session);
16433                            }
16434                    }
16435    
16436                    return count.intValue();
16437            }
16438    
16439            /**
16440             * 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;.
16441             *
16442             * @param groupId the group ID
16443             * @param categoryId the category ID
16444             * @param threadId the thread ID
16445             * @param answer the answer
16446             * @return the number of matching message-boards messages that the user has permission to view
16447             */
16448            @Override
16449            public int filterCountByG_C_T_A(long groupId, long categoryId,
16450                    long threadId, boolean answer) {
16451                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16452                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
16453                    }
16454    
16455                    StringBundler query = new StringBundler(5);
16456    
16457                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16458    
16459                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16460    
16461                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16462    
16463                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16464    
16465                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16466    
16467                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16468                                    MBMessage.class.getName(),
16469                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16470    
16471                    Session session = null;
16472    
16473                    try {
16474                            session = openSession();
16475    
16476                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16477    
16478                            q.addScalar(COUNT_COLUMN_NAME,
16479                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16480    
16481                            QueryPos qPos = QueryPos.getInstance(q);
16482    
16483                            qPos.add(groupId);
16484    
16485                            qPos.add(categoryId);
16486    
16487                            qPos.add(threadId);
16488    
16489                            qPos.add(answer);
16490    
16491                            Long count = (Long)q.uniqueResult();
16492    
16493                            return count.intValue();
16494                    }
16495                    catch (Exception e) {
16496                            throw processException(e);
16497                    }
16498                    finally {
16499                            closeSession(session);
16500                    }
16501            }
16502    
16503            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
16504            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
16505            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
16506            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
16507            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16508                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16509                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
16510                            new String[] {
16511                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16512                                    Integer.class.getName(),
16513                                    
16514                            Integer.class.getName(), Integer.class.getName(),
16515                                    OrderByComparator.class.getName()
16516                            });
16517            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
16518                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16519                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16520                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
16521                            new String[] {
16522                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16523                                    Integer.class.getName()
16524                            },
16525                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16526                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16527                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16528                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
16529                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16530            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16531                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16532                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
16533                            new String[] {
16534                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16535                                    Integer.class.getName()
16536                            });
16537    
16538            /**
16539             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16540             *
16541             * @param groupId the group ID
16542             * @param categoryId the category ID
16543             * @param threadId the thread ID
16544             * @param status the status
16545             * @return the matching message-boards messages
16546             */
16547            @Override
16548            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16549                    long threadId, int status) {
16550                    return findByG_C_T_S(groupId, categoryId, threadId, status,
16551                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16552            }
16553    
16554            /**
16555             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16556             *
16557             * <p>
16558             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16559             * </p>
16560             *
16561             * @param groupId the group ID
16562             * @param categoryId the category ID
16563             * @param threadId the thread ID
16564             * @param status the status
16565             * @param start the lower bound of the range of message-boards messages
16566             * @param end the upper bound of the range of message-boards messages (not inclusive)
16567             * @return the range of matching message-boards messages
16568             */
16569            @Override
16570            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16571                    long threadId, int status, int start, int end) {
16572                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
16573                            null);
16574            }
16575    
16576            /**
16577             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16578             *
16579             * <p>
16580             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16581             * </p>
16582             *
16583             * @param groupId the group ID
16584             * @param categoryId the category ID
16585             * @param threadId the thread ID
16586             * @param status the status
16587             * @param start the lower bound of the range of message-boards messages
16588             * @param end the upper bound of the range of message-boards messages (not inclusive)
16589             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16590             * @return the ordered range of matching message-boards messages
16591             */
16592            @Override
16593            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16594                    long threadId, int status, int start, int end,
16595                    OrderByComparator<MBMessage> orderByComparator) {
16596                    boolean pagination = true;
16597                    FinderPath finderPath = null;
16598                    Object[] finderArgs = null;
16599    
16600                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16601                                    (orderByComparator == null)) {
16602                            pagination = false;
16603                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
16604                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
16605                    }
16606                    else {
16607                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
16608                            finderArgs = new Object[] {
16609                                            groupId, categoryId, threadId, status,
16610                                            
16611                                            start, end, orderByComparator
16612                                    };
16613                    }
16614    
16615                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16616                                    finderArgs, this);
16617    
16618                    if ((list != null) && !list.isEmpty()) {
16619                            for (MBMessage mbMessage : list) {
16620                                    if ((groupId != mbMessage.getGroupId()) ||
16621                                                    (categoryId != mbMessage.getCategoryId()) ||
16622                                                    (threadId != mbMessage.getThreadId()) ||
16623                                                    (status != mbMessage.getStatus())) {
16624                                            list = null;
16625    
16626                                            break;
16627                                    }
16628                            }
16629                    }
16630    
16631                    if (list == null) {
16632                            StringBundler query = null;
16633    
16634                            if (orderByComparator != null) {
16635                                    query = new StringBundler(6 +
16636                                                    (orderByComparator.getOrderByFields().length * 3));
16637                            }
16638                            else {
16639                                    query = new StringBundler(6);
16640                            }
16641    
16642                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16643    
16644                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16645    
16646                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16647    
16648                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16649    
16650                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16651    
16652                            if (orderByComparator != null) {
16653                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16654                                            orderByComparator);
16655                            }
16656                            else
16657                             if (pagination) {
16658                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16659                            }
16660    
16661                            String sql = query.toString();
16662    
16663                            Session session = null;
16664    
16665                            try {
16666                                    session = openSession();
16667    
16668                                    Query q = session.createQuery(sql);
16669    
16670                                    QueryPos qPos = QueryPos.getInstance(q);
16671    
16672                                    qPos.add(groupId);
16673    
16674                                    qPos.add(categoryId);
16675    
16676                                    qPos.add(threadId);
16677    
16678                                    qPos.add(status);
16679    
16680                                    if (!pagination) {
16681                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16682                                                            start, end, false);
16683    
16684                                            Collections.sort(list);
16685    
16686                                            list = Collections.unmodifiableList(list);
16687                                    }
16688                                    else {
16689                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16690                                                            start, end);
16691                                    }
16692    
16693                                    cacheResult(list);
16694    
16695                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16696                            }
16697                            catch (Exception e) {
16698                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16699    
16700                                    throw processException(e);
16701                            }
16702                            finally {
16703                                    closeSession(session);
16704                            }
16705                    }
16706    
16707                    return list;
16708            }
16709    
16710            /**
16711             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16712             *
16713             * @param groupId the group ID
16714             * @param categoryId the category ID
16715             * @param threadId the thread ID
16716             * @param status the status
16717             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16718             * @return the first matching message-boards message
16719             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16720             */
16721            @Override
16722            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
16723                    long threadId, int status,
16724                    OrderByComparator<MBMessage> orderByComparator)
16725                    throws NoSuchMessageException {
16726                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
16727                                    threadId, status, orderByComparator);
16728    
16729                    if (mbMessage != null) {
16730                            return mbMessage;
16731                    }
16732    
16733                    StringBundler msg = new StringBundler(10);
16734    
16735                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16736    
16737                    msg.append("groupId=");
16738                    msg.append(groupId);
16739    
16740                    msg.append(", categoryId=");
16741                    msg.append(categoryId);
16742    
16743                    msg.append(", threadId=");
16744                    msg.append(threadId);
16745    
16746                    msg.append(", status=");
16747                    msg.append(status);
16748    
16749                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16750    
16751                    throw new NoSuchMessageException(msg.toString());
16752            }
16753    
16754            /**
16755             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16756             *
16757             * @param groupId the group ID
16758             * @param categoryId the category ID
16759             * @param threadId the thread ID
16760             * @param status the status
16761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16762             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16763             */
16764            @Override
16765            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
16766                    long threadId, int status,
16767                    OrderByComparator<MBMessage> orderByComparator) {
16768                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16769                                    status, 0, 1, orderByComparator);
16770    
16771                    if (!list.isEmpty()) {
16772                            return list.get(0);
16773                    }
16774    
16775                    return null;
16776            }
16777    
16778            /**
16779             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16780             *
16781             * @param groupId the group ID
16782             * @param categoryId the category ID
16783             * @param threadId the thread ID
16784             * @param status the status
16785             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16786             * @return the last matching message-boards message
16787             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16788             */
16789            @Override
16790            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
16791                    long threadId, int status,
16792                    OrderByComparator<MBMessage> orderByComparator)
16793                    throws NoSuchMessageException {
16794                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
16795                                    threadId, status, orderByComparator);
16796    
16797                    if (mbMessage != null) {
16798                            return mbMessage;
16799                    }
16800    
16801                    StringBundler msg = new StringBundler(10);
16802    
16803                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16804    
16805                    msg.append("groupId=");
16806                    msg.append(groupId);
16807    
16808                    msg.append(", categoryId=");
16809                    msg.append(categoryId);
16810    
16811                    msg.append(", threadId=");
16812                    msg.append(threadId);
16813    
16814                    msg.append(", status=");
16815                    msg.append(status);
16816    
16817                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16818    
16819                    throw new NoSuchMessageException(msg.toString());
16820            }
16821    
16822            /**
16823             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16824             *
16825             * @param groupId the group ID
16826             * @param categoryId the category ID
16827             * @param threadId the thread ID
16828             * @param status the status
16829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16830             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16831             */
16832            @Override
16833            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
16834                    long threadId, int status,
16835                    OrderByComparator<MBMessage> orderByComparator) {
16836                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
16837    
16838                    if (count == 0) {
16839                            return null;
16840                    }
16841    
16842                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16843                                    status, count - 1, count, orderByComparator);
16844    
16845                    if (!list.isEmpty()) {
16846                            return list.get(0);
16847                    }
16848    
16849                    return null;
16850            }
16851    
16852            /**
16853             * 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;.
16854             *
16855             * @param messageId the primary key of the current message-boards message
16856             * @param groupId the group ID
16857             * @param categoryId the category ID
16858             * @param threadId the thread ID
16859             * @param status the status
16860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16861             * @return the previous, current, and next message-boards message
16862             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16863             */
16864            @Override
16865            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
16866                    long categoryId, long threadId, int status,
16867                    OrderByComparator<MBMessage> orderByComparator)
16868                    throws NoSuchMessageException {
16869                    MBMessage mbMessage = findByPrimaryKey(messageId);
16870    
16871                    Session session = null;
16872    
16873                    try {
16874                            session = openSession();
16875    
16876                            MBMessage[] array = new MBMessageImpl[3];
16877    
16878                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16879                                            categoryId, threadId, status, orderByComparator, true);
16880    
16881                            array[1] = mbMessage;
16882    
16883                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16884                                            categoryId, threadId, status, orderByComparator, false);
16885    
16886                            return array;
16887                    }
16888                    catch (Exception e) {
16889                            throw processException(e);
16890                    }
16891                    finally {
16892                            closeSession(session);
16893                    }
16894            }
16895    
16896            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
16897                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16898                    int status, OrderByComparator<MBMessage> orderByComparator,
16899                    boolean previous) {
16900                    StringBundler query = null;
16901    
16902                    if (orderByComparator != null) {
16903                            query = new StringBundler(6 +
16904                                            (orderByComparator.getOrderByFields().length * 6));
16905                    }
16906                    else {
16907                            query = new StringBundler(3);
16908                    }
16909    
16910                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16911    
16912                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16913    
16914                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16915    
16916                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16917    
16918                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16919    
16920                    if (orderByComparator != null) {
16921                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16922    
16923                            if (orderByConditionFields.length > 0) {
16924                                    query.append(WHERE_AND);
16925                            }
16926    
16927                            for (int i = 0; i < orderByConditionFields.length; i++) {
16928                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16929                                    query.append(orderByConditionFields[i]);
16930    
16931                                    if ((i + 1) < orderByConditionFields.length) {
16932                                            if (orderByComparator.isAscending() ^ previous) {
16933                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16934                                            }
16935                                            else {
16936                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16937                                            }
16938                                    }
16939                                    else {
16940                                            if (orderByComparator.isAscending() ^ previous) {
16941                                                    query.append(WHERE_GREATER_THAN);
16942                                            }
16943                                            else {
16944                                                    query.append(WHERE_LESSER_THAN);
16945                                            }
16946                                    }
16947                            }
16948    
16949                            query.append(ORDER_BY_CLAUSE);
16950    
16951                            String[] orderByFields = orderByComparator.getOrderByFields();
16952    
16953                            for (int i = 0; i < orderByFields.length; i++) {
16954                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16955                                    query.append(orderByFields[i]);
16956    
16957                                    if ((i + 1) < orderByFields.length) {
16958                                            if (orderByComparator.isAscending() ^ previous) {
16959                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16960                                            }
16961                                            else {
16962                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16963                                            }
16964                                    }
16965                                    else {
16966                                            if (orderByComparator.isAscending() ^ previous) {
16967                                                    query.append(ORDER_BY_ASC);
16968                                            }
16969                                            else {
16970                                                    query.append(ORDER_BY_DESC);
16971                                            }
16972                                    }
16973                            }
16974                    }
16975                    else {
16976                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16977                    }
16978    
16979                    String sql = query.toString();
16980    
16981                    Query q = session.createQuery(sql);
16982    
16983                    q.setFirstResult(0);
16984                    q.setMaxResults(2);
16985    
16986                    QueryPos qPos = QueryPos.getInstance(q);
16987    
16988                    qPos.add(groupId);
16989    
16990                    qPos.add(categoryId);
16991    
16992                    qPos.add(threadId);
16993    
16994                    qPos.add(status);
16995    
16996                    if (orderByComparator != null) {
16997                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16998    
16999                            for (Object value : values) {
17000                                    qPos.add(value);
17001                            }
17002                    }
17003    
17004                    List<MBMessage> list = q.list();
17005    
17006                    if (list.size() == 2) {
17007                            return list.get(1);
17008                    }
17009                    else {
17010                            return null;
17011                    }
17012            }
17013    
17014            /**
17015             * 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;.
17016             *
17017             * @param groupId the group ID
17018             * @param categoryId the category ID
17019             * @param threadId the thread ID
17020             * @param status the status
17021             * @return the matching message-boards messages that the user has permission to view
17022             */
17023            @Override
17024            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17025                    long threadId, int status) {
17026                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17027                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17028            }
17029    
17030            /**
17031             * 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;.
17032             *
17033             * <p>
17034             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17035             * </p>
17036             *
17037             * @param groupId the group ID
17038             * @param categoryId the category ID
17039             * @param threadId the thread ID
17040             * @param status the status
17041             * @param start the lower bound of the range of message-boards messages
17042             * @param end the upper bound of the range of message-boards messages (not inclusive)
17043             * @return the range of matching message-boards messages that the user has permission to view
17044             */
17045            @Override
17046            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17047                    long threadId, int status, int start, int end) {
17048                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17049                            start, end, null);
17050            }
17051    
17052            /**
17053             * 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;.
17054             *
17055             * <p>
17056             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17057             * </p>
17058             *
17059             * @param groupId the group ID
17060             * @param categoryId the category ID
17061             * @param threadId the thread ID
17062             * @param status the status
17063             * @param start the lower bound of the range of message-boards messages
17064             * @param end the upper bound of the range of message-boards messages (not inclusive)
17065             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17066             * @return the ordered range of matching message-boards messages that the user has permission to view
17067             */
17068            @Override
17069            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17070                    long threadId, int status, int start, int end,
17071                    OrderByComparator<MBMessage> orderByComparator) {
17072                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17073                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17074                                    end, orderByComparator);
17075                    }
17076    
17077                    StringBundler query = null;
17078    
17079                    if (orderByComparator != null) {
17080                            query = new StringBundler(6 +
17081                                            (orderByComparator.getOrderByFields().length * 3));
17082                    }
17083                    else {
17084                            query = new StringBundler(6);
17085                    }
17086    
17087                    if (getDB().isSupportsInlineDistinct()) {
17088                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17089                    }
17090                    else {
17091                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17092                    }
17093    
17094                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17095    
17096                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17097    
17098                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17099    
17100                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17101    
17102                    if (!getDB().isSupportsInlineDistinct()) {
17103                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17104                    }
17105    
17106                    if (orderByComparator != null) {
17107                            if (getDB().isSupportsInlineDistinct()) {
17108                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17109                                            orderByComparator, true);
17110                            }
17111                            else {
17112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17113                                            orderByComparator, true);
17114                            }
17115                    }
17116                    else {
17117                            if (getDB().isSupportsInlineDistinct()) {
17118                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17119                            }
17120                            else {
17121                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17122                            }
17123                    }
17124    
17125                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17126                                    MBMessage.class.getName(),
17127                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17128    
17129                    Session session = null;
17130    
17131                    try {
17132                            session = openSession();
17133    
17134                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17135    
17136                            if (getDB().isSupportsInlineDistinct()) {
17137                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17138                            }
17139                            else {
17140                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17141                            }
17142    
17143                            QueryPos qPos = QueryPos.getInstance(q);
17144    
17145                            qPos.add(groupId);
17146    
17147                            qPos.add(categoryId);
17148    
17149                            qPos.add(threadId);
17150    
17151                            qPos.add(status);
17152    
17153                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17154                    }
17155                    catch (Exception e) {
17156                            throw processException(e);
17157                    }
17158                    finally {
17159                            closeSession(session);
17160                    }
17161            }
17162    
17163            /**
17164             * 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;.
17165             *
17166             * @param messageId the primary key of the current message-boards message
17167             * @param groupId the group ID
17168             * @param categoryId the category ID
17169             * @param threadId the thread ID
17170             * @param status the status
17171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17172             * @return the previous, current, and next message-boards message
17173             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17174             */
17175            @Override
17176            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17177                    long groupId, long categoryId, long threadId, int status,
17178                    OrderByComparator<MBMessage> orderByComparator)
17179                    throws NoSuchMessageException {
17180                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17181                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17182                                    threadId, status, orderByComparator);
17183                    }
17184    
17185                    MBMessage mbMessage = findByPrimaryKey(messageId);
17186    
17187                    Session session = null;
17188    
17189                    try {
17190                            session = openSession();
17191    
17192                            MBMessage[] array = new MBMessageImpl[3];
17193    
17194                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17195                                            groupId, categoryId, threadId, status, orderByComparator,
17196                                            true);
17197    
17198                            array[1] = mbMessage;
17199    
17200                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17201                                            groupId, categoryId, threadId, status, orderByComparator,
17202                                            false);
17203    
17204                            return array;
17205                    }
17206                    catch (Exception e) {
17207                            throw processException(e);
17208                    }
17209                    finally {
17210                            closeSession(session);
17211                    }
17212            }
17213    
17214            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17215                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17216                    int status, OrderByComparator<MBMessage> orderByComparator,
17217                    boolean previous) {
17218                    StringBundler query = null;
17219    
17220                    if (orderByComparator != null) {
17221                            query = new StringBundler(6 +
17222                                            (orderByComparator.getOrderByFields().length * 6));
17223                    }
17224                    else {
17225                            query = new StringBundler(3);
17226                    }
17227    
17228                    if (getDB().isSupportsInlineDistinct()) {
17229                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17230                    }
17231                    else {
17232                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17233                    }
17234    
17235                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17236    
17237                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17238    
17239                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17240    
17241                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17242    
17243                    if (!getDB().isSupportsInlineDistinct()) {
17244                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17245                    }
17246    
17247                    if (orderByComparator != null) {
17248                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17249    
17250                            if (orderByConditionFields.length > 0) {
17251                                    query.append(WHERE_AND);
17252                            }
17253    
17254                            for (int i = 0; i < orderByConditionFields.length; i++) {
17255                                    if (getDB().isSupportsInlineDistinct()) {
17256                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17257                                    }
17258                                    else {
17259                                            query.append(_ORDER_BY_ENTITY_TABLE);
17260                                    }
17261    
17262                                    query.append(orderByConditionFields[i]);
17263    
17264                                    if ((i + 1) < orderByConditionFields.length) {
17265                                            if (orderByComparator.isAscending() ^ previous) {
17266                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17267                                            }
17268                                            else {
17269                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17270                                            }
17271                                    }
17272                                    else {
17273                                            if (orderByComparator.isAscending() ^ previous) {
17274                                                    query.append(WHERE_GREATER_THAN);
17275                                            }
17276                                            else {
17277                                                    query.append(WHERE_LESSER_THAN);
17278                                            }
17279                                    }
17280                            }
17281    
17282                            query.append(ORDER_BY_CLAUSE);
17283    
17284                            String[] orderByFields = orderByComparator.getOrderByFields();
17285    
17286                            for (int i = 0; i < orderByFields.length; i++) {
17287                                    if (getDB().isSupportsInlineDistinct()) {
17288                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17289                                    }
17290                                    else {
17291                                            query.append(_ORDER_BY_ENTITY_TABLE);
17292                                    }
17293    
17294                                    query.append(orderByFields[i]);
17295    
17296                                    if ((i + 1) < orderByFields.length) {
17297                                            if (orderByComparator.isAscending() ^ previous) {
17298                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17299                                            }
17300                                            else {
17301                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17302                                            }
17303                                    }
17304                                    else {
17305                                            if (orderByComparator.isAscending() ^ previous) {
17306                                                    query.append(ORDER_BY_ASC);
17307                                            }
17308                                            else {
17309                                                    query.append(ORDER_BY_DESC);
17310                                            }
17311                                    }
17312                            }
17313                    }
17314                    else {
17315                            if (getDB().isSupportsInlineDistinct()) {
17316                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17317                            }
17318                            else {
17319                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17320                            }
17321                    }
17322    
17323                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17324                                    MBMessage.class.getName(),
17325                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17326    
17327                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17328    
17329                    q.setFirstResult(0);
17330                    q.setMaxResults(2);
17331    
17332                    if (getDB().isSupportsInlineDistinct()) {
17333                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17334                    }
17335                    else {
17336                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17337                    }
17338    
17339                    QueryPos qPos = QueryPos.getInstance(q);
17340    
17341                    qPos.add(groupId);
17342    
17343                    qPos.add(categoryId);
17344    
17345                    qPos.add(threadId);
17346    
17347                    qPos.add(status);
17348    
17349                    if (orderByComparator != null) {
17350                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17351    
17352                            for (Object value : values) {
17353                                    qPos.add(value);
17354                            }
17355                    }
17356    
17357                    List<MBMessage> list = q.list();
17358    
17359                    if (list.size() == 2) {
17360                            return list.get(1);
17361                    }
17362                    else {
17363                            return null;
17364                    }
17365            }
17366    
17367            /**
17368             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
17369             *
17370             * @param groupId the group ID
17371             * @param categoryId the category ID
17372             * @param threadId the thread ID
17373             * @param status the status
17374             */
17375            @Override
17376            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
17377                    int status) {
17378                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
17379                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17380                            remove(mbMessage);
17381                    }
17382            }
17383    
17384            /**
17385             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17386             *
17387             * @param groupId the group ID
17388             * @param categoryId the category ID
17389             * @param threadId the thread ID
17390             * @param status the status
17391             * @return the number of matching message-boards messages
17392             */
17393            @Override
17394            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17395                    int status) {
17396                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
17397    
17398                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17399    
17400                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17401                                    this);
17402    
17403                    if (count == null) {
17404                            StringBundler query = new StringBundler(5);
17405    
17406                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17407    
17408                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17409    
17410                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17411    
17412                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17413    
17414                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17415    
17416                            String sql = query.toString();
17417    
17418                            Session session = null;
17419    
17420                            try {
17421                                    session = openSession();
17422    
17423                                    Query q = session.createQuery(sql);
17424    
17425                                    QueryPos qPos = QueryPos.getInstance(q);
17426    
17427                                    qPos.add(groupId);
17428    
17429                                    qPos.add(categoryId);
17430    
17431                                    qPos.add(threadId);
17432    
17433                                    qPos.add(status);
17434    
17435                                    count = (Long)q.uniqueResult();
17436    
17437                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17438                            }
17439                            catch (Exception e) {
17440                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17441    
17442                                    throw processException(e);
17443                            }
17444                            finally {
17445                                    closeSession(session);
17446                            }
17447                    }
17448    
17449                    return count.intValue();
17450            }
17451    
17452            /**
17453             * 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;.
17454             *
17455             * @param groupId the group ID
17456             * @param categoryId the category ID
17457             * @param threadId the thread ID
17458             * @param status the status
17459             * @return the number of matching message-boards messages that the user has permission to view
17460             */
17461            @Override
17462            public int filterCountByG_C_T_S(long groupId, long categoryId,
17463                    long threadId, int status) {
17464                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17465                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17466                    }
17467    
17468                    StringBundler query = new StringBundler(5);
17469    
17470                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17471    
17472                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17473    
17474                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17475    
17476                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17477    
17478                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17479    
17480                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17481                                    MBMessage.class.getName(),
17482                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17483    
17484                    Session session = null;
17485    
17486                    try {
17487                            session = openSession();
17488    
17489                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17490    
17491                            q.addScalar(COUNT_COLUMN_NAME,
17492                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17493    
17494                            QueryPos qPos = QueryPos.getInstance(q);
17495    
17496                            qPos.add(groupId);
17497    
17498                            qPos.add(categoryId);
17499    
17500                            qPos.add(threadId);
17501    
17502                            qPos.add(status);
17503    
17504                            Long count = (Long)q.uniqueResult();
17505    
17506                            return count.intValue();
17507                    }
17508                    catch (Exception e) {
17509                            throw processException(e);
17510                    }
17511                    finally {
17512                            closeSession(session);
17513                    }
17514            }
17515    
17516            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17517            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17518            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17519            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17520            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17521                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17522                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
17523                            new String[] {
17524                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17525                                    Integer.class.getName(),
17526                                    
17527                            Integer.class.getName(), Integer.class.getName(),
17528                                    OrderByComparator.class.getName()
17529                            });
17530            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
17531                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17532                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17533                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
17534                            new String[] {
17535                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17536                                    Integer.class.getName()
17537                            },
17538                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
17539                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17540                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
17541                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17542                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17543            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17544                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17545                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
17546                            new String[] {
17547                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17548                                    Integer.class.getName()
17549                            });
17550    
17551            /**
17552             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17553             *
17554             * @param userId the user ID
17555             * @param classNameId the class name ID
17556             * @param classPK the class p k
17557             * @param status the status
17558             * @return the matching message-boards messages
17559             */
17560            @Override
17561            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17562                    long classPK, int status) {
17563                    return findByU_C_C_S(userId, classNameId, classPK, status,
17564                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17565            }
17566    
17567            /**
17568             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17569             *
17570             * <p>
17571             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17572             * </p>
17573             *
17574             * @param userId the user ID
17575             * @param classNameId the class name ID
17576             * @param classPK the class p k
17577             * @param status the status
17578             * @param start the lower bound of the range of message-boards messages
17579             * @param end the upper bound of the range of message-boards messages (not inclusive)
17580             * @return the range of matching message-boards messages
17581             */
17582            @Override
17583            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17584                    long classPK, int status, int start, int end) {
17585                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
17586                            null);
17587            }
17588    
17589            /**
17590             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17591             *
17592             * <p>
17593             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17594             * </p>
17595             *
17596             * @param userId the user ID
17597             * @param classNameId the class name ID
17598             * @param classPK the class p k
17599             * @param status the status
17600             * @param start the lower bound of the range of message-boards messages
17601             * @param end the upper bound of the range of message-boards messages (not inclusive)
17602             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17603             * @return the ordered range of matching message-boards messages
17604             */
17605            @Override
17606            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17607                    long classPK, int status, int start, int end,
17608                    OrderByComparator<MBMessage> orderByComparator) {
17609                    boolean pagination = true;
17610                    FinderPath finderPath = null;
17611                    Object[] finderArgs = null;
17612    
17613                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17614                                    (orderByComparator == null)) {
17615                            pagination = false;
17616                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
17617                            finderArgs = new Object[] { userId, classNameId, classPK, status };
17618                    }
17619                    else {
17620                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
17621                            finderArgs = new Object[] {
17622                                            userId, classNameId, classPK, status,
17623                                            
17624                                            start, end, orderByComparator
17625                                    };
17626                    }
17627    
17628                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17629                                    finderArgs, this);
17630    
17631                    if ((list != null) && !list.isEmpty()) {
17632                            for (MBMessage mbMessage : list) {
17633                                    if ((userId != mbMessage.getUserId()) ||
17634                                                    (classNameId != mbMessage.getClassNameId()) ||
17635                                                    (classPK != mbMessage.getClassPK()) ||
17636                                                    (status != mbMessage.getStatus())) {
17637                                            list = null;
17638    
17639                                            break;
17640                                    }
17641                            }
17642                    }
17643    
17644                    if (list == null) {
17645                            StringBundler query = null;
17646    
17647                            if (orderByComparator != null) {
17648                                    query = new StringBundler(6 +
17649                                                    (orderByComparator.getOrderByFields().length * 3));
17650                            }
17651                            else {
17652                                    query = new StringBundler(6);
17653                            }
17654    
17655                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17656    
17657                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17658    
17659                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17660    
17661                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17662    
17663                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17664    
17665                            if (orderByComparator != null) {
17666                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17667                                            orderByComparator);
17668                            }
17669                            else
17670                             if (pagination) {
17671                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17672                            }
17673    
17674                            String sql = query.toString();
17675    
17676                            Session session = null;
17677    
17678                            try {
17679                                    session = openSession();
17680    
17681                                    Query q = session.createQuery(sql);
17682    
17683                                    QueryPos qPos = QueryPos.getInstance(q);
17684    
17685                                    qPos.add(userId);
17686    
17687                                    qPos.add(classNameId);
17688    
17689                                    qPos.add(classPK);
17690    
17691                                    qPos.add(status);
17692    
17693                                    if (!pagination) {
17694                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17695                                                            start, end, false);
17696    
17697                                            Collections.sort(list);
17698    
17699                                            list = Collections.unmodifiableList(list);
17700                                    }
17701                                    else {
17702                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17703                                                            start, end);
17704                                    }
17705    
17706                                    cacheResult(list);
17707    
17708                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17709                            }
17710                            catch (Exception e) {
17711                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17712    
17713                                    throw processException(e);
17714                            }
17715                            finally {
17716                                    closeSession(session);
17717                            }
17718                    }
17719    
17720                    return list;
17721            }
17722    
17723            /**
17724             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17725             *
17726             * @param userId the user ID
17727             * @param classNameId the class name ID
17728             * @param classPK the class p k
17729             * @param status the status
17730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17731             * @return the first matching message-boards message
17732             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17733             */
17734            @Override
17735            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
17736                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
17737                    throws NoSuchMessageException {
17738                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
17739                                    classPK, status, orderByComparator);
17740    
17741                    if (mbMessage != null) {
17742                            return mbMessage;
17743                    }
17744    
17745                    StringBundler msg = new StringBundler(10);
17746    
17747                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17748    
17749                    msg.append("userId=");
17750                    msg.append(userId);
17751    
17752                    msg.append(", classNameId=");
17753                    msg.append(classNameId);
17754    
17755                    msg.append(", classPK=");
17756                    msg.append(classPK);
17757    
17758                    msg.append(", status=");
17759                    msg.append(status);
17760    
17761                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17762    
17763                    throw new NoSuchMessageException(msg.toString());
17764            }
17765    
17766            /**
17767             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17768             *
17769             * @param userId the user ID
17770             * @param classNameId the class name ID
17771             * @param classPK the class p k
17772             * @param status the status
17773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17774             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17775             */
17776            @Override
17777            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
17778                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
17779                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17780                                    status, 0, 1, orderByComparator);
17781    
17782                    if (!list.isEmpty()) {
17783                            return list.get(0);
17784                    }
17785    
17786                    return null;
17787            }
17788    
17789            /**
17790             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17791             *
17792             * @param userId the user ID
17793             * @param classNameId the class name ID
17794             * @param classPK the class p k
17795             * @param status the status
17796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17797             * @return the last matching message-boards message
17798             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17799             */
17800            @Override
17801            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
17802                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
17803                    throws NoSuchMessageException {
17804                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
17805                                    status, orderByComparator);
17806    
17807                    if (mbMessage != null) {
17808                            return mbMessage;
17809                    }
17810    
17811                    StringBundler msg = new StringBundler(10);
17812    
17813                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17814    
17815                    msg.append("userId=");
17816                    msg.append(userId);
17817    
17818                    msg.append(", classNameId=");
17819                    msg.append(classNameId);
17820    
17821                    msg.append(", classPK=");
17822                    msg.append(classPK);
17823    
17824                    msg.append(", status=");
17825                    msg.append(status);
17826    
17827                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17828    
17829                    throw new NoSuchMessageException(msg.toString());
17830            }
17831    
17832            /**
17833             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17834             *
17835             * @param userId the user ID
17836             * @param classNameId the class name ID
17837             * @param classPK the class p k
17838             * @param status the status
17839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17840             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17841             */
17842            @Override
17843            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
17844                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
17845                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
17846    
17847                    if (count == 0) {
17848                            return null;
17849                    }
17850    
17851                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17852                                    status, count - 1, count, orderByComparator);
17853    
17854                    if (!list.isEmpty()) {
17855                            return list.get(0);
17856                    }
17857    
17858                    return null;
17859            }
17860    
17861            /**
17862             * 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;.
17863             *
17864             * @param messageId the primary key of the current message-boards message
17865             * @param userId the user ID
17866             * @param classNameId the class name ID
17867             * @param classPK the class p k
17868             * @param status the status
17869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17870             * @return the previous, current, and next message-boards message
17871             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17872             */
17873            @Override
17874            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
17875                    long classNameId, long classPK, int status,
17876                    OrderByComparator<MBMessage> orderByComparator)
17877                    throws NoSuchMessageException {
17878                    MBMessage mbMessage = findByPrimaryKey(messageId);
17879    
17880                    Session session = null;
17881    
17882                    try {
17883                            session = openSession();
17884    
17885                            MBMessage[] array = new MBMessageImpl[3];
17886    
17887                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17888                                            classNameId, classPK, status, orderByComparator, true);
17889    
17890                            array[1] = mbMessage;
17891    
17892                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17893                                            classNameId, classPK, status, orderByComparator, false);
17894    
17895                            return array;
17896                    }
17897                    catch (Exception e) {
17898                            throw processException(e);
17899                    }
17900                    finally {
17901                            closeSession(session);
17902                    }
17903            }
17904    
17905            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
17906                    MBMessage mbMessage, long userId, long classNameId, long classPK,
17907                    int status, OrderByComparator<MBMessage> orderByComparator,
17908                    boolean previous) {
17909                    StringBundler query = null;
17910    
17911                    if (orderByComparator != null) {
17912                            query = new StringBundler(6 +
17913                                            (orderByComparator.getOrderByFields().length * 6));
17914                    }
17915                    else {
17916                            query = new StringBundler(3);
17917                    }
17918    
17919                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17920    
17921                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17922    
17923                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17924    
17925                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17926    
17927                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17928    
17929                    if (orderByComparator != null) {
17930                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17931    
17932                            if (orderByConditionFields.length > 0) {
17933                                    query.append(WHERE_AND);
17934                            }
17935    
17936                            for (int i = 0; i < orderByConditionFields.length; i++) {
17937                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17938                                    query.append(orderByConditionFields[i]);
17939    
17940                                    if ((i + 1) < orderByConditionFields.length) {
17941                                            if (orderByComparator.isAscending() ^ previous) {
17942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17943                                            }
17944                                            else {
17945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17946                                            }
17947                                    }
17948                                    else {
17949                                            if (orderByComparator.isAscending() ^ previous) {
17950                                                    query.append(WHERE_GREATER_THAN);
17951                                            }
17952                                            else {
17953                                                    query.append(WHERE_LESSER_THAN);
17954                                            }
17955                                    }
17956                            }
17957    
17958                            query.append(ORDER_BY_CLAUSE);
17959    
17960                            String[] orderByFields = orderByComparator.getOrderByFields();
17961    
17962                            for (int i = 0; i < orderByFields.length; i++) {
17963                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17964                                    query.append(orderByFields[i]);
17965    
17966                                    if ((i + 1) < orderByFields.length) {
17967                                            if (orderByComparator.isAscending() ^ previous) {
17968                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17969                                            }
17970                                            else {
17971                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17972                                            }
17973                                    }
17974                                    else {
17975                                            if (orderByComparator.isAscending() ^ previous) {
17976                                                    query.append(ORDER_BY_ASC);
17977                                            }
17978                                            else {
17979                                                    query.append(ORDER_BY_DESC);
17980                                            }
17981                                    }
17982                            }
17983                    }
17984                    else {
17985                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17986                    }
17987    
17988                    String sql = query.toString();
17989    
17990                    Query q = session.createQuery(sql);
17991    
17992                    q.setFirstResult(0);
17993                    q.setMaxResults(2);
17994    
17995                    QueryPos qPos = QueryPos.getInstance(q);
17996    
17997                    qPos.add(userId);
17998    
17999                    qPos.add(classNameId);
18000    
18001                    qPos.add(classPK);
18002    
18003                    qPos.add(status);
18004    
18005                    if (orderByComparator != null) {
18006                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18007    
18008                            for (Object value : values) {
18009                                    qPos.add(value);
18010                            }
18011                    }
18012    
18013                    List<MBMessage> list = q.list();
18014    
18015                    if (list.size() == 2) {
18016                            return list.get(1);
18017                    }
18018                    else {
18019                            return null;
18020                    }
18021            }
18022    
18023            /**
18024             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18025             *
18026             * @param userId the user ID
18027             * @param classNameId the class name ID
18028             * @param classPK the class p k
18029             * @param status the status
18030             */
18031            @Override
18032            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18033                    int status) {
18034                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18035                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18036                            remove(mbMessage);
18037                    }
18038            }
18039    
18040            /**
18041             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18042             *
18043             * @param userId the user ID
18044             * @param classNameId the class name ID
18045             * @param classPK the class p k
18046             * @param status the status
18047             * @return the number of matching message-boards messages
18048             */
18049            @Override
18050            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18051                    int status) {
18052                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18053    
18054                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18055    
18056                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18057                                    this);
18058    
18059                    if (count == null) {
18060                            StringBundler query = new StringBundler(5);
18061    
18062                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18063    
18064                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18065    
18066                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18067    
18068                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18069    
18070                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18071    
18072                            String sql = query.toString();
18073    
18074                            Session session = null;
18075    
18076                            try {
18077                                    session = openSession();
18078    
18079                                    Query q = session.createQuery(sql);
18080    
18081                                    QueryPos qPos = QueryPos.getInstance(q);
18082    
18083                                    qPos.add(userId);
18084    
18085                                    qPos.add(classNameId);
18086    
18087                                    qPos.add(classPK);
18088    
18089                                    qPos.add(status);
18090    
18091                                    count = (Long)q.uniqueResult();
18092    
18093                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18094                            }
18095                            catch (Exception e) {
18096                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18097    
18098                                    throw processException(e);
18099                            }
18100                            finally {
18101                                    closeSession(session);
18102                            }
18103                    }
18104    
18105                    return count.intValue();
18106            }
18107    
18108            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18109            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18110            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18111            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18112    
18113            public MBMessagePersistenceImpl() {
18114                    setModelClass(MBMessage.class);
18115            }
18116    
18117            /**
18118             * Caches the message-boards message in the entity cache if it is enabled.
18119             *
18120             * @param mbMessage the message-boards message
18121             */
18122            @Override
18123            public void cacheResult(MBMessage mbMessage) {
18124                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18125                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18126    
18127                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18128                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18129                            mbMessage);
18130    
18131                    mbMessage.resetOriginalValues();
18132            }
18133    
18134            /**
18135             * Caches the message-boards messages in the entity cache if it is enabled.
18136             *
18137             * @param mbMessages the message-boards messages
18138             */
18139            @Override
18140            public void cacheResult(List<MBMessage> mbMessages) {
18141                    for (MBMessage mbMessage : mbMessages) {
18142                            if (EntityCacheUtil.getResult(
18143                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18144                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18145                                    cacheResult(mbMessage);
18146                            }
18147                            else {
18148                                    mbMessage.resetOriginalValues();
18149                            }
18150                    }
18151            }
18152    
18153            /**
18154             * Clears the cache for all message-boards messages.
18155             *
18156             * <p>
18157             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18158             * </p>
18159             */
18160            @Override
18161            public void clearCache() {
18162                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
18163                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
18164                    }
18165    
18166                    EntityCacheUtil.clearCache(MBMessageImpl.class);
18167    
18168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18169                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18171            }
18172    
18173            /**
18174             * Clears the cache for the message-boards message.
18175             *
18176             * <p>
18177             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18178             * </p>
18179             */
18180            @Override
18181            public void clearCache(MBMessage mbMessage) {
18182                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18183                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18184    
18185                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18187    
18188                    clearUniqueFindersCache(mbMessage);
18189            }
18190    
18191            @Override
18192            public void clearCache(List<MBMessage> mbMessages) {
18193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18195    
18196                    for (MBMessage mbMessage : mbMessages) {
18197                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18198                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18199    
18200                            clearUniqueFindersCache(mbMessage);
18201                    }
18202            }
18203    
18204            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
18205                    if (mbMessage.isNew()) {
18206                            Object[] args = new Object[] {
18207                                            mbMessage.getUuid(), mbMessage.getGroupId()
18208                                    };
18209    
18210                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18211                                    Long.valueOf(1));
18212                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18213                                    mbMessage);
18214                    }
18215                    else {
18216                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18217    
18218                            if ((mbMessageModelImpl.getColumnBitmask() &
18219                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18220                                    Object[] args = new Object[] {
18221                                                    mbMessage.getUuid(), mbMessage.getGroupId()
18222                                            };
18223    
18224                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18225                                            Long.valueOf(1));
18226                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18227                                            mbMessage);
18228                            }
18229                    }
18230            }
18231    
18232            protected void clearUniqueFindersCache(MBMessage mbMessage) {
18233                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18234    
18235                    Object[] args = new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() };
18236    
18237                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18238                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18239    
18240                    if ((mbMessageModelImpl.getColumnBitmask() &
18241                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18242                            args = new Object[] {
18243                                            mbMessageModelImpl.getOriginalUuid(),
18244                                            mbMessageModelImpl.getOriginalGroupId()
18245                                    };
18246    
18247                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18248                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18249                    }
18250            }
18251    
18252            /**
18253             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18254             *
18255             * @param messageId the primary key for the new message-boards message
18256             * @return the new message-boards message
18257             */
18258            @Override
18259            public MBMessage create(long messageId) {
18260                    MBMessage mbMessage = new MBMessageImpl();
18261    
18262                    mbMessage.setNew(true);
18263                    mbMessage.setPrimaryKey(messageId);
18264    
18265                    String uuid = PortalUUIDUtil.generate();
18266    
18267                    mbMessage.setUuid(uuid);
18268    
18269                    return mbMessage;
18270            }
18271    
18272            /**
18273             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18274             *
18275             * @param messageId the primary key of the message-boards message
18276             * @return the message-boards message that was removed
18277             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18278             */
18279            @Override
18280            public MBMessage remove(long messageId) throws NoSuchMessageException {
18281                    return remove((Serializable)messageId);
18282            }
18283    
18284            /**
18285             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18286             *
18287             * @param primaryKey the primary key of the message-boards message
18288             * @return the message-boards message that was removed
18289             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18290             */
18291            @Override
18292            public MBMessage remove(Serializable primaryKey)
18293                    throws NoSuchMessageException {
18294                    Session session = null;
18295    
18296                    try {
18297                            session = openSession();
18298    
18299                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18300                                            primaryKey);
18301    
18302                            if (mbMessage == null) {
18303                                    if (_log.isWarnEnabled()) {
18304                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18305                                    }
18306    
18307                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18308                                            primaryKey);
18309                            }
18310    
18311                            return remove(mbMessage);
18312                    }
18313                    catch (NoSuchMessageException nsee) {
18314                            throw nsee;
18315                    }
18316                    catch (Exception e) {
18317                            throw processException(e);
18318                    }
18319                    finally {
18320                            closeSession(session);
18321                    }
18322            }
18323    
18324            @Override
18325            protected MBMessage removeImpl(MBMessage mbMessage) {
18326                    mbMessage = toUnwrappedModel(mbMessage);
18327    
18328                    Session session = null;
18329    
18330                    try {
18331                            session = openSession();
18332    
18333                            if (!session.contains(mbMessage)) {
18334                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18335                                                    mbMessage.getPrimaryKeyObj());
18336                            }
18337    
18338                            if (mbMessage != null) {
18339                                    session.delete(mbMessage);
18340                            }
18341                    }
18342                    catch (Exception e) {
18343                            throw processException(e);
18344                    }
18345                    finally {
18346                            closeSession(session);
18347                    }
18348    
18349                    if (mbMessage != null) {
18350                            clearCache(mbMessage);
18351                    }
18352    
18353                    return mbMessage;
18354            }
18355    
18356            @Override
18357            public MBMessage updateImpl(
18358                    com.liferay.portlet.messageboards.model.MBMessage mbMessage) {
18359                    mbMessage = toUnwrappedModel(mbMessage);
18360    
18361                    boolean isNew = mbMessage.isNew();
18362    
18363                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18364    
18365                    if (Validator.isNull(mbMessage.getUuid())) {
18366                            String uuid = PortalUUIDUtil.generate();
18367    
18368                            mbMessage.setUuid(uuid);
18369                    }
18370    
18371                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18372    
18373                    if (userId > 0) {
18374                            long companyId = mbMessage.getCompanyId();
18375    
18376                            long groupId = mbMessage.getGroupId();
18377    
18378                            long messageId = 0;
18379    
18380                            if (!isNew) {
18381                                    messageId = mbMessage.getPrimaryKey();
18382                            }
18383    
18384                            try {
18385                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
18386                                                    userId,
18387                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
18388                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18389                                                    mbMessage.getSubject(), null));
18390                            }
18391                            catch (SanitizerException se) {
18392                                    throw new SystemException(se);
18393                            }
18394                    }
18395    
18396                    Session session = null;
18397    
18398                    try {
18399                            session = openSession();
18400    
18401                            if (mbMessage.isNew()) {
18402                                    session.save(mbMessage);
18403    
18404                                    mbMessage.setNew(false);
18405                            }
18406                            else {
18407                                    session.merge(mbMessage);
18408                            }
18409                    }
18410                    catch (Exception e) {
18411                            throw processException(e);
18412                    }
18413                    finally {
18414                            closeSession(session);
18415                    }
18416    
18417                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18418    
18419                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
18420                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18421                    }
18422    
18423                    else {
18424                            if ((mbMessageModelImpl.getColumnBitmask() &
18425                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18426                                    Object[] args = new Object[] {
18427                                                    mbMessageModelImpl.getOriginalUuid()
18428                                            };
18429    
18430                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18431                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18432                                            args);
18433    
18434                                    args = new Object[] { mbMessageModelImpl.getUuid() };
18435    
18436                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18437                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18438                                            args);
18439                            }
18440    
18441                            if ((mbMessageModelImpl.getColumnBitmask() &
18442                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18443                                    Object[] args = new Object[] {
18444                                                    mbMessageModelImpl.getOriginalUuid(),
18445                                                    mbMessageModelImpl.getOriginalCompanyId()
18446                                            };
18447    
18448                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18449                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18450                                            args);
18451    
18452                                    args = new Object[] {
18453                                                    mbMessageModelImpl.getUuid(),
18454                                                    mbMessageModelImpl.getCompanyId()
18455                                            };
18456    
18457                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18458                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18459                                            args);
18460                            }
18461    
18462                            if ((mbMessageModelImpl.getColumnBitmask() &
18463                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
18464                                    Object[] args = new Object[] {
18465                                                    mbMessageModelImpl.getOriginalGroupId()
18466                                            };
18467    
18468                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18469                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18470                                            args);
18471    
18472                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
18473    
18474                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18475                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18476                                            args);
18477                            }
18478    
18479                            if ((mbMessageModelImpl.getColumnBitmask() &
18480                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
18481                                    Object[] args = new Object[] {
18482                                                    mbMessageModelImpl.getOriginalCompanyId()
18483                                            };
18484    
18485                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18486                                            args);
18487                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18488                                            args);
18489    
18490                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
18491    
18492                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18493                                            args);
18494                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18495                                            args);
18496                            }
18497    
18498                            if ((mbMessageModelImpl.getColumnBitmask() &
18499                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
18500                                    Object[] args = new Object[] {
18501                                                    mbMessageModelImpl.getOriginalUserId()
18502                                            };
18503    
18504                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18505                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18506                                            args);
18507    
18508                                    args = new Object[] { mbMessageModelImpl.getUserId() };
18509    
18510                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18511                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18512                                            args);
18513                            }
18514    
18515                            if ((mbMessageModelImpl.getColumnBitmask() &
18516                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
18517                                    Object[] args = new Object[] {
18518                                                    mbMessageModelImpl.getOriginalThreadId()
18519                                            };
18520    
18521                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18522                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18523                                            args);
18524    
18525                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18526    
18527                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18528                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18529                                            args);
18530                            }
18531    
18532                            if ((mbMessageModelImpl.getColumnBitmask() &
18533                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
18534                                    Object[] args = new Object[] {
18535                                                    mbMessageModelImpl.getOriginalThreadId()
18536                                            };
18537    
18538                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18539                                            args);
18540                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18541                                            args);
18542    
18543                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18544    
18545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18546                                            args);
18547                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18548                                            args);
18549                            }
18550    
18551                            if ((mbMessageModelImpl.getColumnBitmask() &
18552                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
18553                                    Object[] args = new Object[] {
18554                                                    mbMessageModelImpl.getOriginalGroupId(),
18555                                                    mbMessageModelImpl.getOriginalUserId()
18556                                            };
18557    
18558                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18559                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18560                                            args);
18561    
18562                                    args = new Object[] {
18563                                                    mbMessageModelImpl.getGroupId(),
18564                                                    mbMessageModelImpl.getUserId()
18565                                            };
18566    
18567                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18568                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18569                                            args);
18570                            }
18571    
18572                            if ((mbMessageModelImpl.getColumnBitmask() &
18573                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
18574                                    Object[] args = new Object[] {
18575                                                    mbMessageModelImpl.getOriginalGroupId(),
18576                                                    mbMessageModelImpl.getOriginalCategoryId()
18577                                            };
18578    
18579                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18580                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18581                                            args);
18582    
18583                                    args = new Object[] {
18584                                                    mbMessageModelImpl.getGroupId(),
18585                                                    mbMessageModelImpl.getCategoryId()
18586                                            };
18587    
18588                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18589                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18590                                            args);
18591                            }
18592    
18593                            if ((mbMessageModelImpl.getColumnBitmask() &
18594                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
18595                                    Object[] args = new Object[] {
18596                                                    mbMessageModelImpl.getOriginalGroupId(),
18597                                                    mbMessageModelImpl.getOriginalStatus()
18598                                            };
18599    
18600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18601                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18602                                            args);
18603    
18604                                    args = new Object[] {
18605                                                    mbMessageModelImpl.getGroupId(),
18606                                                    mbMessageModelImpl.getStatus()
18607                                            };
18608    
18609                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18610                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18611                                            args);
18612                            }
18613    
18614                            if ((mbMessageModelImpl.getColumnBitmask() &
18615                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
18616                                    Object[] args = new Object[] {
18617                                                    mbMessageModelImpl.getOriginalCompanyId(),
18618                                                    mbMessageModelImpl.getOriginalStatus()
18619                                            };
18620    
18621                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18623                                            args);
18624    
18625                                    args = new Object[] {
18626                                                    mbMessageModelImpl.getCompanyId(),
18627                                                    mbMessageModelImpl.getStatus()
18628                                            };
18629    
18630                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18631                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18632                                            args);
18633                            }
18634    
18635                            if ((mbMessageModelImpl.getColumnBitmask() &
18636                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
18637                                    Object[] args = new Object[] {
18638                                                    mbMessageModelImpl.getOriginalUserId(),
18639                                                    mbMessageModelImpl.getOriginalClassNameId()
18640                                            };
18641    
18642                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18643                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18644                                            args);
18645    
18646                                    args = new Object[] {
18647                                                    mbMessageModelImpl.getUserId(),
18648                                                    mbMessageModelImpl.getClassNameId()
18649                                            };
18650    
18651                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18652                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18653                                            args);
18654                            }
18655    
18656                            if ((mbMessageModelImpl.getColumnBitmask() &
18657                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
18658                                    Object[] args = new Object[] {
18659                                                    mbMessageModelImpl.getOriginalClassNameId(),
18660                                                    mbMessageModelImpl.getOriginalClassPK()
18661                                            };
18662    
18663                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18664                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18665                                            args);
18666    
18667                                    args = new Object[] {
18668                                                    mbMessageModelImpl.getClassNameId(),
18669                                                    mbMessageModelImpl.getClassPK()
18670                                            };
18671    
18672                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18673                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18674                                            args);
18675                            }
18676    
18677                            if ((mbMessageModelImpl.getColumnBitmask() &
18678                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
18679                                    Object[] args = new Object[] {
18680                                                    mbMessageModelImpl.getOriginalThreadId(),
18681                                                    mbMessageModelImpl.getOriginalParentMessageId()
18682                                            };
18683    
18684                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18685                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18686                                            args);
18687    
18688                                    args = new Object[] {
18689                                                    mbMessageModelImpl.getThreadId(),
18690                                                    mbMessageModelImpl.getParentMessageId()
18691                                            };
18692    
18693                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18694                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18695                                            args);
18696                            }
18697    
18698                            if ((mbMessageModelImpl.getColumnBitmask() &
18699                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
18700                                    Object[] args = new Object[] {
18701                                                    mbMessageModelImpl.getOriginalThreadId(),
18702                                                    mbMessageModelImpl.getOriginalAnswer()
18703                                            };
18704    
18705                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18706                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18707                                            args);
18708    
18709                                    args = new Object[] {
18710                                                    mbMessageModelImpl.getThreadId(),
18711                                                    mbMessageModelImpl.getAnswer()
18712                                            };
18713    
18714                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18715                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18716                                            args);
18717                            }
18718    
18719                            if ((mbMessageModelImpl.getColumnBitmask() &
18720                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
18721                                    Object[] args = new Object[] {
18722                                                    mbMessageModelImpl.getOriginalThreadId(),
18723                                                    mbMessageModelImpl.getOriginalStatus()
18724                                            };
18725    
18726                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18727                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18728                                            args);
18729    
18730                                    args = new Object[] {
18731                                                    mbMessageModelImpl.getThreadId(),
18732                                                    mbMessageModelImpl.getStatus()
18733                                            };
18734    
18735                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18736                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18737                                            args);
18738                            }
18739    
18740                            if ((mbMessageModelImpl.getColumnBitmask() &
18741                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
18742                                    Object[] args = new Object[] {
18743                                                    mbMessageModelImpl.getOriginalThreadId(),
18744                                                    mbMessageModelImpl.getOriginalStatus()
18745                                            };
18746    
18747                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18748                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18749                                            args);
18750    
18751                                    args = new Object[] {
18752                                                    mbMessageModelImpl.getThreadId(),
18753                                                    mbMessageModelImpl.getStatus()
18754                                            };
18755    
18756                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18757                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18758                                            args);
18759                            }
18760    
18761                            if ((mbMessageModelImpl.getColumnBitmask() &
18762                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
18763                                    Object[] args = new Object[] {
18764                                                    mbMessageModelImpl.getOriginalGroupId(),
18765                                                    mbMessageModelImpl.getOriginalUserId(),
18766                                                    mbMessageModelImpl.getOriginalStatus()
18767                                            };
18768    
18769                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18770                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18771                                            args);
18772    
18773                                    args = new Object[] {
18774                                                    mbMessageModelImpl.getGroupId(),
18775                                                    mbMessageModelImpl.getUserId(),
18776                                                    mbMessageModelImpl.getStatus()
18777                                            };
18778    
18779                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18780                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18781                                            args);
18782                            }
18783    
18784                            if ((mbMessageModelImpl.getColumnBitmask() &
18785                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
18786                                    Object[] args = new Object[] {
18787                                                    mbMessageModelImpl.getOriginalGroupId(),
18788                                                    mbMessageModelImpl.getOriginalCategoryId(),
18789                                                    mbMessageModelImpl.getOriginalThreadId()
18790                                            };
18791    
18792                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18793                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18794                                            args);
18795    
18796                                    args = new Object[] {
18797                                                    mbMessageModelImpl.getGroupId(),
18798                                                    mbMessageModelImpl.getCategoryId(),
18799                                                    mbMessageModelImpl.getThreadId()
18800                                            };
18801    
18802                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18803                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18804                                            args);
18805                            }
18806    
18807                            if ((mbMessageModelImpl.getColumnBitmask() &
18808                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
18809                                    Object[] args = new Object[] {
18810                                                    mbMessageModelImpl.getOriginalGroupId(),
18811                                                    mbMessageModelImpl.getOriginalCategoryId(),
18812                                                    mbMessageModelImpl.getOriginalStatus()
18813                                            };
18814    
18815                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18816                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18817                                            args);
18818    
18819                                    args = new Object[] {
18820                                                    mbMessageModelImpl.getGroupId(),
18821                                                    mbMessageModelImpl.getCategoryId(),
18822                                                    mbMessageModelImpl.getStatus()
18823                                            };
18824    
18825                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18826                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18827                                            args);
18828                            }
18829    
18830                            if ((mbMessageModelImpl.getColumnBitmask() &
18831                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
18832                                    Object[] args = new Object[] {
18833                                                    mbMessageModelImpl.getOriginalUserId(),
18834                                                    mbMessageModelImpl.getOriginalClassNameId(),
18835                                                    mbMessageModelImpl.getOriginalClassPK()
18836                                            };
18837    
18838                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18839                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18840                                            args);
18841    
18842                                    args = new Object[] {
18843                                                    mbMessageModelImpl.getUserId(),
18844                                                    mbMessageModelImpl.getClassNameId(),
18845                                                    mbMessageModelImpl.getClassPK()
18846                                            };
18847    
18848                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18849                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18850                                            args);
18851                            }
18852    
18853                            if ((mbMessageModelImpl.getColumnBitmask() &
18854                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
18855                                    Object[] args = new Object[] {
18856                                                    mbMessageModelImpl.getOriginalUserId(),
18857                                                    mbMessageModelImpl.getOriginalClassNameId(),
18858                                                    mbMessageModelImpl.getOriginalStatus()
18859                                            };
18860    
18861                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18862                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18863                                            args);
18864    
18865                                    args = new Object[] {
18866                                                    mbMessageModelImpl.getUserId(),
18867                                                    mbMessageModelImpl.getClassNameId(),
18868                                                    mbMessageModelImpl.getStatus()
18869                                            };
18870    
18871                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18872                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18873                                            args);
18874                            }
18875    
18876                            if ((mbMessageModelImpl.getColumnBitmask() &
18877                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
18878                                    Object[] args = new Object[] {
18879                                                    mbMessageModelImpl.getOriginalClassNameId(),
18880                                                    mbMessageModelImpl.getOriginalClassPK(),
18881                                                    mbMessageModelImpl.getOriginalStatus()
18882                                            };
18883    
18884                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18885                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18886                                            args);
18887    
18888                                    args = new Object[] {
18889                                                    mbMessageModelImpl.getClassNameId(),
18890                                                    mbMessageModelImpl.getClassPK(),
18891                                                    mbMessageModelImpl.getStatus()
18892                                            };
18893    
18894                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18895                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18896                                            args);
18897                            }
18898    
18899                            if ((mbMessageModelImpl.getColumnBitmask() &
18900                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
18901                                    Object[] args = new Object[] {
18902                                                    mbMessageModelImpl.getOriginalGroupId(),
18903                                                    mbMessageModelImpl.getOriginalCategoryId(),
18904                                                    mbMessageModelImpl.getOriginalThreadId(),
18905                                                    mbMessageModelImpl.getOriginalAnswer()
18906                                            };
18907    
18908                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18909                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18910                                            args);
18911    
18912                                    args = new Object[] {
18913                                                    mbMessageModelImpl.getGroupId(),
18914                                                    mbMessageModelImpl.getCategoryId(),
18915                                                    mbMessageModelImpl.getThreadId(),
18916                                                    mbMessageModelImpl.getAnswer()
18917                                            };
18918    
18919                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18920                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18921                                            args);
18922                            }
18923    
18924                            if ((mbMessageModelImpl.getColumnBitmask() &
18925                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
18926                                    Object[] args = new Object[] {
18927                                                    mbMessageModelImpl.getOriginalGroupId(),
18928                                                    mbMessageModelImpl.getOriginalCategoryId(),
18929                                                    mbMessageModelImpl.getOriginalThreadId(),
18930                                                    mbMessageModelImpl.getOriginalStatus()
18931                                            };
18932    
18933                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18934                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18935                                            args);
18936    
18937                                    args = new Object[] {
18938                                                    mbMessageModelImpl.getGroupId(),
18939                                                    mbMessageModelImpl.getCategoryId(),
18940                                                    mbMessageModelImpl.getThreadId(),
18941                                                    mbMessageModelImpl.getStatus()
18942                                            };
18943    
18944                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18945                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18946                                            args);
18947                            }
18948    
18949                            if ((mbMessageModelImpl.getColumnBitmask() &
18950                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
18951                                    Object[] args = new Object[] {
18952                                                    mbMessageModelImpl.getOriginalUserId(),
18953                                                    mbMessageModelImpl.getOriginalClassNameId(),
18954                                                    mbMessageModelImpl.getOriginalClassPK(),
18955                                                    mbMessageModelImpl.getOriginalStatus()
18956                                            };
18957    
18958                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18959                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18960                                            args);
18961    
18962                                    args = new Object[] {
18963                                                    mbMessageModelImpl.getUserId(),
18964                                                    mbMessageModelImpl.getClassNameId(),
18965                                                    mbMessageModelImpl.getClassPK(),
18966                                                    mbMessageModelImpl.getStatus()
18967                                            };
18968    
18969                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18970                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18971                                            args);
18972                            }
18973                    }
18974    
18975                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18976                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
18977    
18978                    clearUniqueFindersCache(mbMessage);
18979                    cacheUniqueFindersCache(mbMessage);
18980    
18981                    mbMessage.resetOriginalValues();
18982    
18983                    return mbMessage;
18984            }
18985    
18986            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
18987                    if (mbMessage instanceof MBMessageImpl) {
18988                            return mbMessage;
18989                    }
18990    
18991                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
18992    
18993                    mbMessageImpl.setNew(mbMessage.isNew());
18994                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
18995    
18996                    mbMessageImpl.setUuid(mbMessage.getUuid());
18997                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
18998                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
18999                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19000                    mbMessageImpl.setUserId(mbMessage.getUserId());
19001                    mbMessageImpl.setUserName(mbMessage.getUserName());
19002                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19003                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19004                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19005                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19006                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19007                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19008                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19009                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19010                    mbMessageImpl.setSubject(mbMessage.getSubject());
19011                    mbMessageImpl.setBody(mbMessage.getBody());
19012                    mbMessageImpl.setFormat(mbMessage.getFormat());
19013                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19014                    mbMessageImpl.setPriority(mbMessage.getPriority());
19015                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19016                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19017                    mbMessageImpl.setStatus(mbMessage.getStatus());
19018                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19019                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19020                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19021    
19022                    return mbMessageImpl;
19023            }
19024    
19025            /**
19026             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19027             *
19028             * @param primaryKey the primary key of the message-boards message
19029             * @return the message-boards message
19030             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19031             */
19032            @Override
19033            public MBMessage findByPrimaryKey(Serializable primaryKey)
19034                    throws NoSuchMessageException {
19035                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19036    
19037                    if (mbMessage == null) {
19038                            if (_log.isWarnEnabled()) {
19039                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19040                            }
19041    
19042                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19043                                    primaryKey);
19044                    }
19045    
19046                    return mbMessage;
19047            }
19048    
19049            /**
19050             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
19051             *
19052             * @param messageId the primary key of the message-boards message
19053             * @return the message-boards message
19054             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19055             */
19056            @Override
19057            public MBMessage findByPrimaryKey(long messageId)
19058                    throws NoSuchMessageException {
19059                    return findByPrimaryKey((Serializable)messageId);
19060            }
19061    
19062            /**
19063             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19064             *
19065             * @param primaryKey the primary key of the message-boards message
19066             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19067             */
19068            @Override
19069            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19070                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19071                                    MBMessageImpl.class, primaryKey);
19072    
19073                    if (mbMessage == _nullMBMessage) {
19074                            return null;
19075                    }
19076    
19077                    if (mbMessage == null) {
19078                            Session session = null;
19079    
19080                            try {
19081                                    session = openSession();
19082    
19083                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19084                                                    primaryKey);
19085    
19086                                    if (mbMessage != null) {
19087                                            cacheResult(mbMessage);
19088                                    }
19089                                    else {
19090                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19091                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19092                                    }
19093                            }
19094                            catch (Exception e) {
19095                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19096                                            MBMessageImpl.class, primaryKey);
19097    
19098                                    throw processException(e);
19099                            }
19100                            finally {
19101                                    closeSession(session);
19102                            }
19103                    }
19104    
19105                    return mbMessage;
19106            }
19107    
19108            /**
19109             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19110             *
19111             * @param messageId the primary key of the message-boards message
19112             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19113             */
19114            @Override
19115            public MBMessage fetchByPrimaryKey(long messageId) {
19116                    return fetchByPrimaryKey((Serializable)messageId);
19117            }
19118    
19119            @Override
19120            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19121                    Set<Serializable> primaryKeys) {
19122                    if (primaryKeys.isEmpty()) {
19123                            return Collections.emptyMap();
19124                    }
19125    
19126                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19127    
19128                    if (primaryKeys.size() == 1) {
19129                            Iterator<Serializable> iterator = primaryKeys.iterator();
19130    
19131                            Serializable primaryKey = iterator.next();
19132    
19133                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19134    
19135                            if (mbMessage != null) {
19136                                    map.put(primaryKey, mbMessage);
19137                            }
19138    
19139                            return map;
19140                    }
19141    
19142                    Set<Serializable> uncachedPrimaryKeys = null;
19143    
19144                    for (Serializable primaryKey : primaryKeys) {
19145                            MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19146                                            MBMessageImpl.class, primaryKey);
19147    
19148                            if (mbMessage == null) {
19149                                    if (uncachedPrimaryKeys == null) {
19150                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19151                                    }
19152    
19153                                    uncachedPrimaryKeys.add(primaryKey);
19154                            }
19155                            else {
19156                                    map.put(primaryKey, mbMessage);
19157                            }
19158                    }
19159    
19160                    if (uncachedPrimaryKeys == null) {
19161                            return map;
19162                    }
19163    
19164                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19165                                    1);
19166    
19167                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19168    
19169                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19170                            query.append(String.valueOf(primaryKey));
19171    
19172                            query.append(StringPool.COMMA);
19173                    }
19174    
19175                    query.setIndex(query.index() - 1);
19176    
19177                    query.append(StringPool.CLOSE_PARENTHESIS);
19178    
19179                    String sql = query.toString();
19180    
19181                    Session session = null;
19182    
19183                    try {
19184                            session = openSession();
19185    
19186                            Query q = session.createQuery(sql);
19187    
19188                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19189                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19190    
19191                                    cacheResult(mbMessage);
19192    
19193                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19194                            }
19195    
19196                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19197                                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19198                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
19199                            }
19200                    }
19201                    catch (Exception e) {
19202                            throw processException(e);
19203                    }
19204                    finally {
19205                            closeSession(session);
19206                    }
19207    
19208                    return map;
19209            }
19210    
19211            /**
19212             * Returns all the message-boards messages.
19213             *
19214             * @return the message-boards messages
19215             */
19216            @Override
19217            public List<MBMessage> findAll() {
19218                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19219            }
19220    
19221            /**
19222             * Returns a range of all the message-boards messages.
19223             *
19224             * <p>
19225             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19226             * </p>
19227             *
19228             * @param start the lower bound of the range of message-boards messages
19229             * @param end the upper bound of the range of message-boards messages (not inclusive)
19230             * @return the range of message-boards messages
19231             */
19232            @Override
19233            public List<MBMessage> findAll(int start, int end) {
19234                    return findAll(start, end, null);
19235            }
19236    
19237            /**
19238             * Returns an ordered range of all the message-boards messages.
19239             *
19240             * <p>
19241             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19242             * </p>
19243             *
19244             * @param start the lower bound of the range of message-boards messages
19245             * @param end the upper bound of the range of message-boards messages (not inclusive)
19246             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19247             * @return the ordered range of message-boards messages
19248             */
19249            @Override
19250            public List<MBMessage> findAll(int start, int end,
19251                    OrderByComparator<MBMessage> orderByComparator) {
19252                    boolean pagination = true;
19253                    FinderPath finderPath = null;
19254                    Object[] finderArgs = null;
19255    
19256                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19257                                    (orderByComparator == null)) {
19258                            pagination = false;
19259                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19260                            finderArgs = FINDER_ARGS_EMPTY;
19261                    }
19262                    else {
19263                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19264                            finderArgs = new Object[] { start, end, orderByComparator };
19265                    }
19266    
19267                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19268                                    finderArgs, this);
19269    
19270                    if (list == null) {
19271                            StringBundler query = null;
19272                            String sql = null;
19273    
19274                            if (orderByComparator != null) {
19275                                    query = new StringBundler(2 +
19276                                                    (orderByComparator.getOrderByFields().length * 3));
19277    
19278                                    query.append(_SQL_SELECT_MBMESSAGE);
19279    
19280                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19281                                            orderByComparator);
19282    
19283                                    sql = query.toString();
19284                            }
19285                            else {
19286                                    sql = _SQL_SELECT_MBMESSAGE;
19287    
19288                                    if (pagination) {
19289                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
19290                                    }
19291                            }
19292    
19293                            Session session = null;
19294    
19295                            try {
19296                                    session = openSession();
19297    
19298                                    Query q = session.createQuery(sql);
19299    
19300                                    if (!pagination) {
19301                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19302                                                            start, end, false);
19303    
19304                                            Collections.sort(list);
19305    
19306                                            list = Collections.unmodifiableList(list);
19307                                    }
19308                                    else {
19309                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19310                                                            start, end);
19311                                    }
19312    
19313                                    cacheResult(list);
19314    
19315                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19316                            }
19317                            catch (Exception e) {
19318                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19319    
19320                                    throw processException(e);
19321                            }
19322                            finally {
19323                                    closeSession(session);
19324                            }
19325                    }
19326    
19327                    return list;
19328            }
19329    
19330            /**
19331             * Removes all the message-boards messages from the database.
19332             *
19333             */
19334            @Override
19335            public void removeAll() {
19336                    for (MBMessage mbMessage : findAll()) {
19337                            remove(mbMessage);
19338                    }
19339            }
19340    
19341            /**
19342             * Returns the number of message-boards messages.
19343             *
19344             * @return the number of message-boards messages
19345             */
19346            @Override
19347            public int countAll() {
19348                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19349                                    FINDER_ARGS_EMPTY, this);
19350    
19351                    if (count == null) {
19352                            Session session = null;
19353    
19354                            try {
19355                                    session = openSession();
19356    
19357                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
19358    
19359                                    count = (Long)q.uniqueResult();
19360    
19361                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19362                                            FINDER_ARGS_EMPTY, count);
19363                            }
19364                            catch (Exception e) {
19365                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19366                                            FINDER_ARGS_EMPTY);
19367    
19368                                    throw processException(e);
19369                            }
19370                            finally {
19371                                    closeSession(session);
19372                            }
19373                    }
19374    
19375                    return count.intValue();
19376            }
19377    
19378            @Override
19379            protected Set<String> getBadColumnNames() {
19380                    return _badColumnNames;
19381            }
19382    
19383            /**
19384             * Initializes the message-boards message persistence.
19385             */
19386            public void afterPropertiesSet() {
19387            }
19388    
19389            public void destroy() {
19390                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
19391                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19392                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19393                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19394            }
19395    
19396            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19397            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
19398            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19399            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19400            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19401            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19402            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19403            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19404                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19405            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19406                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19407            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19408            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19409            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19410            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19411            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19412            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19413            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19414            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19415            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19416            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
19417                                    "uuid"
19418                            });
19419            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
19420                            @Override
19421                            public Object clone() {
19422                                    return this;
19423                            }
19424    
19425                            @Override
19426                            public CacheModel<MBMessage> toCacheModel() {
19427                                    return _nullMBMessageCacheModel;
19428                            }
19429                    };
19430    
19431            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19432                            @Override
19433                            public MBMessage toEntityModel() {
19434                                    return _nullMBMessage;
19435                            }
19436                    };
19437    }