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.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.SQLQuery;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.sanitizer.Sanitizer;
031    import com.liferay.portal.kernel.sanitizer.SanitizerException;
032    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
033    import com.liferay.portal.kernel.util.ArrayUtil;
034    import com.liferay.portal.kernel.util.ContentTypes;
035    import com.liferay.portal.kernel.util.GetterUtil;
036    import com.liferay.portal.kernel.util.OrderByComparator;
037    import com.liferay.portal.kernel.util.SetUtil;
038    import com.liferay.portal.kernel.util.StringBundler;
039    import com.liferay.portal.kernel.util.StringPool;
040    import com.liferay.portal.kernel.util.StringUtil;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
043    import com.liferay.portal.model.CacheModel;
044    import com.liferay.portal.security.auth.PrincipalThreadLocal;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.ServiceContext;
047    import com.liferay.portal.service.ServiceContextThreadLocal;
048    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049    
050    import com.liferay.portlet.messageboards.NoSuchMessageException;
051    import com.liferay.portlet.messageboards.model.MBMessage;
052    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
053    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
054    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
055    
056    import java.io.Serializable;
057    
058    import java.util.Collections;
059    import java.util.Date;
060    import java.util.HashMap;
061    import java.util.HashSet;
062    import java.util.Iterator;
063    import java.util.List;
064    import java.util.Map;
065    import java.util.Set;
066    
067    /**
068     * The persistence implementation for the message-boards message service.
069     *
070     * <p>
071     * Caching information and settings can be found in <code>portal.properties</code>
072     * </p>
073     *
074     * @author Brian Wing Shun Chan
075     * @see MBMessagePersistence
076     * @see com.liferay.portlet.messageboards.service.persistence.MBMessageUtil
077     * @generated
078     */
079    @ProviderType
080    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
081            implements MBMessagePersistence {
082            /*
083             * NOTE FOR DEVELOPERS:
084             *
085             * 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.
086             */
087            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
088            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
089                    ".List1";
090            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
091                    ".List2";
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
093                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
098            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
099                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
101            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
104                            new String[] {
105                                    String.class.getName(),
106                                    
107                            Integer.class.getName(), Integer.class.getName(),
108                                    OrderByComparator.class.getName()
109                            });
110            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
111                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
113                            new String[] { String.class.getName() },
114                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
115                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
119                            new String[] { String.class.getName() });
120    
121            /**
122             * Returns all the message-boards messages where uuid = &#63;.
123             *
124             * @param uuid the uuid
125             * @return the matching message-boards messages
126             */
127            @Override
128            public List<MBMessage> findByUuid(String uuid) {
129                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
130            }
131    
132            /**
133             * Returns a range of all the message-boards messages where uuid = &#63;.
134             *
135             * <p>
136             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
137             * </p>
138             *
139             * @param uuid the uuid
140             * @param start the lower bound of the range of message-boards messages
141             * @param end the upper bound of the range of message-boards messages (not inclusive)
142             * @return the range of matching message-boards messages
143             */
144            @Override
145            public List<MBMessage> findByUuid(String uuid, int start, int end) {
146                    return findByUuid(uuid, start, end, null);
147            }
148    
149            /**
150             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
151             *
152             * <p>
153             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
154             * </p>
155             *
156             * @param uuid the uuid
157             * @param start the lower bound of the range of message-boards messages
158             * @param end the upper bound of the range of message-boards messages (not inclusive)
159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
160             * @return the ordered range of matching message-boards messages
161             */
162            @Override
163            public List<MBMessage> findByUuid(String uuid, int start, int end,
164                    OrderByComparator<MBMessage> orderByComparator) {
165                    boolean pagination = true;
166                    FinderPath finderPath = null;
167                    Object[] finderArgs = null;
168    
169                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
170                                    (orderByComparator == null)) {
171                            pagination = false;
172                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
173                            finderArgs = new Object[] { uuid };
174                    }
175                    else {
176                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
177                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
178                    }
179    
180                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
181                                    finderArgs, this);
182    
183                    if ((list != null) && !list.isEmpty()) {
184                            for (MBMessage mbMessage : list) {
185                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
186                                            list = null;
187    
188                                            break;
189                                    }
190                            }
191                    }
192    
193                    if (list == null) {
194                            StringBundler query = null;
195    
196                            if (orderByComparator != null) {
197                                    query = new StringBundler(3 +
198                                                    (orderByComparator.getOrderByFields().length * 3));
199                            }
200                            else {
201                                    query = new StringBundler(3);
202                            }
203    
204                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
205    
206                            boolean bindUuid = false;
207    
208                            if (uuid == null) {
209                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
210                            }
211                            else if (uuid.equals(StringPool.BLANK)) {
212                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
213                            }
214                            else {
215                                    bindUuid = true;
216    
217                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
218                            }
219    
220                            if (orderByComparator != null) {
221                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
222                                            orderByComparator);
223                            }
224                            else
225                             if (pagination) {
226                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
227                            }
228    
229                            String sql = query.toString();
230    
231                            Session session = null;
232    
233                            try {
234                                    session = openSession();
235    
236                                    Query q = session.createQuery(sql);
237    
238                                    QueryPos qPos = QueryPos.getInstance(q);
239    
240                                    if (bindUuid) {
241                                            qPos.add(uuid);
242                                    }
243    
244                                    if (!pagination) {
245                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
246                                                            start, end, false);
247    
248                                            Collections.sort(list);
249    
250                                            list = Collections.unmodifiableList(list);
251                                    }
252                                    else {
253                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
254                                                            start, end);
255                                    }
256    
257                                    cacheResult(list);
258    
259                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
260                            }
261                            catch (Exception e) {
262                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
263    
264                                    throw processException(e);
265                            }
266                            finally {
267                                    closeSession(session);
268                            }
269                    }
270    
271                    return list;
272            }
273    
274            /**
275             * Returns the first message-boards message in the ordered set where uuid = &#63;.
276             *
277             * @param uuid the uuid
278             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
279             * @return the first matching message-boards message
280             * @throws NoSuchMessageException if a matching message-boards message could not be found
281             */
282            @Override
283            public MBMessage findByUuid_First(String uuid,
284                    OrderByComparator<MBMessage> orderByComparator)
285                    throws NoSuchMessageException {
286                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
287    
288                    if (mbMessage != null) {
289                            return mbMessage;
290                    }
291    
292                    StringBundler msg = new StringBundler(4);
293    
294                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
295    
296                    msg.append("uuid=");
297                    msg.append(uuid);
298    
299                    msg.append(StringPool.CLOSE_CURLY_BRACE);
300    
301                    throw new NoSuchMessageException(msg.toString());
302            }
303    
304            /**
305             * Returns the first message-boards message in the ordered set where uuid = &#63;.
306             *
307             * @param uuid the uuid
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
310             */
311            @Override
312            public MBMessage fetchByUuid_First(String uuid,
313                    OrderByComparator<MBMessage> orderByComparator) {
314                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
315    
316                    if (!list.isEmpty()) {
317                            return list.get(0);
318                    }
319    
320                    return null;
321            }
322    
323            /**
324             * Returns the last message-boards message in the ordered set where uuid = &#63;.
325             *
326             * @param uuid the uuid
327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
328             * @return the last matching message-boards message
329             * @throws NoSuchMessageException if a matching message-boards message could not be found
330             */
331            @Override
332            public MBMessage findByUuid_Last(String uuid,
333                    OrderByComparator<MBMessage> orderByComparator)
334                    throws NoSuchMessageException {
335                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
336    
337                    if (mbMessage != null) {
338                            return mbMessage;
339                    }
340    
341                    StringBundler msg = new StringBundler(4);
342    
343                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344    
345                    msg.append("uuid=");
346                    msg.append(uuid);
347    
348                    msg.append(StringPool.CLOSE_CURLY_BRACE);
349    
350                    throw new NoSuchMessageException(msg.toString());
351            }
352    
353            /**
354             * Returns the last message-boards message in the ordered set where uuid = &#63;.
355             *
356             * @param uuid the uuid
357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
358             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
359             */
360            @Override
361            public MBMessage fetchByUuid_Last(String uuid,
362                    OrderByComparator<MBMessage> orderByComparator) {
363                    int count = countByUuid(uuid);
364    
365                    if (count == 0) {
366                            return null;
367                    }
368    
369                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
370                                    orderByComparator);
371    
372                    if (!list.isEmpty()) {
373                            return list.get(0);
374                    }
375    
376                    return null;
377            }
378    
379            /**
380             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
381             *
382             * @param messageId the primary key of the current message-boards message
383             * @param uuid the uuid
384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
385             * @return the previous, current, and next message-boards message
386             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
387             */
388            @Override
389            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
390                    OrderByComparator<MBMessage> orderByComparator)
391                    throws NoSuchMessageException {
392                    MBMessage mbMessage = findByPrimaryKey(messageId);
393    
394                    Session session = null;
395    
396                    try {
397                            session = openSession();
398    
399                            MBMessage[] array = new MBMessageImpl[3];
400    
401                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
402                                            orderByComparator, true);
403    
404                            array[1] = mbMessage;
405    
406                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
407                                            orderByComparator, false);
408    
409                            return array;
410                    }
411                    catch (Exception e) {
412                            throw processException(e);
413                    }
414                    finally {
415                            closeSession(session);
416                    }
417            }
418    
419            protected MBMessage getByUuid_PrevAndNext(Session session,
420                    MBMessage mbMessage, String uuid,
421                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
422                    StringBundler query = null;
423    
424                    if (orderByComparator != null) {
425                            query = new StringBundler(6 +
426                                            (orderByComparator.getOrderByFields().length * 6));
427                    }
428                    else {
429                            query = new StringBundler(3);
430                    }
431    
432                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
433    
434                    boolean bindUuid = false;
435    
436                    if (uuid == null) {
437                            query.append(_FINDER_COLUMN_UUID_UUID_1);
438                    }
439                    else if (uuid.equals(StringPool.BLANK)) {
440                            query.append(_FINDER_COLUMN_UUID_UUID_3);
441                    }
442                    else {
443                            bindUuid = true;
444    
445                            query.append(_FINDER_COLUMN_UUID_UUID_2);
446                    }
447    
448                    if (orderByComparator != null) {
449                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
450    
451                            if (orderByConditionFields.length > 0) {
452                                    query.append(WHERE_AND);
453                            }
454    
455                            for (int i = 0; i < orderByConditionFields.length; i++) {
456                                    query.append(_ORDER_BY_ENTITY_ALIAS);
457                                    query.append(orderByConditionFields[i]);
458    
459                                    if ((i + 1) < orderByConditionFields.length) {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
462                                            }
463                                            else {
464                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
465                                            }
466                                    }
467                                    else {
468                                            if (orderByComparator.isAscending() ^ previous) {
469                                                    query.append(WHERE_GREATER_THAN);
470                                            }
471                                            else {
472                                                    query.append(WHERE_LESSER_THAN);
473                                            }
474                                    }
475                            }
476    
477                            query.append(ORDER_BY_CLAUSE);
478    
479                            String[] orderByFields = orderByComparator.getOrderByFields();
480    
481                            for (int i = 0; i < orderByFields.length; i++) {
482                                    query.append(_ORDER_BY_ENTITY_ALIAS);
483                                    query.append(orderByFields[i]);
484    
485                                    if ((i + 1) < orderByFields.length) {
486                                            if (orderByComparator.isAscending() ^ previous) {
487                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
488                                            }
489                                            else {
490                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
491                                            }
492                                    }
493                                    else {
494                                            if (orderByComparator.isAscending() ^ previous) {
495                                                    query.append(ORDER_BY_ASC);
496                                            }
497                                            else {
498                                                    query.append(ORDER_BY_DESC);
499                                            }
500                                    }
501                            }
502                    }
503                    else {
504                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
505                    }
506    
507                    String sql = query.toString();
508    
509                    Query q = session.createQuery(sql);
510    
511                    q.setFirstResult(0);
512                    q.setMaxResults(2);
513    
514                    QueryPos qPos = QueryPos.getInstance(q);
515    
516                    if (bindUuid) {
517                            qPos.add(uuid);
518                    }
519    
520                    if (orderByComparator != null) {
521                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
522    
523                            for (Object value : values) {
524                                    qPos.add(value);
525                            }
526                    }
527    
528                    List<MBMessage> list = q.list();
529    
530                    if (list.size() == 2) {
531                            return list.get(1);
532                    }
533                    else {
534                            return null;
535                    }
536            }
537    
538            /**
539             * Removes all the message-boards messages where uuid = &#63; from the database.
540             *
541             * @param uuid the uuid
542             */
543            @Override
544            public void removeByUuid(String uuid) {
545                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
546                                    QueryUtil.ALL_POS, null)) {
547                            remove(mbMessage);
548                    }
549            }
550    
551            /**
552             * Returns the number of message-boards messages where uuid = &#63;.
553             *
554             * @param uuid the uuid
555             * @return the number of matching message-boards messages
556             */
557            @Override
558            public int countByUuid(String uuid) {
559                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
560    
561                    Object[] finderArgs = new Object[] { uuid };
562    
563                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
564                                    this);
565    
566                    if (count == null) {
567                            StringBundler query = new StringBundler(2);
568    
569                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
570    
571                            boolean bindUuid = false;
572    
573                            if (uuid == null) {
574                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
575                            }
576                            else if (uuid.equals(StringPool.BLANK)) {
577                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
578                            }
579                            else {
580                                    bindUuid = true;
581    
582                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
583                            }
584    
585                            String sql = query.toString();
586    
587                            Session session = null;
588    
589                            try {
590                                    session = openSession();
591    
592                                    Query q = session.createQuery(sql);
593    
594                                    QueryPos qPos = QueryPos.getInstance(q);
595    
596                                    if (bindUuid) {
597                                            qPos.add(uuid);
598                                    }
599    
600                                    count = (Long)q.uniqueResult();
601    
602                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
603                            }
604                            catch (Exception e) {
605                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
606    
607                                    throw processException(e);
608                            }
609                            finally {
610                                    closeSession(session);
611                            }
612                    }
613    
614                    return count.intValue();
615            }
616    
617            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
618            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
619            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
620            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
621                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
622                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
623                            new String[] { String.class.getName(), Long.class.getName() },
624                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
625                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
626            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
627                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
628                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
629                            new String[] { String.class.getName(), Long.class.getName() });
630    
631            /**
632             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
633             *
634             * @param uuid the uuid
635             * @param groupId the group ID
636             * @return the matching message-boards message
637             * @throws NoSuchMessageException if a matching message-boards message could not be found
638             */
639            @Override
640            public MBMessage findByUUID_G(String uuid, long groupId)
641                    throws NoSuchMessageException {
642                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
643    
644                    if (mbMessage == null) {
645                            StringBundler msg = new StringBundler(6);
646    
647                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648    
649                            msg.append("uuid=");
650                            msg.append(uuid);
651    
652                            msg.append(", groupId=");
653                            msg.append(groupId);
654    
655                            msg.append(StringPool.CLOSE_CURLY_BRACE);
656    
657                            if (_log.isWarnEnabled()) {
658                                    _log.warn(msg.toString());
659                            }
660    
661                            throw new NoSuchMessageException(msg.toString());
662                    }
663    
664                    return mbMessage;
665            }
666    
667            /**
668             * 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.
669             *
670             * @param uuid the uuid
671             * @param groupId the group ID
672             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
673             */
674            @Override
675            public MBMessage fetchByUUID_G(String uuid, long groupId) {
676                    return fetchByUUID_G(uuid, groupId, true);
677            }
678    
679            /**
680             * 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.
681             *
682             * @param uuid the uuid
683             * @param groupId the group ID
684             * @param retrieveFromCache whether to use the finder cache
685             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
686             */
687            @Override
688            public MBMessage fetchByUUID_G(String uuid, long groupId,
689                    boolean retrieveFromCache) {
690                    Object[] finderArgs = new Object[] { uuid, groupId };
691    
692                    Object result = null;
693    
694                    if (retrieveFromCache) {
695                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
696                                            finderArgs, this);
697                    }
698    
699                    if (result instanceof MBMessage) {
700                            MBMessage mbMessage = (MBMessage)result;
701    
702                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
703                                            (groupId != mbMessage.getGroupId())) {
704                                    result = null;
705                            }
706                    }
707    
708                    if (result == null) {
709                            StringBundler query = new StringBundler(4);
710    
711                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
712    
713                            boolean bindUuid = false;
714    
715                            if (uuid == null) {
716                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
717                            }
718                            else if (uuid.equals(StringPool.BLANK)) {
719                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
720                            }
721                            else {
722                                    bindUuid = true;
723    
724                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
725                            }
726    
727                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
728    
729                            String sql = query.toString();
730    
731                            Session session = null;
732    
733                            try {
734                                    session = openSession();
735    
736                                    Query q = session.createQuery(sql);
737    
738                                    QueryPos qPos = QueryPos.getInstance(q);
739    
740                                    if (bindUuid) {
741                                            qPos.add(uuid);
742                                    }
743    
744                                    qPos.add(groupId);
745    
746                                    List<MBMessage> list = q.list();
747    
748                                    if (list.isEmpty()) {
749                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
750                                                    finderArgs, list);
751                                    }
752                                    else {
753                                            MBMessage mbMessage = list.get(0);
754    
755                                            result = mbMessage;
756    
757                                            cacheResult(mbMessage);
758    
759                                            if ((mbMessage.getUuid() == null) ||
760                                                            !mbMessage.getUuid().equals(uuid) ||
761                                                            (mbMessage.getGroupId() != groupId)) {
762                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
763                                                            finderArgs, mbMessage);
764                                            }
765                                    }
766                            }
767                            catch (Exception e) {
768                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
769                                            finderArgs);
770    
771                                    throw processException(e);
772                            }
773                            finally {
774                                    closeSession(session);
775                            }
776                    }
777    
778                    if (result instanceof List<?>) {
779                            return null;
780                    }
781                    else {
782                            return (MBMessage)result;
783                    }
784            }
785    
786            /**
787             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
788             *
789             * @param uuid the uuid
790             * @param groupId the group ID
791             * @return the message-boards message that was removed
792             */
793            @Override
794            public MBMessage removeByUUID_G(String uuid, long groupId)
795                    throws NoSuchMessageException {
796                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
797    
798                    return remove(mbMessage);
799            }
800    
801            /**
802             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
803             *
804             * @param uuid the uuid
805             * @param groupId the group ID
806             * @return the number of matching message-boards messages
807             */
808            @Override
809            public int countByUUID_G(String uuid, long groupId) {
810                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
811    
812                    Object[] finderArgs = new Object[] { uuid, groupId };
813    
814                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
815                                    this);
816    
817                    if (count == null) {
818                            StringBundler query = new StringBundler(3);
819    
820                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
821    
822                            boolean bindUuid = false;
823    
824                            if (uuid == null) {
825                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
826                            }
827                            else if (uuid.equals(StringPool.BLANK)) {
828                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
829                            }
830                            else {
831                                    bindUuid = true;
832    
833                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
834                            }
835    
836                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
837    
838                            String sql = query.toString();
839    
840                            Session session = null;
841    
842                            try {
843                                    session = openSession();
844    
845                                    Query q = session.createQuery(sql);
846    
847                                    QueryPos qPos = QueryPos.getInstance(q);
848    
849                                    if (bindUuid) {
850                                            qPos.add(uuid);
851                                    }
852    
853                                    qPos.add(groupId);
854    
855                                    count = (Long)q.uniqueResult();
856    
857                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
858                            }
859                            catch (Exception e) {
860                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
861    
862                                    throw processException(e);
863                            }
864                            finally {
865                                    closeSession(session);
866                            }
867                    }
868    
869                    return count.intValue();
870            }
871    
872            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
873            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
874            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
875            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
876            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
877                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
878                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
879                            new String[] {
880                                    String.class.getName(), Long.class.getName(),
881                                    
882                            Integer.class.getName(), Integer.class.getName(),
883                                    OrderByComparator.class.getName()
884                            });
885            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
886                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
887                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
888                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
889                            new String[] { String.class.getName(), Long.class.getName() },
890                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
891                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
892                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
893            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
894                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
895                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
896                            new String[] { String.class.getName(), Long.class.getName() });
897    
898            /**
899             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
900             *
901             * @param uuid the uuid
902             * @param companyId the company ID
903             * @return the matching message-boards messages
904             */
905            @Override
906            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
907                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
908                            QueryUtil.ALL_POS, null);
909            }
910    
911            /**
912             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
913             *
914             * <p>
915             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
916             * </p>
917             *
918             * @param uuid the uuid
919             * @param companyId the company ID
920             * @param start the lower bound of the range of message-boards messages
921             * @param end the upper bound of the range of message-boards messages (not inclusive)
922             * @return the range of matching message-boards messages
923             */
924            @Override
925            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
926                    int end) {
927                    return findByUuid_C(uuid, companyId, start, end, null);
928            }
929    
930            /**
931             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
932             *
933             * <p>
934             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
935             * </p>
936             *
937             * @param uuid the uuid
938             * @param companyId the company ID
939             * @param start the lower bound of the range of message-boards messages
940             * @param end the upper bound of the range of message-boards messages (not inclusive)
941             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
942             * @return the ordered range of matching message-boards messages
943             */
944            @Override
945            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
946                    int end, OrderByComparator<MBMessage> orderByComparator) {
947                    boolean pagination = true;
948                    FinderPath finderPath = null;
949                    Object[] finderArgs = null;
950    
951                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
952                                    (orderByComparator == null)) {
953                            pagination = false;
954                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
955                            finderArgs = new Object[] { uuid, companyId };
956                    }
957                    else {
958                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
959                            finderArgs = new Object[] {
960                                            uuid, companyId,
961                                            
962                                            start, end, orderByComparator
963                                    };
964                    }
965    
966                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
967                                    finderArgs, this);
968    
969                    if ((list != null) && !list.isEmpty()) {
970                            for (MBMessage mbMessage : list) {
971                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
972                                                    (companyId != mbMessage.getCompanyId())) {
973                                            list = null;
974    
975                                            break;
976                                    }
977                            }
978                    }
979    
980                    if (list == null) {
981                            StringBundler query = null;
982    
983                            if (orderByComparator != null) {
984                                    query = new StringBundler(4 +
985                                                    (orderByComparator.getOrderByFields().length * 3));
986                            }
987                            else {
988                                    query = new StringBundler(4);
989                            }
990    
991                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
992    
993                            boolean bindUuid = false;
994    
995                            if (uuid == null) {
996                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
997                            }
998                            else if (uuid.equals(StringPool.BLANK)) {
999                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1000                            }
1001                            else {
1002                                    bindUuid = true;
1003    
1004                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1005                            }
1006    
1007                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1008    
1009                            if (orderByComparator != null) {
1010                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1011                                            orderByComparator);
1012                            }
1013                            else
1014                             if (pagination) {
1015                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1016                            }
1017    
1018                            String sql = query.toString();
1019    
1020                            Session session = null;
1021    
1022                            try {
1023                                    session = openSession();
1024    
1025                                    Query q = session.createQuery(sql);
1026    
1027                                    QueryPos qPos = QueryPos.getInstance(q);
1028    
1029                                    if (bindUuid) {
1030                                            qPos.add(uuid);
1031                                    }
1032    
1033                                    qPos.add(companyId);
1034    
1035                                    if (!pagination) {
1036                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1037                                                            start, end, false);
1038    
1039                                            Collections.sort(list);
1040    
1041                                            list = Collections.unmodifiableList(list);
1042                                    }
1043                                    else {
1044                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1045                                                            start, end);
1046                                    }
1047    
1048                                    cacheResult(list);
1049    
1050                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1051                            }
1052                            catch (Exception e) {
1053                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1054    
1055                                    throw processException(e);
1056                            }
1057                            finally {
1058                                    closeSession(session);
1059                            }
1060                    }
1061    
1062                    return list;
1063            }
1064    
1065            /**
1066             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1067             *
1068             * @param uuid the uuid
1069             * @param companyId the company ID
1070             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1071             * @return the first matching message-boards message
1072             * @throws NoSuchMessageException if a matching message-boards message could not be found
1073             */
1074            @Override
1075            public MBMessage findByUuid_C_First(String uuid, long companyId,
1076                    OrderByComparator<MBMessage> orderByComparator)
1077                    throws NoSuchMessageException {
1078                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1079                                    orderByComparator);
1080    
1081                    if (mbMessage != null) {
1082                            return mbMessage;
1083                    }
1084    
1085                    StringBundler msg = new StringBundler(6);
1086    
1087                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1088    
1089                    msg.append("uuid=");
1090                    msg.append(uuid);
1091    
1092                    msg.append(", companyId=");
1093                    msg.append(companyId);
1094    
1095                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1096    
1097                    throw new NoSuchMessageException(msg.toString());
1098            }
1099    
1100            /**
1101             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1102             *
1103             * @param uuid the uuid
1104             * @param companyId the company ID
1105             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1106             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1107             */
1108            @Override
1109            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1110                    OrderByComparator<MBMessage> orderByComparator) {
1111                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1112                                    orderByComparator);
1113    
1114                    if (!list.isEmpty()) {
1115                            return list.get(0);
1116                    }
1117    
1118                    return null;
1119            }
1120    
1121            /**
1122             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1123             *
1124             * @param uuid the uuid
1125             * @param companyId the company ID
1126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1127             * @return the last matching message-boards message
1128             * @throws NoSuchMessageException if a matching message-boards message could not be found
1129             */
1130            @Override
1131            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1132                    OrderByComparator<MBMessage> orderByComparator)
1133                    throws NoSuchMessageException {
1134                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1135                                    orderByComparator);
1136    
1137                    if (mbMessage != null) {
1138                            return mbMessage;
1139                    }
1140    
1141                    StringBundler msg = new StringBundler(6);
1142    
1143                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1144    
1145                    msg.append("uuid=");
1146                    msg.append(uuid);
1147    
1148                    msg.append(", companyId=");
1149                    msg.append(companyId);
1150    
1151                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1152    
1153                    throw new NoSuchMessageException(msg.toString());
1154            }
1155    
1156            /**
1157             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1158             *
1159             * @param uuid the uuid
1160             * @param companyId the company ID
1161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1162             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1163             */
1164            @Override
1165            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1166                    OrderByComparator<MBMessage> orderByComparator) {
1167                    int count = countByUuid_C(uuid, companyId);
1168    
1169                    if (count == 0) {
1170                            return null;
1171                    }
1172    
1173                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1174                                    orderByComparator);
1175    
1176                    if (!list.isEmpty()) {
1177                            return list.get(0);
1178                    }
1179    
1180                    return null;
1181            }
1182    
1183            /**
1184             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1185             *
1186             * @param messageId the primary key of the current message-boards message
1187             * @param uuid the uuid
1188             * @param companyId the company ID
1189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1190             * @return the previous, current, and next message-boards message
1191             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1192             */
1193            @Override
1194            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1195                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1196                    throws NoSuchMessageException {
1197                    MBMessage mbMessage = findByPrimaryKey(messageId);
1198    
1199                    Session session = null;
1200    
1201                    try {
1202                            session = openSession();
1203    
1204                            MBMessage[] array = new MBMessageImpl[3];
1205    
1206                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1207                                            companyId, orderByComparator, true);
1208    
1209                            array[1] = mbMessage;
1210    
1211                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1212                                            companyId, orderByComparator, false);
1213    
1214                            return array;
1215                    }
1216                    catch (Exception e) {
1217                            throw processException(e);
1218                    }
1219                    finally {
1220                            closeSession(session);
1221                    }
1222            }
1223    
1224            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1225                    MBMessage mbMessage, String uuid, long companyId,
1226                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1227                    StringBundler query = null;
1228    
1229                    if (orderByComparator != null) {
1230                            query = new StringBundler(6 +
1231                                            (orderByComparator.getOrderByFields().length * 6));
1232                    }
1233                    else {
1234                            query = new StringBundler(3);
1235                    }
1236    
1237                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1238    
1239                    boolean bindUuid = false;
1240    
1241                    if (uuid == null) {
1242                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1243                    }
1244                    else if (uuid.equals(StringPool.BLANK)) {
1245                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1246                    }
1247                    else {
1248                            bindUuid = true;
1249    
1250                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1251                    }
1252    
1253                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1254    
1255                    if (orderByComparator != null) {
1256                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1257    
1258                            if (orderByConditionFields.length > 0) {
1259                                    query.append(WHERE_AND);
1260                            }
1261    
1262                            for (int i = 0; i < orderByConditionFields.length; i++) {
1263                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1264                                    query.append(orderByConditionFields[i]);
1265    
1266                                    if ((i + 1) < orderByConditionFields.length) {
1267                                            if (orderByComparator.isAscending() ^ previous) {
1268                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1269                                            }
1270                                            else {
1271                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1272                                            }
1273                                    }
1274                                    else {
1275                                            if (orderByComparator.isAscending() ^ previous) {
1276                                                    query.append(WHERE_GREATER_THAN);
1277                                            }
1278                                            else {
1279                                                    query.append(WHERE_LESSER_THAN);
1280                                            }
1281                                    }
1282                            }
1283    
1284                            query.append(ORDER_BY_CLAUSE);
1285    
1286                            String[] orderByFields = orderByComparator.getOrderByFields();
1287    
1288                            for (int i = 0; i < orderByFields.length; i++) {
1289                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1290                                    query.append(orderByFields[i]);
1291    
1292                                    if ((i + 1) < orderByFields.length) {
1293                                            if (orderByComparator.isAscending() ^ previous) {
1294                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1295                                            }
1296                                            else {
1297                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1298                                            }
1299                                    }
1300                                    else {
1301                                            if (orderByComparator.isAscending() ^ previous) {
1302                                                    query.append(ORDER_BY_ASC);
1303                                            }
1304                                            else {
1305                                                    query.append(ORDER_BY_DESC);
1306                                            }
1307                                    }
1308                            }
1309                    }
1310                    else {
1311                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1312                    }
1313    
1314                    String sql = query.toString();
1315    
1316                    Query q = session.createQuery(sql);
1317    
1318                    q.setFirstResult(0);
1319                    q.setMaxResults(2);
1320    
1321                    QueryPos qPos = QueryPos.getInstance(q);
1322    
1323                    if (bindUuid) {
1324                            qPos.add(uuid);
1325                    }
1326    
1327                    qPos.add(companyId);
1328    
1329                    if (orderByComparator != null) {
1330                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1331    
1332                            for (Object value : values) {
1333                                    qPos.add(value);
1334                            }
1335                    }
1336    
1337                    List<MBMessage> list = q.list();
1338    
1339                    if (list.size() == 2) {
1340                            return list.get(1);
1341                    }
1342                    else {
1343                            return null;
1344                    }
1345            }
1346    
1347            /**
1348             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1349             *
1350             * @param uuid the uuid
1351             * @param companyId the company ID
1352             */
1353            @Override
1354            public void removeByUuid_C(String uuid, long companyId) {
1355                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1356                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1357                            remove(mbMessage);
1358                    }
1359            }
1360    
1361            /**
1362             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1363             *
1364             * @param uuid the uuid
1365             * @param companyId the company ID
1366             * @return the number of matching message-boards messages
1367             */
1368            @Override
1369            public int countByUuid_C(String uuid, long companyId) {
1370                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1371    
1372                    Object[] finderArgs = new Object[] { uuid, companyId };
1373    
1374                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1375                                    this);
1376    
1377                    if (count == null) {
1378                            StringBundler query = new StringBundler(3);
1379    
1380                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1381    
1382                            boolean bindUuid = false;
1383    
1384                            if (uuid == null) {
1385                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1386                            }
1387                            else if (uuid.equals(StringPool.BLANK)) {
1388                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1389                            }
1390                            else {
1391                                    bindUuid = true;
1392    
1393                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1394                            }
1395    
1396                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1397    
1398                            String sql = query.toString();
1399    
1400                            Session session = null;
1401    
1402                            try {
1403                                    session = openSession();
1404    
1405                                    Query q = session.createQuery(sql);
1406    
1407                                    QueryPos qPos = QueryPos.getInstance(q);
1408    
1409                                    if (bindUuid) {
1410                                            qPos.add(uuid);
1411                                    }
1412    
1413                                    qPos.add(companyId);
1414    
1415                                    count = (Long)q.uniqueResult();
1416    
1417                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1418                            }
1419                            catch (Exception e) {
1420                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1421    
1422                                    throw processException(e);
1423                            }
1424                            finally {
1425                                    closeSession(session);
1426                            }
1427                    }
1428    
1429                    return count.intValue();
1430            }
1431    
1432            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1433            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1434            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1435            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1436            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1437                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1438                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1439                            new String[] {
1440                                    Long.class.getName(),
1441                                    
1442                            Integer.class.getName(), Integer.class.getName(),
1443                                    OrderByComparator.class.getName()
1444                            });
1445            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1446                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1447                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1448                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1449                            new String[] { Long.class.getName() },
1450                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1451                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1452            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1453                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1454                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1455                            new String[] { Long.class.getName() });
1456    
1457            /**
1458             * Returns all the message-boards messages where groupId = &#63;.
1459             *
1460             * @param groupId the group ID
1461             * @return the matching message-boards messages
1462             */
1463            @Override
1464            public List<MBMessage> findByGroupId(long groupId) {
1465                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1466            }
1467    
1468            /**
1469             * Returns a range of all the message-boards messages where groupId = &#63;.
1470             *
1471             * <p>
1472             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1473             * </p>
1474             *
1475             * @param groupId the group ID
1476             * @param start the lower bound of the range of message-boards messages
1477             * @param end the upper bound of the range of message-boards messages (not inclusive)
1478             * @return the range of matching message-boards messages
1479             */
1480            @Override
1481            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1482                    return findByGroupId(groupId, start, end, null);
1483            }
1484    
1485            /**
1486             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1487             *
1488             * <p>
1489             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1490             * </p>
1491             *
1492             * @param groupId the group ID
1493             * @param start the lower bound of the range of message-boards messages
1494             * @param end the upper bound of the range of message-boards messages (not inclusive)
1495             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1496             * @return the ordered range of matching message-boards messages
1497             */
1498            @Override
1499            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1500                    OrderByComparator<MBMessage> orderByComparator) {
1501                    boolean pagination = true;
1502                    FinderPath finderPath = null;
1503                    Object[] finderArgs = null;
1504    
1505                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1506                                    (orderByComparator == null)) {
1507                            pagination = false;
1508                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1509                            finderArgs = new Object[] { groupId };
1510                    }
1511                    else {
1512                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1513                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1514                    }
1515    
1516                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1517                                    finderArgs, this);
1518    
1519                    if ((list != null) && !list.isEmpty()) {
1520                            for (MBMessage mbMessage : list) {
1521                                    if ((groupId != mbMessage.getGroupId())) {
1522                                            list = null;
1523    
1524                                            break;
1525                                    }
1526                            }
1527                    }
1528    
1529                    if (list == null) {
1530                            StringBundler query = null;
1531    
1532                            if (orderByComparator != null) {
1533                                    query = new StringBundler(3 +
1534                                                    (orderByComparator.getOrderByFields().length * 3));
1535                            }
1536                            else {
1537                                    query = new StringBundler(3);
1538                            }
1539    
1540                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1541    
1542                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1543    
1544                            if (orderByComparator != null) {
1545                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1546                                            orderByComparator);
1547                            }
1548                            else
1549                             if (pagination) {
1550                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1551                            }
1552    
1553                            String sql = query.toString();
1554    
1555                            Session session = null;
1556    
1557                            try {
1558                                    session = openSession();
1559    
1560                                    Query q = session.createQuery(sql);
1561    
1562                                    QueryPos qPos = QueryPos.getInstance(q);
1563    
1564                                    qPos.add(groupId);
1565    
1566                                    if (!pagination) {
1567                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1568                                                            start, end, false);
1569    
1570                                            Collections.sort(list);
1571    
1572                                            list = Collections.unmodifiableList(list);
1573                                    }
1574                                    else {
1575                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1576                                                            start, end);
1577                                    }
1578    
1579                                    cacheResult(list);
1580    
1581                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1582                            }
1583                            catch (Exception e) {
1584                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1585    
1586                                    throw processException(e);
1587                            }
1588                            finally {
1589                                    closeSession(session);
1590                            }
1591                    }
1592    
1593                    return list;
1594            }
1595    
1596            /**
1597             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1598             *
1599             * @param groupId the group ID
1600             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1601             * @return the first matching message-boards message
1602             * @throws NoSuchMessageException if a matching message-boards message could not be found
1603             */
1604            @Override
1605            public MBMessage findByGroupId_First(long groupId,
1606                    OrderByComparator<MBMessage> orderByComparator)
1607                    throws NoSuchMessageException {
1608                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1609    
1610                    if (mbMessage != null) {
1611                            return mbMessage;
1612                    }
1613    
1614                    StringBundler msg = new StringBundler(4);
1615    
1616                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1617    
1618                    msg.append("groupId=");
1619                    msg.append(groupId);
1620    
1621                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1622    
1623                    throw new NoSuchMessageException(msg.toString());
1624            }
1625    
1626            /**
1627             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1628             *
1629             * @param groupId the group ID
1630             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1631             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1632             */
1633            @Override
1634            public MBMessage fetchByGroupId_First(long groupId,
1635                    OrderByComparator<MBMessage> orderByComparator) {
1636                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1637    
1638                    if (!list.isEmpty()) {
1639                            return list.get(0);
1640                    }
1641    
1642                    return null;
1643            }
1644    
1645            /**
1646             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1647             *
1648             * @param groupId the group ID
1649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1650             * @return the last matching message-boards message
1651             * @throws NoSuchMessageException if a matching message-boards message could not be found
1652             */
1653            @Override
1654            public MBMessage findByGroupId_Last(long groupId,
1655                    OrderByComparator<MBMessage> orderByComparator)
1656                    throws NoSuchMessageException {
1657                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1658    
1659                    if (mbMessage != null) {
1660                            return mbMessage;
1661                    }
1662    
1663                    StringBundler msg = new StringBundler(4);
1664    
1665                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1666    
1667                    msg.append("groupId=");
1668                    msg.append(groupId);
1669    
1670                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1671    
1672                    throw new NoSuchMessageException(msg.toString());
1673            }
1674    
1675            /**
1676             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1677             *
1678             * @param groupId the group ID
1679             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1680             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1681             */
1682            @Override
1683            public MBMessage fetchByGroupId_Last(long groupId,
1684                    OrderByComparator<MBMessage> orderByComparator) {
1685                    int count = countByGroupId(groupId);
1686    
1687                    if (count == 0) {
1688                            return null;
1689                    }
1690    
1691                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1692                                    orderByComparator);
1693    
1694                    if (!list.isEmpty()) {
1695                            return list.get(0);
1696                    }
1697    
1698                    return null;
1699            }
1700    
1701            /**
1702             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1703             *
1704             * @param messageId the primary key of the current message-boards message
1705             * @param groupId the group ID
1706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1707             * @return the previous, current, and next message-boards message
1708             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1709             */
1710            @Override
1711            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1712                    OrderByComparator<MBMessage> orderByComparator)
1713                    throws NoSuchMessageException {
1714                    MBMessage mbMessage = findByPrimaryKey(messageId);
1715    
1716                    Session session = null;
1717    
1718                    try {
1719                            session = openSession();
1720    
1721                            MBMessage[] array = new MBMessageImpl[3];
1722    
1723                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1724                                            orderByComparator, true);
1725    
1726                            array[1] = mbMessage;
1727    
1728                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1729                                            orderByComparator, false);
1730    
1731                            return array;
1732                    }
1733                    catch (Exception e) {
1734                            throw processException(e);
1735                    }
1736                    finally {
1737                            closeSession(session);
1738                    }
1739            }
1740    
1741            protected MBMessage getByGroupId_PrevAndNext(Session session,
1742                    MBMessage mbMessage, long groupId,
1743                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1744                    StringBundler query = null;
1745    
1746                    if (orderByComparator != null) {
1747                            query = new StringBundler(6 +
1748                                            (orderByComparator.getOrderByFields().length * 6));
1749                    }
1750                    else {
1751                            query = new StringBundler(3);
1752                    }
1753    
1754                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1755    
1756                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1757    
1758                    if (orderByComparator != null) {
1759                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1760    
1761                            if (orderByConditionFields.length > 0) {
1762                                    query.append(WHERE_AND);
1763                            }
1764    
1765                            for (int i = 0; i < orderByConditionFields.length; i++) {
1766                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1767                                    query.append(orderByConditionFields[i]);
1768    
1769                                    if ((i + 1) < orderByConditionFields.length) {
1770                                            if (orderByComparator.isAscending() ^ previous) {
1771                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1772                                            }
1773                                            else {
1774                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1775                                            }
1776                                    }
1777                                    else {
1778                                            if (orderByComparator.isAscending() ^ previous) {
1779                                                    query.append(WHERE_GREATER_THAN);
1780                                            }
1781                                            else {
1782                                                    query.append(WHERE_LESSER_THAN);
1783                                            }
1784                                    }
1785                            }
1786    
1787                            query.append(ORDER_BY_CLAUSE);
1788    
1789                            String[] orderByFields = orderByComparator.getOrderByFields();
1790    
1791                            for (int i = 0; i < orderByFields.length; i++) {
1792                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1793                                    query.append(orderByFields[i]);
1794    
1795                                    if ((i + 1) < orderByFields.length) {
1796                                            if (orderByComparator.isAscending() ^ previous) {
1797                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1798                                            }
1799                                            else {
1800                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1801                                            }
1802                                    }
1803                                    else {
1804                                            if (orderByComparator.isAscending() ^ previous) {
1805                                                    query.append(ORDER_BY_ASC);
1806                                            }
1807                                            else {
1808                                                    query.append(ORDER_BY_DESC);
1809                                            }
1810                                    }
1811                            }
1812                    }
1813                    else {
1814                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1815                    }
1816    
1817                    String sql = query.toString();
1818    
1819                    Query q = session.createQuery(sql);
1820    
1821                    q.setFirstResult(0);
1822                    q.setMaxResults(2);
1823    
1824                    QueryPos qPos = QueryPos.getInstance(q);
1825    
1826                    qPos.add(groupId);
1827    
1828                    if (orderByComparator != null) {
1829                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1830    
1831                            for (Object value : values) {
1832                                    qPos.add(value);
1833                            }
1834                    }
1835    
1836                    List<MBMessage> list = q.list();
1837    
1838                    if (list.size() == 2) {
1839                            return list.get(1);
1840                    }
1841                    else {
1842                            return null;
1843                    }
1844            }
1845    
1846            /**
1847             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1848             *
1849             * @param groupId the group ID
1850             * @return the matching message-boards messages that the user has permission to view
1851             */
1852            @Override
1853            public List<MBMessage> filterFindByGroupId(long groupId) {
1854                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1855                            QueryUtil.ALL_POS, null);
1856            }
1857    
1858            /**
1859             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1860             *
1861             * <p>
1862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1863             * </p>
1864             *
1865             * @param groupId the group ID
1866             * @param start the lower bound of the range of message-boards messages
1867             * @param end the upper bound of the range of message-boards messages (not inclusive)
1868             * @return the range of matching message-boards messages that the user has permission to view
1869             */
1870            @Override
1871            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1872                    return filterFindByGroupId(groupId, start, end, null);
1873            }
1874    
1875            /**
1876             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1877             *
1878             * <p>
1879             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1880             * </p>
1881             *
1882             * @param groupId the group ID
1883             * @param start the lower bound of the range of message-boards messages
1884             * @param end the upper bound of the range of message-boards messages (not inclusive)
1885             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1886             * @return the ordered range of matching message-boards messages that the user has permission to view
1887             */
1888            @Override
1889            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1890                    int end, OrderByComparator<MBMessage> orderByComparator) {
1891                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1892                            return findByGroupId(groupId, start, end, orderByComparator);
1893                    }
1894    
1895                    StringBundler query = null;
1896    
1897                    if (orderByComparator != null) {
1898                            query = new StringBundler(3 +
1899                                            (orderByComparator.getOrderByFields().length * 3));
1900                    }
1901                    else {
1902                            query = new StringBundler(3);
1903                    }
1904    
1905                    if (getDB().isSupportsInlineDistinct()) {
1906                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1907                    }
1908                    else {
1909                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1910                    }
1911    
1912                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1913    
1914                    if (!getDB().isSupportsInlineDistinct()) {
1915                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1916                    }
1917    
1918                    if (orderByComparator != null) {
1919                            if (getDB().isSupportsInlineDistinct()) {
1920                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1921                                            orderByComparator, true);
1922                            }
1923                            else {
1924                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1925                                            orderByComparator, true);
1926                            }
1927                    }
1928                    else {
1929                            if (getDB().isSupportsInlineDistinct()) {
1930                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1931                            }
1932                            else {
1933                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
1934                            }
1935                    }
1936    
1937                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1938                                    MBMessage.class.getName(),
1939                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1940    
1941                    Session session = null;
1942    
1943                    try {
1944                            session = openSession();
1945    
1946                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1947    
1948                            if (getDB().isSupportsInlineDistinct()) {
1949                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1950                            }
1951                            else {
1952                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1953                            }
1954    
1955                            QueryPos qPos = QueryPos.getInstance(q);
1956    
1957                            qPos.add(groupId);
1958    
1959                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1960                    }
1961                    catch (Exception e) {
1962                            throw processException(e);
1963                    }
1964                    finally {
1965                            closeSession(session);
1966                    }
1967            }
1968    
1969            /**
1970             * 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;.
1971             *
1972             * @param messageId the primary key of the current message-boards message
1973             * @param groupId the group ID
1974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1975             * @return the previous, current, and next message-boards message
1976             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1977             */
1978            @Override
1979            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
1980                    long groupId, OrderByComparator<MBMessage> orderByComparator)
1981                    throws NoSuchMessageException {
1982                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1983                            return findByGroupId_PrevAndNext(messageId, groupId,
1984                                    orderByComparator);
1985                    }
1986    
1987                    MBMessage mbMessage = findByPrimaryKey(messageId);
1988    
1989                    Session session = null;
1990    
1991                    try {
1992                            session = openSession();
1993    
1994                            MBMessage[] array = new MBMessageImpl[3];
1995    
1996                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1997                                            groupId, orderByComparator, true);
1998    
1999                            array[1] = mbMessage;
2000    
2001                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2002                                            groupId, orderByComparator, false);
2003    
2004                            return array;
2005                    }
2006                    catch (Exception e) {
2007                            throw processException(e);
2008                    }
2009                    finally {
2010                            closeSession(session);
2011                    }
2012            }
2013    
2014            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2015                    MBMessage mbMessage, long groupId,
2016                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2017                    StringBundler query = null;
2018    
2019                    if (orderByComparator != null) {
2020                            query = new StringBundler(6 +
2021                                            (orderByComparator.getOrderByFields().length * 6));
2022                    }
2023                    else {
2024                            query = new StringBundler(3);
2025                    }
2026    
2027                    if (getDB().isSupportsInlineDistinct()) {
2028                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2029                    }
2030                    else {
2031                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2032                    }
2033    
2034                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2035    
2036                    if (!getDB().isSupportsInlineDistinct()) {
2037                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2038                    }
2039    
2040                    if (orderByComparator != null) {
2041                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2042    
2043                            if (orderByConditionFields.length > 0) {
2044                                    query.append(WHERE_AND);
2045                            }
2046    
2047                            for (int i = 0; i < orderByConditionFields.length; i++) {
2048                                    if (getDB().isSupportsInlineDistinct()) {
2049                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2050                                    }
2051                                    else {
2052                                            query.append(_ORDER_BY_ENTITY_TABLE);
2053                                    }
2054    
2055                                    query.append(orderByConditionFields[i]);
2056    
2057                                    if ((i + 1) < orderByConditionFields.length) {
2058                                            if (orderByComparator.isAscending() ^ previous) {
2059                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2060                                            }
2061                                            else {
2062                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2063                                            }
2064                                    }
2065                                    else {
2066                                            if (orderByComparator.isAscending() ^ previous) {
2067                                                    query.append(WHERE_GREATER_THAN);
2068                                            }
2069                                            else {
2070                                                    query.append(WHERE_LESSER_THAN);
2071                                            }
2072                                    }
2073                            }
2074    
2075                            query.append(ORDER_BY_CLAUSE);
2076    
2077                            String[] orderByFields = orderByComparator.getOrderByFields();
2078    
2079                            for (int i = 0; i < orderByFields.length; i++) {
2080                                    if (getDB().isSupportsInlineDistinct()) {
2081                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2082                                    }
2083                                    else {
2084                                            query.append(_ORDER_BY_ENTITY_TABLE);
2085                                    }
2086    
2087                                    query.append(orderByFields[i]);
2088    
2089                                    if ((i + 1) < orderByFields.length) {
2090                                            if (orderByComparator.isAscending() ^ previous) {
2091                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2092                                            }
2093                                            else {
2094                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2095                                            }
2096                                    }
2097                                    else {
2098                                            if (orderByComparator.isAscending() ^ previous) {
2099                                                    query.append(ORDER_BY_ASC);
2100                                            }
2101                                            else {
2102                                                    query.append(ORDER_BY_DESC);
2103                                            }
2104                                    }
2105                            }
2106                    }
2107                    else {
2108                            if (getDB().isSupportsInlineDistinct()) {
2109                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2110                            }
2111                            else {
2112                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2113                            }
2114                    }
2115    
2116                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2117                                    MBMessage.class.getName(),
2118                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2119    
2120                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2121    
2122                    q.setFirstResult(0);
2123                    q.setMaxResults(2);
2124    
2125                    if (getDB().isSupportsInlineDistinct()) {
2126                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2127                    }
2128                    else {
2129                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2130                    }
2131    
2132                    QueryPos qPos = QueryPos.getInstance(q);
2133    
2134                    qPos.add(groupId);
2135    
2136                    if (orderByComparator != null) {
2137                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2138    
2139                            for (Object value : values) {
2140                                    qPos.add(value);
2141                            }
2142                    }
2143    
2144                    List<MBMessage> list = q.list();
2145    
2146                    if (list.size() == 2) {
2147                            return list.get(1);
2148                    }
2149                    else {
2150                            return null;
2151                    }
2152            }
2153    
2154            /**
2155             * Removes all the message-boards messages where groupId = &#63; from the database.
2156             *
2157             * @param groupId the group ID
2158             */
2159            @Override
2160            public void removeByGroupId(long groupId) {
2161                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2162                                    QueryUtil.ALL_POS, null)) {
2163                            remove(mbMessage);
2164                    }
2165            }
2166    
2167            /**
2168             * Returns the number of message-boards messages where groupId = &#63;.
2169             *
2170             * @param groupId the group ID
2171             * @return the number of matching message-boards messages
2172             */
2173            @Override
2174            public int countByGroupId(long groupId) {
2175                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2176    
2177                    Object[] finderArgs = new Object[] { groupId };
2178    
2179                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2180                                    this);
2181    
2182                    if (count == null) {
2183                            StringBundler query = new StringBundler(2);
2184    
2185                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2186    
2187                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2188    
2189                            String sql = query.toString();
2190    
2191                            Session session = null;
2192    
2193                            try {
2194                                    session = openSession();
2195    
2196                                    Query q = session.createQuery(sql);
2197    
2198                                    QueryPos qPos = QueryPos.getInstance(q);
2199    
2200                                    qPos.add(groupId);
2201    
2202                                    count = (Long)q.uniqueResult();
2203    
2204                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2205                            }
2206                            catch (Exception e) {
2207                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2208    
2209                                    throw processException(e);
2210                            }
2211                            finally {
2212                                    closeSession(session);
2213                            }
2214                    }
2215    
2216                    return count.intValue();
2217            }
2218    
2219            /**
2220             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2221             *
2222             * @param groupId the group ID
2223             * @return the number of matching message-boards messages that the user has permission to view
2224             */
2225            @Override
2226            public int filterCountByGroupId(long groupId) {
2227                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2228                            return countByGroupId(groupId);
2229                    }
2230    
2231                    StringBundler query = new StringBundler(2);
2232    
2233                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2234    
2235                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2236    
2237                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2238                                    MBMessage.class.getName(),
2239                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2240    
2241                    Session session = null;
2242    
2243                    try {
2244                            session = openSession();
2245    
2246                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2247    
2248                            q.addScalar(COUNT_COLUMN_NAME,
2249                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2250    
2251                            QueryPos qPos = QueryPos.getInstance(q);
2252    
2253                            qPos.add(groupId);
2254    
2255                            Long count = (Long)q.uniqueResult();
2256    
2257                            return count.intValue();
2258                    }
2259                    catch (Exception e) {
2260                            throw processException(e);
2261                    }
2262                    finally {
2263                            closeSession(session);
2264                    }
2265            }
2266    
2267            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2268            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2269                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2270                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2271                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2272                            new String[] {
2273                                    Long.class.getName(),
2274                                    
2275                            Integer.class.getName(), Integer.class.getName(),
2276                                    OrderByComparator.class.getName()
2277                            });
2278            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2279                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2280                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2281                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2282                            new String[] { Long.class.getName() },
2283                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2284                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2285            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2286                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2287                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2288                            new String[] { Long.class.getName() });
2289    
2290            /**
2291             * Returns all the message-boards messages where companyId = &#63;.
2292             *
2293             * @param companyId the company ID
2294             * @return the matching message-boards messages
2295             */
2296            @Override
2297            public List<MBMessage> findByCompanyId(long companyId) {
2298                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2299                            null);
2300            }
2301    
2302            /**
2303             * Returns a range of all the message-boards messages where companyId = &#63;.
2304             *
2305             * <p>
2306             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2307             * </p>
2308             *
2309             * @param companyId the company ID
2310             * @param start the lower bound of the range of message-boards messages
2311             * @param end the upper bound of the range of message-boards messages (not inclusive)
2312             * @return the range of matching message-boards messages
2313             */
2314            @Override
2315            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2316                    return findByCompanyId(companyId, start, end, null);
2317            }
2318    
2319            /**
2320             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2321             *
2322             * <p>
2323             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2324             * </p>
2325             *
2326             * @param companyId the company ID
2327             * @param start the lower bound of the range of message-boards messages
2328             * @param end the upper bound of the range of message-boards messages (not inclusive)
2329             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2330             * @return the ordered range of matching message-boards messages
2331             */
2332            @Override
2333            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2334                    OrderByComparator<MBMessage> orderByComparator) {
2335                    boolean pagination = true;
2336                    FinderPath finderPath = null;
2337                    Object[] finderArgs = null;
2338    
2339                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2340                                    (orderByComparator == null)) {
2341                            pagination = false;
2342                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2343                            finderArgs = new Object[] { companyId };
2344                    }
2345                    else {
2346                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2347                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2348                    }
2349    
2350                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2351                                    finderArgs, this);
2352    
2353                    if ((list != null) && !list.isEmpty()) {
2354                            for (MBMessage mbMessage : list) {
2355                                    if ((companyId != mbMessage.getCompanyId())) {
2356                                            list = null;
2357    
2358                                            break;
2359                                    }
2360                            }
2361                    }
2362    
2363                    if (list == null) {
2364                            StringBundler query = null;
2365    
2366                            if (orderByComparator != null) {
2367                                    query = new StringBundler(3 +
2368                                                    (orderByComparator.getOrderByFields().length * 3));
2369                            }
2370                            else {
2371                                    query = new StringBundler(3);
2372                            }
2373    
2374                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2375    
2376                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2377    
2378                            if (orderByComparator != null) {
2379                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2380                                            orderByComparator);
2381                            }
2382                            else
2383                             if (pagination) {
2384                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2385                            }
2386    
2387                            String sql = query.toString();
2388    
2389                            Session session = null;
2390    
2391                            try {
2392                                    session = openSession();
2393    
2394                                    Query q = session.createQuery(sql);
2395    
2396                                    QueryPos qPos = QueryPos.getInstance(q);
2397    
2398                                    qPos.add(companyId);
2399    
2400                                    if (!pagination) {
2401                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2402                                                            start, end, false);
2403    
2404                                            Collections.sort(list);
2405    
2406                                            list = Collections.unmodifiableList(list);
2407                                    }
2408                                    else {
2409                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2410                                                            start, end);
2411                                    }
2412    
2413                                    cacheResult(list);
2414    
2415                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2416                            }
2417                            catch (Exception e) {
2418                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2419    
2420                                    throw processException(e);
2421                            }
2422                            finally {
2423                                    closeSession(session);
2424                            }
2425                    }
2426    
2427                    return list;
2428            }
2429    
2430            /**
2431             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2432             *
2433             * @param companyId the company ID
2434             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2435             * @return the first matching message-boards message
2436             * @throws NoSuchMessageException if a matching message-boards message could not be found
2437             */
2438            @Override
2439            public MBMessage findByCompanyId_First(long companyId,
2440                    OrderByComparator<MBMessage> orderByComparator)
2441                    throws NoSuchMessageException {
2442                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2443                                    orderByComparator);
2444    
2445                    if (mbMessage != null) {
2446                            return mbMessage;
2447                    }
2448    
2449                    StringBundler msg = new StringBundler(4);
2450    
2451                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2452    
2453                    msg.append("companyId=");
2454                    msg.append(companyId);
2455    
2456                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2457    
2458                    throw new NoSuchMessageException(msg.toString());
2459            }
2460    
2461            /**
2462             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2463             *
2464             * @param companyId the company ID
2465             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2466             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2467             */
2468            @Override
2469            public MBMessage fetchByCompanyId_First(long companyId,
2470                    OrderByComparator<MBMessage> orderByComparator) {
2471                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2472                                    orderByComparator);
2473    
2474                    if (!list.isEmpty()) {
2475                            return list.get(0);
2476                    }
2477    
2478                    return null;
2479            }
2480    
2481            /**
2482             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2483             *
2484             * @param companyId the company ID
2485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2486             * @return the last matching message-boards message
2487             * @throws NoSuchMessageException if a matching message-boards message could not be found
2488             */
2489            @Override
2490            public MBMessage findByCompanyId_Last(long companyId,
2491                    OrderByComparator<MBMessage> orderByComparator)
2492                    throws NoSuchMessageException {
2493                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2494    
2495                    if (mbMessage != null) {
2496                            return mbMessage;
2497                    }
2498    
2499                    StringBundler msg = new StringBundler(4);
2500    
2501                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2502    
2503                    msg.append("companyId=");
2504                    msg.append(companyId);
2505    
2506                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2507    
2508                    throw new NoSuchMessageException(msg.toString());
2509            }
2510    
2511            /**
2512             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2513             *
2514             * @param companyId the company ID
2515             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2516             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2517             */
2518            @Override
2519            public MBMessage fetchByCompanyId_Last(long companyId,
2520                    OrderByComparator<MBMessage> orderByComparator) {
2521                    int count = countByCompanyId(companyId);
2522    
2523                    if (count == 0) {
2524                            return null;
2525                    }
2526    
2527                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2528                                    orderByComparator);
2529    
2530                    if (!list.isEmpty()) {
2531                            return list.get(0);
2532                    }
2533    
2534                    return null;
2535            }
2536    
2537            /**
2538             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2539             *
2540             * @param messageId the primary key of the current message-boards message
2541             * @param companyId the company ID
2542             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2543             * @return the previous, current, and next message-boards message
2544             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2545             */
2546            @Override
2547            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2548                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2549                    throws NoSuchMessageException {
2550                    MBMessage mbMessage = findByPrimaryKey(messageId);
2551    
2552                    Session session = null;
2553    
2554                    try {
2555                            session = openSession();
2556    
2557                            MBMessage[] array = new MBMessageImpl[3];
2558    
2559                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2560                                            companyId, orderByComparator, true);
2561    
2562                            array[1] = mbMessage;
2563    
2564                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2565                                            companyId, orderByComparator, false);
2566    
2567                            return array;
2568                    }
2569                    catch (Exception e) {
2570                            throw processException(e);
2571                    }
2572                    finally {
2573                            closeSession(session);
2574                    }
2575            }
2576    
2577            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2578                    MBMessage mbMessage, long companyId,
2579                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2580                    StringBundler query = null;
2581    
2582                    if (orderByComparator != null) {
2583                            query = new StringBundler(6 +
2584                                            (orderByComparator.getOrderByFields().length * 6));
2585                    }
2586                    else {
2587                            query = new StringBundler(3);
2588                    }
2589    
2590                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2591    
2592                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2593    
2594                    if (orderByComparator != null) {
2595                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2596    
2597                            if (orderByConditionFields.length > 0) {
2598                                    query.append(WHERE_AND);
2599                            }
2600    
2601                            for (int i = 0; i < orderByConditionFields.length; i++) {
2602                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2603                                    query.append(orderByConditionFields[i]);
2604    
2605                                    if ((i + 1) < orderByConditionFields.length) {
2606                                            if (orderByComparator.isAscending() ^ previous) {
2607                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2608                                            }
2609                                            else {
2610                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2611                                            }
2612                                    }
2613                                    else {
2614                                            if (orderByComparator.isAscending() ^ previous) {
2615                                                    query.append(WHERE_GREATER_THAN);
2616                                            }
2617                                            else {
2618                                                    query.append(WHERE_LESSER_THAN);
2619                                            }
2620                                    }
2621                            }
2622    
2623                            query.append(ORDER_BY_CLAUSE);
2624    
2625                            String[] orderByFields = orderByComparator.getOrderByFields();
2626    
2627                            for (int i = 0; i < orderByFields.length; i++) {
2628                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2629                                    query.append(orderByFields[i]);
2630    
2631                                    if ((i + 1) < orderByFields.length) {
2632                                            if (orderByComparator.isAscending() ^ previous) {
2633                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2634                                            }
2635                                            else {
2636                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2637                                            }
2638                                    }
2639                                    else {
2640                                            if (orderByComparator.isAscending() ^ previous) {
2641                                                    query.append(ORDER_BY_ASC);
2642                                            }
2643                                            else {
2644                                                    query.append(ORDER_BY_DESC);
2645                                            }
2646                                    }
2647                            }
2648                    }
2649                    else {
2650                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2651                    }
2652    
2653                    String sql = query.toString();
2654    
2655                    Query q = session.createQuery(sql);
2656    
2657                    q.setFirstResult(0);
2658                    q.setMaxResults(2);
2659    
2660                    QueryPos qPos = QueryPos.getInstance(q);
2661    
2662                    qPos.add(companyId);
2663    
2664                    if (orderByComparator != null) {
2665                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2666    
2667                            for (Object value : values) {
2668                                    qPos.add(value);
2669                            }
2670                    }
2671    
2672                    List<MBMessage> list = q.list();
2673    
2674                    if (list.size() == 2) {
2675                            return list.get(1);
2676                    }
2677                    else {
2678                            return null;
2679                    }
2680            }
2681    
2682            /**
2683             * Removes all the message-boards messages where companyId = &#63; from the database.
2684             *
2685             * @param companyId the company ID
2686             */
2687            @Override
2688            public void removeByCompanyId(long companyId) {
2689                    for (MBMessage mbMessage : findByCompanyId(companyId,
2690                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2691                            remove(mbMessage);
2692                    }
2693            }
2694    
2695            /**
2696             * Returns the number of message-boards messages where companyId = &#63;.
2697             *
2698             * @param companyId the company ID
2699             * @return the number of matching message-boards messages
2700             */
2701            @Override
2702            public int countByCompanyId(long companyId) {
2703                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2704    
2705                    Object[] finderArgs = new Object[] { companyId };
2706    
2707                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2708                                    this);
2709    
2710                    if (count == null) {
2711                            StringBundler query = new StringBundler(2);
2712    
2713                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2714    
2715                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2716    
2717                            String sql = query.toString();
2718    
2719                            Session session = null;
2720    
2721                            try {
2722                                    session = openSession();
2723    
2724                                    Query q = session.createQuery(sql);
2725    
2726                                    QueryPos qPos = QueryPos.getInstance(q);
2727    
2728                                    qPos.add(companyId);
2729    
2730                                    count = (Long)q.uniqueResult();
2731    
2732                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2733                            }
2734                            catch (Exception e) {
2735                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2736    
2737                                    throw processException(e);
2738                            }
2739                            finally {
2740                                    closeSession(session);
2741                            }
2742                    }
2743    
2744                    return count.intValue();
2745            }
2746    
2747            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2748            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2749                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2750                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2751                            new String[] {
2752                                    Long.class.getName(),
2753                                    
2754                            Integer.class.getName(), Integer.class.getName(),
2755                                    OrderByComparator.class.getName()
2756                            });
2757            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2758                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2759                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2760                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2761                            new String[] { Long.class.getName() },
2762                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2763                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2764            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2765                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2766                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2767                            new String[] { Long.class.getName() });
2768    
2769            /**
2770             * Returns all the message-boards messages where userId = &#63;.
2771             *
2772             * @param userId the user ID
2773             * @return the matching message-boards messages
2774             */
2775            @Override
2776            public List<MBMessage> findByUserId(long userId) {
2777                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2778            }
2779    
2780            /**
2781             * Returns a range of all the message-boards messages where userId = &#63;.
2782             *
2783             * <p>
2784             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2785             * </p>
2786             *
2787             * @param userId the user ID
2788             * @param start the lower bound of the range of message-boards messages
2789             * @param end the upper bound of the range of message-boards messages (not inclusive)
2790             * @return the range of matching message-boards messages
2791             */
2792            @Override
2793            public List<MBMessage> findByUserId(long userId, int start, int end) {
2794                    return findByUserId(userId, start, end, null);
2795            }
2796    
2797            /**
2798             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2799             *
2800             * <p>
2801             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2802             * </p>
2803             *
2804             * @param userId the user ID
2805             * @param start the lower bound of the range of message-boards messages
2806             * @param end the upper bound of the range of message-boards messages (not inclusive)
2807             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2808             * @return the ordered range of matching message-boards messages
2809             */
2810            @Override
2811            public List<MBMessage> findByUserId(long userId, int start, int end,
2812                    OrderByComparator<MBMessage> orderByComparator) {
2813                    boolean pagination = true;
2814                    FinderPath finderPath = null;
2815                    Object[] finderArgs = null;
2816    
2817                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2818                                    (orderByComparator == null)) {
2819                            pagination = false;
2820                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2821                            finderArgs = new Object[] { userId };
2822                    }
2823                    else {
2824                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2825                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2826                    }
2827    
2828                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2829                                    finderArgs, this);
2830    
2831                    if ((list != null) && !list.isEmpty()) {
2832                            for (MBMessage mbMessage : list) {
2833                                    if ((userId != mbMessage.getUserId())) {
2834                                            list = null;
2835    
2836                                            break;
2837                                    }
2838                            }
2839                    }
2840    
2841                    if (list == null) {
2842                            StringBundler query = null;
2843    
2844                            if (orderByComparator != null) {
2845                                    query = new StringBundler(3 +
2846                                                    (orderByComparator.getOrderByFields().length * 3));
2847                            }
2848                            else {
2849                                    query = new StringBundler(3);
2850                            }
2851    
2852                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2853    
2854                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2855    
2856                            if (orderByComparator != null) {
2857                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2858                                            orderByComparator);
2859                            }
2860                            else
2861                             if (pagination) {
2862                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2863                            }
2864    
2865                            String sql = query.toString();
2866    
2867                            Session session = null;
2868    
2869                            try {
2870                                    session = openSession();
2871    
2872                                    Query q = session.createQuery(sql);
2873    
2874                                    QueryPos qPos = QueryPos.getInstance(q);
2875    
2876                                    qPos.add(userId);
2877    
2878                                    if (!pagination) {
2879                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2880                                                            start, end, false);
2881    
2882                                            Collections.sort(list);
2883    
2884                                            list = Collections.unmodifiableList(list);
2885                                    }
2886                                    else {
2887                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2888                                                            start, end);
2889                                    }
2890    
2891                                    cacheResult(list);
2892    
2893                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2894                            }
2895                            catch (Exception e) {
2896                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2897    
2898                                    throw processException(e);
2899                            }
2900                            finally {
2901                                    closeSession(session);
2902                            }
2903                    }
2904    
2905                    return list;
2906            }
2907    
2908            /**
2909             * Returns the first message-boards message in the ordered set where userId = &#63;.
2910             *
2911             * @param userId the user ID
2912             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2913             * @return the first matching message-boards message
2914             * @throws NoSuchMessageException if a matching message-boards message could not be found
2915             */
2916            @Override
2917            public MBMessage findByUserId_First(long userId,
2918                    OrderByComparator<MBMessage> orderByComparator)
2919                    throws NoSuchMessageException {
2920                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
2921    
2922                    if (mbMessage != null) {
2923                            return mbMessage;
2924                    }
2925    
2926                    StringBundler msg = new StringBundler(4);
2927    
2928                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2929    
2930                    msg.append("userId=");
2931                    msg.append(userId);
2932    
2933                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2934    
2935                    throw new NoSuchMessageException(msg.toString());
2936            }
2937    
2938            /**
2939             * Returns the first message-boards message in the ordered set where userId = &#63;.
2940             *
2941             * @param userId the user ID
2942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2943             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2944             */
2945            @Override
2946            public MBMessage fetchByUserId_First(long userId,
2947                    OrderByComparator<MBMessage> orderByComparator) {
2948                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
2949    
2950                    if (!list.isEmpty()) {
2951                            return list.get(0);
2952                    }
2953    
2954                    return null;
2955            }
2956    
2957            /**
2958             * Returns the last message-boards message in the ordered set where userId = &#63;.
2959             *
2960             * @param userId the user ID
2961             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2962             * @return the last matching message-boards message
2963             * @throws NoSuchMessageException if a matching message-boards message could not be found
2964             */
2965            @Override
2966            public MBMessage findByUserId_Last(long userId,
2967                    OrderByComparator<MBMessage> orderByComparator)
2968                    throws NoSuchMessageException {
2969                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
2970    
2971                    if (mbMessage != null) {
2972                            return mbMessage;
2973                    }
2974    
2975                    StringBundler msg = new StringBundler(4);
2976    
2977                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2978    
2979                    msg.append("userId=");
2980                    msg.append(userId);
2981    
2982                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2983    
2984                    throw new NoSuchMessageException(msg.toString());
2985            }
2986    
2987            /**
2988             * Returns the last message-boards message in the ordered set where userId = &#63;.
2989             *
2990             * @param userId the user ID
2991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2992             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2993             */
2994            @Override
2995            public MBMessage fetchByUserId_Last(long userId,
2996                    OrderByComparator<MBMessage> orderByComparator) {
2997                    int count = countByUserId(userId);
2998    
2999                    if (count == 0) {
3000                            return null;
3001                    }
3002    
3003                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3004                                    orderByComparator);
3005    
3006                    if (!list.isEmpty()) {
3007                            return list.get(0);
3008                    }
3009    
3010                    return null;
3011            }
3012    
3013            /**
3014             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3015             *
3016             * @param messageId the primary key of the current message-boards message
3017             * @param userId the user ID
3018             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3019             * @return the previous, current, and next message-boards message
3020             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3021             */
3022            @Override
3023            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3024                    OrderByComparator<MBMessage> orderByComparator)
3025                    throws NoSuchMessageException {
3026                    MBMessage mbMessage = findByPrimaryKey(messageId);
3027    
3028                    Session session = null;
3029    
3030                    try {
3031                            session = openSession();
3032    
3033                            MBMessage[] array = new MBMessageImpl[3];
3034    
3035                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3036                                            orderByComparator, true);
3037    
3038                            array[1] = mbMessage;
3039    
3040                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3041                                            orderByComparator, false);
3042    
3043                            return array;
3044                    }
3045                    catch (Exception e) {
3046                            throw processException(e);
3047                    }
3048                    finally {
3049                            closeSession(session);
3050                    }
3051            }
3052    
3053            protected MBMessage getByUserId_PrevAndNext(Session session,
3054                    MBMessage mbMessage, long userId,
3055                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3056                    StringBundler query = null;
3057    
3058                    if (orderByComparator != null) {
3059                            query = new StringBundler(6 +
3060                                            (orderByComparator.getOrderByFields().length * 6));
3061                    }
3062                    else {
3063                            query = new StringBundler(3);
3064                    }
3065    
3066                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3067    
3068                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3069    
3070                    if (orderByComparator != null) {
3071                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3072    
3073                            if (orderByConditionFields.length > 0) {
3074                                    query.append(WHERE_AND);
3075                            }
3076    
3077                            for (int i = 0; i < orderByConditionFields.length; i++) {
3078                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3079                                    query.append(orderByConditionFields[i]);
3080    
3081                                    if ((i + 1) < orderByConditionFields.length) {
3082                                            if (orderByComparator.isAscending() ^ previous) {
3083                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3084                                            }
3085                                            else {
3086                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3087                                            }
3088                                    }
3089                                    else {
3090                                            if (orderByComparator.isAscending() ^ previous) {
3091                                                    query.append(WHERE_GREATER_THAN);
3092                                            }
3093                                            else {
3094                                                    query.append(WHERE_LESSER_THAN);
3095                                            }
3096                                    }
3097                            }
3098    
3099                            query.append(ORDER_BY_CLAUSE);
3100    
3101                            String[] orderByFields = orderByComparator.getOrderByFields();
3102    
3103                            for (int i = 0; i < orderByFields.length; i++) {
3104                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3105                                    query.append(orderByFields[i]);
3106    
3107                                    if ((i + 1) < orderByFields.length) {
3108                                            if (orderByComparator.isAscending() ^ previous) {
3109                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3110                                            }
3111                                            else {
3112                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3113                                            }
3114                                    }
3115                                    else {
3116                                            if (orderByComparator.isAscending() ^ previous) {
3117                                                    query.append(ORDER_BY_ASC);
3118                                            }
3119                                            else {
3120                                                    query.append(ORDER_BY_DESC);
3121                                            }
3122                                    }
3123                            }
3124                    }
3125                    else {
3126                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3127                    }
3128    
3129                    String sql = query.toString();
3130    
3131                    Query q = session.createQuery(sql);
3132    
3133                    q.setFirstResult(0);
3134                    q.setMaxResults(2);
3135    
3136                    QueryPos qPos = QueryPos.getInstance(q);
3137    
3138                    qPos.add(userId);
3139    
3140                    if (orderByComparator != null) {
3141                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3142    
3143                            for (Object value : values) {
3144                                    qPos.add(value);
3145                            }
3146                    }
3147    
3148                    List<MBMessage> list = q.list();
3149    
3150                    if (list.size() == 2) {
3151                            return list.get(1);
3152                    }
3153                    else {
3154                            return null;
3155                    }
3156            }
3157    
3158            /**
3159             * Removes all the message-boards messages where userId = &#63; from the database.
3160             *
3161             * @param userId the user ID
3162             */
3163            @Override
3164            public void removeByUserId(long userId) {
3165                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3166                                    QueryUtil.ALL_POS, null)) {
3167                            remove(mbMessage);
3168                    }
3169            }
3170    
3171            /**
3172             * Returns the number of message-boards messages where userId = &#63;.
3173             *
3174             * @param userId the user ID
3175             * @return the number of matching message-boards messages
3176             */
3177            @Override
3178            public int countByUserId(long userId) {
3179                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3180    
3181                    Object[] finderArgs = new Object[] { userId };
3182    
3183                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3184                                    this);
3185    
3186                    if (count == null) {
3187                            StringBundler query = new StringBundler(2);
3188    
3189                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3190    
3191                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3192    
3193                            String sql = query.toString();
3194    
3195                            Session session = null;
3196    
3197                            try {
3198                                    session = openSession();
3199    
3200                                    Query q = session.createQuery(sql);
3201    
3202                                    QueryPos qPos = QueryPos.getInstance(q);
3203    
3204                                    qPos.add(userId);
3205    
3206                                    count = (Long)q.uniqueResult();
3207    
3208                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3209                            }
3210                            catch (Exception e) {
3211                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3212    
3213                                    throw processException(e);
3214                            }
3215                            finally {
3216                                    closeSession(session);
3217                            }
3218                    }
3219    
3220                    return count.intValue();
3221            }
3222    
3223            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3224            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3225                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3226                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3227                            new String[] {
3228                                    Long.class.getName(),
3229                                    
3230                            Integer.class.getName(), Integer.class.getName(),
3231                                    OrderByComparator.class.getName()
3232                            });
3233            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3234                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3235                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3236                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3237                            new String[] { Long.class.getName() },
3238                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3239                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3240            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3241                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3242                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3243                            new String[] { Long.class.getName() });
3244    
3245            /**
3246             * Returns all the message-boards messages where threadId = &#63;.
3247             *
3248             * @param threadId the thread ID
3249             * @return the matching message-boards messages
3250             */
3251            @Override
3252            public List<MBMessage> findByThreadId(long threadId) {
3253                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3254                            null);
3255            }
3256    
3257            /**
3258             * Returns a range of all the message-boards messages where threadId = &#63;.
3259             *
3260             * <p>
3261             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3262             * </p>
3263             *
3264             * @param threadId the thread ID
3265             * @param start the lower bound of the range of message-boards messages
3266             * @param end the upper bound of the range of message-boards messages (not inclusive)
3267             * @return the range of matching message-boards messages
3268             */
3269            @Override
3270            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3271                    return findByThreadId(threadId, start, end, null);
3272            }
3273    
3274            /**
3275             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3276             *
3277             * <p>
3278             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3279             * </p>
3280             *
3281             * @param threadId the thread ID
3282             * @param start the lower bound of the range of message-boards messages
3283             * @param end the upper bound of the range of message-boards messages (not inclusive)
3284             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3285             * @return the ordered range of matching message-boards messages
3286             */
3287            @Override
3288            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3289                    OrderByComparator<MBMessage> orderByComparator) {
3290                    boolean pagination = true;
3291                    FinderPath finderPath = null;
3292                    Object[] finderArgs = null;
3293    
3294                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3295                                    (orderByComparator == null)) {
3296                            pagination = false;
3297                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3298                            finderArgs = new Object[] { threadId };
3299                    }
3300                    else {
3301                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3302                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3303                    }
3304    
3305                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3306                                    finderArgs, this);
3307    
3308                    if ((list != null) && !list.isEmpty()) {
3309                            for (MBMessage mbMessage : list) {
3310                                    if ((threadId != mbMessage.getThreadId())) {
3311                                            list = null;
3312    
3313                                            break;
3314                                    }
3315                            }
3316                    }
3317    
3318                    if (list == null) {
3319                            StringBundler query = null;
3320    
3321                            if (orderByComparator != null) {
3322                                    query = new StringBundler(3 +
3323                                                    (orderByComparator.getOrderByFields().length * 3));
3324                            }
3325                            else {
3326                                    query = new StringBundler(3);
3327                            }
3328    
3329                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3330    
3331                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3332    
3333                            if (orderByComparator != null) {
3334                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3335                                            orderByComparator);
3336                            }
3337                            else
3338                             if (pagination) {
3339                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3340                            }
3341    
3342                            String sql = query.toString();
3343    
3344                            Session session = null;
3345    
3346                            try {
3347                                    session = openSession();
3348    
3349                                    Query q = session.createQuery(sql);
3350    
3351                                    QueryPos qPos = QueryPos.getInstance(q);
3352    
3353                                    qPos.add(threadId);
3354    
3355                                    if (!pagination) {
3356                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3357                                                            start, end, false);
3358    
3359                                            Collections.sort(list);
3360    
3361                                            list = Collections.unmodifiableList(list);
3362                                    }
3363                                    else {
3364                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3365                                                            start, end);
3366                                    }
3367    
3368                                    cacheResult(list);
3369    
3370                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3371                            }
3372                            catch (Exception e) {
3373                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3374    
3375                                    throw processException(e);
3376                            }
3377                            finally {
3378                                    closeSession(session);
3379                            }
3380                    }
3381    
3382                    return list;
3383            }
3384    
3385            /**
3386             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3387             *
3388             * @param threadId the thread ID
3389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3390             * @return the first matching message-boards message
3391             * @throws NoSuchMessageException if a matching message-boards message could not be found
3392             */
3393            @Override
3394            public MBMessage findByThreadId_First(long threadId,
3395                    OrderByComparator<MBMessage> orderByComparator)
3396                    throws NoSuchMessageException {
3397                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3398    
3399                    if (mbMessage != null) {
3400                            return mbMessage;
3401                    }
3402    
3403                    StringBundler msg = new StringBundler(4);
3404    
3405                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3406    
3407                    msg.append("threadId=");
3408                    msg.append(threadId);
3409    
3410                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3411    
3412                    throw new NoSuchMessageException(msg.toString());
3413            }
3414    
3415            /**
3416             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3417             *
3418             * @param threadId the thread ID
3419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3420             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3421             */
3422            @Override
3423            public MBMessage fetchByThreadId_First(long threadId,
3424                    OrderByComparator<MBMessage> orderByComparator) {
3425                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3426    
3427                    if (!list.isEmpty()) {
3428                            return list.get(0);
3429                    }
3430    
3431                    return null;
3432            }
3433    
3434            /**
3435             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3436             *
3437             * @param threadId the thread ID
3438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3439             * @return the last matching message-boards message
3440             * @throws NoSuchMessageException if a matching message-boards message could not be found
3441             */
3442            @Override
3443            public MBMessage findByThreadId_Last(long threadId,
3444                    OrderByComparator<MBMessage> orderByComparator)
3445                    throws NoSuchMessageException {
3446                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3447    
3448                    if (mbMessage != null) {
3449                            return mbMessage;
3450                    }
3451    
3452                    StringBundler msg = new StringBundler(4);
3453    
3454                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3455    
3456                    msg.append("threadId=");
3457                    msg.append(threadId);
3458    
3459                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3460    
3461                    throw new NoSuchMessageException(msg.toString());
3462            }
3463    
3464            /**
3465             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3466             *
3467             * @param threadId the thread ID
3468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3469             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3470             */
3471            @Override
3472            public MBMessage fetchByThreadId_Last(long threadId,
3473                    OrderByComparator<MBMessage> orderByComparator) {
3474                    int count = countByThreadId(threadId);
3475    
3476                    if (count == 0) {
3477                            return null;
3478                    }
3479    
3480                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3481                                    orderByComparator);
3482    
3483                    if (!list.isEmpty()) {
3484                            return list.get(0);
3485                    }
3486    
3487                    return null;
3488            }
3489    
3490            /**
3491             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3492             *
3493             * @param messageId the primary key of the current message-boards message
3494             * @param threadId the thread ID
3495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3496             * @return the previous, current, and next message-boards message
3497             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3498             */
3499            @Override
3500            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3501                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3502                    throws NoSuchMessageException {
3503                    MBMessage mbMessage = findByPrimaryKey(messageId);
3504    
3505                    Session session = null;
3506    
3507                    try {
3508                            session = openSession();
3509    
3510                            MBMessage[] array = new MBMessageImpl[3];
3511    
3512                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3513                                            orderByComparator, true);
3514    
3515                            array[1] = mbMessage;
3516    
3517                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3518                                            orderByComparator, false);
3519    
3520                            return array;
3521                    }
3522                    catch (Exception e) {
3523                            throw processException(e);
3524                    }
3525                    finally {
3526                            closeSession(session);
3527                    }
3528            }
3529    
3530            protected MBMessage getByThreadId_PrevAndNext(Session session,
3531                    MBMessage mbMessage, long threadId,
3532                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3533                    StringBundler query = null;
3534    
3535                    if (orderByComparator != null) {
3536                            query = new StringBundler(6 +
3537                                            (orderByComparator.getOrderByFields().length * 6));
3538                    }
3539                    else {
3540                            query = new StringBundler(3);
3541                    }
3542    
3543                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3544    
3545                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3546    
3547                    if (orderByComparator != null) {
3548                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3549    
3550                            if (orderByConditionFields.length > 0) {
3551                                    query.append(WHERE_AND);
3552                            }
3553    
3554                            for (int i = 0; i < orderByConditionFields.length; i++) {
3555                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3556                                    query.append(orderByConditionFields[i]);
3557    
3558                                    if ((i + 1) < orderByConditionFields.length) {
3559                                            if (orderByComparator.isAscending() ^ previous) {
3560                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3561                                            }
3562                                            else {
3563                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3564                                            }
3565                                    }
3566                                    else {
3567                                            if (orderByComparator.isAscending() ^ previous) {
3568                                                    query.append(WHERE_GREATER_THAN);
3569                                            }
3570                                            else {
3571                                                    query.append(WHERE_LESSER_THAN);
3572                                            }
3573                                    }
3574                            }
3575    
3576                            query.append(ORDER_BY_CLAUSE);
3577    
3578                            String[] orderByFields = orderByComparator.getOrderByFields();
3579    
3580                            for (int i = 0; i < orderByFields.length; i++) {
3581                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3582                                    query.append(orderByFields[i]);
3583    
3584                                    if ((i + 1) < orderByFields.length) {
3585                                            if (orderByComparator.isAscending() ^ previous) {
3586                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3587                                            }
3588                                            else {
3589                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3590                                            }
3591                                    }
3592                                    else {
3593                                            if (orderByComparator.isAscending() ^ previous) {
3594                                                    query.append(ORDER_BY_ASC);
3595                                            }
3596                                            else {
3597                                                    query.append(ORDER_BY_DESC);
3598                                            }
3599                                    }
3600                            }
3601                    }
3602                    else {
3603                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3604                    }
3605    
3606                    String sql = query.toString();
3607    
3608                    Query q = session.createQuery(sql);
3609    
3610                    q.setFirstResult(0);
3611                    q.setMaxResults(2);
3612    
3613                    QueryPos qPos = QueryPos.getInstance(q);
3614    
3615                    qPos.add(threadId);
3616    
3617                    if (orderByComparator != null) {
3618                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3619    
3620                            for (Object value : values) {
3621                                    qPos.add(value);
3622                            }
3623                    }
3624    
3625                    List<MBMessage> list = q.list();
3626    
3627                    if (list.size() == 2) {
3628                            return list.get(1);
3629                    }
3630                    else {
3631                            return null;
3632                    }
3633            }
3634    
3635            /**
3636             * Removes all the message-boards messages where threadId = &#63; from the database.
3637             *
3638             * @param threadId the thread ID
3639             */
3640            @Override
3641            public void removeByThreadId(long threadId) {
3642                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3643                                    QueryUtil.ALL_POS, null)) {
3644                            remove(mbMessage);
3645                    }
3646            }
3647    
3648            /**
3649             * Returns the number of message-boards messages where threadId = &#63;.
3650             *
3651             * @param threadId the thread ID
3652             * @return the number of matching message-boards messages
3653             */
3654            @Override
3655            public int countByThreadId(long threadId) {
3656                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3657    
3658                    Object[] finderArgs = new Object[] { threadId };
3659    
3660                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3661                                    this);
3662    
3663                    if (count == null) {
3664                            StringBundler query = new StringBundler(2);
3665    
3666                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3667    
3668                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3669    
3670                            String sql = query.toString();
3671    
3672                            Session session = null;
3673    
3674                            try {
3675                                    session = openSession();
3676    
3677                                    Query q = session.createQuery(sql);
3678    
3679                                    QueryPos qPos = QueryPos.getInstance(q);
3680    
3681                                    qPos.add(threadId);
3682    
3683                                    count = (Long)q.uniqueResult();
3684    
3685                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3686                            }
3687                            catch (Exception e) {
3688                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3689    
3690                                    throw processException(e);
3691                            }
3692                            finally {
3693                                    closeSession(session);
3694                            }
3695                    }
3696    
3697                    return count.intValue();
3698            }
3699    
3700            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3701            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3702                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3703                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3704                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3705                            new String[] {
3706                                    Long.class.getName(),
3707                                    
3708                            Integer.class.getName(), Integer.class.getName(),
3709                                    OrderByComparator.class.getName()
3710                            });
3711            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3712                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3713                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3714                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3715                            new String[] { Long.class.getName() },
3716                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3717                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3718            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3719                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3720                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3721                            new String[] { Long.class.getName() });
3722    
3723            /**
3724             * Returns all the message-boards messages where threadId = &#63;.
3725             *
3726             * @param threadId the thread ID
3727             * @return the matching message-boards messages
3728             */
3729            @Override
3730            public List<MBMessage> findByThreadReplies(long threadId) {
3731                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3732                            QueryUtil.ALL_POS, null);
3733            }
3734    
3735            /**
3736             * Returns a range of all the message-boards messages where threadId = &#63;.
3737             *
3738             * <p>
3739             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3740             * </p>
3741             *
3742             * @param threadId the thread ID
3743             * @param start the lower bound of the range of message-boards messages
3744             * @param end the upper bound of the range of message-boards messages (not inclusive)
3745             * @return the range of matching message-boards messages
3746             */
3747            @Override
3748            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3749                    return findByThreadReplies(threadId, start, end, null);
3750            }
3751    
3752            /**
3753             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3754             *
3755             * <p>
3756             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3757             * </p>
3758             *
3759             * @param threadId the thread ID
3760             * @param start the lower bound of the range of message-boards messages
3761             * @param end the upper bound of the range of message-boards messages (not inclusive)
3762             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3763             * @return the ordered range of matching message-boards messages
3764             */
3765            @Override
3766            public List<MBMessage> findByThreadReplies(long threadId, int start,
3767                    int end, OrderByComparator<MBMessage> orderByComparator) {
3768                    boolean pagination = true;
3769                    FinderPath finderPath = null;
3770                    Object[] finderArgs = null;
3771    
3772                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3773                                    (orderByComparator == null)) {
3774                            pagination = false;
3775                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3776                            finderArgs = new Object[] { threadId };
3777                    }
3778                    else {
3779                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3780                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3781                    }
3782    
3783                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3784                                    finderArgs, this);
3785    
3786                    if ((list != null) && !list.isEmpty()) {
3787                            for (MBMessage mbMessage : list) {
3788                                    if ((threadId != mbMessage.getThreadId())) {
3789                                            list = null;
3790    
3791                                            break;
3792                                    }
3793                            }
3794                    }
3795    
3796                    if (list == null) {
3797                            StringBundler query = null;
3798    
3799                            if (orderByComparator != null) {
3800                                    query = new StringBundler(3 +
3801                                                    (orderByComparator.getOrderByFields().length * 3));
3802                            }
3803                            else {
3804                                    query = new StringBundler(3);
3805                            }
3806    
3807                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3808    
3809                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3810    
3811                            if (orderByComparator != null) {
3812                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3813                                            orderByComparator);
3814                            }
3815                            else
3816                             if (pagination) {
3817                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3818                            }
3819    
3820                            String sql = query.toString();
3821    
3822                            Session session = null;
3823    
3824                            try {
3825                                    session = openSession();
3826    
3827                                    Query q = session.createQuery(sql);
3828    
3829                                    QueryPos qPos = QueryPos.getInstance(q);
3830    
3831                                    qPos.add(threadId);
3832    
3833                                    if (!pagination) {
3834                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3835                                                            start, end, false);
3836    
3837                                            Collections.sort(list);
3838    
3839                                            list = Collections.unmodifiableList(list);
3840                                    }
3841                                    else {
3842                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3843                                                            start, end);
3844                                    }
3845    
3846                                    cacheResult(list);
3847    
3848                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3849                            }
3850                            catch (Exception e) {
3851                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3852    
3853                                    throw processException(e);
3854                            }
3855                            finally {
3856                                    closeSession(session);
3857                            }
3858                    }
3859    
3860                    return list;
3861            }
3862    
3863            /**
3864             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3865             *
3866             * @param threadId the thread ID
3867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3868             * @return the first matching message-boards message
3869             * @throws NoSuchMessageException if a matching message-boards message could not be found
3870             */
3871            @Override
3872            public MBMessage findByThreadReplies_First(long threadId,
3873                    OrderByComparator<MBMessage> orderByComparator)
3874                    throws NoSuchMessageException {
3875                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3876                                    orderByComparator);
3877    
3878                    if (mbMessage != null) {
3879                            return mbMessage;
3880                    }
3881    
3882                    StringBundler msg = new StringBundler(4);
3883    
3884                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3885    
3886                    msg.append("threadId=");
3887                    msg.append(threadId);
3888    
3889                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3890    
3891                    throw new NoSuchMessageException(msg.toString());
3892            }
3893    
3894            /**
3895             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3896             *
3897             * @param threadId the thread ID
3898             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3899             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3900             */
3901            @Override
3902            public MBMessage fetchByThreadReplies_First(long threadId,
3903                    OrderByComparator<MBMessage> orderByComparator) {
3904                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3905                                    orderByComparator);
3906    
3907                    if (!list.isEmpty()) {
3908                            return list.get(0);
3909                    }
3910    
3911                    return null;
3912            }
3913    
3914            /**
3915             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3916             *
3917             * @param threadId the thread ID
3918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3919             * @return the last matching message-boards message
3920             * @throws NoSuchMessageException if a matching message-boards message could not be found
3921             */
3922            @Override
3923            public MBMessage findByThreadReplies_Last(long threadId,
3924                    OrderByComparator<MBMessage> orderByComparator)
3925                    throws NoSuchMessageException {
3926                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3927                                    orderByComparator);
3928    
3929                    if (mbMessage != null) {
3930                            return mbMessage;
3931                    }
3932    
3933                    StringBundler msg = new StringBundler(4);
3934    
3935                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3936    
3937                    msg.append("threadId=");
3938                    msg.append(threadId);
3939    
3940                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3941    
3942                    throw new NoSuchMessageException(msg.toString());
3943            }
3944    
3945            /**
3946             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3947             *
3948             * @param threadId the thread ID
3949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3950             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3951             */
3952            @Override
3953            public MBMessage fetchByThreadReplies_Last(long threadId,
3954                    OrderByComparator<MBMessage> orderByComparator) {
3955                    int count = countByThreadReplies(threadId);
3956    
3957                    if (count == 0) {
3958                            return null;
3959                    }
3960    
3961                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3962                                    orderByComparator);
3963    
3964                    if (!list.isEmpty()) {
3965                            return list.get(0);
3966                    }
3967    
3968                    return null;
3969            }
3970    
3971            /**
3972             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3973             *
3974             * @param messageId the primary key of the current message-boards message
3975             * @param threadId the thread ID
3976             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3977             * @return the previous, current, and next message-boards message
3978             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3979             */
3980            @Override
3981            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3982                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3983                    throws NoSuchMessageException {
3984                    MBMessage mbMessage = findByPrimaryKey(messageId);
3985    
3986                    Session session = null;
3987    
3988                    try {
3989                            session = openSession();
3990    
3991                            MBMessage[] array = new MBMessageImpl[3];
3992    
3993                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3994                                            threadId, orderByComparator, true);
3995    
3996                            array[1] = mbMessage;
3997    
3998                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3999                                            threadId, orderByComparator, false);
4000    
4001                            return array;
4002                    }
4003                    catch (Exception e) {
4004                            throw processException(e);
4005                    }
4006                    finally {
4007                            closeSession(session);
4008                    }
4009            }
4010    
4011            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4012                    MBMessage mbMessage, long threadId,
4013                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4014                    StringBundler query = null;
4015    
4016                    if (orderByComparator != null) {
4017                            query = new StringBundler(6 +
4018                                            (orderByComparator.getOrderByFields().length * 6));
4019                    }
4020                    else {
4021                            query = new StringBundler(3);
4022                    }
4023    
4024                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4025    
4026                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4027    
4028                    if (orderByComparator != null) {
4029                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4030    
4031                            if (orderByConditionFields.length > 0) {
4032                                    query.append(WHERE_AND);
4033                            }
4034    
4035                            for (int i = 0; i < orderByConditionFields.length; i++) {
4036                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4037                                    query.append(orderByConditionFields[i]);
4038    
4039                                    if ((i + 1) < orderByConditionFields.length) {
4040                                            if (orderByComparator.isAscending() ^ previous) {
4041                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4042                                            }
4043                                            else {
4044                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4045                                            }
4046                                    }
4047                                    else {
4048                                            if (orderByComparator.isAscending() ^ previous) {
4049                                                    query.append(WHERE_GREATER_THAN);
4050                                            }
4051                                            else {
4052                                                    query.append(WHERE_LESSER_THAN);
4053                                            }
4054                                    }
4055                            }
4056    
4057                            query.append(ORDER_BY_CLAUSE);
4058    
4059                            String[] orderByFields = orderByComparator.getOrderByFields();
4060    
4061                            for (int i = 0; i < orderByFields.length; i++) {
4062                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4063                                    query.append(orderByFields[i]);
4064    
4065                                    if ((i + 1) < orderByFields.length) {
4066                                            if (orderByComparator.isAscending() ^ previous) {
4067                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4068                                            }
4069                                            else {
4070                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4071                                            }
4072                                    }
4073                                    else {
4074                                            if (orderByComparator.isAscending() ^ previous) {
4075                                                    query.append(ORDER_BY_ASC);
4076                                            }
4077                                            else {
4078                                                    query.append(ORDER_BY_DESC);
4079                                            }
4080                                    }
4081                            }
4082                    }
4083                    else {
4084                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4085                    }
4086    
4087                    String sql = query.toString();
4088    
4089                    Query q = session.createQuery(sql);
4090    
4091                    q.setFirstResult(0);
4092                    q.setMaxResults(2);
4093    
4094                    QueryPos qPos = QueryPos.getInstance(q);
4095    
4096                    qPos.add(threadId);
4097    
4098                    if (orderByComparator != null) {
4099                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4100    
4101                            for (Object value : values) {
4102                                    qPos.add(value);
4103                            }
4104                    }
4105    
4106                    List<MBMessage> list = q.list();
4107    
4108                    if (list.size() == 2) {
4109                            return list.get(1);
4110                    }
4111                    else {
4112                            return null;
4113                    }
4114            }
4115    
4116            /**
4117             * Removes all the message-boards messages where threadId = &#63; from the database.
4118             *
4119             * @param threadId the thread ID
4120             */
4121            @Override
4122            public void removeByThreadReplies(long threadId) {
4123                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4124                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4125                            remove(mbMessage);
4126                    }
4127            }
4128    
4129            /**
4130             * Returns the number of message-boards messages where threadId = &#63;.
4131             *
4132             * @param threadId the thread ID
4133             * @return the number of matching message-boards messages
4134             */
4135            @Override
4136            public int countByThreadReplies(long threadId) {
4137                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4138    
4139                    Object[] finderArgs = new Object[] { threadId };
4140    
4141                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4142                                    this);
4143    
4144                    if (count == null) {
4145                            StringBundler query = new StringBundler(2);
4146    
4147                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4148    
4149                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4150    
4151                            String sql = query.toString();
4152    
4153                            Session session = null;
4154    
4155                            try {
4156                                    session = openSession();
4157    
4158                                    Query q = session.createQuery(sql);
4159    
4160                                    QueryPos qPos = QueryPos.getInstance(q);
4161    
4162                                    qPos.add(threadId);
4163    
4164                                    count = (Long)q.uniqueResult();
4165    
4166                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4167                            }
4168                            catch (Exception e) {
4169                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4170    
4171                                    throw processException(e);
4172                            }
4173                            finally {
4174                                    closeSession(session);
4175                            }
4176                    }
4177    
4178                    return count.intValue();
4179            }
4180    
4181            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4182            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4183                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4184                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4185                            new String[] {
4186                                    Long.class.getName(), Long.class.getName(),
4187                                    
4188                            Integer.class.getName(), Integer.class.getName(),
4189                                    OrderByComparator.class.getName()
4190                            });
4191            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4192                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4193                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4194                            new String[] { Long.class.getName(), Long.class.getName() },
4195                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4196                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4197                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4198            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4199                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4201                            new String[] { Long.class.getName(), Long.class.getName() });
4202    
4203            /**
4204             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4205             *
4206             * @param groupId the group ID
4207             * @param userId the user ID
4208             * @return the matching message-boards messages
4209             */
4210            @Override
4211            public List<MBMessage> findByG_U(long groupId, long userId) {
4212                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4213                            null);
4214            }
4215    
4216            /**
4217             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4218             *
4219             * <p>
4220             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4221             * </p>
4222             *
4223             * @param groupId the group ID
4224             * @param userId the user ID
4225             * @param start the lower bound of the range of message-boards messages
4226             * @param end the upper bound of the range of message-boards messages (not inclusive)
4227             * @return the range of matching message-boards messages
4228             */
4229            @Override
4230            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4231                    int end) {
4232                    return findByG_U(groupId, userId, start, end, null);
4233            }
4234    
4235            /**
4236             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4237             *
4238             * <p>
4239             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4240             * </p>
4241             *
4242             * @param groupId the group ID
4243             * @param userId the user ID
4244             * @param start the lower bound of the range of message-boards messages
4245             * @param end the upper bound of the range of message-boards messages (not inclusive)
4246             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4247             * @return the ordered range of matching message-boards messages
4248             */
4249            @Override
4250            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4251                    int end, OrderByComparator<MBMessage> orderByComparator) {
4252                    boolean pagination = true;
4253                    FinderPath finderPath = null;
4254                    Object[] finderArgs = null;
4255    
4256                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4257                                    (orderByComparator == null)) {
4258                            pagination = false;
4259                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4260                            finderArgs = new Object[] { groupId, userId };
4261                    }
4262                    else {
4263                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4264                            finderArgs = new Object[] {
4265                                            groupId, userId,
4266                                            
4267                                            start, end, orderByComparator
4268                                    };
4269                    }
4270    
4271                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4272                                    finderArgs, this);
4273    
4274                    if ((list != null) && !list.isEmpty()) {
4275                            for (MBMessage mbMessage : list) {
4276                                    if ((groupId != mbMessage.getGroupId()) ||
4277                                                    (userId != mbMessage.getUserId())) {
4278                                            list = null;
4279    
4280                                            break;
4281                                    }
4282                            }
4283                    }
4284    
4285                    if (list == null) {
4286                            StringBundler query = null;
4287    
4288                            if (orderByComparator != null) {
4289                                    query = new StringBundler(4 +
4290                                                    (orderByComparator.getOrderByFields().length * 3));
4291                            }
4292                            else {
4293                                    query = new StringBundler(4);
4294                            }
4295    
4296                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4297    
4298                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4299    
4300                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4301    
4302                            if (orderByComparator != null) {
4303                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4304                                            orderByComparator);
4305                            }
4306                            else
4307                             if (pagination) {
4308                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4309                            }
4310    
4311                            String sql = query.toString();
4312    
4313                            Session session = null;
4314    
4315                            try {
4316                                    session = openSession();
4317    
4318                                    Query q = session.createQuery(sql);
4319    
4320                                    QueryPos qPos = QueryPos.getInstance(q);
4321    
4322                                    qPos.add(groupId);
4323    
4324                                    qPos.add(userId);
4325    
4326                                    if (!pagination) {
4327                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4328                                                            start, end, false);
4329    
4330                                            Collections.sort(list);
4331    
4332                                            list = Collections.unmodifiableList(list);
4333                                    }
4334                                    else {
4335                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4336                                                            start, end);
4337                                    }
4338    
4339                                    cacheResult(list);
4340    
4341                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4342                            }
4343                            catch (Exception e) {
4344                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4345    
4346                                    throw processException(e);
4347                            }
4348                            finally {
4349                                    closeSession(session);
4350                            }
4351                    }
4352    
4353                    return list;
4354            }
4355    
4356            /**
4357             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4358             *
4359             * @param groupId the group ID
4360             * @param userId the user ID
4361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4362             * @return the first matching message-boards message
4363             * @throws NoSuchMessageException if a matching message-boards message could not be found
4364             */
4365            @Override
4366            public MBMessage findByG_U_First(long groupId, long userId,
4367                    OrderByComparator<MBMessage> orderByComparator)
4368                    throws NoSuchMessageException {
4369                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4370                                    orderByComparator);
4371    
4372                    if (mbMessage != null) {
4373                            return mbMessage;
4374                    }
4375    
4376                    StringBundler msg = new StringBundler(6);
4377    
4378                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4379    
4380                    msg.append("groupId=");
4381                    msg.append(groupId);
4382    
4383                    msg.append(", userId=");
4384                    msg.append(userId);
4385    
4386                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4387    
4388                    throw new NoSuchMessageException(msg.toString());
4389            }
4390    
4391            /**
4392             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4393             *
4394             * @param groupId the group ID
4395             * @param userId the user ID
4396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4397             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4398             */
4399            @Override
4400            public MBMessage fetchByG_U_First(long groupId, long userId,
4401                    OrderByComparator<MBMessage> orderByComparator) {
4402                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4403                                    orderByComparator);
4404    
4405                    if (!list.isEmpty()) {
4406                            return list.get(0);
4407                    }
4408    
4409                    return null;
4410            }
4411    
4412            /**
4413             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4414             *
4415             * @param groupId the group ID
4416             * @param userId the user ID
4417             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4418             * @return the last matching message-boards message
4419             * @throws NoSuchMessageException if a matching message-boards message could not be found
4420             */
4421            @Override
4422            public MBMessage findByG_U_Last(long groupId, long userId,
4423                    OrderByComparator<MBMessage> orderByComparator)
4424                    throws NoSuchMessageException {
4425                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4426    
4427                    if (mbMessage != null) {
4428                            return mbMessage;
4429                    }
4430    
4431                    StringBundler msg = new StringBundler(6);
4432    
4433                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4434    
4435                    msg.append("groupId=");
4436                    msg.append(groupId);
4437    
4438                    msg.append(", userId=");
4439                    msg.append(userId);
4440    
4441                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4442    
4443                    throw new NoSuchMessageException(msg.toString());
4444            }
4445    
4446            /**
4447             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4448             *
4449             * @param groupId the group ID
4450             * @param userId the user ID
4451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4452             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4453             */
4454            @Override
4455            public MBMessage fetchByG_U_Last(long groupId, long userId,
4456                    OrderByComparator<MBMessage> orderByComparator) {
4457                    int count = countByG_U(groupId, userId);
4458    
4459                    if (count == 0) {
4460                            return null;
4461                    }
4462    
4463                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4464                                    orderByComparator);
4465    
4466                    if (!list.isEmpty()) {
4467                            return list.get(0);
4468                    }
4469    
4470                    return null;
4471            }
4472    
4473            /**
4474             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4475             *
4476             * @param messageId the primary key of the current message-boards message
4477             * @param groupId the group ID
4478             * @param userId the user ID
4479             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4480             * @return the previous, current, and next message-boards message
4481             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4482             */
4483            @Override
4484            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4485                    long userId, OrderByComparator<MBMessage> orderByComparator)
4486                    throws NoSuchMessageException {
4487                    MBMessage mbMessage = findByPrimaryKey(messageId);
4488    
4489                    Session session = null;
4490    
4491                    try {
4492                            session = openSession();
4493    
4494                            MBMessage[] array = new MBMessageImpl[3];
4495    
4496                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4497                                            userId, orderByComparator, true);
4498    
4499                            array[1] = mbMessage;
4500    
4501                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4502                                            userId, orderByComparator, false);
4503    
4504                            return array;
4505                    }
4506                    catch (Exception e) {
4507                            throw processException(e);
4508                    }
4509                    finally {
4510                            closeSession(session);
4511                    }
4512            }
4513    
4514            protected MBMessage getByG_U_PrevAndNext(Session session,
4515                    MBMessage mbMessage, long groupId, long userId,
4516                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4517                    StringBundler query = null;
4518    
4519                    if (orderByComparator != null) {
4520                            query = new StringBundler(6 +
4521                                            (orderByComparator.getOrderByFields().length * 6));
4522                    }
4523                    else {
4524                            query = new StringBundler(3);
4525                    }
4526    
4527                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4528    
4529                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4530    
4531                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4532    
4533                    if (orderByComparator != null) {
4534                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4535    
4536                            if (orderByConditionFields.length > 0) {
4537                                    query.append(WHERE_AND);
4538                            }
4539    
4540                            for (int i = 0; i < orderByConditionFields.length; i++) {
4541                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4542                                    query.append(orderByConditionFields[i]);
4543    
4544                                    if ((i + 1) < orderByConditionFields.length) {
4545                                            if (orderByComparator.isAscending() ^ previous) {
4546                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4547                                            }
4548                                            else {
4549                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4550                                            }
4551                                    }
4552                                    else {
4553                                            if (orderByComparator.isAscending() ^ previous) {
4554                                                    query.append(WHERE_GREATER_THAN);
4555                                            }
4556                                            else {
4557                                                    query.append(WHERE_LESSER_THAN);
4558                                            }
4559                                    }
4560                            }
4561    
4562                            query.append(ORDER_BY_CLAUSE);
4563    
4564                            String[] orderByFields = orderByComparator.getOrderByFields();
4565    
4566                            for (int i = 0; i < orderByFields.length; i++) {
4567                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4568                                    query.append(orderByFields[i]);
4569    
4570                                    if ((i + 1) < orderByFields.length) {
4571                                            if (orderByComparator.isAscending() ^ previous) {
4572                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4573                                            }
4574                                            else {
4575                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4576                                            }
4577                                    }
4578                                    else {
4579                                            if (orderByComparator.isAscending() ^ previous) {
4580                                                    query.append(ORDER_BY_ASC);
4581                                            }
4582                                            else {
4583                                                    query.append(ORDER_BY_DESC);
4584                                            }
4585                                    }
4586                            }
4587                    }
4588                    else {
4589                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4590                    }
4591    
4592                    String sql = query.toString();
4593    
4594                    Query q = session.createQuery(sql);
4595    
4596                    q.setFirstResult(0);
4597                    q.setMaxResults(2);
4598    
4599                    QueryPos qPos = QueryPos.getInstance(q);
4600    
4601                    qPos.add(groupId);
4602    
4603                    qPos.add(userId);
4604    
4605                    if (orderByComparator != null) {
4606                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4607    
4608                            for (Object value : values) {
4609                                    qPos.add(value);
4610                            }
4611                    }
4612    
4613                    List<MBMessage> list = q.list();
4614    
4615                    if (list.size() == 2) {
4616                            return list.get(1);
4617                    }
4618                    else {
4619                            return null;
4620                    }
4621            }
4622    
4623            /**
4624             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4625             *
4626             * @param groupId the group ID
4627             * @param userId the user ID
4628             * @return the matching message-boards messages that the user has permission to view
4629             */
4630            @Override
4631            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4632                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4633                            QueryUtil.ALL_POS, null);
4634            }
4635    
4636            /**
4637             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4638             *
4639             * <p>
4640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4641             * </p>
4642             *
4643             * @param groupId the group ID
4644             * @param userId the user ID
4645             * @param start the lower bound of the range of message-boards messages
4646             * @param end the upper bound of the range of message-boards messages (not inclusive)
4647             * @return the range of matching message-boards messages that the user has permission to view
4648             */
4649            @Override
4650            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4651                    int start, int end) {
4652                    return filterFindByG_U(groupId, userId, start, end, null);
4653            }
4654    
4655            /**
4656             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4657             *
4658             * <p>
4659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4660             * </p>
4661             *
4662             * @param groupId the group ID
4663             * @param userId the user ID
4664             * @param start the lower bound of the range of message-boards messages
4665             * @param end the upper bound of the range of message-boards messages (not inclusive)
4666             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4667             * @return the ordered range of matching message-boards messages that the user has permission to view
4668             */
4669            @Override
4670            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4671                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4672                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4673                            return findByG_U(groupId, userId, start, end, orderByComparator);
4674                    }
4675    
4676                    StringBundler query = null;
4677    
4678                    if (orderByComparator != null) {
4679                            query = new StringBundler(4 +
4680                                            (orderByComparator.getOrderByFields().length * 3));
4681                    }
4682                    else {
4683                            query = new StringBundler(4);
4684                    }
4685    
4686                    if (getDB().isSupportsInlineDistinct()) {
4687                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4688                    }
4689                    else {
4690                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4691                    }
4692    
4693                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4694    
4695                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4696    
4697                    if (!getDB().isSupportsInlineDistinct()) {
4698                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4699                    }
4700    
4701                    if (orderByComparator != null) {
4702                            if (getDB().isSupportsInlineDistinct()) {
4703                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4704                                            orderByComparator, true);
4705                            }
4706                            else {
4707                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4708                                            orderByComparator, true);
4709                            }
4710                    }
4711                    else {
4712                            if (getDB().isSupportsInlineDistinct()) {
4713                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4714                            }
4715                            else {
4716                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4717                            }
4718                    }
4719    
4720                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4721                                    MBMessage.class.getName(),
4722                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4723    
4724                    Session session = null;
4725    
4726                    try {
4727                            session = openSession();
4728    
4729                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4730    
4731                            if (getDB().isSupportsInlineDistinct()) {
4732                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4733                            }
4734                            else {
4735                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4736                            }
4737    
4738                            QueryPos qPos = QueryPos.getInstance(q);
4739    
4740                            qPos.add(groupId);
4741    
4742                            qPos.add(userId);
4743    
4744                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4745                    }
4746                    catch (Exception e) {
4747                            throw processException(e);
4748                    }
4749                    finally {
4750                            closeSession(session);
4751                    }
4752            }
4753    
4754            /**
4755             * 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;.
4756             *
4757             * @param messageId the primary key of the current message-boards message
4758             * @param groupId the group ID
4759             * @param userId the user ID
4760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4761             * @return the previous, current, and next message-boards message
4762             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4763             */
4764            @Override
4765            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4766                    long groupId, long userId,
4767                    OrderByComparator<MBMessage> orderByComparator)
4768                    throws NoSuchMessageException {
4769                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4770                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4771                                    orderByComparator);
4772                    }
4773    
4774                    MBMessage mbMessage = findByPrimaryKey(messageId);
4775    
4776                    Session session = null;
4777    
4778                    try {
4779                            session = openSession();
4780    
4781                            MBMessage[] array = new MBMessageImpl[3];
4782    
4783                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4784                                            userId, orderByComparator, true);
4785    
4786                            array[1] = mbMessage;
4787    
4788                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4789                                            userId, orderByComparator, false);
4790    
4791                            return array;
4792                    }
4793                    catch (Exception e) {
4794                            throw processException(e);
4795                    }
4796                    finally {
4797                            closeSession(session);
4798                    }
4799            }
4800    
4801            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4802                    MBMessage mbMessage, long groupId, long userId,
4803                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4804                    StringBundler query = null;
4805    
4806                    if (orderByComparator != null) {
4807                            query = new StringBundler(6 +
4808                                            (orderByComparator.getOrderByFields().length * 6));
4809                    }
4810                    else {
4811                            query = new StringBundler(3);
4812                    }
4813    
4814                    if (getDB().isSupportsInlineDistinct()) {
4815                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4816                    }
4817                    else {
4818                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4819                    }
4820    
4821                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4822    
4823                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4824    
4825                    if (!getDB().isSupportsInlineDistinct()) {
4826                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4827                    }
4828    
4829                    if (orderByComparator != null) {
4830                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4831    
4832                            if (orderByConditionFields.length > 0) {
4833                                    query.append(WHERE_AND);
4834                            }
4835    
4836                            for (int i = 0; i < orderByConditionFields.length; i++) {
4837                                    if (getDB().isSupportsInlineDistinct()) {
4838                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4839                                    }
4840                                    else {
4841                                            query.append(_ORDER_BY_ENTITY_TABLE);
4842                                    }
4843    
4844                                    query.append(orderByConditionFields[i]);
4845    
4846                                    if ((i + 1) < orderByConditionFields.length) {
4847                                            if (orderByComparator.isAscending() ^ previous) {
4848                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4849                                            }
4850                                            else {
4851                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4852                                            }
4853                                    }
4854                                    else {
4855                                            if (orderByComparator.isAscending() ^ previous) {
4856                                                    query.append(WHERE_GREATER_THAN);
4857                                            }
4858                                            else {
4859                                                    query.append(WHERE_LESSER_THAN);
4860                                            }
4861                                    }
4862                            }
4863    
4864                            query.append(ORDER_BY_CLAUSE);
4865    
4866                            String[] orderByFields = orderByComparator.getOrderByFields();
4867    
4868                            for (int i = 0; i < orderByFields.length; i++) {
4869                                    if (getDB().isSupportsInlineDistinct()) {
4870                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4871                                    }
4872                                    else {
4873                                            query.append(_ORDER_BY_ENTITY_TABLE);
4874                                    }
4875    
4876                                    query.append(orderByFields[i]);
4877    
4878                                    if ((i + 1) < orderByFields.length) {
4879                                            if (orderByComparator.isAscending() ^ previous) {
4880                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4881                                            }
4882                                            else {
4883                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4884                                            }
4885                                    }
4886                                    else {
4887                                            if (orderByComparator.isAscending() ^ previous) {
4888                                                    query.append(ORDER_BY_ASC);
4889                                            }
4890                                            else {
4891                                                    query.append(ORDER_BY_DESC);
4892                                            }
4893                                    }
4894                            }
4895                    }
4896                    else {
4897                            if (getDB().isSupportsInlineDistinct()) {
4898                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4899                            }
4900                            else {
4901                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4902                            }
4903                    }
4904    
4905                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4906                                    MBMessage.class.getName(),
4907                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4908    
4909                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4910    
4911                    q.setFirstResult(0);
4912                    q.setMaxResults(2);
4913    
4914                    if (getDB().isSupportsInlineDistinct()) {
4915                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4916                    }
4917                    else {
4918                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4919                    }
4920    
4921                    QueryPos qPos = QueryPos.getInstance(q);
4922    
4923                    qPos.add(groupId);
4924    
4925                    qPos.add(userId);
4926    
4927                    if (orderByComparator != null) {
4928                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4929    
4930                            for (Object value : values) {
4931                                    qPos.add(value);
4932                            }
4933                    }
4934    
4935                    List<MBMessage> list = q.list();
4936    
4937                    if (list.size() == 2) {
4938                            return list.get(1);
4939                    }
4940                    else {
4941                            return null;
4942                    }
4943            }
4944    
4945            /**
4946             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
4947             *
4948             * @param groupId the group ID
4949             * @param userId the user ID
4950             */
4951            @Override
4952            public void removeByG_U(long groupId, long userId) {
4953                    for (MBMessage mbMessage : findByG_U(groupId, userId,
4954                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4955                            remove(mbMessage);
4956                    }
4957            }
4958    
4959            /**
4960             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
4961             *
4962             * @param groupId the group ID
4963             * @param userId the user ID
4964             * @return the number of matching message-boards messages
4965             */
4966            @Override
4967            public int countByG_U(long groupId, long userId) {
4968                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
4969    
4970                    Object[] finderArgs = new Object[] { groupId, userId };
4971    
4972                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4973                                    this);
4974    
4975                    if (count == null) {
4976                            StringBundler query = new StringBundler(3);
4977    
4978                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4979    
4980                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4981    
4982                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4983    
4984                            String sql = query.toString();
4985    
4986                            Session session = null;
4987    
4988                            try {
4989                                    session = openSession();
4990    
4991                                    Query q = session.createQuery(sql);
4992    
4993                                    QueryPos qPos = QueryPos.getInstance(q);
4994    
4995                                    qPos.add(groupId);
4996    
4997                                    qPos.add(userId);
4998    
4999                                    count = (Long)q.uniqueResult();
5000    
5001                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5002                            }
5003                            catch (Exception e) {
5004                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5005    
5006                                    throw processException(e);
5007                            }
5008                            finally {
5009                                    closeSession(session);
5010                            }
5011                    }
5012    
5013                    return count.intValue();
5014            }
5015    
5016            /**
5017             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5018             *
5019             * @param groupId the group ID
5020             * @param userId the user ID
5021             * @return the number of matching message-boards messages that the user has permission to view
5022             */
5023            @Override
5024            public int filterCountByG_U(long groupId, long userId) {
5025                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5026                            return countByG_U(groupId, userId);
5027                    }
5028    
5029                    StringBundler query = new StringBundler(3);
5030    
5031                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5032    
5033                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5034    
5035                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5036    
5037                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5038                                    MBMessage.class.getName(),
5039                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5040    
5041                    Session session = null;
5042    
5043                    try {
5044                            session = openSession();
5045    
5046                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5047    
5048                            q.addScalar(COUNT_COLUMN_NAME,
5049                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5050    
5051                            QueryPos qPos = QueryPos.getInstance(q);
5052    
5053                            qPos.add(groupId);
5054    
5055                            qPos.add(userId);
5056    
5057                            Long count = (Long)q.uniqueResult();
5058    
5059                            return count.intValue();
5060                    }
5061                    catch (Exception e) {
5062                            throw processException(e);
5063                    }
5064                    finally {
5065                            closeSession(session);
5066                    }
5067            }
5068    
5069            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5070            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5071            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5072                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5073                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5074                            new String[] {
5075                                    Long.class.getName(), Long.class.getName(),
5076                                    
5077                            Integer.class.getName(), Integer.class.getName(),
5078                                    OrderByComparator.class.getName()
5079                            });
5080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5081                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5083                            new String[] { Long.class.getName(), Long.class.getName() },
5084                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5085                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5086                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5087            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5088                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5090                            new String[] { Long.class.getName(), Long.class.getName() });
5091    
5092            /**
5093             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5094             *
5095             * @param groupId the group ID
5096             * @param categoryId the category ID
5097             * @return the matching message-boards messages
5098             */
5099            @Override
5100            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5101                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5102                            QueryUtil.ALL_POS, null);
5103            }
5104    
5105            /**
5106             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5107             *
5108             * <p>
5109             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5110             * </p>
5111             *
5112             * @param groupId the group ID
5113             * @param categoryId the category ID
5114             * @param start the lower bound of the range of message-boards messages
5115             * @param end the upper bound of the range of message-boards messages (not inclusive)
5116             * @return the range of matching message-boards messages
5117             */
5118            @Override
5119            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5120                    int end) {
5121                    return findByG_C(groupId, categoryId, start, end, null);
5122            }
5123    
5124            /**
5125             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5126             *
5127             * <p>
5128             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5129             * </p>
5130             *
5131             * @param groupId the group ID
5132             * @param categoryId the category ID
5133             * @param start the lower bound of the range of message-boards messages
5134             * @param end the upper bound of the range of message-boards messages (not inclusive)
5135             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5136             * @return the ordered range of matching message-boards messages
5137             */
5138            @Override
5139            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5140                    int end, OrderByComparator<MBMessage> orderByComparator) {
5141                    boolean pagination = true;
5142                    FinderPath finderPath = null;
5143                    Object[] finderArgs = null;
5144    
5145                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5146                                    (orderByComparator == null)) {
5147                            pagination = false;
5148                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5149                            finderArgs = new Object[] { groupId, categoryId };
5150                    }
5151                    else {
5152                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5153                            finderArgs = new Object[] {
5154                                            groupId, categoryId,
5155                                            
5156                                            start, end, orderByComparator
5157                                    };
5158                    }
5159    
5160                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5161                                    finderArgs, this);
5162    
5163                    if ((list != null) && !list.isEmpty()) {
5164                            for (MBMessage mbMessage : list) {
5165                                    if ((groupId != mbMessage.getGroupId()) ||
5166                                                    (categoryId != mbMessage.getCategoryId())) {
5167                                            list = null;
5168    
5169                                            break;
5170                                    }
5171                            }
5172                    }
5173    
5174                    if (list == null) {
5175                            StringBundler query = null;
5176    
5177                            if (orderByComparator != null) {
5178                                    query = new StringBundler(4 +
5179                                                    (orderByComparator.getOrderByFields().length * 3));
5180                            }
5181                            else {
5182                                    query = new StringBundler(4);
5183                            }
5184    
5185                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5186    
5187                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5188    
5189                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5190    
5191                            if (orderByComparator != null) {
5192                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5193                                            orderByComparator);
5194                            }
5195                            else
5196                             if (pagination) {
5197                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5198                            }
5199    
5200                            String sql = query.toString();
5201    
5202                            Session session = null;
5203    
5204                            try {
5205                                    session = openSession();
5206    
5207                                    Query q = session.createQuery(sql);
5208    
5209                                    QueryPos qPos = QueryPos.getInstance(q);
5210    
5211                                    qPos.add(groupId);
5212    
5213                                    qPos.add(categoryId);
5214    
5215                                    if (!pagination) {
5216                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5217                                                            start, end, false);
5218    
5219                                            Collections.sort(list);
5220    
5221                                            list = Collections.unmodifiableList(list);
5222                                    }
5223                                    else {
5224                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5225                                                            start, end);
5226                                    }
5227    
5228                                    cacheResult(list);
5229    
5230                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5231                            }
5232                            catch (Exception e) {
5233                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5234    
5235                                    throw processException(e);
5236                            }
5237                            finally {
5238                                    closeSession(session);
5239                            }
5240                    }
5241    
5242                    return list;
5243            }
5244    
5245            /**
5246             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5247             *
5248             * @param groupId the group ID
5249             * @param categoryId the category ID
5250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5251             * @return the first matching message-boards message
5252             * @throws NoSuchMessageException if a matching message-boards message could not be found
5253             */
5254            @Override
5255            public MBMessage findByG_C_First(long groupId, long categoryId,
5256                    OrderByComparator<MBMessage> orderByComparator)
5257                    throws NoSuchMessageException {
5258                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5259                                    orderByComparator);
5260    
5261                    if (mbMessage != null) {
5262                            return mbMessage;
5263                    }
5264    
5265                    StringBundler msg = new StringBundler(6);
5266    
5267                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5268    
5269                    msg.append("groupId=");
5270                    msg.append(groupId);
5271    
5272                    msg.append(", categoryId=");
5273                    msg.append(categoryId);
5274    
5275                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5276    
5277                    throw new NoSuchMessageException(msg.toString());
5278            }
5279    
5280            /**
5281             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5282             *
5283             * @param groupId the group ID
5284             * @param categoryId the category ID
5285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5286             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5287             */
5288            @Override
5289            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5290                    OrderByComparator<MBMessage> orderByComparator) {
5291                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5292                                    orderByComparator);
5293    
5294                    if (!list.isEmpty()) {
5295                            return list.get(0);
5296                    }
5297    
5298                    return null;
5299            }
5300    
5301            /**
5302             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5303             *
5304             * @param groupId the group ID
5305             * @param categoryId the category ID
5306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5307             * @return the last matching message-boards message
5308             * @throws NoSuchMessageException if a matching message-boards message could not be found
5309             */
5310            @Override
5311            public MBMessage findByG_C_Last(long groupId, long categoryId,
5312                    OrderByComparator<MBMessage> orderByComparator)
5313                    throws NoSuchMessageException {
5314                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5315                                    orderByComparator);
5316    
5317                    if (mbMessage != null) {
5318                            return mbMessage;
5319                    }
5320    
5321                    StringBundler msg = new StringBundler(6);
5322    
5323                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5324    
5325                    msg.append("groupId=");
5326                    msg.append(groupId);
5327    
5328                    msg.append(", categoryId=");
5329                    msg.append(categoryId);
5330    
5331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5332    
5333                    throw new NoSuchMessageException(msg.toString());
5334            }
5335    
5336            /**
5337             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5338             *
5339             * @param groupId the group ID
5340             * @param categoryId the category ID
5341             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5342             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5343             */
5344            @Override
5345            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5346                    OrderByComparator<MBMessage> orderByComparator) {
5347                    int count = countByG_C(groupId, categoryId);
5348    
5349                    if (count == 0) {
5350                            return null;
5351                    }
5352    
5353                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5354                                    orderByComparator);
5355    
5356                    if (!list.isEmpty()) {
5357                            return list.get(0);
5358                    }
5359    
5360                    return null;
5361            }
5362    
5363            /**
5364             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5365             *
5366             * @param messageId the primary key of the current message-boards message
5367             * @param groupId the group ID
5368             * @param categoryId the category ID
5369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5370             * @return the previous, current, and next message-boards message
5371             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5372             */
5373            @Override
5374            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5375                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5376                    throws NoSuchMessageException {
5377                    MBMessage mbMessage = findByPrimaryKey(messageId);
5378    
5379                    Session session = null;
5380    
5381                    try {
5382                            session = openSession();
5383    
5384                            MBMessage[] array = new MBMessageImpl[3];
5385    
5386                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5387                                            categoryId, orderByComparator, true);
5388    
5389                            array[1] = mbMessage;
5390    
5391                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5392                                            categoryId, orderByComparator, false);
5393    
5394                            return array;
5395                    }
5396                    catch (Exception e) {
5397                            throw processException(e);
5398                    }
5399                    finally {
5400                            closeSession(session);
5401                    }
5402            }
5403    
5404            protected MBMessage getByG_C_PrevAndNext(Session session,
5405                    MBMessage mbMessage, long groupId, long categoryId,
5406                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5407                    StringBundler query = null;
5408    
5409                    if (orderByComparator != null) {
5410                            query = new StringBundler(6 +
5411                                            (orderByComparator.getOrderByFields().length * 6));
5412                    }
5413                    else {
5414                            query = new StringBundler(3);
5415                    }
5416    
5417                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5418    
5419                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5420    
5421                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5422    
5423                    if (orderByComparator != null) {
5424                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5425    
5426                            if (orderByConditionFields.length > 0) {
5427                                    query.append(WHERE_AND);
5428                            }
5429    
5430                            for (int i = 0; i < orderByConditionFields.length; i++) {
5431                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5432                                    query.append(orderByConditionFields[i]);
5433    
5434                                    if ((i + 1) < orderByConditionFields.length) {
5435                                            if (orderByComparator.isAscending() ^ previous) {
5436                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5437                                            }
5438                                            else {
5439                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5440                                            }
5441                                    }
5442                                    else {
5443                                            if (orderByComparator.isAscending() ^ previous) {
5444                                                    query.append(WHERE_GREATER_THAN);
5445                                            }
5446                                            else {
5447                                                    query.append(WHERE_LESSER_THAN);
5448                                            }
5449                                    }
5450                            }
5451    
5452                            query.append(ORDER_BY_CLAUSE);
5453    
5454                            String[] orderByFields = orderByComparator.getOrderByFields();
5455    
5456                            for (int i = 0; i < orderByFields.length; i++) {
5457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5458                                    query.append(orderByFields[i]);
5459    
5460                                    if ((i + 1) < orderByFields.length) {
5461                                            if (orderByComparator.isAscending() ^ previous) {
5462                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5463                                            }
5464                                            else {
5465                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5466                                            }
5467                                    }
5468                                    else {
5469                                            if (orderByComparator.isAscending() ^ previous) {
5470                                                    query.append(ORDER_BY_ASC);
5471                                            }
5472                                            else {
5473                                                    query.append(ORDER_BY_DESC);
5474                                            }
5475                                    }
5476                            }
5477                    }
5478                    else {
5479                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5480                    }
5481    
5482                    String sql = query.toString();
5483    
5484                    Query q = session.createQuery(sql);
5485    
5486                    q.setFirstResult(0);
5487                    q.setMaxResults(2);
5488    
5489                    QueryPos qPos = QueryPos.getInstance(q);
5490    
5491                    qPos.add(groupId);
5492    
5493                    qPos.add(categoryId);
5494    
5495                    if (orderByComparator != null) {
5496                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5497    
5498                            for (Object value : values) {
5499                                    qPos.add(value);
5500                            }
5501                    }
5502    
5503                    List<MBMessage> list = q.list();
5504    
5505                    if (list.size() == 2) {
5506                            return list.get(1);
5507                    }
5508                    else {
5509                            return null;
5510                    }
5511            }
5512    
5513            /**
5514             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5515             *
5516             * @param groupId the group ID
5517             * @param categoryId the category ID
5518             * @return the matching message-boards messages that the user has permission to view
5519             */
5520            @Override
5521            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5522                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5523                            QueryUtil.ALL_POS, null);
5524            }
5525    
5526            /**
5527             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5528             *
5529             * <p>
5530             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5531             * </p>
5532             *
5533             * @param groupId the group ID
5534             * @param categoryId the category ID
5535             * @param start the lower bound of the range of message-boards messages
5536             * @param end the upper bound of the range of message-boards messages (not inclusive)
5537             * @return the range of matching message-boards messages that the user has permission to view
5538             */
5539            @Override
5540            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5541                    int start, int end) {
5542                    return filterFindByG_C(groupId, categoryId, start, end, null);
5543            }
5544    
5545            /**
5546             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5547             *
5548             * <p>
5549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5550             * </p>
5551             *
5552             * @param groupId the group ID
5553             * @param categoryId the category ID
5554             * @param start the lower bound of the range of message-boards messages
5555             * @param end the upper bound of the range of message-boards messages (not inclusive)
5556             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5557             * @return the ordered range of matching message-boards messages that the user has permission to view
5558             */
5559            @Override
5560            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5561                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5562                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5563                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5564                    }
5565    
5566                    StringBundler query = null;
5567    
5568                    if (orderByComparator != null) {
5569                            query = new StringBundler(4 +
5570                                            (orderByComparator.getOrderByFields().length * 3));
5571                    }
5572                    else {
5573                            query = new StringBundler(4);
5574                    }
5575    
5576                    if (getDB().isSupportsInlineDistinct()) {
5577                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5578                    }
5579                    else {
5580                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5581                    }
5582    
5583                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5584    
5585                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5586    
5587                    if (!getDB().isSupportsInlineDistinct()) {
5588                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5589                    }
5590    
5591                    if (orderByComparator != null) {
5592                            if (getDB().isSupportsInlineDistinct()) {
5593                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5594                                            orderByComparator, true);
5595                            }
5596                            else {
5597                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5598                                            orderByComparator, true);
5599                            }
5600                    }
5601                    else {
5602                            if (getDB().isSupportsInlineDistinct()) {
5603                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5604                            }
5605                            else {
5606                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5607                            }
5608                    }
5609    
5610                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5611                                    MBMessage.class.getName(),
5612                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5613    
5614                    Session session = null;
5615    
5616                    try {
5617                            session = openSession();
5618    
5619                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5620    
5621                            if (getDB().isSupportsInlineDistinct()) {
5622                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5623                            }
5624                            else {
5625                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5626                            }
5627    
5628                            QueryPos qPos = QueryPos.getInstance(q);
5629    
5630                            qPos.add(groupId);
5631    
5632                            qPos.add(categoryId);
5633    
5634                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5635                    }
5636                    catch (Exception e) {
5637                            throw processException(e);
5638                    }
5639                    finally {
5640                            closeSession(session);
5641                    }
5642            }
5643    
5644            /**
5645             * 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;.
5646             *
5647             * @param messageId the primary key of the current message-boards message
5648             * @param groupId the group ID
5649             * @param categoryId the category ID
5650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5651             * @return the previous, current, and next message-boards message
5652             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5653             */
5654            @Override
5655            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5656                    long groupId, long categoryId,
5657                    OrderByComparator<MBMessage> orderByComparator)
5658                    throws NoSuchMessageException {
5659                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5660                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5661                                    orderByComparator);
5662                    }
5663    
5664                    MBMessage mbMessage = findByPrimaryKey(messageId);
5665    
5666                    Session session = null;
5667    
5668                    try {
5669                            session = openSession();
5670    
5671                            MBMessage[] array = new MBMessageImpl[3];
5672    
5673                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5674                                            categoryId, orderByComparator, true);
5675    
5676                            array[1] = mbMessage;
5677    
5678                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5679                                            categoryId, orderByComparator, false);
5680    
5681                            return array;
5682                    }
5683                    catch (Exception e) {
5684                            throw processException(e);
5685                    }
5686                    finally {
5687                            closeSession(session);
5688                    }
5689            }
5690    
5691            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5692                    MBMessage mbMessage, long groupId, long categoryId,
5693                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5694                    StringBundler query = null;
5695    
5696                    if (orderByComparator != null) {
5697                            query = new StringBundler(6 +
5698                                            (orderByComparator.getOrderByFields().length * 6));
5699                    }
5700                    else {
5701                            query = new StringBundler(3);
5702                    }
5703    
5704                    if (getDB().isSupportsInlineDistinct()) {
5705                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5706                    }
5707                    else {
5708                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5709                    }
5710    
5711                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5712    
5713                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5714    
5715                    if (!getDB().isSupportsInlineDistinct()) {
5716                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5717                    }
5718    
5719                    if (orderByComparator != null) {
5720                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5721    
5722                            if (orderByConditionFields.length > 0) {
5723                                    query.append(WHERE_AND);
5724                            }
5725    
5726                            for (int i = 0; i < orderByConditionFields.length; i++) {
5727                                    if (getDB().isSupportsInlineDistinct()) {
5728                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5729                                    }
5730                                    else {
5731                                            query.append(_ORDER_BY_ENTITY_TABLE);
5732                                    }
5733    
5734                                    query.append(orderByConditionFields[i]);
5735    
5736                                    if ((i + 1) < orderByConditionFields.length) {
5737                                            if (orderByComparator.isAscending() ^ previous) {
5738                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5739                                            }
5740                                            else {
5741                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5742                                            }
5743                                    }
5744                                    else {
5745                                            if (orderByComparator.isAscending() ^ previous) {
5746                                                    query.append(WHERE_GREATER_THAN);
5747                                            }
5748                                            else {
5749                                                    query.append(WHERE_LESSER_THAN);
5750                                            }
5751                                    }
5752                            }
5753    
5754                            query.append(ORDER_BY_CLAUSE);
5755    
5756                            String[] orderByFields = orderByComparator.getOrderByFields();
5757    
5758                            for (int i = 0; i < orderByFields.length; i++) {
5759                                    if (getDB().isSupportsInlineDistinct()) {
5760                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5761                                    }
5762                                    else {
5763                                            query.append(_ORDER_BY_ENTITY_TABLE);
5764                                    }
5765    
5766                                    query.append(orderByFields[i]);
5767    
5768                                    if ((i + 1) < orderByFields.length) {
5769                                            if (orderByComparator.isAscending() ^ previous) {
5770                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5771                                            }
5772                                            else {
5773                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5774                                            }
5775                                    }
5776                                    else {
5777                                            if (orderByComparator.isAscending() ^ previous) {
5778                                                    query.append(ORDER_BY_ASC);
5779                                            }
5780                                            else {
5781                                                    query.append(ORDER_BY_DESC);
5782                                            }
5783                                    }
5784                            }
5785                    }
5786                    else {
5787                            if (getDB().isSupportsInlineDistinct()) {
5788                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5789                            }
5790                            else {
5791                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5792                            }
5793                    }
5794    
5795                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5796                                    MBMessage.class.getName(),
5797                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5798    
5799                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5800    
5801                    q.setFirstResult(0);
5802                    q.setMaxResults(2);
5803    
5804                    if (getDB().isSupportsInlineDistinct()) {
5805                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5806                    }
5807                    else {
5808                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5809                    }
5810    
5811                    QueryPos qPos = QueryPos.getInstance(q);
5812    
5813                    qPos.add(groupId);
5814    
5815                    qPos.add(categoryId);
5816    
5817                    if (orderByComparator != null) {
5818                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5819    
5820                            for (Object value : values) {
5821                                    qPos.add(value);
5822                            }
5823                    }
5824    
5825                    List<MBMessage> list = q.list();
5826    
5827                    if (list.size() == 2) {
5828                            return list.get(1);
5829                    }
5830                    else {
5831                            return null;
5832                    }
5833            }
5834    
5835            /**
5836             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
5837             *
5838             * @param groupId the group ID
5839             * @param categoryId the category ID
5840             */
5841            @Override
5842            public void removeByG_C(long groupId, long categoryId) {
5843                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5844                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5845                            remove(mbMessage);
5846                    }
5847            }
5848    
5849            /**
5850             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
5851             *
5852             * @param groupId the group ID
5853             * @param categoryId the category ID
5854             * @return the number of matching message-boards messages
5855             */
5856            @Override
5857            public int countByG_C(long groupId, long categoryId) {
5858                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5859    
5860                    Object[] finderArgs = new Object[] { groupId, categoryId };
5861    
5862                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5863                                    this);
5864    
5865                    if (count == null) {
5866                            StringBundler query = new StringBundler(3);
5867    
5868                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5869    
5870                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5871    
5872                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5873    
5874                            String sql = query.toString();
5875    
5876                            Session session = null;
5877    
5878                            try {
5879                                    session = openSession();
5880    
5881                                    Query q = session.createQuery(sql);
5882    
5883                                    QueryPos qPos = QueryPos.getInstance(q);
5884    
5885                                    qPos.add(groupId);
5886    
5887                                    qPos.add(categoryId);
5888    
5889                                    count = (Long)q.uniqueResult();
5890    
5891                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5892                            }
5893                            catch (Exception e) {
5894                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5895    
5896                                    throw processException(e);
5897                            }
5898                            finally {
5899                                    closeSession(session);
5900                            }
5901                    }
5902    
5903                    return count.intValue();
5904            }
5905    
5906            /**
5907             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5908             *
5909             * @param groupId the group ID
5910             * @param categoryId the category ID
5911             * @return the number of matching message-boards messages that the user has permission to view
5912             */
5913            @Override
5914            public int filterCountByG_C(long groupId, long categoryId) {
5915                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5916                            return countByG_C(groupId, categoryId);
5917                    }
5918    
5919                    StringBundler query = new StringBundler(3);
5920    
5921                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5922    
5923                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5924    
5925                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5926    
5927                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5928                                    MBMessage.class.getName(),
5929                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5930    
5931                    Session session = null;
5932    
5933                    try {
5934                            session = openSession();
5935    
5936                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5937    
5938                            q.addScalar(COUNT_COLUMN_NAME,
5939                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5940    
5941                            QueryPos qPos = QueryPos.getInstance(q);
5942    
5943                            qPos.add(groupId);
5944    
5945                            qPos.add(categoryId);
5946    
5947                            Long count = (Long)q.uniqueResult();
5948    
5949                            return count.intValue();
5950                    }
5951                    catch (Exception e) {
5952                            throw processException(e);
5953                    }
5954                    finally {
5955                            closeSession(session);
5956                    }
5957            }
5958    
5959            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
5960            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
5961            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5962                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5963                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
5964                            new String[] {
5965                                    Long.class.getName(), Integer.class.getName(),
5966                                    
5967                            Integer.class.getName(), Integer.class.getName(),
5968                                    OrderByComparator.class.getName()
5969                            });
5970            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5971                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5972                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
5973                            new String[] { Long.class.getName(), Integer.class.getName() },
5974                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5975                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
5976                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5977            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5978                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5979                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
5980                            new String[] { Long.class.getName(), Integer.class.getName() });
5981    
5982            /**
5983             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5984             *
5985             * @param groupId the group ID
5986             * @param status the status
5987             * @return the matching message-boards messages
5988             */
5989            @Override
5990            public List<MBMessage> findByG_S(long groupId, int status) {
5991                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5992                            null);
5993            }
5994    
5995            /**
5996             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5997             *
5998             * <p>
5999             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6000             * </p>
6001             *
6002             * @param groupId the group ID
6003             * @param status the status
6004             * @param start the lower bound of the range of message-boards messages
6005             * @param end the upper bound of the range of message-boards messages (not inclusive)
6006             * @return the range of matching message-boards messages
6007             */
6008            @Override
6009            public List<MBMessage> findByG_S(long groupId, int status, int start,
6010                    int end) {
6011                    return findByG_S(groupId, status, start, end, null);
6012            }
6013    
6014            /**
6015             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6016             *
6017             * <p>
6018             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6019             * </p>
6020             *
6021             * @param groupId the group ID
6022             * @param status the status
6023             * @param start the lower bound of the range of message-boards messages
6024             * @param end the upper bound of the range of message-boards messages (not inclusive)
6025             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6026             * @return the ordered range of matching message-boards messages
6027             */
6028            @Override
6029            public List<MBMessage> findByG_S(long groupId, int status, int start,
6030                    int end, OrderByComparator<MBMessage> orderByComparator) {
6031                    boolean pagination = true;
6032                    FinderPath finderPath = null;
6033                    Object[] finderArgs = null;
6034    
6035                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6036                                    (orderByComparator == null)) {
6037                            pagination = false;
6038                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6039                            finderArgs = new Object[] { groupId, status };
6040                    }
6041                    else {
6042                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6043                            finderArgs = new Object[] {
6044                                            groupId, status,
6045                                            
6046                                            start, end, orderByComparator
6047                                    };
6048                    }
6049    
6050                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6051                                    finderArgs, this);
6052    
6053                    if ((list != null) && !list.isEmpty()) {
6054                            for (MBMessage mbMessage : list) {
6055                                    if ((groupId != mbMessage.getGroupId()) ||
6056                                                    (status != mbMessage.getStatus())) {
6057                                            list = null;
6058    
6059                                            break;
6060                                    }
6061                            }
6062                    }
6063    
6064                    if (list == null) {
6065                            StringBundler query = null;
6066    
6067                            if (orderByComparator != null) {
6068                                    query = new StringBundler(4 +
6069                                                    (orderByComparator.getOrderByFields().length * 3));
6070                            }
6071                            else {
6072                                    query = new StringBundler(4);
6073                            }
6074    
6075                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6076    
6077                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6078    
6079                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6080    
6081                            if (orderByComparator != null) {
6082                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6083                                            orderByComparator);
6084                            }
6085                            else
6086                             if (pagination) {
6087                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6088                            }
6089    
6090                            String sql = query.toString();
6091    
6092                            Session session = null;
6093    
6094                            try {
6095                                    session = openSession();
6096    
6097                                    Query q = session.createQuery(sql);
6098    
6099                                    QueryPos qPos = QueryPos.getInstance(q);
6100    
6101                                    qPos.add(groupId);
6102    
6103                                    qPos.add(status);
6104    
6105                                    if (!pagination) {
6106                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6107                                                            start, end, false);
6108    
6109                                            Collections.sort(list);
6110    
6111                                            list = Collections.unmodifiableList(list);
6112                                    }
6113                                    else {
6114                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6115                                                            start, end);
6116                                    }
6117    
6118                                    cacheResult(list);
6119    
6120                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6121                            }
6122                            catch (Exception e) {
6123                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6124    
6125                                    throw processException(e);
6126                            }
6127                            finally {
6128                                    closeSession(session);
6129                            }
6130                    }
6131    
6132                    return list;
6133            }
6134    
6135            /**
6136             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6137             *
6138             * @param groupId the group ID
6139             * @param status the status
6140             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6141             * @return the first matching message-boards message
6142             * @throws NoSuchMessageException if a matching message-boards message could not be found
6143             */
6144            @Override
6145            public MBMessage findByG_S_First(long groupId, int status,
6146                    OrderByComparator<MBMessage> orderByComparator)
6147                    throws NoSuchMessageException {
6148                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6149                                    orderByComparator);
6150    
6151                    if (mbMessage != null) {
6152                            return mbMessage;
6153                    }
6154    
6155                    StringBundler msg = new StringBundler(6);
6156    
6157                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6158    
6159                    msg.append("groupId=");
6160                    msg.append(groupId);
6161    
6162                    msg.append(", status=");
6163                    msg.append(status);
6164    
6165                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6166    
6167                    throw new NoSuchMessageException(msg.toString());
6168            }
6169    
6170            /**
6171             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6172             *
6173             * @param groupId the group ID
6174             * @param status the status
6175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6176             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6177             */
6178            @Override
6179            public MBMessage fetchByG_S_First(long groupId, int status,
6180                    OrderByComparator<MBMessage> orderByComparator) {
6181                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6182                                    orderByComparator);
6183    
6184                    if (!list.isEmpty()) {
6185                            return list.get(0);
6186                    }
6187    
6188                    return null;
6189            }
6190    
6191            /**
6192             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6193             *
6194             * @param groupId the group ID
6195             * @param status the status
6196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6197             * @return the last matching message-boards message
6198             * @throws NoSuchMessageException if a matching message-boards message could not be found
6199             */
6200            @Override
6201            public MBMessage findByG_S_Last(long groupId, int status,
6202                    OrderByComparator<MBMessage> orderByComparator)
6203                    throws NoSuchMessageException {
6204                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6205    
6206                    if (mbMessage != null) {
6207                            return mbMessage;
6208                    }
6209    
6210                    StringBundler msg = new StringBundler(6);
6211    
6212                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6213    
6214                    msg.append("groupId=");
6215                    msg.append(groupId);
6216    
6217                    msg.append(", status=");
6218                    msg.append(status);
6219    
6220                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6221    
6222                    throw new NoSuchMessageException(msg.toString());
6223            }
6224    
6225            /**
6226             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6227             *
6228             * @param groupId the group ID
6229             * @param status the status
6230             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6231             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6232             */
6233            @Override
6234            public MBMessage fetchByG_S_Last(long groupId, int status,
6235                    OrderByComparator<MBMessage> orderByComparator) {
6236                    int count = countByG_S(groupId, status);
6237    
6238                    if (count == 0) {
6239                            return null;
6240                    }
6241    
6242                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6243                                    orderByComparator);
6244    
6245                    if (!list.isEmpty()) {
6246                            return list.get(0);
6247                    }
6248    
6249                    return null;
6250            }
6251    
6252            /**
6253             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6254             *
6255             * @param messageId the primary key of the current message-boards message
6256             * @param groupId the group ID
6257             * @param status the status
6258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6259             * @return the previous, current, and next message-boards message
6260             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6261             */
6262            @Override
6263            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6264                    int status, OrderByComparator<MBMessage> orderByComparator)
6265                    throws NoSuchMessageException {
6266                    MBMessage mbMessage = findByPrimaryKey(messageId);
6267    
6268                    Session session = null;
6269    
6270                    try {
6271                            session = openSession();
6272    
6273                            MBMessage[] array = new MBMessageImpl[3];
6274    
6275                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6276                                            status, orderByComparator, true);
6277    
6278                            array[1] = mbMessage;
6279    
6280                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6281                                            status, orderByComparator, false);
6282    
6283                            return array;
6284                    }
6285                    catch (Exception e) {
6286                            throw processException(e);
6287                    }
6288                    finally {
6289                            closeSession(session);
6290                    }
6291            }
6292    
6293            protected MBMessage getByG_S_PrevAndNext(Session session,
6294                    MBMessage mbMessage, long groupId, int status,
6295                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6296                    StringBundler query = null;
6297    
6298                    if (orderByComparator != null) {
6299                            query = new StringBundler(6 +
6300                                            (orderByComparator.getOrderByFields().length * 6));
6301                    }
6302                    else {
6303                            query = new StringBundler(3);
6304                    }
6305    
6306                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6307    
6308                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6309    
6310                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6311    
6312                    if (orderByComparator != null) {
6313                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6314    
6315                            if (orderByConditionFields.length > 0) {
6316                                    query.append(WHERE_AND);
6317                            }
6318    
6319                            for (int i = 0; i < orderByConditionFields.length; i++) {
6320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6321                                    query.append(orderByConditionFields[i]);
6322    
6323                                    if ((i + 1) < orderByConditionFields.length) {
6324                                            if (orderByComparator.isAscending() ^ previous) {
6325                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6326                                            }
6327                                            else {
6328                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6329                                            }
6330                                    }
6331                                    else {
6332                                            if (orderByComparator.isAscending() ^ previous) {
6333                                                    query.append(WHERE_GREATER_THAN);
6334                                            }
6335                                            else {
6336                                                    query.append(WHERE_LESSER_THAN);
6337                                            }
6338                                    }
6339                            }
6340    
6341                            query.append(ORDER_BY_CLAUSE);
6342    
6343                            String[] orderByFields = orderByComparator.getOrderByFields();
6344    
6345                            for (int i = 0; i < orderByFields.length; i++) {
6346                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6347                                    query.append(orderByFields[i]);
6348    
6349                                    if ((i + 1) < orderByFields.length) {
6350                                            if (orderByComparator.isAscending() ^ previous) {
6351                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6352                                            }
6353                                            else {
6354                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6355                                            }
6356                                    }
6357                                    else {
6358                                            if (orderByComparator.isAscending() ^ previous) {
6359                                                    query.append(ORDER_BY_ASC);
6360                                            }
6361                                            else {
6362                                                    query.append(ORDER_BY_DESC);
6363                                            }
6364                                    }
6365                            }
6366                    }
6367                    else {
6368                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6369                    }
6370    
6371                    String sql = query.toString();
6372    
6373                    Query q = session.createQuery(sql);
6374    
6375                    q.setFirstResult(0);
6376                    q.setMaxResults(2);
6377    
6378                    QueryPos qPos = QueryPos.getInstance(q);
6379    
6380                    qPos.add(groupId);
6381    
6382                    qPos.add(status);
6383    
6384                    if (orderByComparator != null) {
6385                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6386    
6387                            for (Object value : values) {
6388                                    qPos.add(value);
6389                            }
6390                    }
6391    
6392                    List<MBMessage> list = q.list();
6393    
6394                    if (list.size() == 2) {
6395                            return list.get(1);
6396                    }
6397                    else {
6398                            return null;
6399                    }
6400            }
6401    
6402            /**
6403             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6404             *
6405             * @param groupId the group ID
6406             * @param status the status
6407             * @return the matching message-boards messages that the user has permission to view
6408             */
6409            @Override
6410            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6411                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6412                            QueryUtil.ALL_POS, null);
6413            }
6414    
6415            /**
6416             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6417             *
6418             * <p>
6419             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6420             * </p>
6421             *
6422             * @param groupId the group ID
6423             * @param status the status
6424             * @param start the lower bound of the range of message-boards messages
6425             * @param end the upper bound of the range of message-boards messages (not inclusive)
6426             * @return the range of matching message-boards messages that the user has permission to view
6427             */
6428            @Override
6429            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6430                    int end) {
6431                    return filterFindByG_S(groupId, status, start, end, null);
6432            }
6433    
6434            /**
6435             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6436             *
6437             * <p>
6438             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6439             * </p>
6440             *
6441             * @param groupId the group ID
6442             * @param status the status
6443             * @param start the lower bound of the range of message-boards messages
6444             * @param end the upper bound of the range of message-boards messages (not inclusive)
6445             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6446             * @return the ordered range of matching message-boards messages that the user has permission to view
6447             */
6448            @Override
6449            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6450                    int end, OrderByComparator<MBMessage> orderByComparator) {
6451                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6452                            return findByG_S(groupId, status, start, end, orderByComparator);
6453                    }
6454    
6455                    StringBundler query = null;
6456    
6457                    if (orderByComparator != null) {
6458                            query = new StringBundler(4 +
6459                                            (orderByComparator.getOrderByFields().length * 3));
6460                    }
6461                    else {
6462                            query = new StringBundler(4);
6463                    }
6464    
6465                    if (getDB().isSupportsInlineDistinct()) {
6466                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6467                    }
6468                    else {
6469                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6470                    }
6471    
6472                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6473    
6474                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6475    
6476                    if (!getDB().isSupportsInlineDistinct()) {
6477                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6478                    }
6479    
6480                    if (orderByComparator != null) {
6481                            if (getDB().isSupportsInlineDistinct()) {
6482                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6483                                            orderByComparator, true);
6484                            }
6485                            else {
6486                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6487                                            orderByComparator, true);
6488                            }
6489                    }
6490                    else {
6491                            if (getDB().isSupportsInlineDistinct()) {
6492                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6493                            }
6494                            else {
6495                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6496                            }
6497                    }
6498    
6499                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6500                                    MBMessage.class.getName(),
6501                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6502    
6503                    Session session = null;
6504    
6505                    try {
6506                            session = openSession();
6507    
6508                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6509    
6510                            if (getDB().isSupportsInlineDistinct()) {
6511                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6512                            }
6513                            else {
6514                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6515                            }
6516    
6517                            QueryPos qPos = QueryPos.getInstance(q);
6518    
6519                            qPos.add(groupId);
6520    
6521                            qPos.add(status);
6522    
6523                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6524                    }
6525                    catch (Exception e) {
6526                            throw processException(e);
6527                    }
6528                    finally {
6529                            closeSession(session);
6530                    }
6531            }
6532    
6533            /**
6534             * 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;.
6535             *
6536             * @param messageId the primary key of the current message-boards message
6537             * @param groupId the group ID
6538             * @param status the status
6539             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6540             * @return the previous, current, and next message-boards message
6541             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6542             */
6543            @Override
6544            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6545                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6546                    throws NoSuchMessageException {
6547                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6548                            return findByG_S_PrevAndNext(messageId, groupId, status,
6549                                    orderByComparator);
6550                    }
6551    
6552                    MBMessage mbMessage = findByPrimaryKey(messageId);
6553    
6554                    Session session = null;
6555    
6556                    try {
6557                            session = openSession();
6558    
6559                            MBMessage[] array = new MBMessageImpl[3];
6560    
6561                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6562                                            status, orderByComparator, true);
6563    
6564                            array[1] = mbMessage;
6565    
6566                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6567                                            status, orderByComparator, false);
6568    
6569                            return array;
6570                    }
6571                    catch (Exception e) {
6572                            throw processException(e);
6573                    }
6574                    finally {
6575                            closeSession(session);
6576                    }
6577            }
6578    
6579            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6580                    MBMessage mbMessage, long groupId, int status,
6581                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6582                    StringBundler query = null;
6583    
6584                    if (orderByComparator != null) {
6585                            query = new StringBundler(6 +
6586                                            (orderByComparator.getOrderByFields().length * 6));
6587                    }
6588                    else {
6589                            query = new StringBundler(3);
6590                    }
6591    
6592                    if (getDB().isSupportsInlineDistinct()) {
6593                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6594                    }
6595                    else {
6596                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6597                    }
6598    
6599                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6600    
6601                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6602    
6603                    if (!getDB().isSupportsInlineDistinct()) {
6604                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6605                    }
6606    
6607                    if (orderByComparator != null) {
6608                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6609    
6610                            if (orderByConditionFields.length > 0) {
6611                                    query.append(WHERE_AND);
6612                            }
6613    
6614                            for (int i = 0; i < orderByConditionFields.length; i++) {
6615                                    if (getDB().isSupportsInlineDistinct()) {
6616                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6617                                    }
6618                                    else {
6619                                            query.append(_ORDER_BY_ENTITY_TABLE);
6620                                    }
6621    
6622                                    query.append(orderByConditionFields[i]);
6623    
6624                                    if ((i + 1) < orderByConditionFields.length) {
6625                                            if (orderByComparator.isAscending() ^ previous) {
6626                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6627                                            }
6628                                            else {
6629                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6630                                            }
6631                                    }
6632                                    else {
6633                                            if (orderByComparator.isAscending() ^ previous) {
6634                                                    query.append(WHERE_GREATER_THAN);
6635                                            }
6636                                            else {
6637                                                    query.append(WHERE_LESSER_THAN);
6638                                            }
6639                                    }
6640                            }
6641    
6642                            query.append(ORDER_BY_CLAUSE);
6643    
6644                            String[] orderByFields = orderByComparator.getOrderByFields();
6645    
6646                            for (int i = 0; i < orderByFields.length; i++) {
6647                                    if (getDB().isSupportsInlineDistinct()) {
6648                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6649                                    }
6650                                    else {
6651                                            query.append(_ORDER_BY_ENTITY_TABLE);
6652                                    }
6653    
6654                                    query.append(orderByFields[i]);
6655    
6656                                    if ((i + 1) < orderByFields.length) {
6657                                            if (orderByComparator.isAscending() ^ previous) {
6658                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6659                                            }
6660                                            else {
6661                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6662                                            }
6663                                    }
6664                                    else {
6665                                            if (orderByComparator.isAscending() ^ previous) {
6666                                                    query.append(ORDER_BY_ASC);
6667                                            }
6668                                            else {
6669                                                    query.append(ORDER_BY_DESC);
6670                                            }
6671                                    }
6672                            }
6673                    }
6674                    else {
6675                            if (getDB().isSupportsInlineDistinct()) {
6676                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6677                            }
6678                            else {
6679                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6680                            }
6681                    }
6682    
6683                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6684                                    MBMessage.class.getName(),
6685                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6686    
6687                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6688    
6689                    q.setFirstResult(0);
6690                    q.setMaxResults(2);
6691    
6692                    if (getDB().isSupportsInlineDistinct()) {
6693                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6694                    }
6695                    else {
6696                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6697                    }
6698    
6699                    QueryPos qPos = QueryPos.getInstance(q);
6700    
6701                    qPos.add(groupId);
6702    
6703                    qPos.add(status);
6704    
6705                    if (orderByComparator != null) {
6706                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6707    
6708                            for (Object value : values) {
6709                                    qPos.add(value);
6710                            }
6711                    }
6712    
6713                    List<MBMessage> list = q.list();
6714    
6715                    if (list.size() == 2) {
6716                            return list.get(1);
6717                    }
6718                    else {
6719                            return null;
6720                    }
6721            }
6722    
6723            /**
6724             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6725             *
6726             * @param groupId the group ID
6727             * @param status the status
6728             */
6729            @Override
6730            public void removeByG_S(long groupId, int status) {
6731                    for (MBMessage mbMessage : findByG_S(groupId, status,
6732                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6733                            remove(mbMessage);
6734                    }
6735            }
6736    
6737            /**
6738             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6739             *
6740             * @param groupId the group ID
6741             * @param status the status
6742             * @return the number of matching message-boards messages
6743             */
6744            @Override
6745            public int countByG_S(long groupId, int status) {
6746                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6747    
6748                    Object[] finderArgs = new Object[] { groupId, status };
6749    
6750                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6751                                    this);
6752    
6753                    if (count == null) {
6754                            StringBundler query = new StringBundler(3);
6755    
6756                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6757    
6758                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6759    
6760                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6761    
6762                            String sql = query.toString();
6763    
6764                            Session session = null;
6765    
6766                            try {
6767                                    session = openSession();
6768    
6769                                    Query q = session.createQuery(sql);
6770    
6771                                    QueryPos qPos = QueryPos.getInstance(q);
6772    
6773                                    qPos.add(groupId);
6774    
6775                                    qPos.add(status);
6776    
6777                                    count = (Long)q.uniqueResult();
6778    
6779                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6780                            }
6781                            catch (Exception e) {
6782                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6783    
6784                                    throw processException(e);
6785                            }
6786                            finally {
6787                                    closeSession(session);
6788                            }
6789                    }
6790    
6791                    return count.intValue();
6792            }
6793    
6794            /**
6795             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6796             *
6797             * @param groupId the group ID
6798             * @param status the status
6799             * @return the number of matching message-boards messages that the user has permission to view
6800             */
6801            @Override
6802            public int filterCountByG_S(long groupId, int status) {
6803                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6804                            return countByG_S(groupId, status);
6805                    }
6806    
6807                    StringBundler query = new StringBundler(3);
6808    
6809                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6810    
6811                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6812    
6813                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6814    
6815                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6816                                    MBMessage.class.getName(),
6817                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6818    
6819                    Session session = null;
6820    
6821                    try {
6822                            session = openSession();
6823    
6824                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6825    
6826                            q.addScalar(COUNT_COLUMN_NAME,
6827                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6828    
6829                            QueryPos qPos = QueryPos.getInstance(q);
6830    
6831                            qPos.add(groupId);
6832    
6833                            qPos.add(status);
6834    
6835                            Long count = (Long)q.uniqueResult();
6836    
6837                            return count.intValue();
6838                    }
6839                    catch (Exception e) {
6840                            throw processException(e);
6841                    }
6842                    finally {
6843                            closeSession(session);
6844                    }
6845            }
6846    
6847            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6848            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6849            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6850                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6851                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
6852                            new String[] {
6853                                    Long.class.getName(), Integer.class.getName(),
6854                                    
6855                            Integer.class.getName(), Integer.class.getName(),
6856                                    OrderByComparator.class.getName()
6857                            });
6858            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6859                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6860                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
6861                            new String[] { Long.class.getName(), Integer.class.getName() },
6862                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
6863                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6864                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6865            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6866                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6867                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
6868                            new String[] { Long.class.getName(), Integer.class.getName() });
6869    
6870            /**
6871             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6872             *
6873             * @param companyId the company ID
6874             * @param status the status
6875             * @return the matching message-boards messages
6876             */
6877            @Override
6878            public List<MBMessage> findByC_S(long companyId, int status) {
6879                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6880                            QueryUtil.ALL_POS, null);
6881            }
6882    
6883            /**
6884             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6885             *
6886             * <p>
6887             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6888             * </p>
6889             *
6890             * @param companyId the company ID
6891             * @param status the status
6892             * @param start the lower bound of the range of message-boards messages
6893             * @param end the upper bound of the range of message-boards messages (not inclusive)
6894             * @return the range of matching message-boards messages
6895             */
6896            @Override
6897            public List<MBMessage> findByC_S(long companyId, int status, int start,
6898                    int end) {
6899                    return findByC_S(companyId, status, start, end, null);
6900            }
6901    
6902            /**
6903             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6904             *
6905             * <p>
6906             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6907             * </p>
6908             *
6909             * @param companyId the company ID
6910             * @param status the status
6911             * @param start the lower bound of the range of message-boards messages
6912             * @param end the upper bound of the range of message-boards messages (not inclusive)
6913             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6914             * @return the ordered range of matching message-boards messages
6915             */
6916            @Override
6917            public List<MBMessage> findByC_S(long companyId, int status, int start,
6918                    int end, OrderByComparator<MBMessage> orderByComparator) {
6919                    boolean pagination = true;
6920                    FinderPath finderPath = null;
6921                    Object[] finderArgs = null;
6922    
6923                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6924                                    (orderByComparator == null)) {
6925                            pagination = false;
6926                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6927                            finderArgs = new Object[] { companyId, status };
6928                    }
6929                    else {
6930                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6931                            finderArgs = new Object[] {
6932                                            companyId, status,
6933                                            
6934                                            start, end, orderByComparator
6935                                    };
6936                    }
6937    
6938                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6939                                    finderArgs, this);
6940    
6941                    if ((list != null) && !list.isEmpty()) {
6942                            for (MBMessage mbMessage : list) {
6943                                    if ((companyId != mbMessage.getCompanyId()) ||
6944                                                    (status != mbMessage.getStatus())) {
6945                                            list = null;
6946    
6947                                            break;
6948                                    }
6949                            }
6950                    }
6951    
6952                    if (list == null) {
6953                            StringBundler query = null;
6954    
6955                            if (orderByComparator != null) {
6956                                    query = new StringBundler(4 +
6957                                                    (orderByComparator.getOrderByFields().length * 3));
6958                            }
6959                            else {
6960                                    query = new StringBundler(4);
6961                            }
6962    
6963                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6964    
6965                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6966    
6967                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6968    
6969                            if (orderByComparator != null) {
6970                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6971                                            orderByComparator);
6972                            }
6973                            else
6974                             if (pagination) {
6975                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6976                            }
6977    
6978                            String sql = query.toString();
6979    
6980                            Session session = null;
6981    
6982                            try {
6983                                    session = openSession();
6984    
6985                                    Query q = session.createQuery(sql);
6986    
6987                                    QueryPos qPos = QueryPos.getInstance(q);
6988    
6989                                    qPos.add(companyId);
6990    
6991                                    qPos.add(status);
6992    
6993                                    if (!pagination) {
6994                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6995                                                            start, end, false);
6996    
6997                                            Collections.sort(list);
6998    
6999                                            list = Collections.unmodifiableList(list);
7000                                    }
7001                                    else {
7002                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7003                                                            start, end);
7004                                    }
7005    
7006                                    cacheResult(list);
7007    
7008                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7009                            }
7010                            catch (Exception e) {
7011                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7012    
7013                                    throw processException(e);
7014                            }
7015                            finally {
7016                                    closeSession(session);
7017                            }
7018                    }
7019    
7020                    return list;
7021            }
7022    
7023            /**
7024             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7025             *
7026             * @param companyId the company ID
7027             * @param status the status
7028             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7029             * @return the first matching message-boards message
7030             * @throws NoSuchMessageException if a matching message-boards message could not be found
7031             */
7032            @Override
7033            public MBMessage findByC_S_First(long companyId, int status,
7034                    OrderByComparator<MBMessage> orderByComparator)
7035                    throws NoSuchMessageException {
7036                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7037                                    orderByComparator);
7038    
7039                    if (mbMessage != null) {
7040                            return mbMessage;
7041                    }
7042    
7043                    StringBundler msg = new StringBundler(6);
7044    
7045                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7046    
7047                    msg.append("companyId=");
7048                    msg.append(companyId);
7049    
7050                    msg.append(", status=");
7051                    msg.append(status);
7052    
7053                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7054    
7055                    throw new NoSuchMessageException(msg.toString());
7056            }
7057    
7058            /**
7059             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7060             *
7061             * @param companyId the company ID
7062             * @param status the status
7063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7064             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7065             */
7066            @Override
7067            public MBMessage fetchByC_S_First(long companyId, int status,
7068                    OrderByComparator<MBMessage> orderByComparator) {
7069                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7070                                    orderByComparator);
7071    
7072                    if (!list.isEmpty()) {
7073                            return list.get(0);
7074                    }
7075    
7076                    return null;
7077            }
7078    
7079            /**
7080             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7081             *
7082             * @param companyId the company ID
7083             * @param status the status
7084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7085             * @return the last matching message-boards message
7086             * @throws NoSuchMessageException if a matching message-boards message could not be found
7087             */
7088            @Override
7089            public MBMessage findByC_S_Last(long companyId, int status,
7090                    OrderByComparator<MBMessage> orderByComparator)
7091                    throws NoSuchMessageException {
7092                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7093                                    orderByComparator);
7094    
7095                    if (mbMessage != null) {
7096                            return mbMessage;
7097                    }
7098    
7099                    StringBundler msg = new StringBundler(6);
7100    
7101                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7102    
7103                    msg.append("companyId=");
7104                    msg.append(companyId);
7105    
7106                    msg.append(", status=");
7107                    msg.append(status);
7108    
7109                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7110    
7111                    throw new NoSuchMessageException(msg.toString());
7112            }
7113    
7114            /**
7115             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7116             *
7117             * @param companyId the company ID
7118             * @param status the status
7119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7120             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7121             */
7122            @Override
7123            public MBMessage fetchByC_S_Last(long companyId, int status,
7124                    OrderByComparator<MBMessage> orderByComparator) {
7125                    int count = countByC_S(companyId, status);
7126    
7127                    if (count == 0) {
7128                            return null;
7129                    }
7130    
7131                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7132                                    orderByComparator);
7133    
7134                    if (!list.isEmpty()) {
7135                            return list.get(0);
7136                    }
7137    
7138                    return null;
7139            }
7140    
7141            /**
7142             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7143             *
7144             * @param messageId the primary key of the current message-boards message
7145             * @param companyId the company ID
7146             * @param status the status
7147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7148             * @return the previous, current, and next message-boards message
7149             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7150             */
7151            @Override
7152            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7153                    int status, OrderByComparator<MBMessage> orderByComparator)
7154                    throws NoSuchMessageException {
7155                    MBMessage mbMessage = findByPrimaryKey(messageId);
7156    
7157                    Session session = null;
7158    
7159                    try {
7160                            session = openSession();
7161    
7162                            MBMessage[] array = new MBMessageImpl[3];
7163    
7164                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7165                                            status, orderByComparator, true);
7166    
7167                            array[1] = mbMessage;
7168    
7169                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7170                                            status, orderByComparator, false);
7171    
7172                            return array;
7173                    }
7174                    catch (Exception e) {
7175                            throw processException(e);
7176                    }
7177                    finally {
7178                            closeSession(session);
7179                    }
7180            }
7181    
7182            protected MBMessage getByC_S_PrevAndNext(Session session,
7183                    MBMessage mbMessage, long companyId, int status,
7184                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7185                    StringBundler query = null;
7186    
7187                    if (orderByComparator != null) {
7188                            query = new StringBundler(6 +
7189                                            (orderByComparator.getOrderByFields().length * 6));
7190                    }
7191                    else {
7192                            query = new StringBundler(3);
7193                    }
7194    
7195                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7196    
7197                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7198    
7199                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7200    
7201                    if (orderByComparator != null) {
7202                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7203    
7204                            if (orderByConditionFields.length > 0) {
7205                                    query.append(WHERE_AND);
7206                            }
7207    
7208                            for (int i = 0; i < orderByConditionFields.length; i++) {
7209                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7210                                    query.append(orderByConditionFields[i]);
7211    
7212                                    if ((i + 1) < orderByConditionFields.length) {
7213                                            if (orderByComparator.isAscending() ^ previous) {
7214                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7215                                            }
7216                                            else {
7217                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7218                                            }
7219                                    }
7220                                    else {
7221                                            if (orderByComparator.isAscending() ^ previous) {
7222                                                    query.append(WHERE_GREATER_THAN);
7223                                            }
7224                                            else {
7225                                                    query.append(WHERE_LESSER_THAN);
7226                                            }
7227                                    }
7228                            }
7229    
7230                            query.append(ORDER_BY_CLAUSE);
7231    
7232                            String[] orderByFields = orderByComparator.getOrderByFields();
7233    
7234                            for (int i = 0; i < orderByFields.length; i++) {
7235                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7236                                    query.append(orderByFields[i]);
7237    
7238                                    if ((i + 1) < orderByFields.length) {
7239                                            if (orderByComparator.isAscending() ^ previous) {
7240                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7241                                            }
7242                                            else {
7243                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7244                                            }
7245                                    }
7246                                    else {
7247                                            if (orderByComparator.isAscending() ^ previous) {
7248                                                    query.append(ORDER_BY_ASC);
7249                                            }
7250                                            else {
7251                                                    query.append(ORDER_BY_DESC);
7252                                            }
7253                                    }
7254                            }
7255                    }
7256                    else {
7257                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7258                    }
7259    
7260                    String sql = query.toString();
7261    
7262                    Query q = session.createQuery(sql);
7263    
7264                    q.setFirstResult(0);
7265                    q.setMaxResults(2);
7266    
7267                    QueryPos qPos = QueryPos.getInstance(q);
7268    
7269                    qPos.add(companyId);
7270    
7271                    qPos.add(status);
7272    
7273                    if (orderByComparator != null) {
7274                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7275    
7276                            for (Object value : values) {
7277                                    qPos.add(value);
7278                            }
7279                    }
7280    
7281                    List<MBMessage> list = q.list();
7282    
7283                    if (list.size() == 2) {
7284                            return list.get(1);
7285                    }
7286                    else {
7287                            return null;
7288                    }
7289            }
7290    
7291            /**
7292             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7293             *
7294             * @param companyId the company ID
7295             * @param status the status
7296             */
7297            @Override
7298            public void removeByC_S(long companyId, int status) {
7299                    for (MBMessage mbMessage : findByC_S(companyId, status,
7300                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7301                            remove(mbMessage);
7302                    }
7303            }
7304    
7305            /**
7306             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7307             *
7308             * @param companyId the company ID
7309             * @param status the status
7310             * @return the number of matching message-boards messages
7311             */
7312            @Override
7313            public int countByC_S(long companyId, int status) {
7314                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7315    
7316                    Object[] finderArgs = new Object[] { companyId, status };
7317    
7318                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7319                                    this);
7320    
7321                    if (count == null) {
7322                            StringBundler query = new StringBundler(3);
7323    
7324                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7325    
7326                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7327    
7328                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7329    
7330                            String sql = query.toString();
7331    
7332                            Session session = null;
7333    
7334                            try {
7335                                    session = openSession();
7336    
7337                                    Query q = session.createQuery(sql);
7338    
7339                                    QueryPos qPos = QueryPos.getInstance(q);
7340    
7341                                    qPos.add(companyId);
7342    
7343                                    qPos.add(status);
7344    
7345                                    count = (Long)q.uniqueResult();
7346    
7347                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7348                            }
7349                            catch (Exception e) {
7350                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7351    
7352                                    throw processException(e);
7353                            }
7354                            finally {
7355                                    closeSession(session);
7356                            }
7357                    }
7358    
7359                    return count.intValue();
7360            }
7361    
7362            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7363            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7364            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7365                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7366                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7367                            new String[] {
7368                                    Long.class.getName(), Long.class.getName(),
7369                                    
7370                            Integer.class.getName(), Integer.class.getName(),
7371                                    OrderByComparator.class.getName()
7372                            });
7373            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7374                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7375                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7376                            new String[] { Long.class.getName(), Long.class.getName() },
7377                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7378                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7379                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7380            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7381                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7382                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7383                            new String[] { Long.class.getName(), Long.class.getName() });
7384            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7385                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7386                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7387                            new String[] { Long.class.getName(), Long.class.getName() });
7388    
7389            /**
7390             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7391             *
7392             * @param userId the user ID
7393             * @param classNameId the class name ID
7394             * @return the matching message-boards messages
7395             */
7396            @Override
7397            public List<MBMessage> findByU_C(long userId, long classNameId) {
7398                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7399                            QueryUtil.ALL_POS, null);
7400            }
7401    
7402            /**
7403             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7404             *
7405             * <p>
7406             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7407             * </p>
7408             *
7409             * @param userId the user ID
7410             * @param classNameId the class name ID
7411             * @param start the lower bound of the range of message-boards messages
7412             * @param end the upper bound of the range of message-boards messages (not inclusive)
7413             * @return the range of matching message-boards messages
7414             */
7415            @Override
7416            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7417                    int end) {
7418                    return findByU_C(userId, classNameId, start, end, null);
7419            }
7420    
7421            /**
7422             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7423             *
7424             * <p>
7425             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7426             * </p>
7427             *
7428             * @param userId the user ID
7429             * @param classNameId the class name ID
7430             * @param start the lower bound of the range of message-boards messages
7431             * @param end the upper bound of the range of message-boards messages (not inclusive)
7432             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7433             * @return the ordered range of matching message-boards messages
7434             */
7435            @Override
7436            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7437                    int end, OrderByComparator<MBMessage> orderByComparator) {
7438                    boolean pagination = true;
7439                    FinderPath finderPath = null;
7440                    Object[] finderArgs = null;
7441    
7442                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7443                                    (orderByComparator == null)) {
7444                            pagination = false;
7445                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7446                            finderArgs = new Object[] { userId, classNameId };
7447                    }
7448                    else {
7449                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7450                            finderArgs = new Object[] {
7451                                            userId, classNameId,
7452                                            
7453                                            start, end, orderByComparator
7454                                    };
7455                    }
7456    
7457                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7458                                    finderArgs, this);
7459    
7460                    if ((list != null) && !list.isEmpty()) {
7461                            for (MBMessage mbMessage : list) {
7462                                    if ((userId != mbMessage.getUserId()) ||
7463                                                    (classNameId != mbMessage.getClassNameId())) {
7464                                            list = null;
7465    
7466                                            break;
7467                                    }
7468                            }
7469                    }
7470    
7471                    if (list == null) {
7472                            StringBundler query = null;
7473    
7474                            if (orderByComparator != null) {
7475                                    query = new StringBundler(4 +
7476                                                    (orderByComparator.getOrderByFields().length * 3));
7477                            }
7478                            else {
7479                                    query = new StringBundler(4);
7480                            }
7481    
7482                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7483    
7484                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7485    
7486                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7487    
7488                            if (orderByComparator != null) {
7489                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7490                                            orderByComparator);
7491                            }
7492                            else
7493                             if (pagination) {
7494                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7495                            }
7496    
7497                            String sql = query.toString();
7498    
7499                            Session session = null;
7500    
7501                            try {
7502                                    session = openSession();
7503    
7504                                    Query q = session.createQuery(sql);
7505    
7506                                    QueryPos qPos = QueryPos.getInstance(q);
7507    
7508                                    qPos.add(userId);
7509    
7510                                    qPos.add(classNameId);
7511    
7512                                    if (!pagination) {
7513                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7514                                                            start, end, false);
7515    
7516                                            Collections.sort(list);
7517    
7518                                            list = Collections.unmodifiableList(list);
7519                                    }
7520                                    else {
7521                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7522                                                            start, end);
7523                                    }
7524    
7525                                    cacheResult(list);
7526    
7527                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7528                            }
7529                            catch (Exception e) {
7530                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7531    
7532                                    throw processException(e);
7533                            }
7534                            finally {
7535                                    closeSession(session);
7536                            }
7537                    }
7538    
7539                    return list;
7540            }
7541    
7542            /**
7543             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7544             *
7545             * @param userId the user ID
7546             * @param classNameId the class name ID
7547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7548             * @return the first matching message-boards message
7549             * @throws NoSuchMessageException if a matching message-boards message could not be found
7550             */
7551            @Override
7552            public MBMessage findByU_C_First(long userId, long classNameId,
7553                    OrderByComparator<MBMessage> orderByComparator)
7554                    throws NoSuchMessageException {
7555                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7556                                    orderByComparator);
7557    
7558                    if (mbMessage != null) {
7559                            return mbMessage;
7560                    }
7561    
7562                    StringBundler msg = new StringBundler(6);
7563    
7564                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7565    
7566                    msg.append("userId=");
7567                    msg.append(userId);
7568    
7569                    msg.append(", classNameId=");
7570                    msg.append(classNameId);
7571    
7572                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7573    
7574                    throw new NoSuchMessageException(msg.toString());
7575            }
7576    
7577            /**
7578             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7579             *
7580             * @param userId the user ID
7581             * @param classNameId the class name ID
7582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7583             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7584             */
7585            @Override
7586            public MBMessage fetchByU_C_First(long userId, long classNameId,
7587                    OrderByComparator<MBMessage> orderByComparator) {
7588                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7589                                    orderByComparator);
7590    
7591                    if (!list.isEmpty()) {
7592                            return list.get(0);
7593                    }
7594    
7595                    return null;
7596            }
7597    
7598            /**
7599             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7600             *
7601             * @param userId the user ID
7602             * @param classNameId the class name ID
7603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7604             * @return the last matching message-boards message
7605             * @throws NoSuchMessageException if a matching message-boards message could not be found
7606             */
7607            @Override
7608            public MBMessage findByU_C_Last(long userId, long classNameId,
7609                    OrderByComparator<MBMessage> orderByComparator)
7610                    throws NoSuchMessageException {
7611                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7612                                    orderByComparator);
7613    
7614                    if (mbMessage != null) {
7615                            return mbMessage;
7616                    }
7617    
7618                    StringBundler msg = new StringBundler(6);
7619    
7620                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7621    
7622                    msg.append("userId=");
7623                    msg.append(userId);
7624    
7625                    msg.append(", classNameId=");
7626                    msg.append(classNameId);
7627    
7628                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7629    
7630                    throw new NoSuchMessageException(msg.toString());
7631            }
7632    
7633            /**
7634             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7635             *
7636             * @param userId the user ID
7637             * @param classNameId the class name ID
7638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7639             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7640             */
7641            @Override
7642            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7643                    OrderByComparator<MBMessage> orderByComparator) {
7644                    int count = countByU_C(userId, classNameId);
7645    
7646                    if (count == 0) {
7647                            return null;
7648                    }
7649    
7650                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7651                                    orderByComparator);
7652    
7653                    if (!list.isEmpty()) {
7654                            return list.get(0);
7655                    }
7656    
7657                    return null;
7658            }
7659    
7660            /**
7661             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7662             *
7663             * @param messageId the primary key of the current message-boards message
7664             * @param userId the user ID
7665             * @param classNameId the class name ID
7666             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7667             * @return the previous, current, and next message-boards message
7668             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7669             */
7670            @Override
7671            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7672                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7673                    throws NoSuchMessageException {
7674                    MBMessage mbMessage = findByPrimaryKey(messageId);
7675    
7676                    Session session = null;
7677    
7678                    try {
7679                            session = openSession();
7680    
7681                            MBMessage[] array = new MBMessageImpl[3];
7682    
7683                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7684                                            classNameId, orderByComparator, true);
7685    
7686                            array[1] = mbMessage;
7687    
7688                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7689                                            classNameId, orderByComparator, false);
7690    
7691                            return array;
7692                    }
7693                    catch (Exception e) {
7694                            throw processException(e);
7695                    }
7696                    finally {
7697                            closeSession(session);
7698                    }
7699            }
7700    
7701            protected MBMessage getByU_C_PrevAndNext(Session session,
7702                    MBMessage mbMessage, long userId, long classNameId,
7703                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7704                    StringBundler query = null;
7705    
7706                    if (orderByComparator != null) {
7707                            query = new StringBundler(6 +
7708                                            (orderByComparator.getOrderByFields().length * 6));
7709                    }
7710                    else {
7711                            query = new StringBundler(3);
7712                    }
7713    
7714                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7715    
7716                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7717    
7718                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7719    
7720                    if (orderByComparator != null) {
7721                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7722    
7723                            if (orderByConditionFields.length > 0) {
7724                                    query.append(WHERE_AND);
7725                            }
7726    
7727                            for (int i = 0; i < orderByConditionFields.length; i++) {
7728                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7729                                    query.append(orderByConditionFields[i]);
7730    
7731                                    if ((i + 1) < orderByConditionFields.length) {
7732                                            if (orderByComparator.isAscending() ^ previous) {
7733                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7734                                            }
7735                                            else {
7736                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7737                                            }
7738                                    }
7739                                    else {
7740                                            if (orderByComparator.isAscending() ^ previous) {
7741                                                    query.append(WHERE_GREATER_THAN);
7742                                            }
7743                                            else {
7744                                                    query.append(WHERE_LESSER_THAN);
7745                                            }
7746                                    }
7747                            }
7748    
7749                            query.append(ORDER_BY_CLAUSE);
7750    
7751                            String[] orderByFields = orderByComparator.getOrderByFields();
7752    
7753                            for (int i = 0; i < orderByFields.length; i++) {
7754                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7755                                    query.append(orderByFields[i]);
7756    
7757                                    if ((i + 1) < orderByFields.length) {
7758                                            if (orderByComparator.isAscending() ^ previous) {
7759                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7760                                            }
7761                                            else {
7762                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7763                                            }
7764                                    }
7765                                    else {
7766                                            if (orderByComparator.isAscending() ^ previous) {
7767                                                    query.append(ORDER_BY_ASC);
7768                                            }
7769                                            else {
7770                                                    query.append(ORDER_BY_DESC);
7771                                            }
7772                                    }
7773                            }
7774                    }
7775                    else {
7776                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7777                    }
7778    
7779                    String sql = query.toString();
7780    
7781                    Query q = session.createQuery(sql);
7782    
7783                    q.setFirstResult(0);
7784                    q.setMaxResults(2);
7785    
7786                    QueryPos qPos = QueryPos.getInstance(q);
7787    
7788                    qPos.add(userId);
7789    
7790                    qPos.add(classNameId);
7791    
7792                    if (orderByComparator != null) {
7793                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7794    
7795                            for (Object value : values) {
7796                                    qPos.add(value);
7797                            }
7798                    }
7799    
7800                    List<MBMessage> list = q.list();
7801    
7802                    if (list.size() == 2) {
7803                            return list.get(1);
7804                    }
7805                    else {
7806                            return null;
7807                    }
7808            }
7809    
7810            /**
7811             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7812             *
7813             * <p>
7814             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7815             * </p>
7816             *
7817             * @param userId the user ID
7818             * @param classNameIds the class name IDs
7819             * @return the matching message-boards messages
7820             */
7821            @Override
7822            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
7823                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7824                            QueryUtil.ALL_POS, null);
7825            }
7826    
7827            /**
7828             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7829             *
7830             * <p>
7831             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7832             * </p>
7833             *
7834             * @param userId the user ID
7835             * @param classNameIds the class name IDs
7836             * @param start the lower bound of the range of message-boards messages
7837             * @param end the upper bound of the range of message-boards messages (not inclusive)
7838             * @return the range of matching message-boards messages
7839             */
7840            @Override
7841            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7842                    int start, int end) {
7843                    return findByU_C(userId, classNameIds, start, end, null);
7844            }
7845    
7846            /**
7847             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7848             *
7849             * <p>
7850             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7851             * </p>
7852             *
7853             * @param userId the user ID
7854             * @param classNameIds the class name IDs
7855             * @param start the lower bound of the range of message-boards messages
7856             * @param end the upper bound of the range of message-boards messages (not inclusive)
7857             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7858             * @return the ordered range of matching message-boards messages
7859             */
7860            @Override
7861            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7862                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
7863                    if (classNameIds == null) {
7864                            classNameIds = new long[0];
7865                    }
7866                    else {
7867                            classNameIds = ArrayUtil.unique(classNameIds);
7868                    }
7869    
7870                    if (classNameIds.length == 1) {
7871                            return findByU_C(userId, classNameIds[0], start, end,
7872                                    orderByComparator);
7873                    }
7874    
7875                    boolean pagination = true;
7876                    Object[] finderArgs = null;
7877    
7878                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7879                                    (orderByComparator == null)) {
7880                            pagination = false;
7881                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7882                    }
7883                    else {
7884                            finderArgs = new Object[] {
7885                                            userId, StringUtil.merge(classNameIds),
7886                                            
7887                                            start, end, orderByComparator
7888                                    };
7889                    }
7890    
7891                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7892                                    finderArgs, this);
7893    
7894                    if ((list != null) && !list.isEmpty()) {
7895                            for (MBMessage mbMessage : list) {
7896                                    if ((userId != mbMessage.getUserId()) ||
7897                                                    !ArrayUtil.contains(classNameIds,
7898                                                            mbMessage.getClassNameId())) {
7899                                            list = null;
7900    
7901                                            break;
7902                                    }
7903                            }
7904                    }
7905    
7906                    if (list == null) {
7907                            StringBundler query = new StringBundler();
7908    
7909                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7910    
7911                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7912    
7913                            if (classNameIds.length > 0) {
7914                                    query.append(StringPool.OPEN_PARENTHESIS);
7915    
7916                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
7917    
7918                                    query.append(StringUtil.merge(classNameIds));
7919    
7920                                    query.append(StringPool.CLOSE_PARENTHESIS);
7921    
7922                                    query.append(StringPool.CLOSE_PARENTHESIS);
7923                            }
7924    
7925                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
7926                                                    1)), query.index() - 1);
7927    
7928                            if (orderByComparator != null) {
7929                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7930                                            orderByComparator);
7931                            }
7932                            else
7933                             if (pagination) {
7934                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7935                            }
7936    
7937                            String sql = query.toString();
7938    
7939                            Session session = null;
7940    
7941                            try {
7942                                    session = openSession();
7943    
7944                                    Query q = session.createQuery(sql);
7945    
7946                                    QueryPos qPos = QueryPos.getInstance(q);
7947    
7948                                    qPos.add(userId);
7949    
7950                                    if (!pagination) {
7951                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7952                                                            start, end, false);
7953    
7954                                            Collections.sort(list);
7955    
7956                                            list = Collections.unmodifiableList(list);
7957                                    }
7958                                    else {
7959                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7960                                                            start, end);
7961                                    }
7962    
7963                                    cacheResult(list);
7964    
7965                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7966                                            finderArgs, list);
7967                            }
7968                            catch (Exception e) {
7969                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7970                                            finderArgs);
7971    
7972                                    throw processException(e);
7973                            }
7974                            finally {
7975                                    closeSession(session);
7976                            }
7977                    }
7978    
7979                    return list;
7980            }
7981    
7982            /**
7983             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
7984             *
7985             * @param userId the user ID
7986             * @param classNameId the class name ID
7987             */
7988            @Override
7989            public void removeByU_C(long userId, long classNameId) {
7990                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
7991                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7992                            remove(mbMessage);
7993                    }
7994            }
7995    
7996            /**
7997             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
7998             *
7999             * @param userId the user ID
8000             * @param classNameId the class name ID
8001             * @return the number of matching message-boards messages
8002             */
8003            @Override
8004            public int countByU_C(long userId, long classNameId) {
8005                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8006    
8007                    Object[] finderArgs = new Object[] { userId, classNameId };
8008    
8009                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8010                                    this);
8011    
8012                    if (count == null) {
8013                            StringBundler query = new StringBundler(3);
8014    
8015                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8016    
8017                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8018    
8019                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8020    
8021                            String sql = query.toString();
8022    
8023                            Session session = null;
8024    
8025                            try {
8026                                    session = openSession();
8027    
8028                                    Query q = session.createQuery(sql);
8029    
8030                                    QueryPos qPos = QueryPos.getInstance(q);
8031    
8032                                    qPos.add(userId);
8033    
8034                                    qPos.add(classNameId);
8035    
8036                                    count = (Long)q.uniqueResult();
8037    
8038                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8039                            }
8040                            catch (Exception e) {
8041                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8042    
8043                                    throw processException(e);
8044                            }
8045                            finally {
8046                                    closeSession(session);
8047                            }
8048                    }
8049    
8050                    return count.intValue();
8051            }
8052    
8053            /**
8054             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8055             *
8056             * @param userId the user ID
8057             * @param classNameIds the class name IDs
8058             * @return the number of matching message-boards messages
8059             */
8060            @Override
8061            public int countByU_C(long userId, long[] classNameIds) {
8062                    if (classNameIds == null) {
8063                            classNameIds = new long[0];
8064                    }
8065                    else {
8066                            classNameIds = ArrayUtil.unique(classNameIds);
8067                    }
8068    
8069                    Object[] finderArgs = new Object[] {
8070                                    userId, StringUtil.merge(classNameIds)
8071                            };
8072    
8073                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8074                                    finderArgs, this);
8075    
8076                    if (count == null) {
8077                            StringBundler query = new StringBundler();
8078    
8079                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8080    
8081                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8082    
8083                            if (classNameIds.length > 0) {
8084                                    query.append(StringPool.OPEN_PARENTHESIS);
8085    
8086                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8087    
8088                                    query.append(StringUtil.merge(classNameIds));
8089    
8090                                    query.append(StringPool.CLOSE_PARENTHESIS);
8091    
8092                                    query.append(StringPool.CLOSE_PARENTHESIS);
8093                            }
8094    
8095                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8096                                                    1)), query.index() - 1);
8097    
8098                            String sql = query.toString();
8099    
8100                            Session session = null;
8101    
8102                            try {
8103                                    session = openSession();
8104    
8105                                    Query q = session.createQuery(sql);
8106    
8107                                    QueryPos qPos = QueryPos.getInstance(q);
8108    
8109                                    qPos.add(userId);
8110    
8111                                    count = (Long)q.uniqueResult();
8112    
8113                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8114                                            finderArgs, count);
8115                            }
8116                            catch (Exception e) {
8117                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8118                                            finderArgs);
8119    
8120                                    throw processException(e);
8121                            }
8122                            finally {
8123                                    closeSession(session);
8124                            }
8125                    }
8126    
8127                    return count.intValue();
8128            }
8129    
8130            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8131            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8132            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8133            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8134                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8135                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8136                            new String[] {
8137                                    Long.class.getName(), Long.class.getName(),
8138                                    
8139                            Integer.class.getName(), Integer.class.getName(),
8140                                    OrderByComparator.class.getName()
8141                            });
8142            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8143                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8145                            new String[] { Long.class.getName(), Long.class.getName() },
8146                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8147                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8148                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8149            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8150                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8152                            new String[] { Long.class.getName(), Long.class.getName() });
8153    
8154            /**
8155             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8156             *
8157             * @param classNameId the class name ID
8158             * @param classPK the class p k
8159             * @return the matching message-boards messages
8160             */
8161            @Override
8162            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8163                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8164                            QueryUtil.ALL_POS, null);
8165            }
8166    
8167            /**
8168             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8169             *
8170             * <p>
8171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8172             * </p>
8173             *
8174             * @param classNameId the class name ID
8175             * @param classPK the class p k
8176             * @param start the lower bound of the range of message-boards messages
8177             * @param end the upper bound of the range of message-boards messages (not inclusive)
8178             * @return the range of matching message-boards messages
8179             */
8180            @Override
8181            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8182                    int end) {
8183                    return findByC_C(classNameId, classPK, start, end, null);
8184            }
8185    
8186            /**
8187             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8188             *
8189             * <p>
8190             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8191             * </p>
8192             *
8193             * @param classNameId the class name ID
8194             * @param classPK the class p k
8195             * @param start the lower bound of the range of message-boards messages
8196             * @param end the upper bound of the range of message-boards messages (not inclusive)
8197             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8198             * @return the ordered range of matching message-boards messages
8199             */
8200            @Override
8201            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8202                    int end, OrderByComparator<MBMessage> orderByComparator) {
8203                    boolean pagination = true;
8204                    FinderPath finderPath = null;
8205                    Object[] finderArgs = null;
8206    
8207                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8208                                    (orderByComparator == null)) {
8209                            pagination = false;
8210                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8211                            finderArgs = new Object[] { classNameId, classPK };
8212                    }
8213                    else {
8214                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8215                            finderArgs = new Object[] {
8216                                            classNameId, classPK,
8217                                            
8218                                            start, end, orderByComparator
8219                                    };
8220                    }
8221    
8222                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8223                                    finderArgs, this);
8224    
8225                    if ((list != null) && !list.isEmpty()) {
8226                            for (MBMessage mbMessage : list) {
8227                                    if ((classNameId != mbMessage.getClassNameId()) ||
8228                                                    (classPK != mbMessage.getClassPK())) {
8229                                            list = null;
8230    
8231                                            break;
8232                                    }
8233                            }
8234                    }
8235    
8236                    if (list == null) {
8237                            StringBundler query = null;
8238    
8239                            if (orderByComparator != null) {
8240                                    query = new StringBundler(4 +
8241                                                    (orderByComparator.getOrderByFields().length * 3));
8242                            }
8243                            else {
8244                                    query = new StringBundler(4);
8245                            }
8246    
8247                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8248    
8249                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8250    
8251                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8252    
8253                            if (orderByComparator != null) {
8254                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8255                                            orderByComparator);
8256                            }
8257                            else
8258                             if (pagination) {
8259                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8260                            }
8261    
8262                            String sql = query.toString();
8263    
8264                            Session session = null;
8265    
8266                            try {
8267                                    session = openSession();
8268    
8269                                    Query q = session.createQuery(sql);
8270    
8271                                    QueryPos qPos = QueryPos.getInstance(q);
8272    
8273                                    qPos.add(classNameId);
8274    
8275                                    qPos.add(classPK);
8276    
8277                                    if (!pagination) {
8278                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8279                                                            start, end, false);
8280    
8281                                            Collections.sort(list);
8282    
8283                                            list = Collections.unmodifiableList(list);
8284                                    }
8285                                    else {
8286                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8287                                                            start, end);
8288                                    }
8289    
8290                                    cacheResult(list);
8291    
8292                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8293                            }
8294                            catch (Exception e) {
8295                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8296    
8297                                    throw processException(e);
8298                            }
8299                            finally {
8300                                    closeSession(session);
8301                            }
8302                    }
8303    
8304                    return list;
8305            }
8306    
8307            /**
8308             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8309             *
8310             * @param classNameId the class name ID
8311             * @param classPK the class p k
8312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8313             * @return the first matching message-boards message
8314             * @throws NoSuchMessageException if a matching message-boards message could not be found
8315             */
8316            @Override
8317            public MBMessage findByC_C_First(long classNameId, long classPK,
8318                    OrderByComparator<MBMessage> orderByComparator)
8319                    throws NoSuchMessageException {
8320                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8321                                    orderByComparator);
8322    
8323                    if (mbMessage != null) {
8324                            return mbMessage;
8325                    }
8326    
8327                    StringBundler msg = new StringBundler(6);
8328    
8329                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8330    
8331                    msg.append("classNameId=");
8332                    msg.append(classNameId);
8333    
8334                    msg.append(", classPK=");
8335                    msg.append(classPK);
8336    
8337                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8338    
8339                    throw new NoSuchMessageException(msg.toString());
8340            }
8341    
8342            /**
8343             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8344             *
8345             * @param classNameId the class name ID
8346             * @param classPK the class p k
8347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8348             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8349             */
8350            @Override
8351            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8352                    OrderByComparator<MBMessage> orderByComparator) {
8353                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8354                                    orderByComparator);
8355    
8356                    if (!list.isEmpty()) {
8357                            return list.get(0);
8358                    }
8359    
8360                    return null;
8361            }
8362    
8363            /**
8364             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8365             *
8366             * @param classNameId the class name ID
8367             * @param classPK the class p k
8368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8369             * @return the last matching message-boards message
8370             * @throws NoSuchMessageException if a matching message-boards message could not be found
8371             */
8372            @Override
8373            public MBMessage findByC_C_Last(long classNameId, long classPK,
8374                    OrderByComparator<MBMessage> orderByComparator)
8375                    throws NoSuchMessageException {
8376                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8377                                    orderByComparator);
8378    
8379                    if (mbMessage != null) {
8380                            return mbMessage;
8381                    }
8382    
8383                    StringBundler msg = new StringBundler(6);
8384    
8385                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8386    
8387                    msg.append("classNameId=");
8388                    msg.append(classNameId);
8389    
8390                    msg.append(", classPK=");
8391                    msg.append(classPK);
8392    
8393                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8394    
8395                    throw new NoSuchMessageException(msg.toString());
8396            }
8397    
8398            /**
8399             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8400             *
8401             * @param classNameId the class name ID
8402             * @param classPK the class p k
8403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8404             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8405             */
8406            @Override
8407            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8408                    OrderByComparator<MBMessage> orderByComparator) {
8409                    int count = countByC_C(classNameId, classPK);
8410    
8411                    if (count == 0) {
8412                            return null;
8413                    }
8414    
8415                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8416                                    count, orderByComparator);
8417    
8418                    if (!list.isEmpty()) {
8419                            return list.get(0);
8420                    }
8421    
8422                    return null;
8423            }
8424    
8425            /**
8426             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8427             *
8428             * @param messageId the primary key of the current message-boards message
8429             * @param classNameId the class name ID
8430             * @param classPK the class p k
8431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8432             * @return the previous, current, and next message-boards message
8433             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8434             */
8435            @Override
8436            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8437                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8438                    throws NoSuchMessageException {
8439                    MBMessage mbMessage = findByPrimaryKey(messageId);
8440    
8441                    Session session = null;
8442    
8443                    try {
8444                            session = openSession();
8445    
8446                            MBMessage[] array = new MBMessageImpl[3];
8447    
8448                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8449                                            classPK, orderByComparator, true);
8450    
8451                            array[1] = mbMessage;
8452    
8453                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8454                                            classPK, orderByComparator, false);
8455    
8456                            return array;
8457                    }
8458                    catch (Exception e) {
8459                            throw processException(e);
8460                    }
8461                    finally {
8462                            closeSession(session);
8463                    }
8464            }
8465    
8466            protected MBMessage getByC_C_PrevAndNext(Session session,
8467                    MBMessage mbMessage, long classNameId, long classPK,
8468                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8469                    StringBundler query = null;
8470    
8471                    if (orderByComparator != null) {
8472                            query = new StringBundler(6 +
8473                                            (orderByComparator.getOrderByFields().length * 6));
8474                    }
8475                    else {
8476                            query = new StringBundler(3);
8477                    }
8478    
8479                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8480    
8481                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8482    
8483                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8484    
8485                    if (orderByComparator != null) {
8486                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8487    
8488                            if (orderByConditionFields.length > 0) {
8489                                    query.append(WHERE_AND);
8490                            }
8491    
8492                            for (int i = 0; i < orderByConditionFields.length; i++) {
8493                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8494                                    query.append(orderByConditionFields[i]);
8495    
8496                                    if ((i + 1) < orderByConditionFields.length) {
8497                                            if (orderByComparator.isAscending() ^ previous) {
8498                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8499                                            }
8500                                            else {
8501                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8502                                            }
8503                                    }
8504                                    else {
8505                                            if (orderByComparator.isAscending() ^ previous) {
8506                                                    query.append(WHERE_GREATER_THAN);
8507                                            }
8508                                            else {
8509                                                    query.append(WHERE_LESSER_THAN);
8510                                            }
8511                                    }
8512                            }
8513    
8514                            query.append(ORDER_BY_CLAUSE);
8515    
8516                            String[] orderByFields = orderByComparator.getOrderByFields();
8517    
8518                            for (int i = 0; i < orderByFields.length; i++) {
8519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8520                                    query.append(orderByFields[i]);
8521    
8522                                    if ((i + 1) < orderByFields.length) {
8523                                            if (orderByComparator.isAscending() ^ previous) {
8524                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8525                                            }
8526                                            else {
8527                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8528                                            }
8529                                    }
8530                                    else {
8531                                            if (orderByComparator.isAscending() ^ previous) {
8532                                                    query.append(ORDER_BY_ASC);
8533                                            }
8534                                            else {
8535                                                    query.append(ORDER_BY_DESC);
8536                                            }
8537                                    }
8538                            }
8539                    }
8540                    else {
8541                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8542                    }
8543    
8544                    String sql = query.toString();
8545    
8546                    Query q = session.createQuery(sql);
8547    
8548                    q.setFirstResult(0);
8549                    q.setMaxResults(2);
8550    
8551                    QueryPos qPos = QueryPos.getInstance(q);
8552    
8553                    qPos.add(classNameId);
8554    
8555                    qPos.add(classPK);
8556    
8557                    if (orderByComparator != null) {
8558                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8559    
8560                            for (Object value : values) {
8561                                    qPos.add(value);
8562                            }
8563                    }
8564    
8565                    List<MBMessage> list = q.list();
8566    
8567                    if (list.size() == 2) {
8568                            return list.get(1);
8569                    }
8570                    else {
8571                            return null;
8572                    }
8573            }
8574    
8575            /**
8576             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8577             *
8578             * @param classNameId the class name ID
8579             * @param classPK the class p k
8580             */
8581            @Override
8582            public void removeByC_C(long classNameId, long classPK) {
8583                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8584                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8585                            remove(mbMessage);
8586                    }
8587            }
8588    
8589            /**
8590             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8591             *
8592             * @param classNameId the class name ID
8593             * @param classPK the class p k
8594             * @return the number of matching message-boards messages
8595             */
8596            @Override
8597            public int countByC_C(long classNameId, long classPK) {
8598                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8599    
8600                    Object[] finderArgs = new Object[] { classNameId, classPK };
8601    
8602                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8603                                    this);
8604    
8605                    if (count == null) {
8606                            StringBundler query = new StringBundler(3);
8607    
8608                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8609    
8610                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8611    
8612                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8613    
8614                            String sql = query.toString();
8615    
8616                            Session session = null;
8617    
8618                            try {
8619                                    session = openSession();
8620    
8621                                    Query q = session.createQuery(sql);
8622    
8623                                    QueryPos qPos = QueryPos.getInstance(q);
8624    
8625                                    qPos.add(classNameId);
8626    
8627                                    qPos.add(classPK);
8628    
8629                                    count = (Long)q.uniqueResult();
8630    
8631                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8632                            }
8633                            catch (Exception e) {
8634                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8635    
8636                                    throw processException(e);
8637                            }
8638                            finally {
8639                                    closeSession(session);
8640                            }
8641                    }
8642    
8643                    return count.intValue();
8644            }
8645    
8646            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8647            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8648            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8649                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8650                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8651                            new String[] {
8652                                    Long.class.getName(), Long.class.getName(),
8653                                    
8654                            Integer.class.getName(), Integer.class.getName(),
8655                                    OrderByComparator.class.getName()
8656                            });
8657            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8658                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8659                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8660                            new String[] { Long.class.getName(), Long.class.getName() },
8661                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8662                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8663                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8664            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8665                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8666                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8667                            new String[] { Long.class.getName(), Long.class.getName() });
8668    
8669            /**
8670             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8671             *
8672             * @param threadId the thread ID
8673             * @param parentMessageId the parent message ID
8674             * @return the matching message-boards messages
8675             */
8676            @Override
8677            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
8678                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8679                            QueryUtil.ALL_POS, null);
8680            }
8681    
8682            /**
8683             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8684             *
8685             * <p>
8686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8687             * </p>
8688             *
8689             * @param threadId the thread ID
8690             * @param parentMessageId the parent message ID
8691             * @param start the lower bound of the range of message-boards messages
8692             * @param end the upper bound of the range of message-boards messages (not inclusive)
8693             * @return the range of matching message-boards messages
8694             */
8695            @Override
8696            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8697                    int start, int end) {
8698                    return findByT_P(threadId, parentMessageId, start, end, null);
8699            }
8700    
8701            /**
8702             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8703             *
8704             * <p>
8705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8706             * </p>
8707             *
8708             * @param threadId the thread ID
8709             * @param parentMessageId the parent message ID
8710             * @param start the lower bound of the range of message-boards messages
8711             * @param end the upper bound of the range of message-boards messages (not inclusive)
8712             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8713             * @return the ordered range of matching message-boards messages
8714             */
8715            @Override
8716            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8717                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8718                    boolean pagination = true;
8719                    FinderPath finderPath = null;
8720                    Object[] finderArgs = null;
8721    
8722                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8723                                    (orderByComparator == null)) {
8724                            pagination = false;
8725                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8726                            finderArgs = new Object[] { threadId, parentMessageId };
8727                    }
8728                    else {
8729                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8730                            finderArgs = new Object[] {
8731                                            threadId, parentMessageId,
8732                                            
8733                                            start, end, orderByComparator
8734                                    };
8735                    }
8736    
8737                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8738                                    finderArgs, this);
8739    
8740                    if ((list != null) && !list.isEmpty()) {
8741                            for (MBMessage mbMessage : list) {
8742                                    if ((threadId != mbMessage.getThreadId()) ||
8743                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8744                                            list = null;
8745    
8746                                            break;
8747                                    }
8748                            }
8749                    }
8750    
8751                    if (list == null) {
8752                            StringBundler query = null;
8753    
8754                            if (orderByComparator != null) {
8755                                    query = new StringBundler(4 +
8756                                                    (orderByComparator.getOrderByFields().length * 3));
8757                            }
8758                            else {
8759                                    query = new StringBundler(4);
8760                            }
8761    
8762                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8763    
8764                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8765    
8766                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8767    
8768                            if (orderByComparator != null) {
8769                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8770                                            orderByComparator);
8771                            }
8772                            else
8773                             if (pagination) {
8774                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8775                            }
8776    
8777                            String sql = query.toString();
8778    
8779                            Session session = null;
8780    
8781                            try {
8782                                    session = openSession();
8783    
8784                                    Query q = session.createQuery(sql);
8785    
8786                                    QueryPos qPos = QueryPos.getInstance(q);
8787    
8788                                    qPos.add(threadId);
8789    
8790                                    qPos.add(parentMessageId);
8791    
8792                                    if (!pagination) {
8793                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8794                                                            start, end, false);
8795    
8796                                            Collections.sort(list);
8797    
8798                                            list = Collections.unmodifiableList(list);
8799                                    }
8800                                    else {
8801                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8802                                                            start, end);
8803                                    }
8804    
8805                                    cacheResult(list);
8806    
8807                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8808                            }
8809                            catch (Exception e) {
8810                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8811    
8812                                    throw processException(e);
8813                            }
8814                            finally {
8815                                    closeSession(session);
8816                            }
8817                    }
8818    
8819                    return list;
8820            }
8821    
8822            /**
8823             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8824             *
8825             * @param threadId the thread ID
8826             * @param parentMessageId the parent message ID
8827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8828             * @return the first matching message-boards message
8829             * @throws NoSuchMessageException if a matching message-boards message could not be found
8830             */
8831            @Override
8832            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8833                    OrderByComparator<MBMessage> orderByComparator)
8834                    throws NoSuchMessageException {
8835                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8836                                    orderByComparator);
8837    
8838                    if (mbMessage != null) {
8839                            return mbMessage;
8840                    }
8841    
8842                    StringBundler msg = new StringBundler(6);
8843    
8844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8845    
8846                    msg.append("threadId=");
8847                    msg.append(threadId);
8848    
8849                    msg.append(", parentMessageId=");
8850                    msg.append(parentMessageId);
8851    
8852                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8853    
8854                    throw new NoSuchMessageException(msg.toString());
8855            }
8856    
8857            /**
8858             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8859             *
8860             * @param threadId the thread ID
8861             * @param parentMessageId the parent message ID
8862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8863             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8864             */
8865            @Override
8866            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8867                    OrderByComparator<MBMessage> orderByComparator) {
8868                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8869                                    orderByComparator);
8870    
8871                    if (!list.isEmpty()) {
8872                            return list.get(0);
8873                    }
8874    
8875                    return null;
8876            }
8877    
8878            /**
8879             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8880             *
8881             * @param threadId the thread ID
8882             * @param parentMessageId the parent message ID
8883             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8884             * @return the last matching message-boards message
8885             * @throws NoSuchMessageException if a matching message-boards message could not be found
8886             */
8887            @Override
8888            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8889                    OrderByComparator<MBMessage> orderByComparator)
8890                    throws NoSuchMessageException {
8891                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8892                                    orderByComparator);
8893    
8894                    if (mbMessage != null) {
8895                            return mbMessage;
8896                    }
8897    
8898                    StringBundler msg = new StringBundler(6);
8899    
8900                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8901    
8902                    msg.append("threadId=");
8903                    msg.append(threadId);
8904    
8905                    msg.append(", parentMessageId=");
8906                    msg.append(parentMessageId);
8907    
8908                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8909    
8910                    throw new NoSuchMessageException(msg.toString());
8911            }
8912    
8913            /**
8914             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8915             *
8916             * @param threadId the thread ID
8917             * @param parentMessageId the parent message ID
8918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8919             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8920             */
8921            @Override
8922            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8923                    OrderByComparator<MBMessage> orderByComparator) {
8924                    int count = countByT_P(threadId, parentMessageId);
8925    
8926                    if (count == 0) {
8927                            return null;
8928                    }
8929    
8930                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8931                                    count, orderByComparator);
8932    
8933                    if (!list.isEmpty()) {
8934                            return list.get(0);
8935                    }
8936    
8937                    return null;
8938            }
8939    
8940            /**
8941             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8942             *
8943             * @param messageId the primary key of the current message-boards message
8944             * @param threadId the thread ID
8945             * @param parentMessageId the parent message ID
8946             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8947             * @return the previous, current, and next message-boards message
8948             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8949             */
8950            @Override
8951            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8952                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
8953                    throws NoSuchMessageException {
8954                    MBMessage mbMessage = findByPrimaryKey(messageId);
8955    
8956                    Session session = null;
8957    
8958                    try {
8959                            session = openSession();
8960    
8961                            MBMessage[] array = new MBMessageImpl[3];
8962    
8963                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8964                                            parentMessageId, orderByComparator, true);
8965    
8966                            array[1] = mbMessage;
8967    
8968                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8969                                            parentMessageId, orderByComparator, false);
8970    
8971                            return array;
8972                    }
8973                    catch (Exception e) {
8974                            throw processException(e);
8975                    }
8976                    finally {
8977                            closeSession(session);
8978                    }
8979            }
8980    
8981            protected MBMessage getByT_P_PrevAndNext(Session session,
8982                    MBMessage mbMessage, long threadId, long parentMessageId,
8983                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8984                    StringBundler query = null;
8985    
8986                    if (orderByComparator != null) {
8987                            query = new StringBundler(6 +
8988                                            (orderByComparator.getOrderByFields().length * 6));
8989                    }
8990                    else {
8991                            query = new StringBundler(3);
8992                    }
8993    
8994                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8995    
8996                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8997    
8998                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8999    
9000                    if (orderByComparator != null) {
9001                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9002    
9003                            if (orderByConditionFields.length > 0) {
9004                                    query.append(WHERE_AND);
9005                            }
9006    
9007                            for (int i = 0; i < orderByConditionFields.length; i++) {
9008                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9009                                    query.append(orderByConditionFields[i]);
9010    
9011                                    if ((i + 1) < orderByConditionFields.length) {
9012                                            if (orderByComparator.isAscending() ^ previous) {
9013                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9014                                            }
9015                                            else {
9016                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9017                                            }
9018                                    }
9019                                    else {
9020                                            if (orderByComparator.isAscending() ^ previous) {
9021                                                    query.append(WHERE_GREATER_THAN);
9022                                            }
9023                                            else {
9024                                                    query.append(WHERE_LESSER_THAN);
9025                                            }
9026                                    }
9027                            }
9028    
9029                            query.append(ORDER_BY_CLAUSE);
9030    
9031                            String[] orderByFields = orderByComparator.getOrderByFields();
9032    
9033                            for (int i = 0; i < orderByFields.length; i++) {
9034                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9035                                    query.append(orderByFields[i]);
9036    
9037                                    if ((i + 1) < orderByFields.length) {
9038                                            if (orderByComparator.isAscending() ^ previous) {
9039                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9040                                            }
9041                                            else {
9042                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9043                                            }
9044                                    }
9045                                    else {
9046                                            if (orderByComparator.isAscending() ^ previous) {
9047                                                    query.append(ORDER_BY_ASC);
9048                                            }
9049                                            else {
9050                                                    query.append(ORDER_BY_DESC);
9051                                            }
9052                                    }
9053                            }
9054                    }
9055                    else {
9056                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9057                    }
9058    
9059                    String sql = query.toString();
9060    
9061                    Query q = session.createQuery(sql);
9062    
9063                    q.setFirstResult(0);
9064                    q.setMaxResults(2);
9065    
9066                    QueryPos qPos = QueryPos.getInstance(q);
9067    
9068                    qPos.add(threadId);
9069    
9070                    qPos.add(parentMessageId);
9071    
9072                    if (orderByComparator != null) {
9073                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9074    
9075                            for (Object value : values) {
9076                                    qPos.add(value);
9077                            }
9078                    }
9079    
9080                    List<MBMessage> list = q.list();
9081    
9082                    if (list.size() == 2) {
9083                            return list.get(1);
9084                    }
9085                    else {
9086                            return null;
9087                    }
9088            }
9089    
9090            /**
9091             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9092             *
9093             * @param threadId the thread ID
9094             * @param parentMessageId the parent message ID
9095             */
9096            @Override
9097            public void removeByT_P(long threadId, long parentMessageId) {
9098                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9099                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9100                            remove(mbMessage);
9101                    }
9102            }
9103    
9104            /**
9105             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9106             *
9107             * @param threadId the thread ID
9108             * @param parentMessageId the parent message ID
9109             * @return the number of matching message-boards messages
9110             */
9111            @Override
9112            public int countByT_P(long threadId, long parentMessageId) {
9113                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9114    
9115                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9116    
9117                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9118                                    this);
9119    
9120                    if (count == null) {
9121                            StringBundler query = new StringBundler(3);
9122    
9123                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9124    
9125                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9126    
9127                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9128    
9129                            String sql = query.toString();
9130    
9131                            Session session = null;
9132    
9133                            try {
9134                                    session = openSession();
9135    
9136                                    Query q = session.createQuery(sql);
9137    
9138                                    QueryPos qPos = QueryPos.getInstance(q);
9139    
9140                                    qPos.add(threadId);
9141    
9142                                    qPos.add(parentMessageId);
9143    
9144                                    count = (Long)q.uniqueResult();
9145    
9146                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9147                            }
9148                            catch (Exception e) {
9149                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9150    
9151                                    throw processException(e);
9152                            }
9153                            finally {
9154                                    closeSession(session);
9155                            }
9156                    }
9157    
9158                    return count.intValue();
9159            }
9160    
9161            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9162            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9163            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9164                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9165                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9166                            new String[] {
9167                                    Long.class.getName(), Boolean.class.getName(),
9168                                    
9169                            Integer.class.getName(), Integer.class.getName(),
9170                                    OrderByComparator.class.getName()
9171                            });
9172            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9173                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9174                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9175                            new String[] { Long.class.getName(), Boolean.class.getName() },
9176                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9177                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9178                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9179            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9180                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9182                            new String[] { Long.class.getName(), Boolean.class.getName() });
9183    
9184            /**
9185             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9186             *
9187             * @param threadId the thread ID
9188             * @param answer the answer
9189             * @return the matching message-boards messages
9190             */
9191            @Override
9192            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9193                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9194                            QueryUtil.ALL_POS, null);
9195            }
9196    
9197            /**
9198             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9199             *
9200             * <p>
9201             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9202             * </p>
9203             *
9204             * @param threadId the thread ID
9205             * @param answer the answer
9206             * @param start the lower bound of the range of message-boards messages
9207             * @param end the upper bound of the range of message-boards messages (not inclusive)
9208             * @return the range of matching message-boards messages
9209             */
9210            @Override
9211            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9212                    int end) {
9213                    return findByT_A(threadId, answer, start, end, null);
9214            }
9215    
9216            /**
9217             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9218             *
9219             * <p>
9220             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9221             * </p>
9222             *
9223             * @param threadId the thread ID
9224             * @param answer the answer
9225             * @param start the lower bound of the range of message-boards messages
9226             * @param end the upper bound of the range of message-boards messages (not inclusive)
9227             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9228             * @return the ordered range of matching message-boards messages
9229             */
9230            @Override
9231            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9232                    int end, OrderByComparator<MBMessage> orderByComparator) {
9233                    boolean pagination = true;
9234                    FinderPath finderPath = null;
9235                    Object[] finderArgs = null;
9236    
9237                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9238                                    (orderByComparator == null)) {
9239                            pagination = false;
9240                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9241                            finderArgs = new Object[] { threadId, answer };
9242                    }
9243                    else {
9244                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9245                            finderArgs = new Object[] {
9246                                            threadId, answer,
9247                                            
9248                                            start, end, orderByComparator
9249                                    };
9250                    }
9251    
9252                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9253                                    finderArgs, this);
9254    
9255                    if ((list != null) && !list.isEmpty()) {
9256                            for (MBMessage mbMessage : list) {
9257                                    if ((threadId != mbMessage.getThreadId()) ||
9258                                                    (answer != mbMessage.getAnswer())) {
9259                                            list = null;
9260    
9261                                            break;
9262                                    }
9263                            }
9264                    }
9265    
9266                    if (list == null) {
9267                            StringBundler query = null;
9268    
9269                            if (orderByComparator != null) {
9270                                    query = new StringBundler(4 +
9271                                                    (orderByComparator.getOrderByFields().length * 3));
9272                            }
9273                            else {
9274                                    query = new StringBundler(4);
9275                            }
9276    
9277                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9278    
9279                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9280    
9281                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9282    
9283                            if (orderByComparator != null) {
9284                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9285                                            orderByComparator);
9286                            }
9287                            else
9288                             if (pagination) {
9289                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9290                            }
9291    
9292                            String sql = query.toString();
9293    
9294                            Session session = null;
9295    
9296                            try {
9297                                    session = openSession();
9298    
9299                                    Query q = session.createQuery(sql);
9300    
9301                                    QueryPos qPos = QueryPos.getInstance(q);
9302    
9303                                    qPos.add(threadId);
9304    
9305                                    qPos.add(answer);
9306    
9307                                    if (!pagination) {
9308                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9309                                                            start, end, false);
9310    
9311                                            Collections.sort(list);
9312    
9313                                            list = Collections.unmodifiableList(list);
9314                                    }
9315                                    else {
9316                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9317                                                            start, end);
9318                                    }
9319    
9320                                    cacheResult(list);
9321    
9322                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9323                            }
9324                            catch (Exception e) {
9325                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9326    
9327                                    throw processException(e);
9328                            }
9329                            finally {
9330                                    closeSession(session);
9331                            }
9332                    }
9333    
9334                    return list;
9335            }
9336    
9337            /**
9338             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9339             *
9340             * @param threadId the thread ID
9341             * @param answer the answer
9342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9343             * @return the first matching message-boards message
9344             * @throws NoSuchMessageException if a matching message-boards message could not be found
9345             */
9346            @Override
9347            public MBMessage findByT_A_First(long threadId, boolean answer,
9348                    OrderByComparator<MBMessage> orderByComparator)
9349                    throws NoSuchMessageException {
9350                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9351                                    orderByComparator);
9352    
9353                    if (mbMessage != null) {
9354                            return mbMessage;
9355                    }
9356    
9357                    StringBundler msg = new StringBundler(6);
9358    
9359                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9360    
9361                    msg.append("threadId=");
9362                    msg.append(threadId);
9363    
9364                    msg.append(", answer=");
9365                    msg.append(answer);
9366    
9367                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9368    
9369                    throw new NoSuchMessageException(msg.toString());
9370            }
9371    
9372            /**
9373             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9374             *
9375             * @param threadId the thread ID
9376             * @param answer the answer
9377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9378             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9379             */
9380            @Override
9381            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9382                    OrderByComparator<MBMessage> orderByComparator) {
9383                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9384                                    orderByComparator);
9385    
9386                    if (!list.isEmpty()) {
9387                            return list.get(0);
9388                    }
9389    
9390                    return null;
9391            }
9392    
9393            /**
9394             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9395             *
9396             * @param threadId the thread ID
9397             * @param answer the answer
9398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9399             * @return the last matching message-boards message
9400             * @throws NoSuchMessageException if a matching message-boards message could not be found
9401             */
9402            @Override
9403            public MBMessage findByT_A_Last(long threadId, boolean answer,
9404                    OrderByComparator<MBMessage> orderByComparator)
9405                    throws NoSuchMessageException {
9406                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9407                                    orderByComparator);
9408    
9409                    if (mbMessage != null) {
9410                            return mbMessage;
9411                    }
9412    
9413                    StringBundler msg = new StringBundler(6);
9414    
9415                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9416    
9417                    msg.append("threadId=");
9418                    msg.append(threadId);
9419    
9420                    msg.append(", answer=");
9421                    msg.append(answer);
9422    
9423                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9424    
9425                    throw new NoSuchMessageException(msg.toString());
9426            }
9427    
9428            /**
9429             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9430             *
9431             * @param threadId the thread ID
9432             * @param answer the answer
9433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9434             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9435             */
9436            @Override
9437            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9438                    OrderByComparator<MBMessage> orderByComparator) {
9439                    int count = countByT_A(threadId, answer);
9440    
9441                    if (count == 0) {
9442                            return null;
9443                    }
9444    
9445                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9446                                    orderByComparator);
9447    
9448                    if (!list.isEmpty()) {
9449                            return list.get(0);
9450                    }
9451    
9452                    return null;
9453            }
9454    
9455            /**
9456             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9457             *
9458             * @param messageId the primary key of the current message-boards message
9459             * @param threadId the thread ID
9460             * @param answer the answer
9461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9462             * @return the previous, current, and next message-boards message
9463             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9464             */
9465            @Override
9466            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9467                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9468                    throws NoSuchMessageException {
9469                    MBMessage mbMessage = findByPrimaryKey(messageId);
9470    
9471                    Session session = null;
9472    
9473                    try {
9474                            session = openSession();
9475    
9476                            MBMessage[] array = new MBMessageImpl[3];
9477    
9478                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9479                                            answer, orderByComparator, true);
9480    
9481                            array[1] = mbMessage;
9482    
9483                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9484                                            answer, orderByComparator, false);
9485    
9486                            return array;
9487                    }
9488                    catch (Exception e) {
9489                            throw processException(e);
9490                    }
9491                    finally {
9492                            closeSession(session);
9493                    }
9494            }
9495    
9496            protected MBMessage getByT_A_PrevAndNext(Session session,
9497                    MBMessage mbMessage, long threadId, boolean answer,
9498                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9499                    StringBundler query = null;
9500    
9501                    if (orderByComparator != null) {
9502                            query = new StringBundler(6 +
9503                                            (orderByComparator.getOrderByFields().length * 6));
9504                    }
9505                    else {
9506                            query = new StringBundler(3);
9507                    }
9508    
9509                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9510    
9511                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9512    
9513                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9514    
9515                    if (orderByComparator != null) {
9516                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9517    
9518                            if (orderByConditionFields.length > 0) {
9519                                    query.append(WHERE_AND);
9520                            }
9521    
9522                            for (int i = 0; i < orderByConditionFields.length; i++) {
9523                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9524                                    query.append(orderByConditionFields[i]);
9525    
9526                                    if ((i + 1) < orderByConditionFields.length) {
9527                                            if (orderByComparator.isAscending() ^ previous) {
9528                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9529                                            }
9530                                            else {
9531                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9532                                            }
9533                                    }
9534                                    else {
9535                                            if (orderByComparator.isAscending() ^ previous) {
9536                                                    query.append(WHERE_GREATER_THAN);
9537                                            }
9538                                            else {
9539                                                    query.append(WHERE_LESSER_THAN);
9540                                            }
9541                                    }
9542                            }
9543    
9544                            query.append(ORDER_BY_CLAUSE);
9545    
9546                            String[] orderByFields = orderByComparator.getOrderByFields();
9547    
9548                            for (int i = 0; i < orderByFields.length; i++) {
9549                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9550                                    query.append(orderByFields[i]);
9551    
9552                                    if ((i + 1) < orderByFields.length) {
9553                                            if (orderByComparator.isAscending() ^ previous) {
9554                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9555                                            }
9556                                            else {
9557                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9558                                            }
9559                                    }
9560                                    else {
9561                                            if (orderByComparator.isAscending() ^ previous) {
9562                                                    query.append(ORDER_BY_ASC);
9563                                            }
9564                                            else {
9565                                                    query.append(ORDER_BY_DESC);
9566                                            }
9567                                    }
9568                            }
9569                    }
9570                    else {
9571                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9572                    }
9573    
9574                    String sql = query.toString();
9575    
9576                    Query q = session.createQuery(sql);
9577    
9578                    q.setFirstResult(0);
9579                    q.setMaxResults(2);
9580    
9581                    QueryPos qPos = QueryPos.getInstance(q);
9582    
9583                    qPos.add(threadId);
9584    
9585                    qPos.add(answer);
9586    
9587                    if (orderByComparator != null) {
9588                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9589    
9590                            for (Object value : values) {
9591                                    qPos.add(value);
9592                            }
9593                    }
9594    
9595                    List<MBMessage> list = q.list();
9596    
9597                    if (list.size() == 2) {
9598                            return list.get(1);
9599                    }
9600                    else {
9601                            return null;
9602                    }
9603            }
9604    
9605            /**
9606             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
9607             *
9608             * @param threadId the thread ID
9609             * @param answer the answer
9610             */
9611            @Override
9612            public void removeByT_A(long threadId, boolean answer) {
9613                    for (MBMessage mbMessage : findByT_A(threadId, answer,
9614                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9615                            remove(mbMessage);
9616                    }
9617            }
9618    
9619            /**
9620             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
9621             *
9622             * @param threadId the thread ID
9623             * @param answer the answer
9624             * @return the number of matching message-boards messages
9625             */
9626            @Override
9627            public int countByT_A(long threadId, boolean answer) {
9628                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9629    
9630                    Object[] finderArgs = new Object[] { threadId, answer };
9631    
9632                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9633                                    this);
9634    
9635                    if (count == null) {
9636                            StringBundler query = new StringBundler(3);
9637    
9638                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9639    
9640                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9641    
9642                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9643    
9644                            String sql = query.toString();
9645    
9646                            Session session = null;
9647    
9648                            try {
9649                                    session = openSession();
9650    
9651                                    Query q = session.createQuery(sql);
9652    
9653                                    QueryPos qPos = QueryPos.getInstance(q);
9654    
9655                                    qPos.add(threadId);
9656    
9657                                    qPos.add(answer);
9658    
9659                                    count = (Long)q.uniqueResult();
9660    
9661                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9662                            }
9663                            catch (Exception e) {
9664                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9665    
9666                                    throw processException(e);
9667                            }
9668                            finally {
9669                                    closeSession(session);
9670                            }
9671                    }
9672    
9673                    return count.intValue();
9674            }
9675    
9676            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9677            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9678            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9679                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9680                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9681                            new String[] {
9682                                    Long.class.getName(), Integer.class.getName(),
9683                                    
9684                            Integer.class.getName(), Integer.class.getName(),
9685                                    OrderByComparator.class.getName()
9686                            });
9687            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9688                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9689                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9690                            new String[] { Long.class.getName(), Integer.class.getName() },
9691                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9692                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9693                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9694            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9695                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9696                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9697                            new String[] { Long.class.getName(), Integer.class.getName() });
9698    
9699            /**
9700             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9701             *
9702             * @param threadId the thread ID
9703             * @param status the status
9704             * @return the matching message-boards messages
9705             */
9706            @Override
9707            public List<MBMessage> findByT_S(long threadId, int status) {
9708                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9709                            QueryUtil.ALL_POS, null);
9710            }
9711    
9712            /**
9713             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9714             *
9715             * <p>
9716             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9717             * </p>
9718             *
9719             * @param threadId the thread ID
9720             * @param status the status
9721             * @param start the lower bound of the range of message-boards messages
9722             * @param end the upper bound of the range of message-boards messages (not inclusive)
9723             * @return the range of matching message-boards messages
9724             */
9725            @Override
9726            public List<MBMessage> findByT_S(long threadId, int status, int start,
9727                    int end) {
9728                    return findByT_S(threadId, status, start, end, null);
9729            }
9730    
9731            /**
9732             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9733             *
9734             * <p>
9735             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9736             * </p>
9737             *
9738             * @param threadId the thread ID
9739             * @param status the status
9740             * @param start the lower bound of the range of message-boards messages
9741             * @param end the upper bound of the range of message-boards messages (not inclusive)
9742             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9743             * @return the ordered range of matching message-boards messages
9744             */
9745            @Override
9746            public List<MBMessage> findByT_S(long threadId, int status, int start,
9747                    int end, OrderByComparator<MBMessage> orderByComparator) {
9748                    boolean pagination = true;
9749                    FinderPath finderPath = null;
9750                    Object[] finderArgs = null;
9751    
9752                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9753                                    (orderByComparator == null)) {
9754                            pagination = false;
9755                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9756                            finderArgs = new Object[] { threadId, status };
9757                    }
9758                    else {
9759                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9760                            finderArgs = new Object[] {
9761                                            threadId, status,
9762                                            
9763                                            start, end, orderByComparator
9764                                    };
9765                    }
9766    
9767                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9768                                    finderArgs, this);
9769    
9770                    if ((list != null) && !list.isEmpty()) {
9771                            for (MBMessage mbMessage : list) {
9772                                    if ((threadId != mbMessage.getThreadId()) ||
9773                                                    (status != mbMessage.getStatus())) {
9774                                            list = null;
9775    
9776                                            break;
9777                                    }
9778                            }
9779                    }
9780    
9781                    if (list == null) {
9782                            StringBundler query = null;
9783    
9784                            if (orderByComparator != null) {
9785                                    query = new StringBundler(4 +
9786                                                    (orderByComparator.getOrderByFields().length * 3));
9787                            }
9788                            else {
9789                                    query = new StringBundler(4);
9790                            }
9791    
9792                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9793    
9794                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
9795    
9796                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
9797    
9798                            if (orderByComparator != null) {
9799                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9800                                            orderByComparator);
9801                            }
9802                            else
9803                             if (pagination) {
9804                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9805                            }
9806    
9807                            String sql = query.toString();
9808    
9809                            Session session = null;
9810    
9811                            try {
9812                                    session = openSession();
9813    
9814                                    Query q = session.createQuery(sql);
9815    
9816                                    QueryPos qPos = QueryPos.getInstance(q);
9817    
9818                                    qPos.add(threadId);
9819    
9820                                    qPos.add(status);
9821    
9822                                    if (!pagination) {
9823                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9824                                                            start, end, false);
9825    
9826                                            Collections.sort(list);
9827    
9828                                            list = Collections.unmodifiableList(list);
9829                                    }
9830                                    else {
9831                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9832                                                            start, end);
9833                                    }
9834    
9835                                    cacheResult(list);
9836    
9837                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9838                            }
9839                            catch (Exception e) {
9840                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9841    
9842                                    throw processException(e);
9843                            }
9844                            finally {
9845                                    closeSession(session);
9846                            }
9847                    }
9848    
9849                    return list;
9850            }
9851    
9852            /**
9853             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9854             *
9855             * @param threadId the thread ID
9856             * @param status the status
9857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9858             * @return the first matching message-boards message
9859             * @throws NoSuchMessageException if a matching message-boards message could not be found
9860             */
9861            @Override
9862            public MBMessage findByT_S_First(long threadId, int status,
9863                    OrderByComparator<MBMessage> orderByComparator)
9864                    throws NoSuchMessageException {
9865                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9866                                    orderByComparator);
9867    
9868                    if (mbMessage != null) {
9869                            return mbMessage;
9870                    }
9871    
9872                    StringBundler msg = new StringBundler(6);
9873    
9874                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9875    
9876                    msg.append("threadId=");
9877                    msg.append(threadId);
9878    
9879                    msg.append(", status=");
9880                    msg.append(status);
9881    
9882                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9883    
9884                    throw new NoSuchMessageException(msg.toString());
9885            }
9886    
9887            /**
9888             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9889             *
9890             * @param threadId the thread ID
9891             * @param status the status
9892             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9893             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9894             */
9895            @Override
9896            public MBMessage fetchByT_S_First(long threadId, int status,
9897                    OrderByComparator<MBMessage> orderByComparator) {
9898                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9899                                    orderByComparator);
9900    
9901                    if (!list.isEmpty()) {
9902                            return list.get(0);
9903                    }
9904    
9905                    return null;
9906            }
9907    
9908            /**
9909             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9910             *
9911             * @param threadId the thread ID
9912             * @param status the status
9913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9914             * @return the last matching message-boards message
9915             * @throws NoSuchMessageException if a matching message-boards message could not be found
9916             */
9917            @Override
9918            public MBMessage findByT_S_Last(long threadId, int status,
9919                    OrderByComparator<MBMessage> orderByComparator)
9920                    throws NoSuchMessageException {
9921                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9922                                    orderByComparator);
9923    
9924                    if (mbMessage != null) {
9925                            return mbMessage;
9926                    }
9927    
9928                    StringBundler msg = new StringBundler(6);
9929    
9930                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9931    
9932                    msg.append("threadId=");
9933                    msg.append(threadId);
9934    
9935                    msg.append(", status=");
9936                    msg.append(status);
9937    
9938                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9939    
9940                    throw new NoSuchMessageException(msg.toString());
9941            }
9942    
9943            /**
9944             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9945             *
9946             * @param threadId the thread ID
9947             * @param status the status
9948             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9949             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9950             */
9951            @Override
9952            public MBMessage fetchByT_S_Last(long threadId, int status,
9953                    OrderByComparator<MBMessage> orderByComparator) {
9954                    int count = countByT_S(threadId, status);
9955    
9956                    if (count == 0) {
9957                            return null;
9958                    }
9959    
9960                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9961                                    orderByComparator);
9962    
9963                    if (!list.isEmpty()) {
9964                            return list.get(0);
9965                    }
9966    
9967                    return null;
9968            }
9969    
9970            /**
9971             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9972             *
9973             * @param messageId the primary key of the current message-boards message
9974             * @param threadId the thread ID
9975             * @param status the status
9976             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9977             * @return the previous, current, and next message-boards message
9978             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9979             */
9980            @Override
9981            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9982                    int status, OrderByComparator<MBMessage> orderByComparator)
9983                    throws NoSuchMessageException {
9984                    MBMessage mbMessage = findByPrimaryKey(messageId);
9985    
9986                    Session session = null;
9987    
9988                    try {
9989                            session = openSession();
9990    
9991                            MBMessage[] array = new MBMessageImpl[3];
9992    
9993                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9994                                            status, orderByComparator, true);
9995    
9996                            array[1] = mbMessage;
9997    
9998                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9999                                            status, orderByComparator, false);
10000    
10001                            return array;
10002                    }
10003                    catch (Exception e) {
10004                            throw processException(e);
10005                    }
10006                    finally {
10007                            closeSession(session);
10008                    }
10009            }
10010    
10011            protected MBMessage getByT_S_PrevAndNext(Session session,
10012                    MBMessage mbMessage, long threadId, int status,
10013                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10014                    StringBundler query = null;
10015    
10016                    if (orderByComparator != null) {
10017                            query = new StringBundler(6 +
10018                                            (orderByComparator.getOrderByFields().length * 6));
10019                    }
10020                    else {
10021                            query = new StringBundler(3);
10022                    }
10023    
10024                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10025    
10026                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10027    
10028                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10029    
10030                    if (orderByComparator != null) {
10031                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10032    
10033                            if (orderByConditionFields.length > 0) {
10034                                    query.append(WHERE_AND);
10035                            }
10036    
10037                            for (int i = 0; i < orderByConditionFields.length; i++) {
10038                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10039                                    query.append(orderByConditionFields[i]);
10040    
10041                                    if ((i + 1) < orderByConditionFields.length) {
10042                                            if (orderByComparator.isAscending() ^ previous) {
10043                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10044                                            }
10045                                            else {
10046                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10047                                            }
10048                                    }
10049                                    else {
10050                                            if (orderByComparator.isAscending() ^ previous) {
10051                                                    query.append(WHERE_GREATER_THAN);
10052                                            }
10053                                            else {
10054                                                    query.append(WHERE_LESSER_THAN);
10055                                            }
10056                                    }
10057                            }
10058    
10059                            query.append(ORDER_BY_CLAUSE);
10060    
10061                            String[] orderByFields = orderByComparator.getOrderByFields();
10062    
10063                            for (int i = 0; i < orderByFields.length; i++) {
10064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10065                                    query.append(orderByFields[i]);
10066    
10067                                    if ((i + 1) < orderByFields.length) {
10068                                            if (orderByComparator.isAscending() ^ previous) {
10069                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10070                                            }
10071                                            else {
10072                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10073                                            }
10074                                    }
10075                                    else {
10076                                            if (orderByComparator.isAscending() ^ previous) {
10077                                                    query.append(ORDER_BY_ASC);
10078                                            }
10079                                            else {
10080                                                    query.append(ORDER_BY_DESC);
10081                                            }
10082                                    }
10083                            }
10084                    }
10085                    else {
10086                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10087                    }
10088    
10089                    String sql = query.toString();
10090    
10091                    Query q = session.createQuery(sql);
10092    
10093                    q.setFirstResult(0);
10094                    q.setMaxResults(2);
10095    
10096                    QueryPos qPos = QueryPos.getInstance(q);
10097    
10098                    qPos.add(threadId);
10099    
10100                    qPos.add(status);
10101    
10102                    if (orderByComparator != null) {
10103                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10104    
10105                            for (Object value : values) {
10106                                    qPos.add(value);
10107                            }
10108                    }
10109    
10110                    List<MBMessage> list = q.list();
10111    
10112                    if (list.size() == 2) {
10113                            return list.get(1);
10114                    }
10115                    else {
10116                            return null;
10117                    }
10118            }
10119    
10120            /**
10121             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10122             *
10123             * @param threadId the thread ID
10124             * @param status the status
10125             */
10126            @Override
10127            public void removeByT_S(long threadId, int status) {
10128                    for (MBMessage mbMessage : findByT_S(threadId, status,
10129                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10130                            remove(mbMessage);
10131                    }
10132            }
10133    
10134            /**
10135             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10136             *
10137             * @param threadId the thread ID
10138             * @param status the status
10139             * @return the number of matching message-boards messages
10140             */
10141            @Override
10142            public int countByT_S(long threadId, int status) {
10143                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10144    
10145                    Object[] finderArgs = new Object[] { threadId, status };
10146    
10147                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10148                                    this);
10149    
10150                    if (count == null) {
10151                            StringBundler query = new StringBundler(3);
10152    
10153                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10154    
10155                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10156    
10157                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10158    
10159                            String sql = query.toString();
10160    
10161                            Session session = null;
10162    
10163                            try {
10164                                    session = openSession();
10165    
10166                                    Query q = session.createQuery(sql);
10167    
10168                                    QueryPos qPos = QueryPos.getInstance(q);
10169    
10170                                    qPos.add(threadId);
10171    
10172                                    qPos.add(status);
10173    
10174                                    count = (Long)q.uniqueResult();
10175    
10176                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10177                            }
10178                            catch (Exception e) {
10179                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10180    
10181                                    throw processException(e);
10182                            }
10183                            finally {
10184                                    closeSession(session);
10185                            }
10186                    }
10187    
10188                    return count.intValue();
10189            }
10190    
10191            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10192            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10193            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10194                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10195                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10196                            new String[] {
10197                                    Long.class.getName(), Integer.class.getName(),
10198                                    
10199                            Integer.class.getName(), Integer.class.getName(),
10200                                    OrderByComparator.class.getName()
10201                            });
10202            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10203                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10204                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10205                            new String[] { Long.class.getName(), Integer.class.getName() },
10206                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10207                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10208                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10209            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10210                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10211                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10212                            new String[] { Long.class.getName(), Integer.class.getName() });
10213    
10214            /**
10215             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10216             *
10217             * @param threadId the thread ID
10218             * @param status the status
10219             * @return the matching message-boards messages
10220             */
10221            @Override
10222            public List<MBMessage> findByTR_S(long threadId, int status) {
10223                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10224                            QueryUtil.ALL_POS, null);
10225            }
10226    
10227            /**
10228             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10229             *
10230             * <p>
10231             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10232             * </p>
10233             *
10234             * @param threadId the thread ID
10235             * @param status the status
10236             * @param start the lower bound of the range of message-boards messages
10237             * @param end the upper bound of the range of message-boards messages (not inclusive)
10238             * @return the range of matching message-boards messages
10239             */
10240            @Override
10241            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10242                    int end) {
10243                    return findByTR_S(threadId, status, start, end, null);
10244            }
10245    
10246            /**
10247             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10248             *
10249             * <p>
10250             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10251             * </p>
10252             *
10253             * @param threadId the thread ID
10254             * @param status the status
10255             * @param start the lower bound of the range of message-boards messages
10256             * @param end the upper bound of the range of message-boards messages (not inclusive)
10257             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10258             * @return the ordered range of matching message-boards messages
10259             */
10260            @Override
10261            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10262                    int end, OrderByComparator<MBMessage> orderByComparator) {
10263                    boolean pagination = true;
10264                    FinderPath finderPath = null;
10265                    Object[] finderArgs = null;
10266    
10267                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10268                                    (orderByComparator == null)) {
10269                            pagination = false;
10270                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10271                            finderArgs = new Object[] { threadId, status };
10272                    }
10273                    else {
10274                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10275                            finderArgs = new Object[] {
10276                                            threadId, status,
10277                                            
10278                                            start, end, orderByComparator
10279                                    };
10280                    }
10281    
10282                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10283                                    finderArgs, this);
10284    
10285                    if ((list != null) && !list.isEmpty()) {
10286                            for (MBMessage mbMessage : list) {
10287                                    if ((threadId != mbMessage.getThreadId()) ||
10288                                                    (status != mbMessage.getStatus())) {
10289                                            list = null;
10290    
10291                                            break;
10292                                    }
10293                            }
10294                    }
10295    
10296                    if (list == null) {
10297                            StringBundler query = null;
10298    
10299                            if (orderByComparator != null) {
10300                                    query = new StringBundler(4 +
10301                                                    (orderByComparator.getOrderByFields().length * 3));
10302                            }
10303                            else {
10304                                    query = new StringBundler(4);
10305                            }
10306    
10307                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10308    
10309                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10310    
10311                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10312    
10313                            if (orderByComparator != null) {
10314                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10315                                            orderByComparator);
10316                            }
10317                            else
10318                             if (pagination) {
10319                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10320                            }
10321    
10322                            String sql = query.toString();
10323    
10324                            Session session = null;
10325    
10326                            try {
10327                                    session = openSession();
10328    
10329                                    Query q = session.createQuery(sql);
10330    
10331                                    QueryPos qPos = QueryPos.getInstance(q);
10332    
10333                                    qPos.add(threadId);
10334    
10335                                    qPos.add(status);
10336    
10337                                    if (!pagination) {
10338                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10339                                                            start, end, false);
10340    
10341                                            Collections.sort(list);
10342    
10343                                            list = Collections.unmodifiableList(list);
10344                                    }
10345                                    else {
10346                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10347                                                            start, end);
10348                                    }
10349    
10350                                    cacheResult(list);
10351    
10352                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10353                            }
10354                            catch (Exception e) {
10355                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10356    
10357                                    throw processException(e);
10358                            }
10359                            finally {
10360                                    closeSession(session);
10361                            }
10362                    }
10363    
10364                    return list;
10365            }
10366    
10367            /**
10368             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10369             *
10370             * @param threadId the thread ID
10371             * @param status the status
10372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10373             * @return the first matching message-boards message
10374             * @throws NoSuchMessageException if a matching message-boards message could not be found
10375             */
10376            @Override
10377            public MBMessage findByTR_S_First(long threadId, int status,
10378                    OrderByComparator<MBMessage> orderByComparator)
10379                    throws NoSuchMessageException {
10380                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10381                                    orderByComparator);
10382    
10383                    if (mbMessage != null) {
10384                            return mbMessage;
10385                    }
10386    
10387                    StringBundler msg = new StringBundler(6);
10388    
10389                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10390    
10391                    msg.append("threadId=");
10392                    msg.append(threadId);
10393    
10394                    msg.append(", status=");
10395                    msg.append(status);
10396    
10397                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10398    
10399                    throw new NoSuchMessageException(msg.toString());
10400            }
10401    
10402            /**
10403             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10404             *
10405             * @param threadId the thread ID
10406             * @param status the status
10407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10408             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10409             */
10410            @Override
10411            public MBMessage fetchByTR_S_First(long threadId, int status,
10412                    OrderByComparator<MBMessage> orderByComparator) {
10413                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10414                                    orderByComparator);
10415    
10416                    if (!list.isEmpty()) {
10417                            return list.get(0);
10418                    }
10419    
10420                    return null;
10421            }
10422    
10423            /**
10424             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10425             *
10426             * @param threadId the thread ID
10427             * @param status the status
10428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10429             * @return the last matching message-boards message
10430             * @throws NoSuchMessageException if a matching message-boards message could not be found
10431             */
10432            @Override
10433            public MBMessage findByTR_S_Last(long threadId, int status,
10434                    OrderByComparator<MBMessage> orderByComparator)
10435                    throws NoSuchMessageException {
10436                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10437                                    orderByComparator);
10438    
10439                    if (mbMessage != null) {
10440                            return mbMessage;
10441                    }
10442    
10443                    StringBundler msg = new StringBundler(6);
10444    
10445                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10446    
10447                    msg.append("threadId=");
10448                    msg.append(threadId);
10449    
10450                    msg.append(", status=");
10451                    msg.append(status);
10452    
10453                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10454    
10455                    throw new NoSuchMessageException(msg.toString());
10456            }
10457    
10458            /**
10459             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10460             *
10461             * @param threadId the thread ID
10462             * @param status the status
10463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10464             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10465             */
10466            @Override
10467            public MBMessage fetchByTR_S_Last(long threadId, int status,
10468                    OrderByComparator<MBMessage> orderByComparator) {
10469                    int count = countByTR_S(threadId, status);
10470    
10471                    if (count == 0) {
10472                            return null;
10473                    }
10474    
10475                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10476                                    orderByComparator);
10477    
10478                    if (!list.isEmpty()) {
10479                            return list.get(0);
10480                    }
10481    
10482                    return null;
10483            }
10484    
10485            /**
10486             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10487             *
10488             * @param messageId the primary key of the current message-boards message
10489             * @param threadId the thread ID
10490             * @param status the status
10491             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10492             * @return the previous, current, and next message-boards message
10493             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10494             */
10495            @Override
10496            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10497                    int status, OrderByComparator<MBMessage> orderByComparator)
10498                    throws NoSuchMessageException {
10499                    MBMessage mbMessage = findByPrimaryKey(messageId);
10500    
10501                    Session session = null;
10502    
10503                    try {
10504                            session = openSession();
10505    
10506                            MBMessage[] array = new MBMessageImpl[3];
10507    
10508                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10509                                            status, orderByComparator, true);
10510    
10511                            array[1] = mbMessage;
10512    
10513                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10514                                            status, orderByComparator, false);
10515    
10516                            return array;
10517                    }
10518                    catch (Exception e) {
10519                            throw processException(e);
10520                    }
10521                    finally {
10522                            closeSession(session);
10523                    }
10524            }
10525    
10526            protected MBMessage getByTR_S_PrevAndNext(Session session,
10527                    MBMessage mbMessage, long threadId, int status,
10528                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10529                    StringBundler query = null;
10530    
10531                    if (orderByComparator != null) {
10532                            query = new StringBundler(6 +
10533                                            (orderByComparator.getOrderByFields().length * 6));
10534                    }
10535                    else {
10536                            query = new StringBundler(3);
10537                    }
10538    
10539                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10540    
10541                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10542    
10543                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10544    
10545                    if (orderByComparator != null) {
10546                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10547    
10548                            if (orderByConditionFields.length > 0) {
10549                                    query.append(WHERE_AND);
10550                            }
10551    
10552                            for (int i = 0; i < orderByConditionFields.length; i++) {
10553                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10554                                    query.append(orderByConditionFields[i]);
10555    
10556                                    if ((i + 1) < orderByConditionFields.length) {
10557                                            if (orderByComparator.isAscending() ^ previous) {
10558                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10559                                            }
10560                                            else {
10561                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10562                                            }
10563                                    }
10564                                    else {
10565                                            if (orderByComparator.isAscending() ^ previous) {
10566                                                    query.append(WHERE_GREATER_THAN);
10567                                            }
10568                                            else {
10569                                                    query.append(WHERE_LESSER_THAN);
10570                                            }
10571                                    }
10572                            }
10573    
10574                            query.append(ORDER_BY_CLAUSE);
10575    
10576                            String[] orderByFields = orderByComparator.getOrderByFields();
10577    
10578                            for (int i = 0; i < orderByFields.length; i++) {
10579                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10580                                    query.append(orderByFields[i]);
10581    
10582                                    if ((i + 1) < orderByFields.length) {
10583                                            if (orderByComparator.isAscending() ^ previous) {
10584                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10585                                            }
10586                                            else {
10587                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10588                                            }
10589                                    }
10590                                    else {
10591                                            if (orderByComparator.isAscending() ^ previous) {
10592                                                    query.append(ORDER_BY_ASC);
10593                                            }
10594                                            else {
10595                                                    query.append(ORDER_BY_DESC);
10596                                            }
10597                                    }
10598                            }
10599                    }
10600                    else {
10601                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10602                    }
10603    
10604                    String sql = query.toString();
10605    
10606                    Query q = session.createQuery(sql);
10607    
10608                    q.setFirstResult(0);
10609                    q.setMaxResults(2);
10610    
10611                    QueryPos qPos = QueryPos.getInstance(q);
10612    
10613                    qPos.add(threadId);
10614    
10615                    qPos.add(status);
10616    
10617                    if (orderByComparator != null) {
10618                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10619    
10620                            for (Object value : values) {
10621                                    qPos.add(value);
10622                            }
10623                    }
10624    
10625                    List<MBMessage> list = q.list();
10626    
10627                    if (list.size() == 2) {
10628                            return list.get(1);
10629                    }
10630                    else {
10631                            return null;
10632                    }
10633            }
10634    
10635            /**
10636             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10637             *
10638             * @param threadId the thread ID
10639             * @param status the status
10640             */
10641            @Override
10642            public void removeByTR_S(long threadId, int status) {
10643                    for (MBMessage mbMessage : findByTR_S(threadId, status,
10644                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10645                            remove(mbMessage);
10646                    }
10647            }
10648    
10649            /**
10650             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10651             *
10652             * @param threadId the thread ID
10653             * @param status the status
10654             * @return the number of matching message-boards messages
10655             */
10656            @Override
10657            public int countByTR_S(long threadId, int status) {
10658                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10659    
10660                    Object[] finderArgs = new Object[] { threadId, status };
10661    
10662                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10663                                    this);
10664    
10665                    if (count == null) {
10666                            StringBundler query = new StringBundler(3);
10667    
10668                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10669    
10670                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10671    
10672                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10673    
10674                            String sql = query.toString();
10675    
10676                            Session session = null;
10677    
10678                            try {
10679                                    session = openSession();
10680    
10681                                    Query q = session.createQuery(sql);
10682    
10683                                    QueryPos qPos = QueryPos.getInstance(q);
10684    
10685                                    qPos.add(threadId);
10686    
10687                                    qPos.add(status);
10688    
10689                                    count = (Long)q.uniqueResult();
10690    
10691                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10692                            }
10693                            catch (Exception e) {
10694                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10695    
10696                                    throw processException(e);
10697                            }
10698                            finally {
10699                                    closeSession(session);
10700                            }
10701                    }
10702    
10703                    return count.intValue();
10704            }
10705    
10706            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10707            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10708            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10709                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10710                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10711                            new String[] {
10712                                    Long.class.getName(), Long.class.getName(),
10713                                    Integer.class.getName(),
10714                                    
10715                            Integer.class.getName(), Integer.class.getName(),
10716                                    OrderByComparator.class.getName()
10717                            });
10718            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10719                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10720                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10721                            new String[] {
10722                                    Long.class.getName(), Long.class.getName(),
10723                                    Integer.class.getName()
10724                            },
10725                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10726                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
10727                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10728                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10729            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10730                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10731                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10732                            new String[] {
10733                                    Long.class.getName(), Long.class.getName(),
10734                                    Integer.class.getName()
10735                            });
10736    
10737            /**
10738             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10739             *
10740             * @param groupId the group ID
10741             * @param userId the user ID
10742             * @param status the status
10743             * @return the matching message-boards messages
10744             */
10745            @Override
10746            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
10747                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10748                            QueryUtil.ALL_POS, null);
10749            }
10750    
10751            /**
10752             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10753             *
10754             * <p>
10755             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10756             * </p>
10757             *
10758             * @param groupId the group ID
10759             * @param userId the user ID
10760             * @param status the status
10761             * @param start the lower bound of the range of message-boards messages
10762             * @param end the upper bound of the range of message-boards messages (not inclusive)
10763             * @return the range of matching message-boards messages
10764             */
10765            @Override
10766            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10767                    int start, int end) {
10768                    return findByG_U_S(groupId, userId, status, start, end, null);
10769            }
10770    
10771            /**
10772             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10773             *
10774             * <p>
10775             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10776             * </p>
10777             *
10778             * @param groupId the group ID
10779             * @param userId the user ID
10780             * @param status the status
10781             * @param start the lower bound of the range of message-boards messages
10782             * @param end the upper bound of the range of message-boards messages (not inclusive)
10783             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10784             * @return the ordered range of matching message-boards messages
10785             */
10786            @Override
10787            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10788                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
10789                    boolean pagination = true;
10790                    FinderPath finderPath = null;
10791                    Object[] finderArgs = null;
10792    
10793                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10794                                    (orderByComparator == null)) {
10795                            pagination = false;
10796                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10797                            finderArgs = new Object[] { groupId, userId, status };
10798                    }
10799                    else {
10800                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10801                            finderArgs = new Object[] {
10802                                            groupId, userId, status,
10803                                            
10804                                            start, end, orderByComparator
10805                                    };
10806                    }
10807    
10808                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10809                                    finderArgs, this);
10810    
10811                    if ((list != null) && !list.isEmpty()) {
10812                            for (MBMessage mbMessage : list) {
10813                                    if ((groupId != mbMessage.getGroupId()) ||
10814                                                    (userId != mbMessage.getUserId()) ||
10815                                                    (status != mbMessage.getStatus())) {
10816                                            list = null;
10817    
10818                                            break;
10819                                    }
10820                            }
10821                    }
10822    
10823                    if (list == null) {
10824                            StringBundler query = null;
10825    
10826                            if (orderByComparator != null) {
10827                                    query = new StringBundler(5 +
10828                                                    (orderByComparator.getOrderByFields().length * 3));
10829                            }
10830                            else {
10831                                    query = new StringBundler(5);
10832                            }
10833    
10834                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10835    
10836                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10837    
10838                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10839    
10840                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10841    
10842                            if (orderByComparator != null) {
10843                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10844                                            orderByComparator);
10845                            }
10846                            else
10847                             if (pagination) {
10848                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10849                            }
10850    
10851                            String sql = query.toString();
10852    
10853                            Session session = null;
10854    
10855                            try {
10856                                    session = openSession();
10857    
10858                                    Query q = session.createQuery(sql);
10859    
10860                                    QueryPos qPos = QueryPos.getInstance(q);
10861    
10862                                    qPos.add(groupId);
10863    
10864                                    qPos.add(userId);
10865    
10866                                    qPos.add(status);
10867    
10868                                    if (!pagination) {
10869                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10870                                                            start, end, false);
10871    
10872                                            Collections.sort(list);
10873    
10874                                            list = Collections.unmodifiableList(list);
10875                                    }
10876                                    else {
10877                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10878                                                            start, end);
10879                                    }
10880    
10881                                    cacheResult(list);
10882    
10883                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10884                            }
10885                            catch (Exception e) {
10886                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10887    
10888                                    throw processException(e);
10889                            }
10890                            finally {
10891                                    closeSession(session);
10892                            }
10893                    }
10894    
10895                    return list;
10896            }
10897    
10898            /**
10899             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10900             *
10901             * @param groupId the group ID
10902             * @param userId the user ID
10903             * @param status the status
10904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10905             * @return the first matching message-boards message
10906             * @throws NoSuchMessageException if a matching message-boards message could not be found
10907             */
10908            @Override
10909            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10910                    OrderByComparator<MBMessage> orderByComparator)
10911                    throws NoSuchMessageException {
10912                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10913                                    orderByComparator);
10914    
10915                    if (mbMessage != null) {
10916                            return mbMessage;
10917                    }
10918    
10919                    StringBundler msg = new StringBundler(8);
10920    
10921                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10922    
10923                    msg.append("groupId=");
10924                    msg.append(groupId);
10925    
10926                    msg.append(", userId=");
10927                    msg.append(userId);
10928    
10929                    msg.append(", status=");
10930                    msg.append(status);
10931    
10932                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10933    
10934                    throw new NoSuchMessageException(msg.toString());
10935            }
10936    
10937            /**
10938             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10939             *
10940             * @param groupId the group ID
10941             * @param userId the user ID
10942             * @param status the status
10943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10944             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10945             */
10946            @Override
10947            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10948                    OrderByComparator<MBMessage> orderByComparator) {
10949                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10950                                    orderByComparator);
10951    
10952                    if (!list.isEmpty()) {
10953                            return list.get(0);
10954                    }
10955    
10956                    return null;
10957            }
10958    
10959            /**
10960             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10961             *
10962             * @param groupId the group ID
10963             * @param userId the user ID
10964             * @param status the status
10965             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10966             * @return the last matching message-boards message
10967             * @throws NoSuchMessageException if a matching message-boards message could not be found
10968             */
10969            @Override
10970            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10971                    OrderByComparator<MBMessage> orderByComparator)
10972                    throws NoSuchMessageException {
10973                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10974                                    orderByComparator);
10975    
10976                    if (mbMessage != null) {
10977                            return mbMessage;
10978                    }
10979    
10980                    StringBundler msg = new StringBundler(8);
10981    
10982                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10983    
10984                    msg.append("groupId=");
10985                    msg.append(groupId);
10986    
10987                    msg.append(", userId=");
10988                    msg.append(userId);
10989    
10990                    msg.append(", status=");
10991                    msg.append(status);
10992    
10993                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10994    
10995                    throw new NoSuchMessageException(msg.toString());
10996            }
10997    
10998            /**
10999             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11000             *
11001             * @param groupId the group ID
11002             * @param userId the user ID
11003             * @param status the status
11004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11005             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11006             */
11007            @Override
11008            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11009                    OrderByComparator<MBMessage> orderByComparator) {
11010                    int count = countByG_U_S(groupId, userId, status);
11011    
11012                    if (count == 0) {
11013                            return null;
11014                    }
11015    
11016                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11017                                    count, orderByComparator);
11018    
11019                    if (!list.isEmpty()) {
11020                            return list.get(0);
11021                    }
11022    
11023                    return null;
11024            }
11025    
11026            /**
11027             * 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;.
11028             *
11029             * @param messageId the primary key of the current message-boards message
11030             * @param groupId the group ID
11031             * @param userId the user ID
11032             * @param status the status
11033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11034             * @return the previous, current, and next message-boards message
11035             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11036             */
11037            @Override
11038            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11039                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11040                    throws NoSuchMessageException {
11041                    MBMessage mbMessage = findByPrimaryKey(messageId);
11042    
11043                    Session session = null;
11044    
11045                    try {
11046                            session = openSession();
11047    
11048                            MBMessage[] array = new MBMessageImpl[3];
11049    
11050                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11051                                            userId, status, orderByComparator, true);
11052    
11053                            array[1] = mbMessage;
11054    
11055                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11056                                            userId, status, orderByComparator, false);
11057    
11058                            return array;
11059                    }
11060                    catch (Exception e) {
11061                            throw processException(e);
11062                    }
11063                    finally {
11064                            closeSession(session);
11065                    }
11066            }
11067    
11068            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11069                    MBMessage mbMessage, long groupId, long userId, int status,
11070                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11071                    StringBundler query = null;
11072    
11073                    if (orderByComparator != null) {
11074                            query = new StringBundler(6 +
11075                                            (orderByComparator.getOrderByFields().length * 6));
11076                    }
11077                    else {
11078                            query = new StringBundler(3);
11079                    }
11080    
11081                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11082    
11083                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11084    
11085                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11086    
11087                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11088    
11089                    if (orderByComparator != null) {
11090                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11091    
11092                            if (orderByConditionFields.length > 0) {
11093                                    query.append(WHERE_AND);
11094                            }
11095    
11096                            for (int i = 0; i < orderByConditionFields.length; i++) {
11097                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11098                                    query.append(orderByConditionFields[i]);
11099    
11100                                    if ((i + 1) < orderByConditionFields.length) {
11101                                            if (orderByComparator.isAscending() ^ previous) {
11102                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11103                                            }
11104                                            else {
11105                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11106                                            }
11107                                    }
11108                                    else {
11109                                            if (orderByComparator.isAscending() ^ previous) {
11110                                                    query.append(WHERE_GREATER_THAN);
11111                                            }
11112                                            else {
11113                                                    query.append(WHERE_LESSER_THAN);
11114                                            }
11115                                    }
11116                            }
11117    
11118                            query.append(ORDER_BY_CLAUSE);
11119    
11120                            String[] orderByFields = orderByComparator.getOrderByFields();
11121    
11122                            for (int i = 0; i < orderByFields.length; i++) {
11123                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11124                                    query.append(orderByFields[i]);
11125    
11126                                    if ((i + 1) < orderByFields.length) {
11127                                            if (orderByComparator.isAscending() ^ previous) {
11128                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11129                                            }
11130                                            else {
11131                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11132                                            }
11133                                    }
11134                                    else {
11135                                            if (orderByComparator.isAscending() ^ previous) {
11136                                                    query.append(ORDER_BY_ASC);
11137                                            }
11138                                            else {
11139                                                    query.append(ORDER_BY_DESC);
11140                                            }
11141                                    }
11142                            }
11143                    }
11144                    else {
11145                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11146                    }
11147    
11148                    String sql = query.toString();
11149    
11150                    Query q = session.createQuery(sql);
11151    
11152                    q.setFirstResult(0);
11153                    q.setMaxResults(2);
11154    
11155                    QueryPos qPos = QueryPos.getInstance(q);
11156    
11157                    qPos.add(groupId);
11158    
11159                    qPos.add(userId);
11160    
11161                    qPos.add(status);
11162    
11163                    if (orderByComparator != null) {
11164                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11165    
11166                            for (Object value : values) {
11167                                    qPos.add(value);
11168                            }
11169                    }
11170    
11171                    List<MBMessage> list = q.list();
11172    
11173                    if (list.size() == 2) {
11174                            return list.get(1);
11175                    }
11176                    else {
11177                            return null;
11178                    }
11179            }
11180    
11181            /**
11182             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11183             *
11184             * @param groupId the group ID
11185             * @param userId the user ID
11186             * @param status the status
11187             * @return the matching message-boards messages that the user has permission to view
11188             */
11189            @Override
11190            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11191                    int status) {
11192                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11193                            QueryUtil.ALL_POS, null);
11194            }
11195    
11196            /**
11197             * 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;.
11198             *
11199             * <p>
11200             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11201             * </p>
11202             *
11203             * @param groupId the group ID
11204             * @param userId the user ID
11205             * @param status the status
11206             * @param start the lower bound of the range of message-boards messages
11207             * @param end the upper bound of the range of message-boards messages (not inclusive)
11208             * @return the range of matching message-boards messages that the user has permission to view
11209             */
11210            @Override
11211            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11212                    int status, int start, int end) {
11213                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11214            }
11215    
11216            /**
11217             * 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;.
11218             *
11219             * <p>
11220             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11221             * </p>
11222             *
11223             * @param groupId the group ID
11224             * @param userId the user ID
11225             * @param status the status
11226             * @param start the lower bound of the range of message-boards messages
11227             * @param end the upper bound of the range of message-boards messages (not inclusive)
11228             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11229             * @return the ordered range of matching message-boards messages that the user has permission to view
11230             */
11231            @Override
11232            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11233                    int status, int start, int end,
11234                    OrderByComparator<MBMessage> orderByComparator) {
11235                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11236                            return findByG_U_S(groupId, userId, status, start, end,
11237                                    orderByComparator);
11238                    }
11239    
11240                    StringBundler query = null;
11241    
11242                    if (orderByComparator != null) {
11243                            query = new StringBundler(5 +
11244                                            (orderByComparator.getOrderByFields().length * 3));
11245                    }
11246                    else {
11247                            query = new StringBundler(5);
11248                    }
11249    
11250                    if (getDB().isSupportsInlineDistinct()) {
11251                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11252                    }
11253                    else {
11254                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11255                    }
11256    
11257                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11258    
11259                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11260    
11261                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11262    
11263                    if (!getDB().isSupportsInlineDistinct()) {
11264                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11265                    }
11266    
11267                    if (orderByComparator != null) {
11268                            if (getDB().isSupportsInlineDistinct()) {
11269                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11270                                            orderByComparator, true);
11271                            }
11272                            else {
11273                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11274                                            orderByComparator, true);
11275                            }
11276                    }
11277                    else {
11278                            if (getDB().isSupportsInlineDistinct()) {
11279                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11280                            }
11281                            else {
11282                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11283                            }
11284                    }
11285    
11286                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11287                                    MBMessage.class.getName(),
11288                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11289    
11290                    Session session = null;
11291    
11292                    try {
11293                            session = openSession();
11294    
11295                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11296    
11297                            if (getDB().isSupportsInlineDistinct()) {
11298                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11299                            }
11300                            else {
11301                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11302                            }
11303    
11304                            QueryPos qPos = QueryPos.getInstance(q);
11305    
11306                            qPos.add(groupId);
11307    
11308                            qPos.add(userId);
11309    
11310                            qPos.add(status);
11311    
11312                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11313                    }
11314                    catch (Exception e) {
11315                            throw processException(e);
11316                    }
11317                    finally {
11318                            closeSession(session);
11319                    }
11320            }
11321    
11322            /**
11323             * 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;.
11324             *
11325             * @param messageId the primary key of the current message-boards message
11326             * @param groupId the group ID
11327             * @param userId the user ID
11328             * @param status the status
11329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11330             * @return the previous, current, and next message-boards message
11331             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11332             */
11333            @Override
11334            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11335                    long groupId, long userId, int status,
11336                    OrderByComparator<MBMessage> orderByComparator)
11337                    throws NoSuchMessageException {
11338                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11339                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11340                                    orderByComparator);
11341                    }
11342    
11343                    MBMessage mbMessage = findByPrimaryKey(messageId);
11344    
11345                    Session session = null;
11346    
11347                    try {
11348                            session = openSession();
11349    
11350                            MBMessage[] array = new MBMessageImpl[3];
11351    
11352                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11353                                            groupId, userId, status, orderByComparator, true);
11354    
11355                            array[1] = mbMessage;
11356    
11357                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11358                                            groupId, userId, status, orderByComparator, false);
11359    
11360                            return array;
11361                    }
11362                    catch (Exception e) {
11363                            throw processException(e);
11364                    }
11365                    finally {
11366                            closeSession(session);
11367                    }
11368            }
11369    
11370            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11371                    MBMessage mbMessage, long groupId, long userId, int status,
11372                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11373                    StringBundler query = null;
11374    
11375                    if (orderByComparator != null) {
11376                            query = new StringBundler(6 +
11377                                            (orderByComparator.getOrderByFields().length * 6));
11378                    }
11379                    else {
11380                            query = new StringBundler(3);
11381                    }
11382    
11383                    if (getDB().isSupportsInlineDistinct()) {
11384                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11385                    }
11386                    else {
11387                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11388                    }
11389    
11390                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11391    
11392                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11393    
11394                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11395    
11396                    if (!getDB().isSupportsInlineDistinct()) {
11397                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11398                    }
11399    
11400                    if (orderByComparator != null) {
11401                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11402    
11403                            if (orderByConditionFields.length > 0) {
11404                                    query.append(WHERE_AND);
11405                            }
11406    
11407                            for (int i = 0; i < orderByConditionFields.length; i++) {
11408                                    if (getDB().isSupportsInlineDistinct()) {
11409                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11410                                    }
11411                                    else {
11412                                            query.append(_ORDER_BY_ENTITY_TABLE);
11413                                    }
11414    
11415                                    query.append(orderByConditionFields[i]);
11416    
11417                                    if ((i + 1) < orderByConditionFields.length) {
11418                                            if (orderByComparator.isAscending() ^ previous) {
11419                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11420                                            }
11421                                            else {
11422                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11423                                            }
11424                                    }
11425                                    else {
11426                                            if (orderByComparator.isAscending() ^ previous) {
11427                                                    query.append(WHERE_GREATER_THAN);
11428                                            }
11429                                            else {
11430                                                    query.append(WHERE_LESSER_THAN);
11431                                            }
11432                                    }
11433                            }
11434    
11435                            query.append(ORDER_BY_CLAUSE);
11436    
11437                            String[] orderByFields = orderByComparator.getOrderByFields();
11438    
11439                            for (int i = 0; i < orderByFields.length; i++) {
11440                                    if (getDB().isSupportsInlineDistinct()) {
11441                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11442                                    }
11443                                    else {
11444                                            query.append(_ORDER_BY_ENTITY_TABLE);
11445                                    }
11446    
11447                                    query.append(orderByFields[i]);
11448    
11449                                    if ((i + 1) < orderByFields.length) {
11450                                            if (orderByComparator.isAscending() ^ previous) {
11451                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11452                                            }
11453                                            else {
11454                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11455                                            }
11456                                    }
11457                                    else {
11458                                            if (orderByComparator.isAscending() ^ previous) {
11459                                                    query.append(ORDER_BY_ASC);
11460                                            }
11461                                            else {
11462                                                    query.append(ORDER_BY_DESC);
11463                                            }
11464                                    }
11465                            }
11466                    }
11467                    else {
11468                            if (getDB().isSupportsInlineDistinct()) {
11469                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11470                            }
11471                            else {
11472                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11473                            }
11474                    }
11475    
11476                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11477                                    MBMessage.class.getName(),
11478                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11479    
11480                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11481    
11482                    q.setFirstResult(0);
11483                    q.setMaxResults(2);
11484    
11485                    if (getDB().isSupportsInlineDistinct()) {
11486                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11487                    }
11488                    else {
11489                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11490                    }
11491    
11492                    QueryPos qPos = QueryPos.getInstance(q);
11493    
11494                    qPos.add(groupId);
11495    
11496                    qPos.add(userId);
11497    
11498                    qPos.add(status);
11499    
11500                    if (orderByComparator != null) {
11501                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11502    
11503                            for (Object value : values) {
11504                                    qPos.add(value);
11505                            }
11506                    }
11507    
11508                    List<MBMessage> list = q.list();
11509    
11510                    if (list.size() == 2) {
11511                            return list.get(1);
11512                    }
11513                    else {
11514                            return null;
11515                    }
11516            }
11517    
11518            /**
11519             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
11520             *
11521             * @param groupId the group ID
11522             * @param userId the user ID
11523             * @param status the status
11524             */
11525            @Override
11526            public void removeByG_U_S(long groupId, long userId, int status) {
11527                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11528                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11529                            remove(mbMessage);
11530                    }
11531            }
11532    
11533            /**
11534             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11535             *
11536             * @param groupId the group ID
11537             * @param userId the user ID
11538             * @param status the status
11539             * @return the number of matching message-boards messages
11540             */
11541            @Override
11542            public int countByG_U_S(long groupId, long userId, int status) {
11543                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11544    
11545                    Object[] finderArgs = new Object[] { groupId, userId, status };
11546    
11547                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11548                                    this);
11549    
11550                    if (count == null) {
11551                            StringBundler query = new StringBundler(4);
11552    
11553                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11554    
11555                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11556    
11557                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11558    
11559                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11560    
11561                            String sql = query.toString();
11562    
11563                            Session session = null;
11564    
11565                            try {
11566                                    session = openSession();
11567    
11568                                    Query q = session.createQuery(sql);
11569    
11570                                    QueryPos qPos = QueryPos.getInstance(q);
11571    
11572                                    qPos.add(groupId);
11573    
11574                                    qPos.add(userId);
11575    
11576                                    qPos.add(status);
11577    
11578                                    count = (Long)q.uniqueResult();
11579    
11580                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11581                            }
11582                            catch (Exception e) {
11583                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11584    
11585                                    throw processException(e);
11586                            }
11587                            finally {
11588                                    closeSession(session);
11589                            }
11590                    }
11591    
11592                    return count.intValue();
11593            }
11594    
11595            /**
11596             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11597             *
11598             * @param groupId the group ID
11599             * @param userId the user ID
11600             * @param status the status
11601             * @return the number of matching message-boards messages that the user has permission to view
11602             */
11603            @Override
11604            public int filterCountByG_U_S(long groupId, long userId, int status) {
11605                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11606                            return countByG_U_S(groupId, userId, status);
11607                    }
11608    
11609                    StringBundler query = new StringBundler(4);
11610    
11611                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11612    
11613                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11614    
11615                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11616    
11617                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11618    
11619                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11620                                    MBMessage.class.getName(),
11621                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11622    
11623                    Session session = null;
11624    
11625                    try {
11626                            session = openSession();
11627    
11628                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11629    
11630                            q.addScalar(COUNT_COLUMN_NAME,
11631                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11632    
11633                            QueryPos qPos = QueryPos.getInstance(q);
11634    
11635                            qPos.add(groupId);
11636    
11637                            qPos.add(userId);
11638    
11639                            qPos.add(status);
11640    
11641                            Long count = (Long)q.uniqueResult();
11642    
11643                            return count.intValue();
11644                    }
11645                    catch (Exception e) {
11646                            throw processException(e);
11647                    }
11648                    finally {
11649                            closeSession(session);
11650                    }
11651            }
11652    
11653            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11654            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11655            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11656            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11657                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11658                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11659                            new String[] {
11660                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
11661                                    
11662                            Integer.class.getName(), Integer.class.getName(),
11663                                    OrderByComparator.class.getName()
11664                            });
11665            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11666                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11667                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11668                            new String[] {
11669                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11670                            },
11671                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11672                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11673                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11674                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11675            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11676                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11677                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11678                            new String[] {
11679                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11680                            });
11681    
11682            /**
11683             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11684             *
11685             * @param groupId the group ID
11686             * @param categoryId the category ID
11687             * @param threadId the thread ID
11688             * @return the matching message-boards messages
11689             */
11690            @Override
11691            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11692                    long threadId) {
11693                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11694                            QueryUtil.ALL_POS, null);
11695            }
11696    
11697            /**
11698             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11699             *
11700             * <p>
11701             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11702             * </p>
11703             *
11704             * @param groupId the group ID
11705             * @param categoryId the category ID
11706             * @param threadId the thread ID
11707             * @param start the lower bound of the range of message-boards messages
11708             * @param end the upper bound of the range of message-boards messages (not inclusive)
11709             * @return the range of matching message-boards messages
11710             */
11711            @Override
11712            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11713                    long threadId, int start, int end) {
11714                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
11715            }
11716    
11717            /**
11718             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11719             *
11720             * <p>
11721             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11722             * </p>
11723             *
11724             * @param groupId the group ID
11725             * @param categoryId the category ID
11726             * @param threadId the thread ID
11727             * @param start the lower bound of the range of message-boards messages
11728             * @param end the upper bound of the range of message-boards messages (not inclusive)
11729             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11730             * @return the ordered range of matching message-boards messages
11731             */
11732            @Override
11733            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11734                    long threadId, int start, int end,
11735                    OrderByComparator<MBMessage> orderByComparator) {
11736                    boolean pagination = true;
11737                    FinderPath finderPath = null;
11738                    Object[] finderArgs = null;
11739    
11740                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11741                                    (orderByComparator == null)) {
11742                            pagination = false;
11743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
11744                            finderArgs = new Object[] { groupId, categoryId, threadId };
11745                    }
11746                    else {
11747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
11748                            finderArgs = new Object[] {
11749                                            groupId, categoryId, threadId,
11750                                            
11751                                            start, end, orderByComparator
11752                                    };
11753                    }
11754    
11755                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11756                                    finderArgs, this);
11757    
11758                    if ((list != null) && !list.isEmpty()) {
11759                            for (MBMessage mbMessage : list) {
11760                                    if ((groupId != mbMessage.getGroupId()) ||
11761                                                    (categoryId != mbMessage.getCategoryId()) ||
11762                                                    (threadId != mbMessage.getThreadId())) {
11763                                            list = null;
11764    
11765                                            break;
11766                                    }
11767                            }
11768                    }
11769    
11770                    if (list == null) {
11771                            StringBundler query = null;
11772    
11773                            if (orderByComparator != null) {
11774                                    query = new StringBundler(5 +
11775                                                    (orderByComparator.getOrderByFields().length * 3));
11776                            }
11777                            else {
11778                                    query = new StringBundler(5);
11779                            }
11780    
11781                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11782    
11783                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11784    
11785                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11786    
11787                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11788    
11789                            if (orderByComparator != null) {
11790                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11791                                            orderByComparator);
11792                            }
11793                            else
11794                             if (pagination) {
11795                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11796                            }
11797    
11798                            String sql = query.toString();
11799    
11800                            Session session = null;
11801    
11802                            try {
11803                                    session = openSession();
11804    
11805                                    Query q = session.createQuery(sql);
11806    
11807                                    QueryPos qPos = QueryPos.getInstance(q);
11808    
11809                                    qPos.add(groupId);
11810    
11811                                    qPos.add(categoryId);
11812    
11813                                    qPos.add(threadId);
11814    
11815                                    if (!pagination) {
11816                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11817                                                            start, end, false);
11818    
11819                                            Collections.sort(list);
11820    
11821                                            list = Collections.unmodifiableList(list);
11822                                    }
11823                                    else {
11824                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11825                                                            start, end);
11826                                    }
11827    
11828                                    cacheResult(list);
11829    
11830                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11831                            }
11832                            catch (Exception e) {
11833                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11834    
11835                                    throw processException(e);
11836                            }
11837                            finally {
11838                                    closeSession(session);
11839                            }
11840                    }
11841    
11842                    return list;
11843            }
11844    
11845            /**
11846             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11847             *
11848             * @param groupId the group ID
11849             * @param categoryId the category ID
11850             * @param threadId the thread ID
11851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11852             * @return the first matching message-boards message
11853             * @throws NoSuchMessageException if a matching message-boards message could not be found
11854             */
11855            @Override
11856            public MBMessage findByG_C_T_First(long groupId, long categoryId,
11857                    long threadId, OrderByComparator<MBMessage> orderByComparator)
11858                    throws NoSuchMessageException {
11859                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11860                                    orderByComparator);
11861    
11862                    if (mbMessage != null) {
11863                            return mbMessage;
11864                    }
11865    
11866                    StringBundler msg = new StringBundler(8);
11867    
11868                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11869    
11870                    msg.append("groupId=");
11871                    msg.append(groupId);
11872    
11873                    msg.append(", categoryId=");
11874                    msg.append(categoryId);
11875    
11876                    msg.append(", threadId=");
11877                    msg.append(threadId);
11878    
11879                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11880    
11881                    throw new NoSuchMessageException(msg.toString());
11882            }
11883    
11884            /**
11885             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11886             *
11887             * @param groupId the group ID
11888             * @param categoryId the category ID
11889             * @param threadId the thread ID
11890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11891             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11892             */
11893            @Override
11894            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11895                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
11896                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11897                                    orderByComparator);
11898    
11899                    if (!list.isEmpty()) {
11900                            return list.get(0);
11901                    }
11902    
11903                    return null;
11904            }
11905    
11906            /**
11907             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11908             *
11909             * @param groupId the group ID
11910             * @param categoryId the category ID
11911             * @param threadId the thread ID
11912             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11913             * @return the last matching message-boards message
11914             * @throws NoSuchMessageException if a matching message-boards message could not be found
11915             */
11916            @Override
11917            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11918                    long threadId, OrderByComparator<MBMessage> orderByComparator)
11919                    throws NoSuchMessageException {
11920                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11921                                    orderByComparator);
11922    
11923                    if (mbMessage != null) {
11924                            return mbMessage;
11925                    }
11926    
11927                    StringBundler msg = new StringBundler(8);
11928    
11929                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11930    
11931                    msg.append("groupId=");
11932                    msg.append(groupId);
11933    
11934                    msg.append(", categoryId=");
11935                    msg.append(categoryId);
11936    
11937                    msg.append(", threadId=");
11938                    msg.append(threadId);
11939    
11940                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11941    
11942                    throw new NoSuchMessageException(msg.toString());
11943            }
11944    
11945            /**
11946             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11947             *
11948             * @param groupId the group ID
11949             * @param categoryId the category ID
11950             * @param threadId the thread ID
11951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11952             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11953             */
11954            @Override
11955            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11956                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
11957                    int count = countByG_C_T(groupId, categoryId, threadId);
11958    
11959                    if (count == 0) {
11960                            return null;
11961                    }
11962    
11963                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11964                                    count - 1, count, orderByComparator);
11965    
11966                    if (!list.isEmpty()) {
11967                            return list.get(0);
11968                    }
11969    
11970                    return null;
11971            }
11972    
11973            /**
11974             * 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;.
11975             *
11976             * @param messageId the primary key of the current message-boards message
11977             * @param groupId the group ID
11978             * @param categoryId the category ID
11979             * @param threadId the thread ID
11980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11981             * @return the previous, current, and next message-boards message
11982             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11983             */
11984            @Override
11985            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11986                    long categoryId, long threadId,
11987                    OrderByComparator<MBMessage> orderByComparator)
11988                    throws NoSuchMessageException {
11989                    MBMessage mbMessage = findByPrimaryKey(messageId);
11990    
11991                    Session session = null;
11992    
11993                    try {
11994                            session = openSession();
11995    
11996                            MBMessage[] array = new MBMessageImpl[3];
11997    
11998                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11999                                            categoryId, threadId, orderByComparator, true);
12000    
12001                            array[1] = mbMessage;
12002    
12003                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12004                                            categoryId, threadId, orderByComparator, false);
12005    
12006                            return array;
12007                    }
12008                    catch (Exception e) {
12009                            throw processException(e);
12010                    }
12011                    finally {
12012                            closeSession(session);
12013                    }
12014            }
12015    
12016            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12017                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12018                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12019                    StringBundler query = null;
12020    
12021                    if (orderByComparator != null) {
12022                            query = new StringBundler(6 +
12023                                            (orderByComparator.getOrderByFields().length * 6));
12024                    }
12025                    else {
12026                            query = new StringBundler(3);
12027                    }
12028    
12029                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12030    
12031                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12032    
12033                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12034    
12035                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12036    
12037                    if (orderByComparator != null) {
12038                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12039    
12040                            if (orderByConditionFields.length > 0) {
12041                                    query.append(WHERE_AND);
12042                            }
12043    
12044                            for (int i = 0; i < orderByConditionFields.length; i++) {
12045                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12046                                    query.append(orderByConditionFields[i]);
12047    
12048                                    if ((i + 1) < orderByConditionFields.length) {
12049                                            if (orderByComparator.isAscending() ^ previous) {
12050                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12051                                            }
12052                                            else {
12053                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12054                                            }
12055                                    }
12056                                    else {
12057                                            if (orderByComparator.isAscending() ^ previous) {
12058                                                    query.append(WHERE_GREATER_THAN);
12059                                            }
12060                                            else {
12061                                                    query.append(WHERE_LESSER_THAN);
12062                                            }
12063                                    }
12064                            }
12065    
12066                            query.append(ORDER_BY_CLAUSE);
12067    
12068                            String[] orderByFields = orderByComparator.getOrderByFields();
12069    
12070                            for (int i = 0; i < orderByFields.length; i++) {
12071                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12072                                    query.append(orderByFields[i]);
12073    
12074                                    if ((i + 1) < orderByFields.length) {
12075                                            if (orderByComparator.isAscending() ^ previous) {
12076                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12077                                            }
12078                                            else {
12079                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12080                                            }
12081                                    }
12082                                    else {
12083                                            if (orderByComparator.isAscending() ^ previous) {
12084                                                    query.append(ORDER_BY_ASC);
12085                                            }
12086                                            else {
12087                                                    query.append(ORDER_BY_DESC);
12088                                            }
12089                                    }
12090                            }
12091                    }
12092                    else {
12093                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12094                    }
12095    
12096                    String sql = query.toString();
12097    
12098                    Query q = session.createQuery(sql);
12099    
12100                    q.setFirstResult(0);
12101                    q.setMaxResults(2);
12102    
12103                    QueryPos qPos = QueryPos.getInstance(q);
12104    
12105                    qPos.add(groupId);
12106    
12107                    qPos.add(categoryId);
12108    
12109                    qPos.add(threadId);
12110    
12111                    if (orderByComparator != null) {
12112                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12113    
12114                            for (Object value : values) {
12115                                    qPos.add(value);
12116                            }
12117                    }
12118    
12119                    List<MBMessage> list = q.list();
12120    
12121                    if (list.size() == 2) {
12122                            return list.get(1);
12123                    }
12124                    else {
12125                            return null;
12126                    }
12127            }
12128    
12129            /**
12130             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12131             *
12132             * @param groupId the group ID
12133             * @param categoryId the category ID
12134             * @param threadId the thread ID
12135             * @return the matching message-boards messages that the user has permission to view
12136             */
12137            @Override
12138            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12139                    long threadId) {
12140                    return filterFindByG_C_T(groupId, categoryId, threadId,
12141                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12142            }
12143    
12144            /**
12145             * 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;.
12146             *
12147             * <p>
12148             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12149             * </p>
12150             *
12151             * @param groupId the group ID
12152             * @param categoryId the category ID
12153             * @param threadId the thread ID
12154             * @param start the lower bound of the range of message-boards messages
12155             * @param end the upper bound of the range of message-boards messages (not inclusive)
12156             * @return the range of matching message-boards messages that the user has permission to view
12157             */
12158            @Override
12159            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12160                    long threadId, int start, int end) {
12161                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12162            }
12163    
12164            /**
12165             * 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;.
12166             *
12167             * <p>
12168             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12169             * </p>
12170             *
12171             * @param groupId the group ID
12172             * @param categoryId the category ID
12173             * @param threadId the thread ID
12174             * @param start the lower bound of the range of message-boards messages
12175             * @param end the upper bound of the range of message-boards messages (not inclusive)
12176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12177             * @return the ordered range of matching message-boards messages that the user has permission to view
12178             */
12179            @Override
12180            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12181                    long threadId, int start, int end,
12182                    OrderByComparator<MBMessage> orderByComparator) {
12183                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12184                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12185                                    orderByComparator);
12186                    }
12187    
12188                    StringBundler query = null;
12189    
12190                    if (orderByComparator != null) {
12191                            query = new StringBundler(5 +
12192                                            (orderByComparator.getOrderByFields().length * 3));
12193                    }
12194                    else {
12195                            query = new StringBundler(5);
12196                    }
12197    
12198                    if (getDB().isSupportsInlineDistinct()) {
12199                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12200                    }
12201                    else {
12202                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12203                    }
12204    
12205                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12206    
12207                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12208    
12209                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12210    
12211                    if (!getDB().isSupportsInlineDistinct()) {
12212                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12213                    }
12214    
12215                    if (orderByComparator != null) {
12216                            if (getDB().isSupportsInlineDistinct()) {
12217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12218                                            orderByComparator, true);
12219                            }
12220                            else {
12221                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12222                                            orderByComparator, true);
12223                            }
12224                    }
12225                    else {
12226                            if (getDB().isSupportsInlineDistinct()) {
12227                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12228                            }
12229                            else {
12230                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12231                            }
12232                    }
12233    
12234                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12235                                    MBMessage.class.getName(),
12236                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12237    
12238                    Session session = null;
12239    
12240                    try {
12241                            session = openSession();
12242    
12243                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12244    
12245                            if (getDB().isSupportsInlineDistinct()) {
12246                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12247                            }
12248                            else {
12249                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12250                            }
12251    
12252                            QueryPos qPos = QueryPos.getInstance(q);
12253    
12254                            qPos.add(groupId);
12255    
12256                            qPos.add(categoryId);
12257    
12258                            qPos.add(threadId);
12259    
12260                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12261                    }
12262                    catch (Exception e) {
12263                            throw processException(e);
12264                    }
12265                    finally {
12266                            closeSession(session);
12267                    }
12268            }
12269    
12270            /**
12271             * 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;.
12272             *
12273             * @param messageId the primary key of the current message-boards message
12274             * @param groupId the group ID
12275             * @param categoryId the category ID
12276             * @param threadId the thread ID
12277             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12278             * @return the previous, current, and next message-boards message
12279             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12280             */
12281            @Override
12282            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12283                    long groupId, long categoryId, long threadId,
12284                    OrderByComparator<MBMessage> orderByComparator)
12285                    throws NoSuchMessageException {
12286                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12287                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12288                                    threadId, orderByComparator);
12289                    }
12290    
12291                    MBMessage mbMessage = findByPrimaryKey(messageId);
12292    
12293                    Session session = null;
12294    
12295                    try {
12296                            session = openSession();
12297    
12298                            MBMessage[] array = new MBMessageImpl[3];
12299    
12300                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12301                                            groupId, categoryId, threadId, orderByComparator, true);
12302    
12303                            array[1] = mbMessage;
12304    
12305                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12306                                            groupId, categoryId, threadId, orderByComparator, false);
12307    
12308                            return array;
12309                    }
12310                    catch (Exception e) {
12311                            throw processException(e);
12312                    }
12313                    finally {
12314                            closeSession(session);
12315                    }
12316            }
12317    
12318            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12319                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12320                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12321                    StringBundler query = null;
12322    
12323                    if (orderByComparator != null) {
12324                            query = new StringBundler(6 +
12325                                            (orderByComparator.getOrderByFields().length * 6));
12326                    }
12327                    else {
12328                            query = new StringBundler(3);
12329                    }
12330    
12331                    if (getDB().isSupportsInlineDistinct()) {
12332                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12333                    }
12334                    else {
12335                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12336                    }
12337    
12338                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12339    
12340                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12341    
12342                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12343    
12344                    if (!getDB().isSupportsInlineDistinct()) {
12345                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12346                    }
12347    
12348                    if (orderByComparator != null) {
12349                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12350    
12351                            if (orderByConditionFields.length > 0) {
12352                                    query.append(WHERE_AND);
12353                            }
12354    
12355                            for (int i = 0; i < orderByConditionFields.length; i++) {
12356                                    if (getDB().isSupportsInlineDistinct()) {
12357                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12358                                    }
12359                                    else {
12360                                            query.append(_ORDER_BY_ENTITY_TABLE);
12361                                    }
12362    
12363                                    query.append(orderByConditionFields[i]);
12364    
12365                                    if ((i + 1) < orderByConditionFields.length) {
12366                                            if (orderByComparator.isAscending() ^ previous) {
12367                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12368                                            }
12369                                            else {
12370                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12371                                            }
12372                                    }
12373                                    else {
12374                                            if (orderByComparator.isAscending() ^ previous) {
12375                                                    query.append(WHERE_GREATER_THAN);
12376                                            }
12377                                            else {
12378                                                    query.append(WHERE_LESSER_THAN);
12379                                            }
12380                                    }
12381                            }
12382    
12383                            query.append(ORDER_BY_CLAUSE);
12384    
12385                            String[] orderByFields = orderByComparator.getOrderByFields();
12386    
12387                            for (int i = 0; i < orderByFields.length; i++) {
12388                                    if (getDB().isSupportsInlineDistinct()) {
12389                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12390                                    }
12391                                    else {
12392                                            query.append(_ORDER_BY_ENTITY_TABLE);
12393                                    }
12394    
12395                                    query.append(orderByFields[i]);
12396    
12397                                    if ((i + 1) < orderByFields.length) {
12398                                            if (orderByComparator.isAscending() ^ previous) {
12399                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12400                                            }
12401                                            else {
12402                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12403                                            }
12404                                    }
12405                                    else {
12406                                            if (orderByComparator.isAscending() ^ previous) {
12407                                                    query.append(ORDER_BY_ASC);
12408                                            }
12409                                            else {
12410                                                    query.append(ORDER_BY_DESC);
12411                                            }
12412                                    }
12413                            }
12414                    }
12415                    else {
12416                            if (getDB().isSupportsInlineDistinct()) {
12417                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12418                            }
12419                            else {
12420                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12421                            }
12422                    }
12423    
12424                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12425                                    MBMessage.class.getName(),
12426                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12427    
12428                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12429    
12430                    q.setFirstResult(0);
12431                    q.setMaxResults(2);
12432    
12433                    if (getDB().isSupportsInlineDistinct()) {
12434                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12435                    }
12436                    else {
12437                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12438                    }
12439    
12440                    QueryPos qPos = QueryPos.getInstance(q);
12441    
12442                    qPos.add(groupId);
12443    
12444                    qPos.add(categoryId);
12445    
12446                    qPos.add(threadId);
12447    
12448                    if (orderByComparator != null) {
12449                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12450    
12451                            for (Object value : values) {
12452                                    qPos.add(value);
12453                            }
12454                    }
12455    
12456                    List<MBMessage> list = q.list();
12457    
12458                    if (list.size() == 2) {
12459                            return list.get(1);
12460                    }
12461                    else {
12462                            return null;
12463                    }
12464            }
12465    
12466            /**
12467             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12468             *
12469             * @param groupId the group ID
12470             * @param categoryId the category ID
12471             * @param threadId the thread ID
12472             */
12473            @Override
12474            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
12475                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12476                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12477                            remove(mbMessage);
12478                    }
12479            }
12480    
12481            /**
12482             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12483             *
12484             * @param groupId the group ID
12485             * @param categoryId the category ID
12486             * @param threadId the thread ID
12487             * @return the number of matching message-boards messages
12488             */
12489            @Override
12490            public int countByG_C_T(long groupId, long categoryId, long threadId) {
12491                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12492    
12493                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12494    
12495                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12496                                    this);
12497    
12498                    if (count == null) {
12499                            StringBundler query = new StringBundler(4);
12500    
12501                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12502    
12503                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12504    
12505                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12506    
12507                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12508    
12509                            String sql = query.toString();
12510    
12511                            Session session = null;
12512    
12513                            try {
12514                                    session = openSession();
12515    
12516                                    Query q = session.createQuery(sql);
12517    
12518                                    QueryPos qPos = QueryPos.getInstance(q);
12519    
12520                                    qPos.add(groupId);
12521    
12522                                    qPos.add(categoryId);
12523    
12524                                    qPos.add(threadId);
12525    
12526                                    count = (Long)q.uniqueResult();
12527    
12528                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12529                            }
12530                            catch (Exception e) {
12531                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12532    
12533                                    throw processException(e);
12534                            }
12535                            finally {
12536                                    closeSession(session);
12537                            }
12538                    }
12539    
12540                    return count.intValue();
12541            }
12542    
12543            /**
12544             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12545             *
12546             * @param groupId the group ID
12547             * @param categoryId the category ID
12548             * @param threadId the thread ID
12549             * @return the number of matching message-boards messages that the user has permission to view
12550             */
12551            @Override
12552            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
12553                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12554                            return countByG_C_T(groupId, categoryId, threadId);
12555                    }
12556    
12557                    StringBundler query = new StringBundler(4);
12558    
12559                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12560    
12561                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12562    
12563                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12564    
12565                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12566    
12567                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12568                                    MBMessage.class.getName(),
12569                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12570    
12571                    Session session = null;
12572    
12573                    try {
12574                            session = openSession();
12575    
12576                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12577    
12578                            q.addScalar(COUNT_COLUMN_NAME,
12579                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12580    
12581                            QueryPos qPos = QueryPos.getInstance(q);
12582    
12583                            qPos.add(groupId);
12584    
12585                            qPos.add(categoryId);
12586    
12587                            qPos.add(threadId);
12588    
12589                            Long count = (Long)q.uniqueResult();
12590    
12591                            return count.intValue();
12592                    }
12593                    catch (Exception e) {
12594                            throw processException(e);
12595                    }
12596                    finally {
12597                            closeSession(session);
12598                    }
12599            }
12600    
12601            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12602            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12603            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12604            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12605                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12606                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12607                            new String[] {
12608                                    Long.class.getName(), Long.class.getName(),
12609                                    Integer.class.getName(),
12610                                    
12611                            Integer.class.getName(), Integer.class.getName(),
12612                                    OrderByComparator.class.getName()
12613                            });
12614            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12615                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12616                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12617                            new String[] {
12618                                    Long.class.getName(), Long.class.getName(),
12619                                    Integer.class.getName()
12620                            },
12621                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12622                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12623                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12624                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12625            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12626                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12627                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12628                            new String[] {
12629                                    Long.class.getName(), Long.class.getName(),
12630                                    Integer.class.getName()
12631                            });
12632    
12633            /**
12634             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12635             *
12636             * @param groupId the group ID
12637             * @param categoryId the category ID
12638             * @param status the status
12639             * @return the matching message-boards messages
12640             */
12641            @Override
12642            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
12643                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12644                            QueryUtil.ALL_POS, null);
12645            }
12646    
12647            /**
12648             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12649             *
12650             * <p>
12651             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12652             * </p>
12653             *
12654             * @param groupId the group ID
12655             * @param categoryId the category ID
12656             * @param status the status
12657             * @param start the lower bound of the range of message-boards messages
12658             * @param end the upper bound of the range of message-boards messages (not inclusive)
12659             * @return the range of matching message-boards messages
12660             */
12661            @Override
12662            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12663                    int status, int start, int end) {
12664                    return findByG_C_S(groupId, categoryId, status, start, end, null);
12665            }
12666    
12667            /**
12668             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12669             *
12670             * <p>
12671             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12672             * </p>
12673             *
12674             * @param groupId the group ID
12675             * @param categoryId the category ID
12676             * @param status the status
12677             * @param start the lower bound of the range of message-boards messages
12678             * @param end the upper bound of the range of message-boards messages (not inclusive)
12679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12680             * @return the ordered range of matching message-boards messages
12681             */
12682            @Override
12683            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12684                    int status, int start, int end,
12685                    OrderByComparator<MBMessage> orderByComparator) {
12686                    boolean pagination = true;
12687                    FinderPath finderPath = null;
12688                    Object[] finderArgs = null;
12689    
12690                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12691                                    (orderByComparator == null)) {
12692                            pagination = false;
12693                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
12694                            finderArgs = new Object[] { groupId, categoryId, status };
12695                    }
12696                    else {
12697                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
12698                            finderArgs = new Object[] {
12699                                            groupId, categoryId, status,
12700                                            
12701                                            start, end, orderByComparator
12702                                    };
12703                    }
12704    
12705                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12706                                    finderArgs, this);
12707    
12708                    if ((list != null) && !list.isEmpty()) {
12709                            for (MBMessage mbMessage : list) {
12710                                    if ((groupId != mbMessage.getGroupId()) ||
12711                                                    (categoryId != mbMessage.getCategoryId()) ||
12712                                                    (status != mbMessage.getStatus())) {
12713                                            list = null;
12714    
12715                                            break;
12716                                    }
12717                            }
12718                    }
12719    
12720                    if (list == null) {
12721                            StringBundler query = null;
12722    
12723                            if (orderByComparator != null) {
12724                                    query = new StringBundler(5 +
12725                                                    (orderByComparator.getOrderByFields().length * 3));
12726                            }
12727                            else {
12728                                    query = new StringBundler(5);
12729                            }
12730    
12731                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12732    
12733                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12734    
12735                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12736    
12737                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12738    
12739                            if (orderByComparator != null) {
12740                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12741                                            orderByComparator);
12742                            }
12743                            else
12744                             if (pagination) {
12745                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12746                            }
12747    
12748                            String sql = query.toString();
12749    
12750                            Session session = null;
12751    
12752                            try {
12753                                    session = openSession();
12754    
12755                                    Query q = session.createQuery(sql);
12756    
12757                                    QueryPos qPos = QueryPos.getInstance(q);
12758    
12759                                    qPos.add(groupId);
12760    
12761                                    qPos.add(categoryId);
12762    
12763                                    qPos.add(status);
12764    
12765                                    if (!pagination) {
12766                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12767                                                            start, end, false);
12768    
12769                                            Collections.sort(list);
12770    
12771                                            list = Collections.unmodifiableList(list);
12772                                    }
12773                                    else {
12774                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12775                                                            start, end);
12776                                    }
12777    
12778                                    cacheResult(list);
12779    
12780                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12781                            }
12782                            catch (Exception e) {
12783                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12784    
12785                                    throw processException(e);
12786                            }
12787                            finally {
12788                                    closeSession(session);
12789                            }
12790                    }
12791    
12792                    return list;
12793            }
12794    
12795            /**
12796             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12797             *
12798             * @param groupId the group ID
12799             * @param categoryId the category ID
12800             * @param status the status
12801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12802             * @return the first matching message-boards message
12803             * @throws NoSuchMessageException if a matching message-boards message could not be found
12804             */
12805            @Override
12806            public MBMessage findByG_C_S_First(long groupId, long categoryId,
12807                    int status, OrderByComparator<MBMessage> orderByComparator)
12808                    throws NoSuchMessageException {
12809                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
12810                                    orderByComparator);
12811    
12812                    if (mbMessage != null) {
12813                            return mbMessage;
12814                    }
12815    
12816                    StringBundler msg = new StringBundler(8);
12817    
12818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12819    
12820                    msg.append("groupId=");
12821                    msg.append(groupId);
12822    
12823                    msg.append(", categoryId=");
12824                    msg.append(categoryId);
12825    
12826                    msg.append(", status=");
12827                    msg.append(status);
12828    
12829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12830    
12831                    throw new NoSuchMessageException(msg.toString());
12832            }
12833    
12834            /**
12835             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12836             *
12837             * @param groupId the group ID
12838             * @param categoryId the category ID
12839             * @param status the status
12840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12841             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12842             */
12843            @Override
12844            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
12845                    int status, OrderByComparator<MBMessage> orderByComparator) {
12846                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
12847                                    orderByComparator);
12848    
12849                    if (!list.isEmpty()) {
12850                            return list.get(0);
12851                    }
12852    
12853                    return null;
12854            }
12855    
12856            /**
12857             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12858             *
12859             * @param groupId the group ID
12860             * @param categoryId the category ID
12861             * @param status the status
12862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12863             * @return the last matching message-boards message
12864             * @throws NoSuchMessageException if a matching message-boards message could not be found
12865             */
12866            @Override
12867            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
12868                    int status, OrderByComparator<MBMessage> orderByComparator)
12869                    throws NoSuchMessageException {
12870                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
12871                                    orderByComparator);
12872    
12873                    if (mbMessage != null) {
12874                            return mbMessage;
12875                    }
12876    
12877                    StringBundler msg = new StringBundler(8);
12878    
12879                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12880    
12881                    msg.append("groupId=");
12882                    msg.append(groupId);
12883    
12884                    msg.append(", categoryId=");
12885                    msg.append(categoryId);
12886    
12887                    msg.append(", status=");
12888                    msg.append(status);
12889    
12890                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12891    
12892                    throw new NoSuchMessageException(msg.toString());
12893            }
12894    
12895            /**
12896             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12897             *
12898             * @param groupId the group ID
12899             * @param categoryId the category ID
12900             * @param status the status
12901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12902             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12903             */
12904            @Override
12905            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
12906                    int status, OrderByComparator<MBMessage> orderByComparator) {
12907                    int count = countByG_C_S(groupId, categoryId, status);
12908    
12909                    if (count == 0) {
12910                            return null;
12911                    }
12912    
12913                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
12914                                    count - 1, count, orderByComparator);
12915    
12916                    if (!list.isEmpty()) {
12917                            return list.get(0);
12918                    }
12919    
12920                    return null;
12921            }
12922    
12923            /**
12924             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12925             *
12926             * @param messageId the primary key of the current message-boards message
12927             * @param groupId the group ID
12928             * @param categoryId the category ID
12929             * @param status the status
12930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12931             * @return the previous, current, and next message-boards message
12932             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12933             */
12934            @Override
12935            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
12936                    long categoryId, int status,
12937                    OrderByComparator<MBMessage> orderByComparator)
12938                    throws NoSuchMessageException {
12939                    MBMessage mbMessage = findByPrimaryKey(messageId);
12940    
12941                    Session session = null;
12942    
12943                    try {
12944                            session = openSession();
12945    
12946                            MBMessage[] array = new MBMessageImpl[3];
12947    
12948                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12949                                            categoryId, status, orderByComparator, true);
12950    
12951                            array[1] = mbMessage;
12952    
12953                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12954                                            categoryId, status, orderByComparator, false);
12955    
12956                            return array;
12957                    }
12958                    catch (Exception e) {
12959                            throw processException(e);
12960                    }
12961                    finally {
12962                            closeSession(session);
12963                    }
12964            }
12965    
12966            protected MBMessage getByG_C_S_PrevAndNext(Session session,
12967                    MBMessage mbMessage, long groupId, long categoryId, int status,
12968                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12969                    StringBundler query = null;
12970    
12971                    if (orderByComparator != null) {
12972                            query = new StringBundler(6 +
12973                                            (orderByComparator.getOrderByFields().length * 6));
12974                    }
12975                    else {
12976                            query = new StringBundler(3);
12977                    }
12978    
12979                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12980    
12981                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12982    
12983                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12984    
12985                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12986    
12987                    if (orderByComparator != null) {
12988                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12989    
12990                            if (orderByConditionFields.length > 0) {
12991                                    query.append(WHERE_AND);
12992                            }
12993    
12994                            for (int i = 0; i < orderByConditionFields.length; i++) {
12995                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12996                                    query.append(orderByConditionFields[i]);
12997    
12998                                    if ((i + 1) < orderByConditionFields.length) {
12999                                            if (orderByComparator.isAscending() ^ previous) {
13000                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13001                                            }
13002                                            else {
13003                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13004                                            }
13005                                    }
13006                                    else {
13007                                            if (orderByComparator.isAscending() ^ previous) {
13008                                                    query.append(WHERE_GREATER_THAN);
13009                                            }
13010                                            else {
13011                                                    query.append(WHERE_LESSER_THAN);
13012                                            }
13013                                    }
13014                            }
13015    
13016                            query.append(ORDER_BY_CLAUSE);
13017    
13018                            String[] orderByFields = orderByComparator.getOrderByFields();
13019    
13020                            for (int i = 0; i < orderByFields.length; i++) {
13021                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13022                                    query.append(orderByFields[i]);
13023    
13024                                    if ((i + 1) < orderByFields.length) {
13025                                            if (orderByComparator.isAscending() ^ previous) {
13026                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13027                                            }
13028                                            else {
13029                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13030                                            }
13031                                    }
13032                                    else {
13033                                            if (orderByComparator.isAscending() ^ previous) {
13034                                                    query.append(ORDER_BY_ASC);
13035                                            }
13036                                            else {
13037                                                    query.append(ORDER_BY_DESC);
13038                                            }
13039                                    }
13040                            }
13041                    }
13042                    else {
13043                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13044                    }
13045    
13046                    String sql = query.toString();
13047    
13048                    Query q = session.createQuery(sql);
13049    
13050                    q.setFirstResult(0);
13051                    q.setMaxResults(2);
13052    
13053                    QueryPos qPos = QueryPos.getInstance(q);
13054    
13055                    qPos.add(groupId);
13056    
13057                    qPos.add(categoryId);
13058    
13059                    qPos.add(status);
13060    
13061                    if (orderByComparator != null) {
13062                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13063    
13064                            for (Object value : values) {
13065                                    qPos.add(value);
13066                            }
13067                    }
13068    
13069                    List<MBMessage> list = q.list();
13070    
13071                    if (list.size() == 2) {
13072                            return list.get(1);
13073                    }
13074                    else {
13075                            return null;
13076                    }
13077            }
13078    
13079            /**
13080             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13081             *
13082             * @param groupId the group ID
13083             * @param categoryId the category ID
13084             * @param status the status
13085             * @return the matching message-boards messages that the user has permission to view
13086             */
13087            @Override
13088            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13089                    int status) {
13090                    return filterFindByG_C_S(groupId, categoryId, status,
13091                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13092            }
13093    
13094            /**
13095             * 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;.
13096             *
13097             * <p>
13098             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13099             * </p>
13100             *
13101             * @param groupId the group ID
13102             * @param categoryId the category ID
13103             * @param status the status
13104             * @param start the lower bound of the range of message-boards messages
13105             * @param end the upper bound of the range of message-boards messages (not inclusive)
13106             * @return the range of matching message-boards messages that the user has permission to view
13107             */
13108            @Override
13109            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13110                    int status, int start, int end) {
13111                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13112            }
13113    
13114            /**
13115             * 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;.
13116             *
13117             * <p>
13118             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13119             * </p>
13120             *
13121             * @param groupId the group ID
13122             * @param categoryId the category ID
13123             * @param status the status
13124             * @param start the lower bound of the range of message-boards messages
13125             * @param end the upper bound of the range of message-boards messages (not inclusive)
13126             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13127             * @return the ordered range of matching message-boards messages that the user has permission to view
13128             */
13129            @Override
13130            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13131                    int status, int start, int end,
13132                    OrderByComparator<MBMessage> orderByComparator) {
13133                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13134                            return findByG_C_S(groupId, categoryId, status, start, end,
13135                                    orderByComparator);
13136                    }
13137    
13138                    StringBundler query = null;
13139    
13140                    if (orderByComparator != null) {
13141                            query = new StringBundler(5 +
13142                                            (orderByComparator.getOrderByFields().length * 3));
13143                    }
13144                    else {
13145                            query = new StringBundler(5);
13146                    }
13147    
13148                    if (getDB().isSupportsInlineDistinct()) {
13149                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13150                    }
13151                    else {
13152                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13153                    }
13154    
13155                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13156    
13157                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13158    
13159                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13160    
13161                    if (!getDB().isSupportsInlineDistinct()) {
13162                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13163                    }
13164    
13165                    if (orderByComparator != null) {
13166                            if (getDB().isSupportsInlineDistinct()) {
13167                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13168                                            orderByComparator, true);
13169                            }
13170                            else {
13171                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13172                                            orderByComparator, true);
13173                            }
13174                    }
13175                    else {
13176                            if (getDB().isSupportsInlineDistinct()) {
13177                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13178                            }
13179                            else {
13180                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13181                            }
13182                    }
13183    
13184                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13185                                    MBMessage.class.getName(),
13186                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13187    
13188                    Session session = null;
13189    
13190                    try {
13191                            session = openSession();
13192    
13193                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13194    
13195                            if (getDB().isSupportsInlineDistinct()) {
13196                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13197                            }
13198                            else {
13199                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13200                            }
13201    
13202                            QueryPos qPos = QueryPos.getInstance(q);
13203    
13204                            qPos.add(groupId);
13205    
13206                            qPos.add(categoryId);
13207    
13208                            qPos.add(status);
13209    
13210                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13211                    }
13212                    catch (Exception e) {
13213                            throw processException(e);
13214                    }
13215                    finally {
13216                            closeSession(session);
13217                    }
13218            }
13219    
13220            /**
13221             * 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;.
13222             *
13223             * @param messageId the primary key of the current message-boards message
13224             * @param groupId the group ID
13225             * @param categoryId the category ID
13226             * @param status the status
13227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13228             * @return the previous, current, and next message-boards message
13229             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13230             */
13231            @Override
13232            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13233                    long groupId, long categoryId, int status,
13234                    OrderByComparator<MBMessage> orderByComparator)
13235                    throws NoSuchMessageException {
13236                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13237                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13238                                    status, orderByComparator);
13239                    }
13240    
13241                    MBMessage mbMessage = findByPrimaryKey(messageId);
13242    
13243                    Session session = null;
13244    
13245                    try {
13246                            session = openSession();
13247    
13248                            MBMessage[] array = new MBMessageImpl[3];
13249    
13250                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13251                                            groupId, categoryId, status, orderByComparator, true);
13252    
13253                            array[1] = mbMessage;
13254    
13255                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13256                                            groupId, categoryId, status, orderByComparator, false);
13257    
13258                            return array;
13259                    }
13260                    catch (Exception e) {
13261                            throw processException(e);
13262                    }
13263                    finally {
13264                            closeSession(session);
13265                    }
13266            }
13267    
13268            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13269                    MBMessage mbMessage, long groupId, long categoryId, int status,
13270                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13271                    StringBundler query = null;
13272    
13273                    if (orderByComparator != null) {
13274                            query = new StringBundler(6 +
13275                                            (orderByComparator.getOrderByFields().length * 6));
13276                    }
13277                    else {
13278                            query = new StringBundler(3);
13279                    }
13280    
13281                    if (getDB().isSupportsInlineDistinct()) {
13282                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13283                    }
13284                    else {
13285                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13286                    }
13287    
13288                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13289    
13290                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13291    
13292                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13293    
13294                    if (!getDB().isSupportsInlineDistinct()) {
13295                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13296                    }
13297    
13298                    if (orderByComparator != null) {
13299                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13300    
13301                            if (orderByConditionFields.length > 0) {
13302                                    query.append(WHERE_AND);
13303                            }
13304    
13305                            for (int i = 0; i < orderByConditionFields.length; i++) {
13306                                    if (getDB().isSupportsInlineDistinct()) {
13307                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13308                                    }
13309                                    else {
13310                                            query.append(_ORDER_BY_ENTITY_TABLE);
13311                                    }
13312    
13313                                    query.append(orderByConditionFields[i]);
13314    
13315                                    if ((i + 1) < orderByConditionFields.length) {
13316                                            if (orderByComparator.isAscending() ^ previous) {
13317                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13318                                            }
13319                                            else {
13320                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13321                                            }
13322                                    }
13323                                    else {
13324                                            if (orderByComparator.isAscending() ^ previous) {
13325                                                    query.append(WHERE_GREATER_THAN);
13326                                            }
13327                                            else {
13328                                                    query.append(WHERE_LESSER_THAN);
13329                                            }
13330                                    }
13331                            }
13332    
13333                            query.append(ORDER_BY_CLAUSE);
13334    
13335                            String[] orderByFields = orderByComparator.getOrderByFields();
13336    
13337                            for (int i = 0; i < orderByFields.length; i++) {
13338                                    if (getDB().isSupportsInlineDistinct()) {
13339                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13340                                    }
13341                                    else {
13342                                            query.append(_ORDER_BY_ENTITY_TABLE);
13343                                    }
13344    
13345                                    query.append(orderByFields[i]);
13346    
13347                                    if ((i + 1) < orderByFields.length) {
13348                                            if (orderByComparator.isAscending() ^ previous) {
13349                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13350                                            }
13351                                            else {
13352                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13353                                            }
13354                                    }
13355                                    else {
13356                                            if (orderByComparator.isAscending() ^ previous) {
13357                                                    query.append(ORDER_BY_ASC);
13358                                            }
13359                                            else {
13360                                                    query.append(ORDER_BY_DESC);
13361                                            }
13362                                    }
13363                            }
13364                    }
13365                    else {
13366                            if (getDB().isSupportsInlineDistinct()) {
13367                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13368                            }
13369                            else {
13370                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13371                            }
13372                    }
13373    
13374                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13375                                    MBMessage.class.getName(),
13376                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13377    
13378                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13379    
13380                    q.setFirstResult(0);
13381                    q.setMaxResults(2);
13382    
13383                    if (getDB().isSupportsInlineDistinct()) {
13384                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13385                    }
13386                    else {
13387                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13388                    }
13389    
13390                    QueryPos qPos = QueryPos.getInstance(q);
13391    
13392                    qPos.add(groupId);
13393    
13394                    qPos.add(categoryId);
13395    
13396                    qPos.add(status);
13397    
13398                    if (orderByComparator != null) {
13399                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13400    
13401                            for (Object value : values) {
13402                                    qPos.add(value);
13403                            }
13404                    }
13405    
13406                    List<MBMessage> list = q.list();
13407    
13408                    if (list.size() == 2) {
13409                            return list.get(1);
13410                    }
13411                    else {
13412                            return null;
13413                    }
13414            }
13415    
13416            /**
13417             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13418             *
13419             * @param groupId the group ID
13420             * @param categoryId the category ID
13421             * @param status the status
13422             */
13423            @Override
13424            public void removeByG_C_S(long groupId, long categoryId, int status) {
13425                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13426                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13427                            remove(mbMessage);
13428                    }
13429            }
13430    
13431            /**
13432             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13433             *
13434             * @param groupId the group ID
13435             * @param categoryId the category ID
13436             * @param status the status
13437             * @return the number of matching message-boards messages
13438             */
13439            @Override
13440            public int countByG_C_S(long groupId, long categoryId, int status) {
13441                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13442    
13443                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13444    
13445                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13446                                    this);
13447    
13448                    if (count == null) {
13449                            StringBundler query = new StringBundler(4);
13450    
13451                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13452    
13453                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13454    
13455                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13456    
13457                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13458    
13459                            String sql = query.toString();
13460    
13461                            Session session = null;
13462    
13463                            try {
13464                                    session = openSession();
13465    
13466                                    Query q = session.createQuery(sql);
13467    
13468                                    QueryPos qPos = QueryPos.getInstance(q);
13469    
13470                                    qPos.add(groupId);
13471    
13472                                    qPos.add(categoryId);
13473    
13474                                    qPos.add(status);
13475    
13476                                    count = (Long)q.uniqueResult();
13477    
13478                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13479                            }
13480                            catch (Exception e) {
13481                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13482    
13483                                    throw processException(e);
13484                            }
13485                            finally {
13486                                    closeSession(session);
13487                            }
13488                    }
13489    
13490                    return count.intValue();
13491            }
13492    
13493            /**
13494             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13495             *
13496             * @param groupId the group ID
13497             * @param categoryId the category ID
13498             * @param status the status
13499             * @return the number of matching message-boards messages that the user has permission to view
13500             */
13501            @Override
13502            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
13503                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13504                            return countByG_C_S(groupId, categoryId, status);
13505                    }
13506    
13507                    StringBundler query = new StringBundler(4);
13508    
13509                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13510    
13511                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13512    
13513                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13514    
13515                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13516    
13517                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13518                                    MBMessage.class.getName(),
13519                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13520    
13521                    Session session = null;
13522    
13523                    try {
13524                            session = openSession();
13525    
13526                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13527    
13528                            q.addScalar(COUNT_COLUMN_NAME,
13529                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13530    
13531                            QueryPos qPos = QueryPos.getInstance(q);
13532    
13533                            qPos.add(groupId);
13534    
13535                            qPos.add(categoryId);
13536    
13537                            qPos.add(status);
13538    
13539                            Long count = (Long)q.uniqueResult();
13540    
13541                            return count.intValue();
13542                    }
13543                    catch (Exception e) {
13544                            throw processException(e);
13545                    }
13546                    finally {
13547                            closeSession(session);
13548                    }
13549            }
13550    
13551            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13552            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13553            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13554            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13555                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13556                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13557                            new String[] {
13558                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13559                                    
13560                            Integer.class.getName(), Integer.class.getName(),
13561                                    OrderByComparator.class.getName()
13562                            });
13563            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13564                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13565                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13566                            new String[] {
13567                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13568                            },
13569                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
13570                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13571                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13572                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13573            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13574                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13575                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13576                            new String[] {
13577                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13578                            });
13579    
13580            /**
13581             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13582             *
13583             * @param userId the user ID
13584             * @param classNameId the class name ID
13585             * @param classPK the class p k
13586             * @return the matching message-boards messages
13587             */
13588            @Override
13589            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13590                    long classPK) {
13591                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13592                            QueryUtil.ALL_POS, null);
13593            }
13594    
13595            /**
13596             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13597             *
13598             * <p>
13599             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13600             * </p>
13601             *
13602             * @param userId the user ID
13603             * @param classNameId the class name ID
13604             * @param classPK the class p k
13605             * @param start the lower bound of the range of message-boards messages
13606             * @param end the upper bound of the range of message-boards messages (not inclusive)
13607             * @return the range of matching message-boards messages
13608             */
13609            @Override
13610            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13611                    long classPK, int start, int end) {
13612                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
13613            }
13614    
13615            /**
13616             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13617             *
13618             * <p>
13619             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13620             * </p>
13621             *
13622             * @param userId the user ID
13623             * @param classNameId the class name ID
13624             * @param classPK the class p k
13625             * @param start the lower bound of the range of message-boards messages
13626             * @param end the upper bound of the range of message-boards messages (not inclusive)
13627             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13628             * @return the ordered range of matching message-boards messages
13629             */
13630            @Override
13631            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13632                    long classPK, int start, int end,
13633                    OrderByComparator<MBMessage> orderByComparator) {
13634                    boolean pagination = true;
13635                    FinderPath finderPath = null;
13636                    Object[] finderArgs = null;
13637    
13638                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13639                                    (orderByComparator == null)) {
13640                            pagination = false;
13641                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13642                            finderArgs = new Object[] { userId, classNameId, classPK };
13643                    }
13644                    else {
13645                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13646                            finderArgs = new Object[] {
13647                                            userId, classNameId, classPK,
13648                                            
13649                                            start, end, orderByComparator
13650                                    };
13651                    }
13652    
13653                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13654                                    finderArgs, this);
13655    
13656                    if ((list != null) && !list.isEmpty()) {
13657                            for (MBMessage mbMessage : list) {
13658                                    if ((userId != mbMessage.getUserId()) ||
13659                                                    (classNameId != mbMessage.getClassNameId()) ||
13660                                                    (classPK != mbMessage.getClassPK())) {
13661                                            list = null;
13662    
13663                                            break;
13664                                    }
13665                            }
13666                    }
13667    
13668                    if (list == null) {
13669                            StringBundler query = null;
13670    
13671                            if (orderByComparator != null) {
13672                                    query = new StringBundler(5 +
13673                                                    (orderByComparator.getOrderByFields().length * 3));
13674                            }
13675                            else {
13676                                    query = new StringBundler(5);
13677                            }
13678    
13679                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13680    
13681                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13682    
13683                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13684    
13685                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13686    
13687                            if (orderByComparator != null) {
13688                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13689                                            orderByComparator);
13690                            }
13691                            else
13692                             if (pagination) {
13693                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13694                            }
13695    
13696                            String sql = query.toString();
13697    
13698                            Session session = null;
13699    
13700                            try {
13701                                    session = openSession();
13702    
13703                                    Query q = session.createQuery(sql);
13704    
13705                                    QueryPos qPos = QueryPos.getInstance(q);
13706    
13707                                    qPos.add(userId);
13708    
13709                                    qPos.add(classNameId);
13710    
13711                                    qPos.add(classPK);
13712    
13713                                    if (!pagination) {
13714                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13715                                                            start, end, false);
13716    
13717                                            Collections.sort(list);
13718    
13719                                            list = Collections.unmodifiableList(list);
13720                                    }
13721                                    else {
13722                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13723                                                            start, end);
13724                                    }
13725    
13726                                    cacheResult(list);
13727    
13728                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13729                            }
13730                            catch (Exception e) {
13731                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13732    
13733                                    throw processException(e);
13734                            }
13735                            finally {
13736                                    closeSession(session);
13737                            }
13738                    }
13739    
13740                    return list;
13741            }
13742    
13743            /**
13744             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13745             *
13746             * @param userId the user ID
13747             * @param classNameId the class name ID
13748             * @param classPK the class p k
13749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13750             * @return the first matching message-boards message
13751             * @throws NoSuchMessageException if a matching message-boards message could not be found
13752             */
13753            @Override
13754            public MBMessage findByU_C_C_First(long userId, long classNameId,
13755                    long classPK, OrderByComparator<MBMessage> orderByComparator)
13756                    throws NoSuchMessageException {
13757                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
13758                                    orderByComparator);
13759    
13760                    if (mbMessage != null) {
13761                            return mbMessage;
13762                    }
13763    
13764                    StringBundler msg = new StringBundler(8);
13765    
13766                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13767    
13768                    msg.append("userId=");
13769                    msg.append(userId);
13770    
13771                    msg.append(", classNameId=");
13772                    msg.append(classNameId);
13773    
13774                    msg.append(", classPK=");
13775                    msg.append(classPK);
13776    
13777                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13778    
13779                    throw new NoSuchMessageException(msg.toString());
13780            }
13781    
13782            /**
13783             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13784             *
13785             * @param userId the user ID
13786             * @param classNameId the class name ID
13787             * @param classPK the class p k
13788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13789             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13790             */
13791            @Override
13792            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
13793                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
13794                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
13795                                    orderByComparator);
13796    
13797                    if (!list.isEmpty()) {
13798                            return list.get(0);
13799                    }
13800    
13801                    return null;
13802            }
13803    
13804            /**
13805             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13806             *
13807             * @param userId the user ID
13808             * @param classNameId the class name ID
13809             * @param classPK the class p k
13810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13811             * @return the last matching message-boards message
13812             * @throws NoSuchMessageException if a matching message-boards message could not be found
13813             */
13814            @Override
13815            public MBMessage findByU_C_C_Last(long userId, long classNameId,
13816                    long classPK, OrderByComparator<MBMessage> orderByComparator)
13817                    throws NoSuchMessageException {
13818                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
13819                                    orderByComparator);
13820    
13821                    if (mbMessage != null) {
13822                            return mbMessage;
13823                    }
13824    
13825                    StringBundler msg = new StringBundler(8);
13826    
13827                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13828    
13829                    msg.append("userId=");
13830                    msg.append(userId);
13831    
13832                    msg.append(", classNameId=");
13833                    msg.append(classNameId);
13834    
13835                    msg.append(", classPK=");
13836                    msg.append(classPK);
13837    
13838                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13839    
13840                    throw new NoSuchMessageException(msg.toString());
13841            }
13842    
13843            /**
13844             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13845             *
13846             * @param userId the user ID
13847             * @param classNameId the class name ID
13848             * @param classPK the class p k
13849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13850             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13851             */
13852            @Override
13853            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
13854                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
13855                    int count = countByU_C_C(userId, classNameId, classPK);
13856    
13857                    if (count == 0) {
13858                            return null;
13859                    }
13860    
13861                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
13862                                    count - 1, count, orderByComparator);
13863    
13864                    if (!list.isEmpty()) {
13865                            return list.get(0);
13866                    }
13867    
13868                    return null;
13869            }
13870    
13871            /**
13872             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13873             *
13874             * @param messageId the primary key of the current message-boards message
13875             * @param userId the user ID
13876             * @param classNameId the class name ID
13877             * @param classPK the class p k
13878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13879             * @return the previous, current, and next message-boards message
13880             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13881             */
13882            @Override
13883            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
13884                    long classNameId, long classPK,
13885                    OrderByComparator<MBMessage> orderByComparator)
13886                    throws NoSuchMessageException {
13887                    MBMessage mbMessage = findByPrimaryKey(messageId);
13888    
13889                    Session session = null;
13890    
13891                    try {
13892                            session = openSession();
13893    
13894                            MBMessage[] array = new MBMessageImpl[3];
13895    
13896                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13897                                            classNameId, classPK, orderByComparator, true);
13898    
13899                            array[1] = mbMessage;
13900    
13901                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13902                                            classNameId, classPK, orderByComparator, false);
13903    
13904                            return array;
13905                    }
13906                    catch (Exception e) {
13907                            throw processException(e);
13908                    }
13909                    finally {
13910                            closeSession(session);
13911                    }
13912            }
13913    
13914            protected MBMessage getByU_C_C_PrevAndNext(Session session,
13915                    MBMessage mbMessage, long userId, long classNameId, long classPK,
13916                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13917                    StringBundler query = null;
13918    
13919                    if (orderByComparator != null) {
13920                            query = new StringBundler(6 +
13921                                            (orderByComparator.getOrderByFields().length * 6));
13922                    }
13923                    else {
13924                            query = new StringBundler(3);
13925                    }
13926    
13927                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13928    
13929                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13930    
13931                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13932    
13933                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13934    
13935                    if (orderByComparator != null) {
13936                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13937    
13938                            if (orderByConditionFields.length > 0) {
13939                                    query.append(WHERE_AND);
13940                            }
13941    
13942                            for (int i = 0; i < orderByConditionFields.length; i++) {
13943                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13944                                    query.append(orderByConditionFields[i]);
13945    
13946                                    if ((i + 1) < orderByConditionFields.length) {
13947                                            if (orderByComparator.isAscending() ^ previous) {
13948                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13949                                            }
13950                                            else {
13951                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13952                                            }
13953                                    }
13954                                    else {
13955                                            if (orderByComparator.isAscending() ^ previous) {
13956                                                    query.append(WHERE_GREATER_THAN);
13957                                            }
13958                                            else {
13959                                                    query.append(WHERE_LESSER_THAN);
13960                                            }
13961                                    }
13962                            }
13963    
13964                            query.append(ORDER_BY_CLAUSE);
13965    
13966                            String[] orderByFields = orderByComparator.getOrderByFields();
13967    
13968                            for (int i = 0; i < orderByFields.length; i++) {
13969                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13970                                    query.append(orderByFields[i]);
13971    
13972                                    if ((i + 1) < orderByFields.length) {
13973                                            if (orderByComparator.isAscending() ^ previous) {
13974                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13975                                            }
13976                                            else {
13977                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13978                                            }
13979                                    }
13980                                    else {
13981                                            if (orderByComparator.isAscending() ^ previous) {
13982                                                    query.append(ORDER_BY_ASC);
13983                                            }
13984                                            else {
13985                                                    query.append(ORDER_BY_DESC);
13986                                            }
13987                                    }
13988                            }
13989                    }
13990                    else {
13991                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13992                    }
13993    
13994                    String sql = query.toString();
13995    
13996                    Query q = session.createQuery(sql);
13997    
13998                    q.setFirstResult(0);
13999                    q.setMaxResults(2);
14000    
14001                    QueryPos qPos = QueryPos.getInstance(q);
14002    
14003                    qPos.add(userId);
14004    
14005                    qPos.add(classNameId);
14006    
14007                    qPos.add(classPK);
14008    
14009                    if (orderByComparator != null) {
14010                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14011    
14012                            for (Object value : values) {
14013                                    qPos.add(value);
14014                            }
14015                    }
14016    
14017                    List<MBMessage> list = q.list();
14018    
14019                    if (list.size() == 2) {
14020                            return list.get(1);
14021                    }
14022                    else {
14023                            return null;
14024                    }
14025            }
14026    
14027            /**
14028             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14029             *
14030             * @param userId the user ID
14031             * @param classNameId the class name ID
14032             * @param classPK the class p k
14033             */
14034            @Override
14035            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14036                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14037                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14038                            remove(mbMessage);
14039                    }
14040            }
14041    
14042            /**
14043             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14044             *
14045             * @param userId the user ID
14046             * @param classNameId the class name ID
14047             * @param classPK the class p k
14048             * @return the number of matching message-boards messages
14049             */
14050            @Override
14051            public int countByU_C_C(long userId, long classNameId, long classPK) {
14052                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14053    
14054                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14055    
14056                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14057                                    this);
14058    
14059                    if (count == null) {
14060                            StringBundler query = new StringBundler(4);
14061    
14062                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14063    
14064                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14065    
14066                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14067    
14068                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14069    
14070                            String sql = query.toString();
14071    
14072                            Session session = null;
14073    
14074                            try {
14075                                    session = openSession();
14076    
14077                                    Query q = session.createQuery(sql);
14078    
14079                                    QueryPos qPos = QueryPos.getInstance(q);
14080    
14081                                    qPos.add(userId);
14082    
14083                                    qPos.add(classNameId);
14084    
14085                                    qPos.add(classPK);
14086    
14087                                    count = (Long)q.uniqueResult();
14088    
14089                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14090                            }
14091                            catch (Exception e) {
14092                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14093    
14094                                    throw processException(e);
14095                            }
14096                            finally {
14097                                    closeSession(session);
14098                            }
14099                    }
14100    
14101                    return count.intValue();
14102            }
14103    
14104            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14105            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14106            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14108                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14109                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14110                            new String[] {
14111                                    Long.class.getName(), Long.class.getName(),
14112                                    Integer.class.getName(),
14113                                    
14114                            Integer.class.getName(), Integer.class.getName(),
14115                                    OrderByComparator.class.getName()
14116                            });
14117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14118                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14120                            new String[] {
14121                                    Long.class.getName(), Long.class.getName(),
14122                                    Integer.class.getName()
14123                            },
14124                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14125                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14126                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14127                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14128            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14129                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14131                            new String[] {
14132                                    Long.class.getName(), Long.class.getName(),
14133                                    Integer.class.getName()
14134                            });
14135            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14136                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14137                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14138                            new String[] {
14139                                    Long.class.getName(), Long.class.getName(),
14140                                    Integer.class.getName()
14141                            });
14142    
14143            /**
14144             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14145             *
14146             * @param userId the user ID
14147             * @param classNameId the class name ID
14148             * @param status the status
14149             * @return the matching message-boards messages
14150             */
14151            @Override
14152            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14153                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14154                            QueryUtil.ALL_POS, null);
14155            }
14156    
14157            /**
14158             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14159             *
14160             * <p>
14161             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14162             * </p>
14163             *
14164             * @param userId the user ID
14165             * @param classNameId the class name ID
14166             * @param status the status
14167             * @param start the lower bound of the range of message-boards messages
14168             * @param end the upper bound of the range of message-boards messages (not inclusive)
14169             * @return the range of matching message-boards messages
14170             */
14171            @Override
14172            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14173                    int status, int start, int end) {
14174                    return findByU_C_S(userId, classNameId, status, start, end, null);
14175            }
14176    
14177            /**
14178             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14179             *
14180             * <p>
14181             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14182             * </p>
14183             *
14184             * @param userId the user ID
14185             * @param classNameId the class name ID
14186             * @param status the status
14187             * @param start the lower bound of the range of message-boards messages
14188             * @param end the upper bound of the range of message-boards messages (not inclusive)
14189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14190             * @return the ordered range of matching message-boards messages
14191             */
14192            @Override
14193            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14194                    int status, int start, int end,
14195                    OrderByComparator<MBMessage> orderByComparator) {
14196                    boolean pagination = true;
14197                    FinderPath finderPath = null;
14198                    Object[] finderArgs = null;
14199    
14200                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14201                                    (orderByComparator == null)) {
14202                            pagination = false;
14203                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14204                            finderArgs = new Object[] { userId, classNameId, status };
14205                    }
14206                    else {
14207                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14208                            finderArgs = new Object[] {
14209                                            userId, classNameId, status,
14210                                            
14211                                            start, end, orderByComparator
14212                                    };
14213                    }
14214    
14215                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14216                                    finderArgs, this);
14217    
14218                    if ((list != null) && !list.isEmpty()) {
14219                            for (MBMessage mbMessage : list) {
14220                                    if ((userId != mbMessage.getUserId()) ||
14221                                                    (classNameId != mbMessage.getClassNameId()) ||
14222                                                    (status != mbMessage.getStatus())) {
14223                                            list = null;
14224    
14225                                            break;
14226                                    }
14227                            }
14228                    }
14229    
14230                    if (list == null) {
14231                            StringBundler query = null;
14232    
14233                            if (orderByComparator != null) {
14234                                    query = new StringBundler(5 +
14235                                                    (orderByComparator.getOrderByFields().length * 3));
14236                            }
14237                            else {
14238                                    query = new StringBundler(5);
14239                            }
14240    
14241                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14242    
14243                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14244    
14245                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14246    
14247                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14248    
14249                            if (orderByComparator != null) {
14250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14251                                            orderByComparator);
14252                            }
14253                            else
14254                             if (pagination) {
14255                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14256                            }
14257    
14258                            String sql = query.toString();
14259    
14260                            Session session = null;
14261    
14262                            try {
14263                                    session = openSession();
14264    
14265                                    Query q = session.createQuery(sql);
14266    
14267                                    QueryPos qPos = QueryPos.getInstance(q);
14268    
14269                                    qPos.add(userId);
14270    
14271                                    qPos.add(classNameId);
14272    
14273                                    qPos.add(status);
14274    
14275                                    if (!pagination) {
14276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14277                                                            start, end, false);
14278    
14279                                            Collections.sort(list);
14280    
14281                                            list = Collections.unmodifiableList(list);
14282                                    }
14283                                    else {
14284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14285                                                            start, end);
14286                                    }
14287    
14288                                    cacheResult(list);
14289    
14290                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14291                            }
14292                            catch (Exception e) {
14293                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14294    
14295                                    throw processException(e);
14296                            }
14297                            finally {
14298                                    closeSession(session);
14299                            }
14300                    }
14301    
14302                    return list;
14303            }
14304    
14305            /**
14306             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14307             *
14308             * @param userId the user ID
14309             * @param classNameId the class name ID
14310             * @param status the status
14311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14312             * @return the first matching message-boards message
14313             * @throws NoSuchMessageException if a matching message-boards message could not be found
14314             */
14315            @Override
14316            public MBMessage findByU_C_S_First(long userId, long classNameId,
14317                    int status, OrderByComparator<MBMessage> orderByComparator)
14318                    throws NoSuchMessageException {
14319                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14320                                    orderByComparator);
14321    
14322                    if (mbMessage != null) {
14323                            return mbMessage;
14324                    }
14325    
14326                    StringBundler msg = new StringBundler(8);
14327    
14328                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14329    
14330                    msg.append("userId=");
14331                    msg.append(userId);
14332    
14333                    msg.append(", classNameId=");
14334                    msg.append(classNameId);
14335    
14336                    msg.append(", status=");
14337                    msg.append(status);
14338    
14339                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14340    
14341                    throw new NoSuchMessageException(msg.toString());
14342            }
14343    
14344            /**
14345             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14346             *
14347             * @param userId the user ID
14348             * @param classNameId the class name ID
14349             * @param status the status
14350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14351             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14352             */
14353            @Override
14354            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14355                    int status, OrderByComparator<MBMessage> orderByComparator) {
14356                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14357                                    orderByComparator);
14358    
14359                    if (!list.isEmpty()) {
14360                            return list.get(0);
14361                    }
14362    
14363                    return null;
14364            }
14365    
14366            /**
14367             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14368             *
14369             * @param userId the user ID
14370             * @param classNameId the class name ID
14371             * @param status the status
14372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14373             * @return the last matching message-boards message
14374             * @throws NoSuchMessageException if a matching message-boards message could not be found
14375             */
14376            @Override
14377            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14378                    int status, OrderByComparator<MBMessage> orderByComparator)
14379                    throws NoSuchMessageException {
14380                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14381                                    orderByComparator);
14382    
14383                    if (mbMessage != null) {
14384                            return mbMessage;
14385                    }
14386    
14387                    StringBundler msg = new StringBundler(8);
14388    
14389                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14390    
14391                    msg.append("userId=");
14392                    msg.append(userId);
14393    
14394                    msg.append(", classNameId=");
14395                    msg.append(classNameId);
14396    
14397                    msg.append(", status=");
14398                    msg.append(status);
14399    
14400                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14401    
14402                    throw new NoSuchMessageException(msg.toString());
14403            }
14404    
14405            /**
14406             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14407             *
14408             * @param userId the user ID
14409             * @param classNameId the class name ID
14410             * @param status the status
14411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14412             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14413             */
14414            @Override
14415            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14416                    int status, OrderByComparator<MBMessage> orderByComparator) {
14417                    int count = countByU_C_S(userId, classNameId, status);
14418    
14419                    if (count == 0) {
14420                            return null;
14421                    }
14422    
14423                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14424                                    count - 1, count, orderByComparator);
14425    
14426                    if (!list.isEmpty()) {
14427                            return list.get(0);
14428                    }
14429    
14430                    return null;
14431            }
14432    
14433            /**
14434             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14435             *
14436             * @param messageId the primary key of the current message-boards message
14437             * @param userId the user ID
14438             * @param classNameId the class name ID
14439             * @param status the status
14440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14441             * @return the previous, current, and next message-boards message
14442             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14443             */
14444            @Override
14445            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14446                    long classNameId, int status,
14447                    OrderByComparator<MBMessage> orderByComparator)
14448                    throws NoSuchMessageException {
14449                    MBMessage mbMessage = findByPrimaryKey(messageId);
14450    
14451                    Session session = null;
14452    
14453                    try {
14454                            session = openSession();
14455    
14456                            MBMessage[] array = new MBMessageImpl[3];
14457    
14458                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14459                                            classNameId, status, orderByComparator, true);
14460    
14461                            array[1] = mbMessage;
14462    
14463                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14464                                            classNameId, status, orderByComparator, false);
14465    
14466                            return array;
14467                    }
14468                    catch (Exception e) {
14469                            throw processException(e);
14470                    }
14471                    finally {
14472                            closeSession(session);
14473                    }
14474            }
14475    
14476            protected MBMessage getByU_C_S_PrevAndNext(Session session,
14477                    MBMessage mbMessage, long userId, long classNameId, int status,
14478                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14479                    StringBundler query = null;
14480    
14481                    if (orderByComparator != null) {
14482                            query = new StringBundler(6 +
14483                                            (orderByComparator.getOrderByFields().length * 6));
14484                    }
14485                    else {
14486                            query = new StringBundler(3);
14487                    }
14488    
14489                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14490    
14491                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14492    
14493                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14494    
14495                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14496    
14497                    if (orderByComparator != null) {
14498                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14499    
14500                            if (orderByConditionFields.length > 0) {
14501                                    query.append(WHERE_AND);
14502                            }
14503    
14504                            for (int i = 0; i < orderByConditionFields.length; i++) {
14505                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14506                                    query.append(orderByConditionFields[i]);
14507    
14508                                    if ((i + 1) < orderByConditionFields.length) {
14509                                            if (orderByComparator.isAscending() ^ previous) {
14510                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14511                                            }
14512                                            else {
14513                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14514                                            }
14515                                    }
14516                                    else {
14517                                            if (orderByComparator.isAscending() ^ previous) {
14518                                                    query.append(WHERE_GREATER_THAN);
14519                                            }
14520                                            else {
14521                                                    query.append(WHERE_LESSER_THAN);
14522                                            }
14523                                    }
14524                            }
14525    
14526                            query.append(ORDER_BY_CLAUSE);
14527    
14528                            String[] orderByFields = orderByComparator.getOrderByFields();
14529    
14530                            for (int i = 0; i < orderByFields.length; i++) {
14531                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14532                                    query.append(orderByFields[i]);
14533    
14534                                    if ((i + 1) < orderByFields.length) {
14535                                            if (orderByComparator.isAscending() ^ previous) {
14536                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14537                                            }
14538                                            else {
14539                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14540                                            }
14541                                    }
14542                                    else {
14543                                            if (orderByComparator.isAscending() ^ previous) {
14544                                                    query.append(ORDER_BY_ASC);
14545                                            }
14546                                            else {
14547                                                    query.append(ORDER_BY_DESC);
14548                                            }
14549                                    }
14550                            }
14551                    }
14552                    else {
14553                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14554                    }
14555    
14556                    String sql = query.toString();
14557    
14558                    Query q = session.createQuery(sql);
14559    
14560                    q.setFirstResult(0);
14561                    q.setMaxResults(2);
14562    
14563                    QueryPos qPos = QueryPos.getInstance(q);
14564    
14565                    qPos.add(userId);
14566    
14567                    qPos.add(classNameId);
14568    
14569                    qPos.add(status);
14570    
14571                    if (orderByComparator != null) {
14572                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14573    
14574                            for (Object value : values) {
14575                                    qPos.add(value);
14576                            }
14577                    }
14578    
14579                    List<MBMessage> list = q.list();
14580    
14581                    if (list.size() == 2) {
14582                            return list.get(1);
14583                    }
14584                    else {
14585                            return null;
14586                    }
14587            }
14588    
14589            /**
14590             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14591             *
14592             * <p>
14593             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14594             * </p>
14595             *
14596             * @param userId the user ID
14597             * @param classNameIds the class name IDs
14598             * @param status the status
14599             * @return the matching message-boards messages
14600             */
14601            @Override
14602            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14603                    int status) {
14604                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14605                            QueryUtil.ALL_POS, null);
14606            }
14607    
14608            /**
14609             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14610             *
14611             * <p>
14612             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14613             * </p>
14614             *
14615             * @param userId the user ID
14616             * @param classNameIds the class name IDs
14617             * @param status the status
14618             * @param start the lower bound of the range of message-boards messages
14619             * @param end the upper bound of the range of message-boards messages (not inclusive)
14620             * @return the range of matching message-boards messages
14621             */
14622            @Override
14623            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14624                    int status, int start, int end) {
14625                    return findByU_C_S(userId, classNameIds, status, start, end, null);
14626            }
14627    
14628            /**
14629             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14630             *
14631             * <p>
14632             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14633             * </p>
14634             *
14635             * @param userId the user ID
14636             * @param classNameIds the class name IDs
14637             * @param status the status
14638             * @param start the lower bound of the range of message-boards messages
14639             * @param end the upper bound of the range of message-boards messages (not inclusive)
14640             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14641             * @return the ordered range of matching message-boards messages
14642             */
14643            @Override
14644            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14645                    int status, int start, int end,
14646                    OrderByComparator<MBMessage> orderByComparator) {
14647                    if (classNameIds == null) {
14648                            classNameIds = new long[0];
14649                    }
14650                    else {
14651                            classNameIds = ArrayUtil.unique(classNameIds);
14652                    }
14653    
14654                    if (classNameIds.length == 1) {
14655                            return findByU_C_S(userId, classNameIds[0], status, start, end,
14656                                    orderByComparator);
14657                    }
14658    
14659                    boolean pagination = true;
14660                    Object[] finderArgs = null;
14661    
14662                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14663                                    (orderByComparator == null)) {
14664                            pagination = false;
14665                            finderArgs = new Object[] {
14666                                            userId, StringUtil.merge(classNameIds), status
14667                                    };
14668                    }
14669                    else {
14670                            finderArgs = new Object[] {
14671                                            userId, StringUtil.merge(classNameIds), status,
14672                                            
14673                                            start, end, orderByComparator
14674                                    };
14675                    }
14676    
14677                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14678                                    finderArgs, this);
14679    
14680                    if ((list != null) && !list.isEmpty()) {
14681                            for (MBMessage mbMessage : list) {
14682                                    if ((userId != mbMessage.getUserId()) ||
14683                                                    !ArrayUtil.contains(classNameIds,
14684                                                            mbMessage.getClassNameId()) ||
14685                                                    (status != mbMessage.getStatus())) {
14686                                            list = null;
14687    
14688                                            break;
14689                                    }
14690                            }
14691                    }
14692    
14693                    if (list == null) {
14694                            StringBundler query = new StringBundler();
14695    
14696                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14697    
14698                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14699    
14700                            if (classNameIds.length > 0) {
14701                                    query.append(StringPool.OPEN_PARENTHESIS);
14702    
14703                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
14704    
14705                                    query.append(StringUtil.merge(classNameIds));
14706    
14707                                    query.append(StringPool.CLOSE_PARENTHESIS);
14708    
14709                                    query.append(StringPool.CLOSE_PARENTHESIS);
14710    
14711                                    query.append(WHERE_AND);
14712                            }
14713    
14714                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14715    
14716                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
14717                                                    1)), query.index() - 1);
14718    
14719                            if (orderByComparator != null) {
14720                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14721                                            orderByComparator);
14722                            }
14723                            else
14724                             if (pagination) {
14725                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14726                            }
14727    
14728                            String sql = query.toString();
14729    
14730                            Session session = null;
14731    
14732                            try {
14733                                    session = openSession();
14734    
14735                                    Query q = session.createQuery(sql);
14736    
14737                                    QueryPos qPos = QueryPos.getInstance(q);
14738    
14739                                    qPos.add(userId);
14740    
14741                                    qPos.add(status);
14742    
14743                                    if (!pagination) {
14744                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14745                                                            start, end, false);
14746    
14747                                            Collections.sort(list);
14748    
14749                                            list = Collections.unmodifiableList(list);
14750                                    }
14751                                    else {
14752                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14753                                                            start, end);
14754                                    }
14755    
14756                                    cacheResult(list);
14757    
14758                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14759                                            finderArgs, list);
14760                            }
14761                            catch (Exception e) {
14762                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14763                                            finderArgs);
14764    
14765                                    throw processException(e);
14766                            }
14767                            finally {
14768                                    closeSession(session);
14769                            }
14770                    }
14771    
14772                    return list;
14773            }
14774    
14775            /**
14776             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
14777             *
14778             * @param userId the user ID
14779             * @param classNameId the class name ID
14780             * @param status the status
14781             */
14782            @Override
14783            public void removeByU_C_S(long userId, long classNameId, int status) {
14784                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
14785                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14786                            remove(mbMessage);
14787                    }
14788            }
14789    
14790            /**
14791             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14792             *
14793             * @param userId the user ID
14794             * @param classNameId the class name ID
14795             * @param status the status
14796             * @return the number of matching message-boards messages
14797             */
14798            @Override
14799            public int countByU_C_S(long userId, long classNameId, int status) {
14800                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
14801    
14802                    Object[] finderArgs = new Object[] { userId, classNameId, status };
14803    
14804                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14805                                    this);
14806    
14807                    if (count == null) {
14808                            StringBundler query = new StringBundler(4);
14809    
14810                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14811    
14812                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14813    
14814                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14815    
14816                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14817    
14818                            String sql = query.toString();
14819    
14820                            Session session = null;
14821    
14822                            try {
14823                                    session = openSession();
14824    
14825                                    Query q = session.createQuery(sql);
14826    
14827                                    QueryPos qPos = QueryPos.getInstance(q);
14828    
14829                                    qPos.add(userId);
14830    
14831                                    qPos.add(classNameId);
14832    
14833                                    qPos.add(status);
14834    
14835                                    count = (Long)q.uniqueResult();
14836    
14837                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14838                            }
14839                            catch (Exception e) {
14840                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14841    
14842                                    throw processException(e);
14843                            }
14844                            finally {
14845                                    closeSession(session);
14846                            }
14847                    }
14848    
14849                    return count.intValue();
14850            }
14851    
14852            /**
14853             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14854             *
14855             * @param userId the user ID
14856             * @param classNameIds the class name IDs
14857             * @param status the status
14858             * @return the number of matching message-boards messages
14859             */
14860            @Override
14861            public int countByU_C_S(long userId, long[] classNameIds, int status) {
14862                    if (classNameIds == null) {
14863                            classNameIds = new long[0];
14864                    }
14865                    else {
14866                            classNameIds = ArrayUtil.unique(classNameIds);
14867                    }
14868    
14869                    Object[] finderArgs = new Object[] {
14870                                    userId, StringUtil.merge(classNameIds), status
14871                            };
14872    
14873                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14874                                    finderArgs, this);
14875    
14876                    if (count == null) {
14877                            StringBundler query = new StringBundler();
14878    
14879                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14880    
14881                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14882    
14883                            if (classNameIds.length > 0) {
14884                                    query.append(StringPool.OPEN_PARENTHESIS);
14885    
14886                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
14887    
14888                                    query.append(StringUtil.merge(classNameIds));
14889    
14890                                    query.append(StringPool.CLOSE_PARENTHESIS);
14891    
14892                                    query.append(StringPool.CLOSE_PARENTHESIS);
14893    
14894                                    query.append(WHERE_AND);
14895                            }
14896    
14897                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14898    
14899                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
14900                                                    1)), query.index() - 1);
14901    
14902                            String sql = query.toString();
14903    
14904                            Session session = null;
14905    
14906                            try {
14907                                    session = openSession();
14908    
14909                                    Query q = session.createQuery(sql);
14910    
14911                                    QueryPos qPos = QueryPos.getInstance(q);
14912    
14913                                    qPos.add(userId);
14914    
14915                                    qPos.add(status);
14916    
14917                                    count = (Long)q.uniqueResult();
14918    
14919                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14920                                            finderArgs, count);
14921                            }
14922                            catch (Exception e) {
14923                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14924                                            finderArgs);
14925    
14926                                    throw processException(e);
14927                            }
14928                            finally {
14929                                    closeSession(session);
14930                            }
14931                    }
14932    
14933                    return count.intValue();
14934            }
14935    
14936            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
14937            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14938            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
14939            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
14940            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14941                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14942                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
14943                            new String[] {
14944                                    Long.class.getName(), Long.class.getName(),
14945                                    Integer.class.getName(),
14946                                    
14947                            Integer.class.getName(), Integer.class.getName(),
14948                                    OrderByComparator.class.getName()
14949                            });
14950            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14951                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14952                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
14953                            new String[] {
14954                                    Long.class.getName(), Long.class.getName(),
14955                                    Integer.class.getName()
14956                            },
14957                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14958                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14959                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14960                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14961            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14962                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14963                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
14964                            new String[] {
14965                                    Long.class.getName(), Long.class.getName(),
14966                                    Integer.class.getName()
14967                            });
14968    
14969            /**
14970             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
14971             *
14972             * @param classNameId the class name ID
14973             * @param classPK the class p k
14974             * @param status the status
14975             * @return the matching message-boards messages
14976             */
14977            @Override
14978            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
14979                    int status) {
14980                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
14981                            QueryUtil.ALL_POS, null);
14982            }
14983    
14984            /**
14985             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
14986             *
14987             * <p>
14988             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14989             * </p>
14990             *
14991             * @param classNameId the class name ID
14992             * @param classPK the class p k
14993             * @param status the status
14994             * @param start the lower bound of the range of message-boards messages
14995             * @param end the upper bound of the range of message-boards messages (not inclusive)
14996             * @return the range of matching message-boards messages
14997             */
14998            @Override
14999            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15000                    int status, int start, int end) {
15001                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15002            }
15003    
15004            /**
15005             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15006             *
15007             * <p>
15008             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15009             * </p>
15010             *
15011             * @param classNameId the class name ID
15012             * @param classPK the class p k
15013             * @param status the status
15014             * @param start the lower bound of the range of message-boards messages
15015             * @param end the upper bound of the range of message-boards messages (not inclusive)
15016             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15017             * @return the ordered range of matching message-boards messages
15018             */
15019            @Override
15020            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15021                    int status, int start, int end,
15022                    OrderByComparator<MBMessage> orderByComparator) {
15023                    boolean pagination = true;
15024                    FinderPath finderPath = null;
15025                    Object[] finderArgs = null;
15026    
15027                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15028                                    (orderByComparator == null)) {
15029                            pagination = false;
15030                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15031                            finderArgs = new Object[] { classNameId, classPK, status };
15032                    }
15033                    else {
15034                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15035                            finderArgs = new Object[] {
15036                                            classNameId, classPK, status,
15037                                            
15038                                            start, end, orderByComparator
15039                                    };
15040                    }
15041    
15042                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15043                                    finderArgs, this);
15044    
15045                    if ((list != null) && !list.isEmpty()) {
15046                            for (MBMessage mbMessage : list) {
15047                                    if ((classNameId != mbMessage.getClassNameId()) ||
15048                                                    (classPK != mbMessage.getClassPK()) ||
15049                                                    (status != mbMessage.getStatus())) {
15050                                            list = null;
15051    
15052                                            break;
15053                                    }
15054                            }
15055                    }
15056    
15057                    if (list == null) {
15058                            StringBundler query = null;
15059    
15060                            if (orderByComparator != null) {
15061                                    query = new StringBundler(5 +
15062                                                    (orderByComparator.getOrderByFields().length * 3));
15063                            }
15064                            else {
15065                                    query = new StringBundler(5);
15066                            }
15067    
15068                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15069    
15070                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15071    
15072                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15073    
15074                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15075    
15076                            if (orderByComparator != null) {
15077                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15078                                            orderByComparator);
15079                            }
15080                            else
15081                             if (pagination) {
15082                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15083                            }
15084    
15085                            String sql = query.toString();
15086    
15087                            Session session = null;
15088    
15089                            try {
15090                                    session = openSession();
15091    
15092                                    Query q = session.createQuery(sql);
15093    
15094                                    QueryPos qPos = QueryPos.getInstance(q);
15095    
15096                                    qPos.add(classNameId);
15097    
15098                                    qPos.add(classPK);
15099    
15100                                    qPos.add(status);
15101    
15102                                    if (!pagination) {
15103                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15104                                                            start, end, false);
15105    
15106                                            Collections.sort(list);
15107    
15108                                            list = Collections.unmodifiableList(list);
15109                                    }
15110                                    else {
15111                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15112                                                            start, end);
15113                                    }
15114    
15115                                    cacheResult(list);
15116    
15117                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15118                            }
15119                            catch (Exception e) {
15120                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15121    
15122                                    throw processException(e);
15123                            }
15124                            finally {
15125                                    closeSession(session);
15126                            }
15127                    }
15128    
15129                    return list;
15130            }
15131    
15132            /**
15133             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15134             *
15135             * @param classNameId the class name ID
15136             * @param classPK the class p k
15137             * @param status the status
15138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15139             * @return the first matching message-boards message
15140             * @throws NoSuchMessageException if a matching message-boards message could not be found
15141             */
15142            @Override
15143            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15144                    int status, OrderByComparator<MBMessage> orderByComparator)
15145                    throws NoSuchMessageException {
15146                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15147                                    orderByComparator);
15148    
15149                    if (mbMessage != null) {
15150                            return mbMessage;
15151                    }
15152    
15153                    StringBundler msg = new StringBundler(8);
15154    
15155                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15156    
15157                    msg.append("classNameId=");
15158                    msg.append(classNameId);
15159    
15160                    msg.append(", classPK=");
15161                    msg.append(classPK);
15162    
15163                    msg.append(", status=");
15164                    msg.append(status);
15165    
15166                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15167    
15168                    throw new NoSuchMessageException(msg.toString());
15169            }
15170    
15171            /**
15172             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15173             *
15174             * @param classNameId the class name ID
15175             * @param classPK the class p k
15176             * @param status the status
15177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15178             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15179             */
15180            @Override
15181            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15182                    int status, OrderByComparator<MBMessage> orderByComparator) {
15183                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15184                                    orderByComparator);
15185    
15186                    if (!list.isEmpty()) {
15187                            return list.get(0);
15188                    }
15189    
15190                    return null;
15191            }
15192    
15193            /**
15194             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15195             *
15196             * @param classNameId the class name ID
15197             * @param classPK the class p k
15198             * @param status the status
15199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15200             * @return the last matching message-boards message
15201             * @throws NoSuchMessageException if a matching message-boards message could not be found
15202             */
15203            @Override
15204            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15205                    int status, OrderByComparator<MBMessage> orderByComparator)
15206                    throws NoSuchMessageException {
15207                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15208                                    orderByComparator);
15209    
15210                    if (mbMessage != null) {
15211                            return mbMessage;
15212                    }
15213    
15214                    StringBundler msg = new StringBundler(8);
15215    
15216                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15217    
15218                    msg.append("classNameId=");
15219                    msg.append(classNameId);
15220    
15221                    msg.append(", classPK=");
15222                    msg.append(classPK);
15223    
15224                    msg.append(", status=");
15225                    msg.append(status);
15226    
15227                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15228    
15229                    throw new NoSuchMessageException(msg.toString());
15230            }
15231    
15232            /**
15233             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15234             *
15235             * @param classNameId the class name ID
15236             * @param classPK the class p k
15237             * @param status the status
15238             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15239             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15240             */
15241            @Override
15242            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15243                    int status, OrderByComparator<MBMessage> orderByComparator) {
15244                    int count = countByC_C_S(classNameId, classPK, status);
15245    
15246                    if (count == 0) {
15247                            return null;
15248                    }
15249    
15250                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15251                                    count - 1, count, orderByComparator);
15252    
15253                    if (!list.isEmpty()) {
15254                            return list.get(0);
15255                    }
15256    
15257                    return null;
15258            }
15259    
15260            /**
15261             * 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;.
15262             *
15263             * @param messageId the primary key of the current message-boards message
15264             * @param classNameId the class name ID
15265             * @param classPK the class p k
15266             * @param status the status
15267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15268             * @return the previous, current, and next message-boards message
15269             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15270             */
15271            @Override
15272            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15273                    long classNameId, long classPK, int status,
15274                    OrderByComparator<MBMessage> orderByComparator)
15275                    throws NoSuchMessageException {
15276                    MBMessage mbMessage = findByPrimaryKey(messageId);
15277    
15278                    Session session = null;
15279    
15280                    try {
15281                            session = openSession();
15282    
15283                            MBMessage[] array = new MBMessageImpl[3];
15284    
15285                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15286                                            classPK, status, orderByComparator, true);
15287    
15288                            array[1] = mbMessage;
15289    
15290                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15291                                            classPK, status, orderByComparator, false);
15292    
15293                            return array;
15294                    }
15295                    catch (Exception e) {
15296                            throw processException(e);
15297                    }
15298                    finally {
15299                            closeSession(session);
15300                    }
15301            }
15302    
15303            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15304                    MBMessage mbMessage, long classNameId, long classPK, int status,
15305                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15306                    StringBundler query = null;
15307    
15308                    if (orderByComparator != null) {
15309                            query = new StringBundler(6 +
15310                                            (orderByComparator.getOrderByFields().length * 6));
15311                    }
15312                    else {
15313                            query = new StringBundler(3);
15314                    }
15315    
15316                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15317    
15318                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15319    
15320                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15321    
15322                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15323    
15324                    if (orderByComparator != null) {
15325                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15326    
15327                            if (orderByConditionFields.length > 0) {
15328                                    query.append(WHERE_AND);
15329                            }
15330    
15331                            for (int i = 0; i < orderByConditionFields.length; i++) {
15332                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15333                                    query.append(orderByConditionFields[i]);
15334    
15335                                    if ((i + 1) < orderByConditionFields.length) {
15336                                            if (orderByComparator.isAscending() ^ previous) {
15337                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15338                                            }
15339                                            else {
15340                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15341                                            }
15342                                    }
15343                                    else {
15344                                            if (orderByComparator.isAscending() ^ previous) {
15345                                                    query.append(WHERE_GREATER_THAN);
15346                                            }
15347                                            else {
15348                                                    query.append(WHERE_LESSER_THAN);
15349                                            }
15350                                    }
15351                            }
15352    
15353                            query.append(ORDER_BY_CLAUSE);
15354    
15355                            String[] orderByFields = orderByComparator.getOrderByFields();
15356    
15357                            for (int i = 0; i < orderByFields.length; i++) {
15358                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15359                                    query.append(orderByFields[i]);
15360    
15361                                    if ((i + 1) < orderByFields.length) {
15362                                            if (orderByComparator.isAscending() ^ previous) {
15363                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15364                                            }
15365                                            else {
15366                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15367                                            }
15368                                    }
15369                                    else {
15370                                            if (orderByComparator.isAscending() ^ previous) {
15371                                                    query.append(ORDER_BY_ASC);
15372                                            }
15373                                            else {
15374                                                    query.append(ORDER_BY_DESC);
15375                                            }
15376                                    }
15377                            }
15378                    }
15379                    else {
15380                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15381                    }
15382    
15383                    String sql = query.toString();
15384    
15385                    Query q = session.createQuery(sql);
15386    
15387                    q.setFirstResult(0);
15388                    q.setMaxResults(2);
15389    
15390                    QueryPos qPos = QueryPos.getInstance(q);
15391    
15392                    qPos.add(classNameId);
15393    
15394                    qPos.add(classPK);
15395    
15396                    qPos.add(status);
15397    
15398                    if (orderByComparator != null) {
15399                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15400    
15401                            for (Object value : values) {
15402                                    qPos.add(value);
15403                            }
15404                    }
15405    
15406                    List<MBMessage> list = q.list();
15407    
15408                    if (list.size() == 2) {
15409                            return list.get(1);
15410                    }
15411                    else {
15412                            return null;
15413                    }
15414            }
15415    
15416            /**
15417             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15418             *
15419             * @param classNameId the class name ID
15420             * @param classPK the class p k
15421             * @param status the status
15422             */
15423            @Override
15424            public void removeByC_C_S(long classNameId, long classPK, int status) {
15425                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15426                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15427                            remove(mbMessage);
15428                    }
15429            }
15430    
15431            /**
15432             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15433             *
15434             * @param classNameId the class name ID
15435             * @param classPK the class p k
15436             * @param status the status
15437             * @return the number of matching message-boards messages
15438             */
15439            @Override
15440            public int countByC_C_S(long classNameId, long classPK, int status) {
15441                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15442    
15443                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
15444    
15445                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15446                                    this);
15447    
15448                    if (count == null) {
15449                            StringBundler query = new StringBundler(4);
15450    
15451                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15452    
15453                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15454    
15455                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15456    
15457                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15458    
15459                            String sql = query.toString();
15460    
15461                            Session session = null;
15462    
15463                            try {
15464                                    session = openSession();
15465    
15466                                    Query q = session.createQuery(sql);
15467    
15468                                    QueryPos qPos = QueryPos.getInstance(q);
15469    
15470                                    qPos.add(classNameId);
15471    
15472                                    qPos.add(classPK);
15473    
15474                                    qPos.add(status);
15475    
15476                                    count = (Long)q.uniqueResult();
15477    
15478                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15479                            }
15480                            catch (Exception e) {
15481                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15482    
15483                                    throw processException(e);
15484                            }
15485                            finally {
15486                                    closeSession(session);
15487                            }
15488                    }
15489    
15490                    return count.intValue();
15491            }
15492    
15493            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15494            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15495            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15496            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15497                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15498                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
15499                            new String[] {
15500                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15501                                    Boolean.class.getName(),
15502                                    
15503                            Integer.class.getName(), Integer.class.getName(),
15504                                    OrderByComparator.class.getName()
15505                            });
15506            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
15507                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15508                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15509                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
15510                            new String[] {
15511                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15512                                    Boolean.class.getName()
15513                            },
15514                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15515                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15516                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
15517                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
15518                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15519            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15520                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15521                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
15522                            new String[] {
15523                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15524                                    Boolean.class.getName()
15525                            });
15526    
15527            /**
15528             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15529             *
15530             * @param groupId the group ID
15531             * @param categoryId the category ID
15532             * @param threadId the thread ID
15533             * @param answer the answer
15534             * @return the matching message-boards messages
15535             */
15536            @Override
15537            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15538                    long threadId, boolean answer) {
15539                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
15540                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15541            }
15542    
15543            /**
15544             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15545             *
15546             * <p>
15547             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15548             * </p>
15549             *
15550             * @param groupId the group ID
15551             * @param categoryId the category ID
15552             * @param threadId the thread ID
15553             * @param answer the answer
15554             * @param start the lower bound of the range of message-boards messages
15555             * @param end the upper bound of the range of message-boards messages (not inclusive)
15556             * @return the range of matching message-boards messages
15557             */
15558            @Override
15559            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15560                    long threadId, boolean answer, int start, int end) {
15561                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
15562                            null);
15563            }
15564    
15565            /**
15566             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15567             *
15568             * <p>
15569             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15570             * </p>
15571             *
15572             * @param groupId the group ID
15573             * @param categoryId the category ID
15574             * @param threadId the thread ID
15575             * @param answer the answer
15576             * @param start the lower bound of the range of message-boards messages
15577             * @param end the upper bound of the range of message-boards messages (not inclusive)
15578             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15579             * @return the ordered range of matching message-boards messages
15580             */
15581            @Override
15582            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15583                    long threadId, boolean answer, int start, int end,
15584                    OrderByComparator<MBMessage> orderByComparator) {
15585                    boolean pagination = true;
15586                    FinderPath finderPath = null;
15587                    Object[] finderArgs = null;
15588    
15589                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15590                                    (orderByComparator == null)) {
15591                            pagination = false;
15592                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
15593                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
15594                    }
15595                    else {
15596                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
15597                            finderArgs = new Object[] {
15598                                            groupId, categoryId, threadId, answer,
15599                                            
15600                                            start, end, orderByComparator
15601                                    };
15602                    }
15603    
15604                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15605                                    finderArgs, this);
15606    
15607                    if ((list != null) && !list.isEmpty()) {
15608                            for (MBMessage mbMessage : list) {
15609                                    if ((groupId != mbMessage.getGroupId()) ||
15610                                                    (categoryId != mbMessage.getCategoryId()) ||
15611                                                    (threadId != mbMessage.getThreadId()) ||
15612                                                    (answer != mbMessage.getAnswer())) {
15613                                            list = null;
15614    
15615                                            break;
15616                                    }
15617                            }
15618                    }
15619    
15620                    if (list == null) {
15621                            StringBundler query = null;
15622    
15623                            if (orderByComparator != null) {
15624                                    query = new StringBundler(6 +
15625                                                    (orderByComparator.getOrderByFields().length * 3));
15626                            }
15627                            else {
15628                                    query = new StringBundler(6);
15629                            }
15630    
15631                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15632    
15633                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15634    
15635                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15636    
15637                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15638    
15639                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15640    
15641                            if (orderByComparator != null) {
15642                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15643                                            orderByComparator);
15644                            }
15645                            else
15646                             if (pagination) {
15647                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15648                            }
15649    
15650                            String sql = query.toString();
15651    
15652                            Session session = null;
15653    
15654                            try {
15655                                    session = openSession();
15656    
15657                                    Query q = session.createQuery(sql);
15658    
15659                                    QueryPos qPos = QueryPos.getInstance(q);
15660    
15661                                    qPos.add(groupId);
15662    
15663                                    qPos.add(categoryId);
15664    
15665                                    qPos.add(threadId);
15666    
15667                                    qPos.add(answer);
15668    
15669                                    if (!pagination) {
15670                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15671                                                            start, end, false);
15672    
15673                                            Collections.sort(list);
15674    
15675                                            list = Collections.unmodifiableList(list);
15676                                    }
15677                                    else {
15678                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15679                                                            start, end);
15680                                    }
15681    
15682                                    cacheResult(list);
15683    
15684                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15685                            }
15686                            catch (Exception e) {
15687                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15688    
15689                                    throw processException(e);
15690                            }
15691                            finally {
15692                                    closeSession(session);
15693                            }
15694                    }
15695    
15696                    return list;
15697            }
15698    
15699            /**
15700             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15701             *
15702             * @param groupId the group ID
15703             * @param categoryId the category ID
15704             * @param threadId the thread ID
15705             * @param answer the answer
15706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15707             * @return the first matching message-boards message
15708             * @throws NoSuchMessageException if a matching message-boards message could not be found
15709             */
15710            @Override
15711            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
15712                    long threadId, boolean answer,
15713                    OrderByComparator<MBMessage> orderByComparator)
15714                    throws NoSuchMessageException {
15715                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
15716                                    threadId, answer, orderByComparator);
15717    
15718                    if (mbMessage != null) {
15719                            return mbMessage;
15720                    }
15721    
15722                    StringBundler msg = new StringBundler(10);
15723    
15724                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15725    
15726                    msg.append("groupId=");
15727                    msg.append(groupId);
15728    
15729                    msg.append(", categoryId=");
15730                    msg.append(categoryId);
15731    
15732                    msg.append(", threadId=");
15733                    msg.append(threadId);
15734    
15735                    msg.append(", answer=");
15736                    msg.append(answer);
15737    
15738                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15739    
15740                    throw new NoSuchMessageException(msg.toString());
15741            }
15742    
15743            /**
15744             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15745             *
15746             * @param groupId the group ID
15747             * @param categoryId the category ID
15748             * @param threadId the thread ID
15749             * @param answer the answer
15750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15751             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15752             */
15753            @Override
15754            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
15755                    long threadId, boolean answer,
15756                    OrderByComparator<MBMessage> orderByComparator) {
15757                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15758                                    answer, 0, 1, orderByComparator);
15759    
15760                    if (!list.isEmpty()) {
15761                            return list.get(0);
15762                    }
15763    
15764                    return null;
15765            }
15766    
15767            /**
15768             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15769             *
15770             * @param groupId the group ID
15771             * @param categoryId the category ID
15772             * @param threadId the thread ID
15773             * @param answer the answer
15774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15775             * @return the last matching message-boards message
15776             * @throws NoSuchMessageException if a matching message-boards message could not be found
15777             */
15778            @Override
15779            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
15780                    long threadId, boolean answer,
15781                    OrderByComparator<MBMessage> orderByComparator)
15782                    throws NoSuchMessageException {
15783                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
15784                                    threadId, answer, orderByComparator);
15785    
15786                    if (mbMessage != null) {
15787                            return mbMessage;
15788                    }
15789    
15790                    StringBundler msg = new StringBundler(10);
15791    
15792                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15793    
15794                    msg.append("groupId=");
15795                    msg.append(groupId);
15796    
15797                    msg.append(", categoryId=");
15798                    msg.append(categoryId);
15799    
15800                    msg.append(", threadId=");
15801                    msg.append(threadId);
15802    
15803                    msg.append(", answer=");
15804                    msg.append(answer);
15805    
15806                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15807    
15808                    throw new NoSuchMessageException(msg.toString());
15809            }
15810    
15811            /**
15812             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15813             *
15814             * @param groupId the group ID
15815             * @param categoryId the category ID
15816             * @param threadId the thread ID
15817             * @param answer the answer
15818             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15819             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15820             */
15821            @Override
15822            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
15823                    long threadId, boolean answer,
15824                    OrderByComparator<MBMessage> orderByComparator) {
15825                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
15826    
15827                    if (count == 0) {
15828                            return null;
15829                    }
15830    
15831                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15832                                    answer, count - 1, count, orderByComparator);
15833    
15834                    if (!list.isEmpty()) {
15835                            return list.get(0);
15836                    }
15837    
15838                    return null;
15839            }
15840    
15841            /**
15842             * 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;.
15843             *
15844             * @param messageId the primary key of the current message-boards message
15845             * @param groupId the group ID
15846             * @param categoryId the category ID
15847             * @param threadId the thread ID
15848             * @param answer the answer
15849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15850             * @return the previous, current, and next message-boards message
15851             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15852             */
15853            @Override
15854            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
15855                    long categoryId, long threadId, boolean answer,
15856                    OrderByComparator<MBMessage> orderByComparator)
15857                    throws NoSuchMessageException {
15858                    MBMessage mbMessage = findByPrimaryKey(messageId);
15859    
15860                    Session session = null;
15861    
15862                    try {
15863                            session = openSession();
15864    
15865                            MBMessage[] array = new MBMessageImpl[3];
15866    
15867                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15868                                            categoryId, threadId, answer, orderByComparator, true);
15869    
15870                            array[1] = mbMessage;
15871    
15872                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15873                                            categoryId, threadId, answer, orderByComparator, false);
15874    
15875                            return array;
15876                    }
15877                    catch (Exception e) {
15878                            throw processException(e);
15879                    }
15880                    finally {
15881                            closeSession(session);
15882                    }
15883            }
15884    
15885            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
15886                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
15887                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
15888                    boolean previous) {
15889                    StringBundler query = null;
15890    
15891                    if (orderByComparator != null) {
15892                            query = new StringBundler(6 +
15893                                            (orderByComparator.getOrderByFields().length * 6));
15894                    }
15895                    else {
15896                            query = new StringBundler(3);
15897                    }
15898    
15899                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15900    
15901                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15902    
15903                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15904    
15905                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15906    
15907                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15908    
15909                    if (orderByComparator != null) {
15910                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15911    
15912                            if (orderByConditionFields.length > 0) {
15913                                    query.append(WHERE_AND);
15914                            }
15915    
15916                            for (int i = 0; i < orderByConditionFields.length; i++) {
15917                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15918                                    query.append(orderByConditionFields[i]);
15919    
15920                                    if ((i + 1) < orderByConditionFields.length) {
15921                                            if (orderByComparator.isAscending() ^ previous) {
15922                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15923                                            }
15924                                            else {
15925                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15926                                            }
15927                                    }
15928                                    else {
15929                                            if (orderByComparator.isAscending() ^ previous) {
15930                                                    query.append(WHERE_GREATER_THAN);
15931                                            }
15932                                            else {
15933                                                    query.append(WHERE_LESSER_THAN);
15934                                            }
15935                                    }
15936                            }
15937    
15938                            query.append(ORDER_BY_CLAUSE);
15939    
15940                            String[] orderByFields = orderByComparator.getOrderByFields();
15941    
15942                            for (int i = 0; i < orderByFields.length; i++) {
15943                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15944                                    query.append(orderByFields[i]);
15945    
15946                                    if ((i + 1) < orderByFields.length) {
15947                                            if (orderByComparator.isAscending() ^ previous) {
15948                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15949                                            }
15950                                            else {
15951                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15952                                            }
15953                                    }
15954                                    else {
15955                                            if (orderByComparator.isAscending() ^ previous) {
15956                                                    query.append(ORDER_BY_ASC);
15957                                            }
15958                                            else {
15959                                                    query.append(ORDER_BY_DESC);
15960                                            }
15961                                    }
15962                            }
15963                    }
15964                    else {
15965                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15966                    }
15967    
15968                    String sql = query.toString();
15969    
15970                    Query q = session.createQuery(sql);
15971    
15972                    q.setFirstResult(0);
15973                    q.setMaxResults(2);
15974    
15975                    QueryPos qPos = QueryPos.getInstance(q);
15976    
15977                    qPos.add(groupId);
15978    
15979                    qPos.add(categoryId);
15980    
15981                    qPos.add(threadId);
15982    
15983                    qPos.add(answer);
15984    
15985                    if (orderByComparator != null) {
15986                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15987    
15988                            for (Object value : values) {
15989                                    qPos.add(value);
15990                            }
15991                    }
15992    
15993                    List<MBMessage> list = q.list();
15994    
15995                    if (list.size() == 2) {
15996                            return list.get(1);
15997                    }
15998                    else {
15999                            return null;
16000                    }
16001            }
16002    
16003            /**
16004             * 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;.
16005             *
16006             * @param groupId the group ID
16007             * @param categoryId the category ID
16008             * @param threadId the thread ID
16009             * @param answer the answer
16010             * @return the matching message-boards messages that the user has permission to view
16011             */
16012            @Override
16013            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16014                    long threadId, boolean answer) {
16015                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16016                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16017            }
16018    
16019            /**
16020             * 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;.
16021             *
16022             * <p>
16023             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16024             * </p>
16025             *
16026             * @param groupId the group ID
16027             * @param categoryId the category ID
16028             * @param threadId the thread ID
16029             * @param answer the answer
16030             * @param start the lower bound of the range of message-boards messages
16031             * @param end the upper bound of the range of message-boards messages (not inclusive)
16032             * @return the range of matching message-boards messages that the user has permission to view
16033             */
16034            @Override
16035            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16036                    long threadId, boolean answer, int start, int end) {
16037                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16038                            start, end, null);
16039            }
16040    
16041            /**
16042             * 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;.
16043             *
16044             * <p>
16045             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16046             * </p>
16047             *
16048             * @param groupId the group ID
16049             * @param categoryId the category ID
16050             * @param threadId the thread ID
16051             * @param answer the answer
16052             * @param start the lower bound of the range of message-boards messages
16053             * @param end the upper bound of the range of message-boards messages (not inclusive)
16054             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16055             * @return the ordered range of matching message-boards messages that the user has permission to view
16056             */
16057            @Override
16058            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16059                    long threadId, boolean answer, int start, int end,
16060                    OrderByComparator<MBMessage> orderByComparator) {
16061                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16062                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16063                                    end, orderByComparator);
16064                    }
16065    
16066                    StringBundler query = null;
16067    
16068                    if (orderByComparator != null) {
16069                            query = new StringBundler(6 +
16070                                            (orderByComparator.getOrderByFields().length * 3));
16071                    }
16072                    else {
16073                            query = new StringBundler(6);
16074                    }
16075    
16076                    if (getDB().isSupportsInlineDistinct()) {
16077                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16078                    }
16079                    else {
16080                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16081                    }
16082    
16083                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16084    
16085                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16086    
16087                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16088    
16089                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16090    
16091                    if (!getDB().isSupportsInlineDistinct()) {
16092                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16093                    }
16094    
16095                    if (orderByComparator != null) {
16096                            if (getDB().isSupportsInlineDistinct()) {
16097                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16098                                            orderByComparator, true);
16099                            }
16100                            else {
16101                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16102                                            orderByComparator, true);
16103                            }
16104                    }
16105                    else {
16106                            if (getDB().isSupportsInlineDistinct()) {
16107                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16108                            }
16109                            else {
16110                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16111                            }
16112                    }
16113    
16114                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16115                                    MBMessage.class.getName(),
16116                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16117    
16118                    Session session = null;
16119    
16120                    try {
16121                            session = openSession();
16122    
16123                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16124    
16125                            if (getDB().isSupportsInlineDistinct()) {
16126                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16127                            }
16128                            else {
16129                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16130                            }
16131    
16132                            QueryPos qPos = QueryPos.getInstance(q);
16133    
16134                            qPos.add(groupId);
16135    
16136                            qPos.add(categoryId);
16137    
16138                            qPos.add(threadId);
16139    
16140                            qPos.add(answer);
16141    
16142                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16143                    }
16144                    catch (Exception e) {
16145                            throw processException(e);
16146                    }
16147                    finally {
16148                            closeSession(session);
16149                    }
16150            }
16151    
16152            /**
16153             * 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;.
16154             *
16155             * @param messageId the primary key of the current message-boards message
16156             * @param groupId the group ID
16157             * @param categoryId the category ID
16158             * @param threadId the thread ID
16159             * @param answer the answer
16160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16161             * @return the previous, current, and next message-boards message
16162             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16163             */
16164            @Override
16165            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16166                    long groupId, long categoryId, long threadId, boolean answer,
16167                    OrderByComparator<MBMessage> orderByComparator)
16168                    throws NoSuchMessageException {
16169                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16170                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16171                                    threadId, answer, orderByComparator);
16172                    }
16173    
16174                    MBMessage mbMessage = findByPrimaryKey(messageId);
16175    
16176                    Session session = null;
16177    
16178                    try {
16179                            session = openSession();
16180    
16181                            MBMessage[] array = new MBMessageImpl[3];
16182    
16183                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16184                                            groupId, categoryId, threadId, answer, orderByComparator,
16185                                            true);
16186    
16187                            array[1] = mbMessage;
16188    
16189                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16190                                            groupId, categoryId, threadId, answer, orderByComparator,
16191                                            false);
16192    
16193                            return array;
16194                    }
16195                    catch (Exception e) {
16196                            throw processException(e);
16197                    }
16198                    finally {
16199                            closeSession(session);
16200                    }
16201            }
16202    
16203            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16204                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16205                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16206                    boolean previous) {
16207                    StringBundler query = null;
16208    
16209                    if (orderByComparator != null) {
16210                            query = new StringBundler(6 +
16211                                            (orderByComparator.getOrderByFields().length * 6));
16212                    }
16213                    else {
16214                            query = new StringBundler(3);
16215                    }
16216    
16217                    if (getDB().isSupportsInlineDistinct()) {
16218                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16219                    }
16220                    else {
16221                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16222                    }
16223    
16224                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16225    
16226                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16227    
16228                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16229    
16230                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16231    
16232                    if (!getDB().isSupportsInlineDistinct()) {
16233                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16234                    }
16235    
16236                    if (orderByComparator != null) {
16237                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16238    
16239                            if (orderByConditionFields.length > 0) {
16240                                    query.append(WHERE_AND);
16241                            }
16242    
16243                            for (int i = 0; i < orderByConditionFields.length; i++) {
16244                                    if (getDB().isSupportsInlineDistinct()) {
16245                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16246                                    }
16247                                    else {
16248                                            query.append(_ORDER_BY_ENTITY_TABLE);
16249                                    }
16250    
16251                                    query.append(orderByConditionFields[i]);
16252    
16253                                    if ((i + 1) < orderByConditionFields.length) {
16254                                            if (orderByComparator.isAscending() ^ previous) {
16255                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16256                                            }
16257                                            else {
16258                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16259                                            }
16260                                    }
16261                                    else {
16262                                            if (orderByComparator.isAscending() ^ previous) {
16263                                                    query.append(WHERE_GREATER_THAN);
16264                                            }
16265                                            else {
16266                                                    query.append(WHERE_LESSER_THAN);
16267                                            }
16268                                    }
16269                            }
16270    
16271                            query.append(ORDER_BY_CLAUSE);
16272    
16273                            String[] orderByFields = orderByComparator.getOrderByFields();
16274    
16275                            for (int i = 0; i < orderByFields.length; i++) {
16276                                    if (getDB().isSupportsInlineDistinct()) {
16277                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16278                                    }
16279                                    else {
16280                                            query.append(_ORDER_BY_ENTITY_TABLE);
16281                                    }
16282    
16283                                    query.append(orderByFields[i]);
16284    
16285                                    if ((i + 1) < orderByFields.length) {
16286                                            if (orderByComparator.isAscending() ^ previous) {
16287                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16288                                            }
16289                                            else {
16290                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16291                                            }
16292                                    }
16293                                    else {
16294                                            if (orderByComparator.isAscending() ^ previous) {
16295                                                    query.append(ORDER_BY_ASC);
16296                                            }
16297                                            else {
16298                                                    query.append(ORDER_BY_DESC);
16299                                            }
16300                                    }
16301                            }
16302                    }
16303                    else {
16304                            if (getDB().isSupportsInlineDistinct()) {
16305                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16306                            }
16307                            else {
16308                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16309                            }
16310                    }
16311    
16312                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16313                                    MBMessage.class.getName(),
16314                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16315    
16316                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
16317    
16318                    q.setFirstResult(0);
16319                    q.setMaxResults(2);
16320    
16321                    if (getDB().isSupportsInlineDistinct()) {
16322                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16323                    }
16324                    else {
16325                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16326                    }
16327    
16328                    QueryPos qPos = QueryPos.getInstance(q);
16329    
16330                    qPos.add(groupId);
16331    
16332                    qPos.add(categoryId);
16333    
16334                    qPos.add(threadId);
16335    
16336                    qPos.add(answer);
16337    
16338                    if (orderByComparator != null) {
16339                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16340    
16341                            for (Object value : values) {
16342                                    qPos.add(value);
16343                            }
16344                    }
16345    
16346                    List<MBMessage> list = q.list();
16347    
16348                    if (list.size() == 2) {
16349                            return list.get(1);
16350                    }
16351                    else {
16352                            return null;
16353                    }
16354            }
16355    
16356            /**
16357             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16358             *
16359             * @param groupId the group ID
16360             * @param categoryId the category ID
16361             * @param threadId the thread ID
16362             * @param answer the answer
16363             */
16364            @Override
16365            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16366                    boolean answer) {
16367                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16368                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16369                            remove(mbMessage);
16370                    }
16371            }
16372    
16373            /**
16374             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16375             *
16376             * @param groupId the group ID
16377             * @param categoryId the category ID
16378             * @param threadId the thread ID
16379             * @param answer the answer
16380             * @return the number of matching message-boards messages
16381             */
16382            @Override
16383            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16384                    boolean answer) {
16385                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
16386    
16387                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16388    
16389                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16390                                    this);
16391    
16392                    if (count == null) {
16393                            StringBundler query = new StringBundler(5);
16394    
16395                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16396    
16397                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16398    
16399                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16400    
16401                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16402    
16403                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16404    
16405                            String sql = query.toString();
16406    
16407                            Session session = null;
16408    
16409                            try {
16410                                    session = openSession();
16411    
16412                                    Query q = session.createQuery(sql);
16413    
16414                                    QueryPos qPos = QueryPos.getInstance(q);
16415    
16416                                    qPos.add(groupId);
16417    
16418                                    qPos.add(categoryId);
16419    
16420                                    qPos.add(threadId);
16421    
16422                                    qPos.add(answer);
16423    
16424                                    count = (Long)q.uniqueResult();
16425    
16426                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16427                            }
16428                            catch (Exception e) {
16429                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16430    
16431                                    throw processException(e);
16432                            }
16433                            finally {
16434                                    closeSession(session);
16435                            }
16436                    }
16437    
16438                    return count.intValue();
16439            }
16440    
16441            /**
16442             * 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;.
16443             *
16444             * @param groupId the group ID
16445             * @param categoryId the category ID
16446             * @param threadId the thread ID
16447             * @param answer the answer
16448             * @return the number of matching message-boards messages that the user has permission to view
16449             */
16450            @Override
16451            public int filterCountByG_C_T_A(long groupId, long categoryId,
16452                    long threadId, boolean answer) {
16453                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16454                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
16455                    }
16456    
16457                    StringBundler query = new StringBundler(5);
16458    
16459                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16460    
16461                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16462    
16463                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16464    
16465                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16466    
16467                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16468    
16469                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16470                                    MBMessage.class.getName(),
16471                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16472    
16473                    Session session = null;
16474    
16475                    try {
16476                            session = openSession();
16477    
16478                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16479    
16480                            q.addScalar(COUNT_COLUMN_NAME,
16481                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16482    
16483                            QueryPos qPos = QueryPos.getInstance(q);
16484    
16485                            qPos.add(groupId);
16486    
16487                            qPos.add(categoryId);
16488    
16489                            qPos.add(threadId);
16490    
16491                            qPos.add(answer);
16492    
16493                            Long count = (Long)q.uniqueResult();
16494    
16495                            return count.intValue();
16496                    }
16497                    catch (Exception e) {
16498                            throw processException(e);
16499                    }
16500                    finally {
16501                            closeSession(session);
16502                    }
16503            }
16504    
16505            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
16506            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
16507            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
16508            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
16509            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16510                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16511                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
16512                            new String[] {
16513                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16514                                    Integer.class.getName(),
16515                                    
16516                            Integer.class.getName(), Integer.class.getName(),
16517                                    OrderByComparator.class.getName()
16518                            });
16519            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
16520                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16521                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16522                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
16523                            new String[] {
16524                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16525                                    Integer.class.getName()
16526                            },
16527                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16528                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16529                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16530                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
16531                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16532            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16533                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16534                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
16535                            new String[] {
16536                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16537                                    Integer.class.getName()
16538                            });
16539    
16540            /**
16541             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16542             *
16543             * @param groupId the group ID
16544             * @param categoryId the category ID
16545             * @param threadId the thread ID
16546             * @param status the status
16547             * @return the matching message-boards messages
16548             */
16549            @Override
16550            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16551                    long threadId, int status) {
16552                    return findByG_C_T_S(groupId, categoryId, threadId, status,
16553                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16554            }
16555    
16556            /**
16557             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16558             *
16559             * <p>
16560             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16561             * </p>
16562             *
16563             * @param groupId the group ID
16564             * @param categoryId the category ID
16565             * @param threadId the thread ID
16566             * @param status the status
16567             * @param start the lower bound of the range of message-boards messages
16568             * @param end the upper bound of the range of message-boards messages (not inclusive)
16569             * @return the range of matching message-boards messages
16570             */
16571            @Override
16572            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16573                    long threadId, int status, int start, int end) {
16574                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
16575                            null);
16576            }
16577    
16578            /**
16579             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16580             *
16581             * <p>
16582             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16583             * </p>
16584             *
16585             * @param groupId the group ID
16586             * @param categoryId the category ID
16587             * @param threadId the thread ID
16588             * @param status the status
16589             * @param start the lower bound of the range of message-boards messages
16590             * @param end the upper bound of the range of message-boards messages (not inclusive)
16591             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16592             * @return the ordered range of matching message-boards messages
16593             */
16594            @Override
16595            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16596                    long threadId, int status, int start, int end,
16597                    OrderByComparator<MBMessage> orderByComparator) {
16598                    boolean pagination = true;
16599                    FinderPath finderPath = null;
16600                    Object[] finderArgs = null;
16601    
16602                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16603                                    (orderByComparator == null)) {
16604                            pagination = false;
16605                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
16606                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
16607                    }
16608                    else {
16609                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
16610                            finderArgs = new Object[] {
16611                                            groupId, categoryId, threadId, status,
16612                                            
16613                                            start, end, orderByComparator
16614                                    };
16615                    }
16616    
16617                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16618                                    finderArgs, this);
16619    
16620                    if ((list != null) && !list.isEmpty()) {
16621                            for (MBMessage mbMessage : list) {
16622                                    if ((groupId != mbMessage.getGroupId()) ||
16623                                                    (categoryId != mbMessage.getCategoryId()) ||
16624                                                    (threadId != mbMessage.getThreadId()) ||
16625                                                    (status != mbMessage.getStatus())) {
16626                                            list = null;
16627    
16628                                            break;
16629                                    }
16630                            }
16631                    }
16632    
16633                    if (list == null) {
16634                            StringBundler query = null;
16635    
16636                            if (orderByComparator != null) {
16637                                    query = new StringBundler(6 +
16638                                                    (orderByComparator.getOrderByFields().length * 3));
16639                            }
16640                            else {
16641                                    query = new StringBundler(6);
16642                            }
16643    
16644                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16645    
16646                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16647    
16648                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16649    
16650                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16651    
16652                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16653    
16654                            if (orderByComparator != null) {
16655                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16656                                            orderByComparator);
16657                            }
16658                            else
16659                             if (pagination) {
16660                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16661                            }
16662    
16663                            String sql = query.toString();
16664    
16665                            Session session = null;
16666    
16667                            try {
16668                                    session = openSession();
16669    
16670                                    Query q = session.createQuery(sql);
16671    
16672                                    QueryPos qPos = QueryPos.getInstance(q);
16673    
16674                                    qPos.add(groupId);
16675    
16676                                    qPos.add(categoryId);
16677    
16678                                    qPos.add(threadId);
16679    
16680                                    qPos.add(status);
16681    
16682                                    if (!pagination) {
16683                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16684                                                            start, end, false);
16685    
16686                                            Collections.sort(list);
16687    
16688                                            list = Collections.unmodifiableList(list);
16689                                    }
16690                                    else {
16691                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16692                                                            start, end);
16693                                    }
16694    
16695                                    cacheResult(list);
16696    
16697                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16698                            }
16699                            catch (Exception e) {
16700                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16701    
16702                                    throw processException(e);
16703                            }
16704                            finally {
16705                                    closeSession(session);
16706                            }
16707                    }
16708    
16709                    return list;
16710            }
16711    
16712            /**
16713             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16714             *
16715             * @param groupId the group ID
16716             * @param categoryId the category ID
16717             * @param threadId the thread ID
16718             * @param status the status
16719             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16720             * @return the first matching message-boards message
16721             * @throws NoSuchMessageException if a matching message-boards message could not be found
16722             */
16723            @Override
16724            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
16725                    long threadId, int status,
16726                    OrderByComparator<MBMessage> orderByComparator)
16727                    throws NoSuchMessageException {
16728                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
16729                                    threadId, status, orderByComparator);
16730    
16731                    if (mbMessage != null) {
16732                            return mbMessage;
16733                    }
16734    
16735                    StringBundler msg = new StringBundler(10);
16736    
16737                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16738    
16739                    msg.append("groupId=");
16740                    msg.append(groupId);
16741    
16742                    msg.append(", categoryId=");
16743                    msg.append(categoryId);
16744    
16745                    msg.append(", threadId=");
16746                    msg.append(threadId);
16747    
16748                    msg.append(", status=");
16749                    msg.append(status);
16750    
16751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16752    
16753                    throw new NoSuchMessageException(msg.toString());
16754            }
16755    
16756            /**
16757             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16758             *
16759             * @param groupId the group ID
16760             * @param categoryId the category ID
16761             * @param threadId the thread ID
16762             * @param status the status
16763             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16764             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16765             */
16766            @Override
16767            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
16768                    long threadId, int status,
16769                    OrderByComparator<MBMessage> orderByComparator) {
16770                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16771                                    status, 0, 1, orderByComparator);
16772    
16773                    if (!list.isEmpty()) {
16774                            return list.get(0);
16775                    }
16776    
16777                    return null;
16778            }
16779    
16780            /**
16781             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16782             *
16783             * @param groupId the group ID
16784             * @param categoryId the category ID
16785             * @param threadId the thread ID
16786             * @param status the status
16787             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16788             * @return the last matching message-boards message
16789             * @throws NoSuchMessageException if a matching message-boards message could not be found
16790             */
16791            @Override
16792            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
16793                    long threadId, int status,
16794                    OrderByComparator<MBMessage> orderByComparator)
16795                    throws NoSuchMessageException {
16796                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
16797                                    threadId, status, orderByComparator);
16798    
16799                    if (mbMessage != null) {
16800                            return mbMessage;
16801                    }
16802    
16803                    StringBundler msg = new StringBundler(10);
16804    
16805                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16806    
16807                    msg.append("groupId=");
16808                    msg.append(groupId);
16809    
16810                    msg.append(", categoryId=");
16811                    msg.append(categoryId);
16812    
16813                    msg.append(", threadId=");
16814                    msg.append(threadId);
16815    
16816                    msg.append(", status=");
16817                    msg.append(status);
16818    
16819                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16820    
16821                    throw new NoSuchMessageException(msg.toString());
16822            }
16823    
16824            /**
16825             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16826             *
16827             * @param groupId the group ID
16828             * @param categoryId the category ID
16829             * @param threadId the thread ID
16830             * @param status the status
16831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16832             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16833             */
16834            @Override
16835            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
16836                    long threadId, int status,
16837                    OrderByComparator<MBMessage> orderByComparator) {
16838                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
16839    
16840                    if (count == 0) {
16841                            return null;
16842                    }
16843    
16844                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16845                                    status, count - 1, count, orderByComparator);
16846    
16847                    if (!list.isEmpty()) {
16848                            return list.get(0);
16849                    }
16850    
16851                    return null;
16852            }
16853    
16854            /**
16855             * 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;.
16856             *
16857             * @param messageId the primary key of the current message-boards message
16858             * @param groupId the group ID
16859             * @param categoryId the category ID
16860             * @param threadId the thread ID
16861             * @param status the status
16862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16863             * @return the previous, current, and next message-boards message
16864             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16865             */
16866            @Override
16867            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
16868                    long categoryId, long threadId, int status,
16869                    OrderByComparator<MBMessage> orderByComparator)
16870                    throws NoSuchMessageException {
16871                    MBMessage mbMessage = findByPrimaryKey(messageId);
16872    
16873                    Session session = null;
16874    
16875                    try {
16876                            session = openSession();
16877    
16878                            MBMessage[] array = new MBMessageImpl[3];
16879    
16880                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16881                                            categoryId, threadId, status, orderByComparator, true);
16882    
16883                            array[1] = mbMessage;
16884    
16885                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16886                                            categoryId, threadId, status, orderByComparator, false);
16887    
16888                            return array;
16889                    }
16890                    catch (Exception e) {
16891                            throw processException(e);
16892                    }
16893                    finally {
16894                            closeSession(session);
16895                    }
16896            }
16897    
16898            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
16899                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16900                    int status, OrderByComparator<MBMessage> orderByComparator,
16901                    boolean previous) {
16902                    StringBundler query = null;
16903    
16904                    if (orderByComparator != null) {
16905                            query = new StringBundler(6 +
16906                                            (orderByComparator.getOrderByFields().length * 6));
16907                    }
16908                    else {
16909                            query = new StringBundler(3);
16910                    }
16911    
16912                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16913    
16914                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16915    
16916                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16917    
16918                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16919    
16920                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16921    
16922                    if (orderByComparator != null) {
16923                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16924    
16925                            if (orderByConditionFields.length > 0) {
16926                                    query.append(WHERE_AND);
16927                            }
16928    
16929                            for (int i = 0; i < orderByConditionFields.length; i++) {
16930                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16931                                    query.append(orderByConditionFields[i]);
16932    
16933                                    if ((i + 1) < orderByConditionFields.length) {
16934                                            if (orderByComparator.isAscending() ^ previous) {
16935                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16936                                            }
16937                                            else {
16938                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16939                                            }
16940                                    }
16941                                    else {
16942                                            if (orderByComparator.isAscending() ^ previous) {
16943                                                    query.append(WHERE_GREATER_THAN);
16944                                            }
16945                                            else {
16946                                                    query.append(WHERE_LESSER_THAN);
16947                                            }
16948                                    }
16949                            }
16950    
16951                            query.append(ORDER_BY_CLAUSE);
16952    
16953                            String[] orderByFields = orderByComparator.getOrderByFields();
16954    
16955                            for (int i = 0; i < orderByFields.length; i++) {
16956                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16957                                    query.append(orderByFields[i]);
16958    
16959                                    if ((i + 1) < orderByFields.length) {
16960                                            if (orderByComparator.isAscending() ^ previous) {
16961                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16962                                            }
16963                                            else {
16964                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16965                                            }
16966                                    }
16967                                    else {
16968                                            if (orderByComparator.isAscending() ^ previous) {
16969                                                    query.append(ORDER_BY_ASC);
16970                                            }
16971                                            else {
16972                                                    query.append(ORDER_BY_DESC);
16973                                            }
16974                                    }
16975                            }
16976                    }
16977                    else {
16978                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16979                    }
16980    
16981                    String sql = query.toString();
16982    
16983                    Query q = session.createQuery(sql);
16984    
16985                    q.setFirstResult(0);
16986                    q.setMaxResults(2);
16987    
16988                    QueryPos qPos = QueryPos.getInstance(q);
16989    
16990                    qPos.add(groupId);
16991    
16992                    qPos.add(categoryId);
16993    
16994                    qPos.add(threadId);
16995    
16996                    qPos.add(status);
16997    
16998                    if (orderByComparator != null) {
16999                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17000    
17001                            for (Object value : values) {
17002                                    qPos.add(value);
17003                            }
17004                    }
17005    
17006                    List<MBMessage> list = q.list();
17007    
17008                    if (list.size() == 2) {
17009                            return list.get(1);
17010                    }
17011                    else {
17012                            return null;
17013                    }
17014            }
17015    
17016            /**
17017             * 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;.
17018             *
17019             * @param groupId the group ID
17020             * @param categoryId the category ID
17021             * @param threadId the thread ID
17022             * @param status the status
17023             * @return the matching message-boards messages that the user has permission to view
17024             */
17025            @Override
17026            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17027                    long threadId, int status) {
17028                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17029                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17030            }
17031    
17032            /**
17033             * 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;.
17034             *
17035             * <p>
17036             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17037             * </p>
17038             *
17039             * @param groupId the group ID
17040             * @param categoryId the category ID
17041             * @param threadId the thread ID
17042             * @param status the status
17043             * @param start the lower bound of the range of message-boards messages
17044             * @param end the upper bound of the range of message-boards messages (not inclusive)
17045             * @return the range of matching message-boards messages that the user has permission to view
17046             */
17047            @Override
17048            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17049                    long threadId, int status, int start, int end) {
17050                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17051                            start, end, null);
17052            }
17053    
17054            /**
17055             * 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;.
17056             *
17057             * <p>
17058             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17059             * </p>
17060             *
17061             * @param groupId the group ID
17062             * @param categoryId the category ID
17063             * @param threadId the thread ID
17064             * @param status the status
17065             * @param start the lower bound of the range of message-boards messages
17066             * @param end the upper bound of the range of message-boards messages (not inclusive)
17067             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17068             * @return the ordered range of matching message-boards messages that the user has permission to view
17069             */
17070            @Override
17071            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17072                    long threadId, int status, int start, int end,
17073                    OrderByComparator<MBMessage> orderByComparator) {
17074                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17075                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17076                                    end, orderByComparator);
17077                    }
17078    
17079                    StringBundler query = null;
17080    
17081                    if (orderByComparator != null) {
17082                            query = new StringBundler(6 +
17083                                            (orderByComparator.getOrderByFields().length * 3));
17084                    }
17085                    else {
17086                            query = new StringBundler(6);
17087                    }
17088    
17089                    if (getDB().isSupportsInlineDistinct()) {
17090                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17091                    }
17092                    else {
17093                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17094                    }
17095    
17096                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17097    
17098                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17099    
17100                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17101    
17102                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17103    
17104                    if (!getDB().isSupportsInlineDistinct()) {
17105                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17106                    }
17107    
17108                    if (orderByComparator != null) {
17109                            if (getDB().isSupportsInlineDistinct()) {
17110                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17111                                            orderByComparator, true);
17112                            }
17113                            else {
17114                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17115                                            orderByComparator, true);
17116                            }
17117                    }
17118                    else {
17119                            if (getDB().isSupportsInlineDistinct()) {
17120                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17121                            }
17122                            else {
17123                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17124                            }
17125                    }
17126    
17127                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17128                                    MBMessage.class.getName(),
17129                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17130    
17131                    Session session = null;
17132    
17133                    try {
17134                            session = openSession();
17135    
17136                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17137    
17138                            if (getDB().isSupportsInlineDistinct()) {
17139                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17140                            }
17141                            else {
17142                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17143                            }
17144    
17145                            QueryPos qPos = QueryPos.getInstance(q);
17146    
17147                            qPos.add(groupId);
17148    
17149                            qPos.add(categoryId);
17150    
17151                            qPos.add(threadId);
17152    
17153                            qPos.add(status);
17154    
17155                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17156                    }
17157                    catch (Exception e) {
17158                            throw processException(e);
17159                    }
17160                    finally {
17161                            closeSession(session);
17162                    }
17163            }
17164    
17165            /**
17166             * 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;.
17167             *
17168             * @param messageId the primary key of the current message-boards message
17169             * @param groupId the group ID
17170             * @param categoryId the category ID
17171             * @param threadId the thread ID
17172             * @param status the status
17173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17174             * @return the previous, current, and next message-boards message
17175             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17176             */
17177            @Override
17178            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17179                    long groupId, long categoryId, long threadId, int status,
17180                    OrderByComparator<MBMessage> orderByComparator)
17181                    throws NoSuchMessageException {
17182                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17183                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17184                                    threadId, status, orderByComparator);
17185                    }
17186    
17187                    MBMessage mbMessage = findByPrimaryKey(messageId);
17188    
17189                    Session session = null;
17190    
17191                    try {
17192                            session = openSession();
17193    
17194                            MBMessage[] array = new MBMessageImpl[3];
17195    
17196                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17197                                            groupId, categoryId, threadId, status, orderByComparator,
17198                                            true);
17199    
17200                            array[1] = mbMessage;
17201    
17202                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17203                                            groupId, categoryId, threadId, status, orderByComparator,
17204                                            false);
17205    
17206                            return array;
17207                    }
17208                    catch (Exception e) {
17209                            throw processException(e);
17210                    }
17211                    finally {
17212                            closeSession(session);
17213                    }
17214            }
17215    
17216            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17217                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17218                    int status, OrderByComparator<MBMessage> orderByComparator,
17219                    boolean previous) {
17220                    StringBundler query = null;
17221    
17222                    if (orderByComparator != null) {
17223                            query = new StringBundler(6 +
17224                                            (orderByComparator.getOrderByFields().length * 6));
17225                    }
17226                    else {
17227                            query = new StringBundler(3);
17228                    }
17229    
17230                    if (getDB().isSupportsInlineDistinct()) {
17231                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17232                    }
17233                    else {
17234                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17235                    }
17236    
17237                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17238    
17239                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17240    
17241                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17242    
17243                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17244    
17245                    if (!getDB().isSupportsInlineDistinct()) {
17246                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17247                    }
17248    
17249                    if (orderByComparator != null) {
17250                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17251    
17252                            if (orderByConditionFields.length > 0) {
17253                                    query.append(WHERE_AND);
17254                            }
17255    
17256                            for (int i = 0; i < orderByConditionFields.length; i++) {
17257                                    if (getDB().isSupportsInlineDistinct()) {
17258                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17259                                    }
17260                                    else {
17261                                            query.append(_ORDER_BY_ENTITY_TABLE);
17262                                    }
17263    
17264                                    query.append(orderByConditionFields[i]);
17265    
17266                                    if ((i + 1) < orderByConditionFields.length) {
17267                                            if (orderByComparator.isAscending() ^ previous) {
17268                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17269                                            }
17270                                            else {
17271                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17272                                            }
17273                                    }
17274                                    else {
17275                                            if (orderByComparator.isAscending() ^ previous) {
17276                                                    query.append(WHERE_GREATER_THAN);
17277                                            }
17278                                            else {
17279                                                    query.append(WHERE_LESSER_THAN);
17280                                            }
17281                                    }
17282                            }
17283    
17284                            query.append(ORDER_BY_CLAUSE);
17285    
17286                            String[] orderByFields = orderByComparator.getOrderByFields();
17287    
17288                            for (int i = 0; i < orderByFields.length; i++) {
17289                                    if (getDB().isSupportsInlineDistinct()) {
17290                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17291                                    }
17292                                    else {
17293                                            query.append(_ORDER_BY_ENTITY_TABLE);
17294                                    }
17295    
17296                                    query.append(orderByFields[i]);
17297    
17298                                    if ((i + 1) < orderByFields.length) {
17299                                            if (orderByComparator.isAscending() ^ previous) {
17300                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17301                                            }
17302                                            else {
17303                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17304                                            }
17305                                    }
17306                                    else {
17307                                            if (orderByComparator.isAscending() ^ previous) {
17308                                                    query.append(ORDER_BY_ASC);
17309                                            }
17310                                            else {
17311                                                    query.append(ORDER_BY_DESC);
17312                                            }
17313                                    }
17314                            }
17315                    }
17316                    else {
17317                            if (getDB().isSupportsInlineDistinct()) {
17318                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17319                            }
17320                            else {
17321                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17322                            }
17323                    }
17324    
17325                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17326                                    MBMessage.class.getName(),
17327                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17328    
17329                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17330    
17331                    q.setFirstResult(0);
17332                    q.setMaxResults(2);
17333    
17334                    if (getDB().isSupportsInlineDistinct()) {
17335                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17336                    }
17337                    else {
17338                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17339                    }
17340    
17341                    QueryPos qPos = QueryPos.getInstance(q);
17342    
17343                    qPos.add(groupId);
17344    
17345                    qPos.add(categoryId);
17346    
17347                    qPos.add(threadId);
17348    
17349                    qPos.add(status);
17350    
17351                    if (orderByComparator != null) {
17352                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17353    
17354                            for (Object value : values) {
17355                                    qPos.add(value);
17356                            }
17357                    }
17358    
17359                    List<MBMessage> list = q.list();
17360    
17361                    if (list.size() == 2) {
17362                            return list.get(1);
17363                    }
17364                    else {
17365                            return null;
17366                    }
17367            }
17368    
17369            /**
17370             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
17371             *
17372             * @param groupId the group ID
17373             * @param categoryId the category ID
17374             * @param threadId the thread ID
17375             * @param status the status
17376             */
17377            @Override
17378            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
17379                    int status) {
17380                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
17381                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17382                            remove(mbMessage);
17383                    }
17384            }
17385    
17386            /**
17387             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17388             *
17389             * @param groupId the group ID
17390             * @param categoryId the category ID
17391             * @param threadId the thread ID
17392             * @param status the status
17393             * @return the number of matching message-boards messages
17394             */
17395            @Override
17396            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17397                    int status) {
17398                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
17399    
17400                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17401    
17402                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17403                                    this);
17404    
17405                    if (count == null) {
17406                            StringBundler query = new StringBundler(5);
17407    
17408                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17409    
17410                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17411    
17412                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17413    
17414                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17415    
17416                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17417    
17418                            String sql = query.toString();
17419    
17420                            Session session = null;
17421    
17422                            try {
17423                                    session = openSession();
17424    
17425                                    Query q = session.createQuery(sql);
17426    
17427                                    QueryPos qPos = QueryPos.getInstance(q);
17428    
17429                                    qPos.add(groupId);
17430    
17431                                    qPos.add(categoryId);
17432    
17433                                    qPos.add(threadId);
17434    
17435                                    qPos.add(status);
17436    
17437                                    count = (Long)q.uniqueResult();
17438    
17439                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17440                            }
17441                            catch (Exception e) {
17442                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17443    
17444                                    throw processException(e);
17445                            }
17446                            finally {
17447                                    closeSession(session);
17448                            }
17449                    }
17450    
17451                    return count.intValue();
17452            }
17453    
17454            /**
17455             * 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;.
17456             *
17457             * @param groupId the group ID
17458             * @param categoryId the category ID
17459             * @param threadId the thread ID
17460             * @param status the status
17461             * @return the number of matching message-boards messages that the user has permission to view
17462             */
17463            @Override
17464            public int filterCountByG_C_T_S(long groupId, long categoryId,
17465                    long threadId, int status) {
17466                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17467                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17468                    }
17469    
17470                    StringBundler query = new StringBundler(5);
17471    
17472                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17473    
17474                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17475    
17476                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17477    
17478                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17479    
17480                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17481    
17482                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17483                                    MBMessage.class.getName(),
17484                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17485    
17486                    Session session = null;
17487    
17488                    try {
17489                            session = openSession();
17490    
17491                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17492    
17493                            q.addScalar(COUNT_COLUMN_NAME,
17494                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17495    
17496                            QueryPos qPos = QueryPos.getInstance(q);
17497    
17498                            qPos.add(groupId);
17499    
17500                            qPos.add(categoryId);
17501    
17502                            qPos.add(threadId);
17503    
17504                            qPos.add(status);
17505    
17506                            Long count = (Long)q.uniqueResult();
17507    
17508                            return count.intValue();
17509                    }
17510                    catch (Exception e) {
17511                            throw processException(e);
17512                    }
17513                    finally {
17514                            closeSession(session);
17515                    }
17516            }
17517    
17518            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17519            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17520            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17521            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17522            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17523                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17524                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
17525                            new String[] {
17526                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17527                                    Integer.class.getName(),
17528                                    
17529                            Integer.class.getName(), Integer.class.getName(),
17530                                    OrderByComparator.class.getName()
17531                            });
17532            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
17533                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17534                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17535                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
17536                            new String[] {
17537                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17538                                    Integer.class.getName()
17539                            },
17540                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
17541                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17542                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
17543                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17544                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17545            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17546                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17547                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
17548                            new String[] {
17549                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17550                                    Integer.class.getName()
17551                            });
17552    
17553            /**
17554             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17555             *
17556             * @param userId the user ID
17557             * @param classNameId the class name ID
17558             * @param classPK the class p k
17559             * @param status the status
17560             * @return the matching message-boards messages
17561             */
17562            @Override
17563            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17564                    long classPK, int status) {
17565                    return findByU_C_C_S(userId, classNameId, classPK, status,
17566                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17567            }
17568    
17569            /**
17570             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17571             *
17572             * <p>
17573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17574             * </p>
17575             *
17576             * @param userId the user ID
17577             * @param classNameId the class name ID
17578             * @param classPK the class p k
17579             * @param status the status
17580             * @param start the lower bound of the range of message-boards messages
17581             * @param end the upper bound of the range of message-boards messages (not inclusive)
17582             * @return the range of matching message-boards messages
17583             */
17584            @Override
17585            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17586                    long classPK, int status, int start, int end) {
17587                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
17588                            null);
17589            }
17590    
17591            /**
17592             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17593             *
17594             * <p>
17595             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17596             * </p>
17597             *
17598             * @param userId the user ID
17599             * @param classNameId the class name ID
17600             * @param classPK the class p k
17601             * @param status the status
17602             * @param start the lower bound of the range of message-boards messages
17603             * @param end the upper bound of the range of message-boards messages (not inclusive)
17604             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17605             * @return the ordered range of matching message-boards messages
17606             */
17607            @Override
17608            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17609                    long classPK, int status, int start, int end,
17610                    OrderByComparator<MBMessage> orderByComparator) {
17611                    boolean pagination = true;
17612                    FinderPath finderPath = null;
17613                    Object[] finderArgs = null;
17614    
17615                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17616                                    (orderByComparator == null)) {
17617                            pagination = false;
17618                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
17619                            finderArgs = new Object[] { userId, classNameId, classPK, status };
17620                    }
17621                    else {
17622                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
17623                            finderArgs = new Object[] {
17624                                            userId, classNameId, classPK, status,
17625                                            
17626                                            start, end, orderByComparator
17627                                    };
17628                    }
17629    
17630                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17631                                    finderArgs, this);
17632    
17633                    if ((list != null) && !list.isEmpty()) {
17634                            for (MBMessage mbMessage : list) {
17635                                    if ((userId != mbMessage.getUserId()) ||
17636                                                    (classNameId != mbMessage.getClassNameId()) ||
17637                                                    (classPK != mbMessage.getClassPK()) ||
17638                                                    (status != mbMessage.getStatus())) {
17639                                            list = null;
17640    
17641                                            break;
17642                                    }
17643                            }
17644                    }
17645    
17646                    if (list == null) {
17647                            StringBundler query = null;
17648    
17649                            if (orderByComparator != null) {
17650                                    query = new StringBundler(6 +
17651                                                    (orderByComparator.getOrderByFields().length * 3));
17652                            }
17653                            else {
17654                                    query = new StringBundler(6);
17655                            }
17656    
17657                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17658    
17659                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17660    
17661                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17662    
17663                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17664    
17665                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17666    
17667                            if (orderByComparator != null) {
17668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17669                                            orderByComparator);
17670                            }
17671                            else
17672                             if (pagination) {
17673                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17674                            }
17675    
17676                            String sql = query.toString();
17677    
17678                            Session session = null;
17679    
17680                            try {
17681                                    session = openSession();
17682    
17683                                    Query q = session.createQuery(sql);
17684    
17685                                    QueryPos qPos = QueryPos.getInstance(q);
17686    
17687                                    qPos.add(userId);
17688    
17689                                    qPos.add(classNameId);
17690    
17691                                    qPos.add(classPK);
17692    
17693                                    qPos.add(status);
17694    
17695                                    if (!pagination) {
17696                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17697                                                            start, end, false);
17698    
17699                                            Collections.sort(list);
17700    
17701                                            list = Collections.unmodifiableList(list);
17702                                    }
17703                                    else {
17704                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17705                                                            start, end);
17706                                    }
17707    
17708                                    cacheResult(list);
17709    
17710                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17711                            }
17712                            catch (Exception e) {
17713                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17714    
17715                                    throw processException(e);
17716                            }
17717                            finally {
17718                                    closeSession(session);
17719                            }
17720                    }
17721    
17722                    return list;
17723            }
17724    
17725            /**
17726             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17727             *
17728             * @param userId the user ID
17729             * @param classNameId the class name ID
17730             * @param classPK the class p k
17731             * @param status the status
17732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17733             * @return the first matching message-boards message
17734             * @throws NoSuchMessageException if a matching message-boards message could not be found
17735             */
17736            @Override
17737            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
17738                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
17739                    throws NoSuchMessageException {
17740                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
17741                                    classPK, status, orderByComparator);
17742    
17743                    if (mbMessage != null) {
17744                            return mbMessage;
17745                    }
17746    
17747                    StringBundler msg = new StringBundler(10);
17748    
17749                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17750    
17751                    msg.append("userId=");
17752                    msg.append(userId);
17753    
17754                    msg.append(", classNameId=");
17755                    msg.append(classNameId);
17756    
17757                    msg.append(", classPK=");
17758                    msg.append(classPK);
17759    
17760                    msg.append(", status=");
17761                    msg.append(status);
17762    
17763                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17764    
17765                    throw new NoSuchMessageException(msg.toString());
17766            }
17767    
17768            /**
17769             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17770             *
17771             * @param userId the user ID
17772             * @param classNameId the class name ID
17773             * @param classPK the class p k
17774             * @param status the status
17775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17776             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17777             */
17778            @Override
17779            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
17780                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
17781                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17782                                    status, 0, 1, orderByComparator);
17783    
17784                    if (!list.isEmpty()) {
17785                            return list.get(0);
17786                    }
17787    
17788                    return null;
17789            }
17790    
17791            /**
17792             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17793             *
17794             * @param userId the user ID
17795             * @param classNameId the class name ID
17796             * @param classPK the class p k
17797             * @param status the status
17798             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17799             * @return the last matching message-boards message
17800             * @throws NoSuchMessageException if a matching message-boards message could not be found
17801             */
17802            @Override
17803            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
17804                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
17805                    throws NoSuchMessageException {
17806                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
17807                                    status, orderByComparator);
17808    
17809                    if (mbMessage != null) {
17810                            return mbMessage;
17811                    }
17812    
17813                    StringBundler msg = new StringBundler(10);
17814    
17815                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17816    
17817                    msg.append("userId=");
17818                    msg.append(userId);
17819    
17820                    msg.append(", classNameId=");
17821                    msg.append(classNameId);
17822    
17823                    msg.append(", classPK=");
17824                    msg.append(classPK);
17825    
17826                    msg.append(", status=");
17827                    msg.append(status);
17828    
17829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17830    
17831                    throw new NoSuchMessageException(msg.toString());
17832            }
17833    
17834            /**
17835             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17836             *
17837             * @param userId the user ID
17838             * @param classNameId the class name ID
17839             * @param classPK the class p k
17840             * @param status the status
17841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17842             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17843             */
17844            @Override
17845            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
17846                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
17847                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
17848    
17849                    if (count == 0) {
17850                            return null;
17851                    }
17852    
17853                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17854                                    status, count - 1, count, orderByComparator);
17855    
17856                    if (!list.isEmpty()) {
17857                            return list.get(0);
17858                    }
17859    
17860                    return null;
17861            }
17862    
17863            /**
17864             * 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;.
17865             *
17866             * @param messageId the primary key of the current message-boards message
17867             * @param userId the user ID
17868             * @param classNameId the class name ID
17869             * @param classPK the class p k
17870             * @param status the status
17871             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17872             * @return the previous, current, and next message-boards message
17873             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17874             */
17875            @Override
17876            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
17877                    long classNameId, long classPK, int status,
17878                    OrderByComparator<MBMessage> orderByComparator)
17879                    throws NoSuchMessageException {
17880                    MBMessage mbMessage = findByPrimaryKey(messageId);
17881    
17882                    Session session = null;
17883    
17884                    try {
17885                            session = openSession();
17886    
17887                            MBMessage[] array = new MBMessageImpl[3];
17888    
17889                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17890                                            classNameId, classPK, status, orderByComparator, true);
17891    
17892                            array[1] = mbMessage;
17893    
17894                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17895                                            classNameId, classPK, status, orderByComparator, false);
17896    
17897                            return array;
17898                    }
17899                    catch (Exception e) {
17900                            throw processException(e);
17901                    }
17902                    finally {
17903                            closeSession(session);
17904                    }
17905            }
17906    
17907            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
17908                    MBMessage mbMessage, long userId, long classNameId, long classPK,
17909                    int status, OrderByComparator<MBMessage> orderByComparator,
17910                    boolean previous) {
17911                    StringBundler query = null;
17912    
17913                    if (orderByComparator != null) {
17914                            query = new StringBundler(6 +
17915                                            (orderByComparator.getOrderByFields().length * 6));
17916                    }
17917                    else {
17918                            query = new StringBundler(3);
17919                    }
17920    
17921                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17922    
17923                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17924    
17925                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17926    
17927                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17928    
17929                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17930    
17931                    if (orderByComparator != null) {
17932                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17933    
17934                            if (orderByConditionFields.length > 0) {
17935                                    query.append(WHERE_AND);
17936                            }
17937    
17938                            for (int i = 0; i < orderByConditionFields.length; i++) {
17939                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17940                                    query.append(orderByConditionFields[i]);
17941    
17942                                    if ((i + 1) < orderByConditionFields.length) {
17943                                            if (orderByComparator.isAscending() ^ previous) {
17944                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17945                                            }
17946                                            else {
17947                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17948                                            }
17949                                    }
17950                                    else {
17951                                            if (orderByComparator.isAscending() ^ previous) {
17952                                                    query.append(WHERE_GREATER_THAN);
17953                                            }
17954                                            else {
17955                                                    query.append(WHERE_LESSER_THAN);
17956                                            }
17957                                    }
17958                            }
17959    
17960                            query.append(ORDER_BY_CLAUSE);
17961    
17962                            String[] orderByFields = orderByComparator.getOrderByFields();
17963    
17964                            for (int i = 0; i < orderByFields.length; i++) {
17965                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17966                                    query.append(orderByFields[i]);
17967    
17968                                    if ((i + 1) < orderByFields.length) {
17969                                            if (orderByComparator.isAscending() ^ previous) {
17970                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17971                                            }
17972                                            else {
17973                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17974                                            }
17975                                    }
17976                                    else {
17977                                            if (orderByComparator.isAscending() ^ previous) {
17978                                                    query.append(ORDER_BY_ASC);
17979                                            }
17980                                            else {
17981                                                    query.append(ORDER_BY_DESC);
17982                                            }
17983                                    }
17984                            }
17985                    }
17986                    else {
17987                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17988                    }
17989    
17990                    String sql = query.toString();
17991    
17992                    Query q = session.createQuery(sql);
17993    
17994                    q.setFirstResult(0);
17995                    q.setMaxResults(2);
17996    
17997                    QueryPos qPos = QueryPos.getInstance(q);
17998    
17999                    qPos.add(userId);
18000    
18001                    qPos.add(classNameId);
18002    
18003                    qPos.add(classPK);
18004    
18005                    qPos.add(status);
18006    
18007                    if (orderByComparator != null) {
18008                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18009    
18010                            for (Object value : values) {
18011                                    qPos.add(value);
18012                            }
18013                    }
18014    
18015                    List<MBMessage> list = q.list();
18016    
18017                    if (list.size() == 2) {
18018                            return list.get(1);
18019                    }
18020                    else {
18021                            return null;
18022                    }
18023            }
18024    
18025            /**
18026             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18027             *
18028             * @param userId the user ID
18029             * @param classNameId the class name ID
18030             * @param classPK the class p k
18031             * @param status the status
18032             */
18033            @Override
18034            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18035                    int status) {
18036                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18037                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18038                            remove(mbMessage);
18039                    }
18040            }
18041    
18042            /**
18043             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18044             *
18045             * @param userId the user ID
18046             * @param classNameId the class name ID
18047             * @param classPK the class p k
18048             * @param status the status
18049             * @return the number of matching message-boards messages
18050             */
18051            @Override
18052            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18053                    int status) {
18054                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18055    
18056                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18057    
18058                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18059                                    this);
18060    
18061                    if (count == null) {
18062                            StringBundler query = new StringBundler(5);
18063    
18064                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18065    
18066                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18067    
18068                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18069    
18070                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18071    
18072                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18073    
18074                            String sql = query.toString();
18075    
18076                            Session session = null;
18077    
18078                            try {
18079                                    session = openSession();
18080    
18081                                    Query q = session.createQuery(sql);
18082    
18083                                    QueryPos qPos = QueryPos.getInstance(q);
18084    
18085                                    qPos.add(userId);
18086    
18087                                    qPos.add(classNameId);
18088    
18089                                    qPos.add(classPK);
18090    
18091                                    qPos.add(status);
18092    
18093                                    count = (Long)q.uniqueResult();
18094    
18095                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18096                            }
18097                            catch (Exception e) {
18098                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18099    
18100                                    throw processException(e);
18101                            }
18102                            finally {
18103                                    closeSession(session);
18104                            }
18105                    }
18106    
18107                    return count.intValue();
18108            }
18109    
18110            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18111            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18112            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18113            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18114    
18115            public MBMessagePersistenceImpl() {
18116                    setModelClass(MBMessage.class);
18117            }
18118    
18119            /**
18120             * Caches the message-boards message in the entity cache if it is enabled.
18121             *
18122             * @param mbMessage the message-boards message
18123             */
18124            @Override
18125            public void cacheResult(MBMessage mbMessage) {
18126                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18127                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18128    
18129                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18130                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18131                            mbMessage);
18132    
18133                    mbMessage.resetOriginalValues();
18134            }
18135    
18136            /**
18137             * Caches the message-boards messages in the entity cache if it is enabled.
18138             *
18139             * @param mbMessages the message-boards messages
18140             */
18141            @Override
18142            public void cacheResult(List<MBMessage> mbMessages) {
18143                    for (MBMessage mbMessage : mbMessages) {
18144                            if (EntityCacheUtil.getResult(
18145                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18146                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18147                                    cacheResult(mbMessage);
18148                            }
18149                            else {
18150                                    mbMessage.resetOriginalValues();
18151                            }
18152                    }
18153            }
18154    
18155            /**
18156             * Clears the cache for all message-boards messages.
18157             *
18158             * <p>
18159             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18160             * </p>
18161             */
18162            @Override
18163            public void clearCache() {
18164                    EntityCacheUtil.clearCache(MBMessageImpl.class);
18165    
18166                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18169            }
18170    
18171            /**
18172             * Clears the cache for the message-boards message.
18173             *
18174             * <p>
18175             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18176             * </p>
18177             */
18178            @Override
18179            public void clearCache(MBMessage mbMessage) {
18180                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18181                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18182    
18183                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18184                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18185    
18186                    clearUniqueFindersCache(mbMessage);
18187            }
18188    
18189            @Override
18190            public void clearCache(List<MBMessage> mbMessages) {
18191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18192                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18193    
18194                    for (MBMessage mbMessage : mbMessages) {
18195                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18196                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18197    
18198                            clearUniqueFindersCache(mbMessage);
18199                    }
18200            }
18201    
18202            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
18203                    if (mbMessage.isNew()) {
18204                            Object[] args = new Object[] {
18205                                            mbMessage.getUuid(), mbMessage.getGroupId()
18206                                    };
18207    
18208                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18209                                    Long.valueOf(1));
18210                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18211                                    mbMessage);
18212                    }
18213                    else {
18214                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18215    
18216                            if ((mbMessageModelImpl.getColumnBitmask() &
18217                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18218                                    Object[] args = new Object[] {
18219                                                    mbMessage.getUuid(), mbMessage.getGroupId()
18220                                            };
18221    
18222                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18223                                            Long.valueOf(1));
18224                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18225                                            mbMessage);
18226                            }
18227                    }
18228            }
18229    
18230            protected void clearUniqueFindersCache(MBMessage mbMessage) {
18231                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18232    
18233                    Object[] args = new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() };
18234    
18235                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18237    
18238                    if ((mbMessageModelImpl.getColumnBitmask() &
18239                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18240                            args = new Object[] {
18241                                            mbMessageModelImpl.getOriginalUuid(),
18242                                            mbMessageModelImpl.getOriginalGroupId()
18243                                    };
18244    
18245                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18246                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18247                    }
18248            }
18249    
18250            /**
18251             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18252             *
18253             * @param messageId the primary key for the new message-boards message
18254             * @return the new message-boards message
18255             */
18256            @Override
18257            public MBMessage create(long messageId) {
18258                    MBMessage mbMessage = new MBMessageImpl();
18259    
18260                    mbMessage.setNew(true);
18261                    mbMessage.setPrimaryKey(messageId);
18262    
18263                    String uuid = PortalUUIDUtil.generate();
18264    
18265                    mbMessage.setUuid(uuid);
18266    
18267                    return mbMessage;
18268            }
18269    
18270            /**
18271             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18272             *
18273             * @param messageId the primary key of the message-boards message
18274             * @return the message-boards message that was removed
18275             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18276             */
18277            @Override
18278            public MBMessage remove(long messageId) throws NoSuchMessageException {
18279                    return remove((Serializable)messageId);
18280            }
18281    
18282            /**
18283             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18284             *
18285             * @param primaryKey the primary key of the message-boards message
18286             * @return the message-boards message that was removed
18287             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18288             */
18289            @Override
18290            public MBMessage remove(Serializable primaryKey)
18291                    throws NoSuchMessageException {
18292                    Session session = null;
18293    
18294                    try {
18295                            session = openSession();
18296    
18297                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18298                                            primaryKey);
18299    
18300                            if (mbMessage == null) {
18301                                    if (_log.isWarnEnabled()) {
18302                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18303                                    }
18304    
18305                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18306                                            primaryKey);
18307                            }
18308    
18309                            return remove(mbMessage);
18310                    }
18311                    catch (NoSuchMessageException nsee) {
18312                            throw nsee;
18313                    }
18314                    catch (Exception e) {
18315                            throw processException(e);
18316                    }
18317                    finally {
18318                            closeSession(session);
18319                    }
18320            }
18321    
18322            @Override
18323            protected MBMessage removeImpl(MBMessage mbMessage) {
18324                    mbMessage = toUnwrappedModel(mbMessage);
18325    
18326                    Session session = null;
18327    
18328                    try {
18329                            session = openSession();
18330    
18331                            if (!session.contains(mbMessage)) {
18332                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18333                                                    mbMessage.getPrimaryKeyObj());
18334                            }
18335    
18336                            if (mbMessage != null) {
18337                                    session.delete(mbMessage);
18338                            }
18339                    }
18340                    catch (Exception e) {
18341                            throw processException(e);
18342                    }
18343                    finally {
18344                            closeSession(session);
18345                    }
18346    
18347                    if (mbMessage != null) {
18348                            clearCache(mbMessage);
18349                    }
18350    
18351                    return mbMessage;
18352            }
18353    
18354            @Override
18355            public MBMessage updateImpl(MBMessage mbMessage) {
18356                    mbMessage = toUnwrappedModel(mbMessage);
18357    
18358                    boolean isNew = mbMessage.isNew();
18359    
18360                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18361    
18362                    if (Validator.isNull(mbMessage.getUuid())) {
18363                            String uuid = PortalUUIDUtil.generate();
18364    
18365                            mbMessage.setUuid(uuid);
18366                    }
18367    
18368                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
18369    
18370                    Date now = new Date();
18371    
18372                    if (isNew && (mbMessage.getCreateDate() == null)) {
18373                            if (serviceContext == null) {
18374                                    mbMessage.setCreateDate(now);
18375                            }
18376                            else {
18377                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
18378                            }
18379                    }
18380    
18381                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
18382                            if (serviceContext == null) {
18383                                    mbMessage.setModifiedDate(now);
18384                            }
18385                            else {
18386                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
18387                            }
18388                    }
18389    
18390                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18391    
18392                    if (userId > 0) {
18393                            long companyId = mbMessage.getCompanyId();
18394    
18395                            long groupId = mbMessage.getGroupId();
18396    
18397                            long messageId = 0;
18398    
18399                            if (!isNew) {
18400                                    messageId = mbMessage.getPrimaryKey();
18401                            }
18402    
18403                            try {
18404                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
18405                                                    userId, MBMessage.class.getName(), messageId,
18406                                                    ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18407                                                    mbMessage.getSubject(), null));
18408                            }
18409                            catch (SanitizerException se) {
18410                                    throw new SystemException(se);
18411                            }
18412                    }
18413    
18414                    Session session = null;
18415    
18416                    try {
18417                            session = openSession();
18418    
18419                            if (mbMessage.isNew()) {
18420                                    session.save(mbMessage);
18421    
18422                                    mbMessage.setNew(false);
18423                            }
18424                            else {
18425                                    session.merge(mbMessage);
18426                            }
18427                    }
18428                    catch (Exception e) {
18429                            throw processException(e);
18430                    }
18431                    finally {
18432                            closeSession(session);
18433                    }
18434    
18435                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18436    
18437                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
18438                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18439                    }
18440    
18441                    else {
18442                            if ((mbMessageModelImpl.getColumnBitmask() &
18443                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18444                                    Object[] args = new Object[] {
18445                                                    mbMessageModelImpl.getOriginalUuid()
18446                                            };
18447    
18448                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18449                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18450                                            args);
18451    
18452                                    args = new Object[] { mbMessageModelImpl.getUuid() };
18453    
18454                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18455                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18456                                            args);
18457                            }
18458    
18459                            if ((mbMessageModelImpl.getColumnBitmask() &
18460                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18461                                    Object[] args = new Object[] {
18462                                                    mbMessageModelImpl.getOriginalUuid(),
18463                                                    mbMessageModelImpl.getOriginalCompanyId()
18464                                            };
18465    
18466                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18467                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18468                                            args);
18469    
18470                                    args = new Object[] {
18471                                                    mbMessageModelImpl.getUuid(),
18472                                                    mbMessageModelImpl.getCompanyId()
18473                                            };
18474    
18475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18477                                            args);
18478                            }
18479    
18480                            if ((mbMessageModelImpl.getColumnBitmask() &
18481                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
18482                                    Object[] args = new Object[] {
18483                                                    mbMessageModelImpl.getOriginalGroupId()
18484                                            };
18485    
18486                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18487                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18488                                            args);
18489    
18490                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
18491    
18492                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18493                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18494                                            args);
18495                            }
18496    
18497                            if ((mbMessageModelImpl.getColumnBitmask() &
18498                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
18499                                    Object[] args = new Object[] {
18500                                                    mbMessageModelImpl.getOriginalCompanyId()
18501                                            };
18502    
18503                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18504                                            args);
18505                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18506                                            args);
18507    
18508                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
18509    
18510                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18511                                            args);
18512                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18513                                            args);
18514                            }
18515    
18516                            if ((mbMessageModelImpl.getColumnBitmask() &
18517                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
18518                                    Object[] args = new Object[] {
18519                                                    mbMessageModelImpl.getOriginalUserId()
18520                                            };
18521    
18522                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18523                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18524                                            args);
18525    
18526                                    args = new Object[] { mbMessageModelImpl.getUserId() };
18527    
18528                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18529                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18530                                            args);
18531                            }
18532    
18533                            if ((mbMessageModelImpl.getColumnBitmask() &
18534                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
18535                                    Object[] args = new Object[] {
18536                                                    mbMessageModelImpl.getOriginalThreadId()
18537                                            };
18538    
18539                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18540                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18541                                            args);
18542    
18543                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18544    
18545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18546                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18547                                            args);
18548                            }
18549    
18550                            if ((mbMessageModelImpl.getColumnBitmask() &
18551                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
18552                                    Object[] args = new Object[] {
18553                                                    mbMessageModelImpl.getOriginalThreadId()
18554                                            };
18555    
18556                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18557                                            args);
18558                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18559                                            args);
18560    
18561                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18562    
18563                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18564                                            args);
18565                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18566                                            args);
18567                            }
18568    
18569                            if ((mbMessageModelImpl.getColumnBitmask() &
18570                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
18571                                    Object[] args = new Object[] {
18572                                                    mbMessageModelImpl.getOriginalGroupId(),
18573                                                    mbMessageModelImpl.getOriginalUserId()
18574                                            };
18575    
18576                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18577                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18578                                            args);
18579    
18580                                    args = new Object[] {
18581                                                    mbMessageModelImpl.getGroupId(),
18582                                                    mbMessageModelImpl.getUserId()
18583                                            };
18584    
18585                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18586                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18587                                            args);
18588                            }
18589    
18590                            if ((mbMessageModelImpl.getColumnBitmask() &
18591                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
18592                                    Object[] args = new Object[] {
18593                                                    mbMessageModelImpl.getOriginalGroupId(),
18594                                                    mbMessageModelImpl.getOriginalCategoryId()
18595                                            };
18596    
18597                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18598                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18599                                            args);
18600    
18601                                    args = new Object[] {
18602                                                    mbMessageModelImpl.getGroupId(),
18603                                                    mbMessageModelImpl.getCategoryId()
18604                                            };
18605    
18606                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18607                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18608                                            args);
18609                            }
18610    
18611                            if ((mbMessageModelImpl.getColumnBitmask() &
18612                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
18613                                    Object[] args = new Object[] {
18614                                                    mbMessageModelImpl.getOriginalGroupId(),
18615                                                    mbMessageModelImpl.getOriginalStatus()
18616                                            };
18617    
18618                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18619                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18620                                            args);
18621    
18622                                    args = new Object[] {
18623                                                    mbMessageModelImpl.getGroupId(),
18624                                                    mbMessageModelImpl.getStatus()
18625                                            };
18626    
18627                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18628                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18629                                            args);
18630                            }
18631    
18632                            if ((mbMessageModelImpl.getColumnBitmask() &
18633                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
18634                                    Object[] args = new Object[] {
18635                                                    mbMessageModelImpl.getOriginalCompanyId(),
18636                                                    mbMessageModelImpl.getOriginalStatus()
18637                                            };
18638    
18639                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18640                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18641                                            args);
18642    
18643                                    args = new Object[] {
18644                                                    mbMessageModelImpl.getCompanyId(),
18645                                                    mbMessageModelImpl.getStatus()
18646                                            };
18647    
18648                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18649                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18650                                            args);
18651                            }
18652    
18653                            if ((mbMessageModelImpl.getColumnBitmask() &
18654                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
18655                                    Object[] args = new Object[] {
18656                                                    mbMessageModelImpl.getOriginalUserId(),
18657                                                    mbMessageModelImpl.getOriginalClassNameId()
18658                                            };
18659    
18660                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18661                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18662                                            args);
18663    
18664                                    args = new Object[] {
18665                                                    mbMessageModelImpl.getUserId(),
18666                                                    mbMessageModelImpl.getClassNameId()
18667                                            };
18668    
18669                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18670                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18671                                            args);
18672                            }
18673    
18674                            if ((mbMessageModelImpl.getColumnBitmask() &
18675                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
18676                                    Object[] args = new Object[] {
18677                                                    mbMessageModelImpl.getOriginalClassNameId(),
18678                                                    mbMessageModelImpl.getOriginalClassPK()
18679                                            };
18680    
18681                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18682                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18683                                            args);
18684    
18685                                    args = new Object[] {
18686                                                    mbMessageModelImpl.getClassNameId(),
18687                                                    mbMessageModelImpl.getClassPK()
18688                                            };
18689    
18690                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18691                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18692                                            args);
18693                            }
18694    
18695                            if ((mbMessageModelImpl.getColumnBitmask() &
18696                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
18697                                    Object[] args = new Object[] {
18698                                                    mbMessageModelImpl.getOriginalThreadId(),
18699                                                    mbMessageModelImpl.getOriginalParentMessageId()
18700                                            };
18701    
18702                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18703                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18704                                            args);
18705    
18706                                    args = new Object[] {
18707                                                    mbMessageModelImpl.getThreadId(),
18708                                                    mbMessageModelImpl.getParentMessageId()
18709                                            };
18710    
18711                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18712                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18713                                            args);
18714                            }
18715    
18716                            if ((mbMessageModelImpl.getColumnBitmask() &
18717                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
18718                                    Object[] args = new Object[] {
18719                                                    mbMessageModelImpl.getOriginalThreadId(),
18720                                                    mbMessageModelImpl.getOriginalAnswer()
18721                                            };
18722    
18723                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18724                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18725                                            args);
18726    
18727                                    args = new Object[] {
18728                                                    mbMessageModelImpl.getThreadId(),
18729                                                    mbMessageModelImpl.getAnswer()
18730                                            };
18731    
18732                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18733                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18734                                            args);
18735                            }
18736    
18737                            if ((mbMessageModelImpl.getColumnBitmask() &
18738                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
18739                                    Object[] args = new Object[] {
18740                                                    mbMessageModelImpl.getOriginalThreadId(),
18741                                                    mbMessageModelImpl.getOriginalStatus()
18742                                            };
18743    
18744                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18745                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18746                                            args);
18747    
18748                                    args = new Object[] {
18749                                                    mbMessageModelImpl.getThreadId(),
18750                                                    mbMessageModelImpl.getStatus()
18751                                            };
18752    
18753                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18754                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18755                                            args);
18756                            }
18757    
18758                            if ((mbMessageModelImpl.getColumnBitmask() &
18759                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
18760                                    Object[] args = new Object[] {
18761                                                    mbMessageModelImpl.getOriginalThreadId(),
18762                                                    mbMessageModelImpl.getOriginalStatus()
18763                                            };
18764    
18765                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18766                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18767                                            args);
18768    
18769                                    args = new Object[] {
18770                                                    mbMessageModelImpl.getThreadId(),
18771                                                    mbMessageModelImpl.getStatus()
18772                                            };
18773    
18774                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18775                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18776                                            args);
18777                            }
18778    
18779                            if ((mbMessageModelImpl.getColumnBitmask() &
18780                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
18781                                    Object[] args = new Object[] {
18782                                                    mbMessageModelImpl.getOriginalGroupId(),
18783                                                    mbMessageModelImpl.getOriginalUserId(),
18784                                                    mbMessageModelImpl.getOriginalStatus()
18785                                            };
18786    
18787                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18788                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18789                                            args);
18790    
18791                                    args = new Object[] {
18792                                                    mbMessageModelImpl.getGroupId(),
18793                                                    mbMessageModelImpl.getUserId(),
18794                                                    mbMessageModelImpl.getStatus()
18795                                            };
18796    
18797                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18798                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18799                                            args);
18800                            }
18801    
18802                            if ((mbMessageModelImpl.getColumnBitmask() &
18803                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
18804                                    Object[] args = new Object[] {
18805                                                    mbMessageModelImpl.getOriginalGroupId(),
18806                                                    mbMessageModelImpl.getOriginalCategoryId(),
18807                                                    mbMessageModelImpl.getOriginalThreadId()
18808                                            };
18809    
18810                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18811                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18812                                            args);
18813    
18814                                    args = new Object[] {
18815                                                    mbMessageModelImpl.getGroupId(),
18816                                                    mbMessageModelImpl.getCategoryId(),
18817                                                    mbMessageModelImpl.getThreadId()
18818                                            };
18819    
18820                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18821                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18822                                            args);
18823                            }
18824    
18825                            if ((mbMessageModelImpl.getColumnBitmask() &
18826                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
18827                                    Object[] args = new Object[] {
18828                                                    mbMessageModelImpl.getOriginalGroupId(),
18829                                                    mbMessageModelImpl.getOriginalCategoryId(),
18830                                                    mbMessageModelImpl.getOriginalStatus()
18831                                            };
18832    
18833                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18834                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18835                                            args);
18836    
18837                                    args = new Object[] {
18838                                                    mbMessageModelImpl.getGroupId(),
18839                                                    mbMessageModelImpl.getCategoryId(),
18840                                                    mbMessageModelImpl.getStatus()
18841                                            };
18842    
18843                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18844                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18845                                            args);
18846                            }
18847    
18848                            if ((mbMessageModelImpl.getColumnBitmask() &
18849                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
18850                                    Object[] args = new Object[] {
18851                                                    mbMessageModelImpl.getOriginalUserId(),
18852                                                    mbMessageModelImpl.getOriginalClassNameId(),
18853                                                    mbMessageModelImpl.getOriginalClassPK()
18854                                            };
18855    
18856                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18857                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18858                                            args);
18859    
18860                                    args = new Object[] {
18861                                                    mbMessageModelImpl.getUserId(),
18862                                                    mbMessageModelImpl.getClassNameId(),
18863                                                    mbMessageModelImpl.getClassPK()
18864                                            };
18865    
18866                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18867                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18868                                            args);
18869                            }
18870    
18871                            if ((mbMessageModelImpl.getColumnBitmask() &
18872                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
18873                                    Object[] args = new Object[] {
18874                                                    mbMessageModelImpl.getOriginalUserId(),
18875                                                    mbMessageModelImpl.getOriginalClassNameId(),
18876                                                    mbMessageModelImpl.getOriginalStatus()
18877                                            };
18878    
18879                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18880                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18881                                            args);
18882    
18883                                    args = new Object[] {
18884                                                    mbMessageModelImpl.getUserId(),
18885                                                    mbMessageModelImpl.getClassNameId(),
18886                                                    mbMessageModelImpl.getStatus()
18887                                            };
18888    
18889                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18890                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18891                                            args);
18892                            }
18893    
18894                            if ((mbMessageModelImpl.getColumnBitmask() &
18895                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
18896                                    Object[] args = new Object[] {
18897                                                    mbMessageModelImpl.getOriginalClassNameId(),
18898                                                    mbMessageModelImpl.getOriginalClassPK(),
18899                                                    mbMessageModelImpl.getOriginalStatus()
18900                                            };
18901    
18902                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18903                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18904                                            args);
18905    
18906                                    args = new Object[] {
18907                                                    mbMessageModelImpl.getClassNameId(),
18908                                                    mbMessageModelImpl.getClassPK(),
18909                                                    mbMessageModelImpl.getStatus()
18910                                            };
18911    
18912                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18913                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18914                                            args);
18915                            }
18916    
18917                            if ((mbMessageModelImpl.getColumnBitmask() &
18918                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
18919                                    Object[] args = new Object[] {
18920                                                    mbMessageModelImpl.getOriginalGroupId(),
18921                                                    mbMessageModelImpl.getOriginalCategoryId(),
18922                                                    mbMessageModelImpl.getOriginalThreadId(),
18923                                                    mbMessageModelImpl.getOriginalAnswer()
18924                                            };
18925    
18926                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18927                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18928                                            args);
18929    
18930                                    args = new Object[] {
18931                                                    mbMessageModelImpl.getGroupId(),
18932                                                    mbMessageModelImpl.getCategoryId(),
18933                                                    mbMessageModelImpl.getThreadId(),
18934                                                    mbMessageModelImpl.getAnswer()
18935                                            };
18936    
18937                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18938                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18939                                            args);
18940                            }
18941    
18942                            if ((mbMessageModelImpl.getColumnBitmask() &
18943                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
18944                                    Object[] args = new Object[] {
18945                                                    mbMessageModelImpl.getOriginalGroupId(),
18946                                                    mbMessageModelImpl.getOriginalCategoryId(),
18947                                                    mbMessageModelImpl.getOriginalThreadId(),
18948                                                    mbMessageModelImpl.getOriginalStatus()
18949                                            };
18950    
18951                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18952                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18953                                            args);
18954    
18955                                    args = new Object[] {
18956                                                    mbMessageModelImpl.getGroupId(),
18957                                                    mbMessageModelImpl.getCategoryId(),
18958                                                    mbMessageModelImpl.getThreadId(),
18959                                                    mbMessageModelImpl.getStatus()
18960                                            };
18961    
18962                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18963                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18964                                            args);
18965                            }
18966    
18967                            if ((mbMessageModelImpl.getColumnBitmask() &
18968                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
18969                                    Object[] args = new Object[] {
18970                                                    mbMessageModelImpl.getOriginalUserId(),
18971                                                    mbMessageModelImpl.getOriginalClassNameId(),
18972                                                    mbMessageModelImpl.getOriginalClassPK(),
18973                                                    mbMessageModelImpl.getOriginalStatus()
18974                                            };
18975    
18976                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18977                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18978                                            args);
18979    
18980                                    args = new Object[] {
18981                                                    mbMessageModelImpl.getUserId(),
18982                                                    mbMessageModelImpl.getClassNameId(),
18983                                                    mbMessageModelImpl.getClassPK(),
18984                                                    mbMessageModelImpl.getStatus()
18985                                            };
18986    
18987                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18988                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18989                                            args);
18990                            }
18991                    }
18992    
18993                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18994                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
18995    
18996                    clearUniqueFindersCache(mbMessage);
18997                    cacheUniqueFindersCache(mbMessage);
18998    
18999                    mbMessage.resetOriginalValues();
19000    
19001                    return mbMessage;
19002            }
19003    
19004            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19005                    if (mbMessage instanceof MBMessageImpl) {
19006                            return mbMessage;
19007                    }
19008    
19009                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19010    
19011                    mbMessageImpl.setNew(mbMessage.isNew());
19012                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19013    
19014                    mbMessageImpl.setUuid(mbMessage.getUuid());
19015                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19016                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19017                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19018                    mbMessageImpl.setUserId(mbMessage.getUserId());
19019                    mbMessageImpl.setUserName(mbMessage.getUserName());
19020                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19021                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19022                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19023                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19024                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19025                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19026                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19027                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19028                    mbMessageImpl.setSubject(mbMessage.getSubject());
19029                    mbMessageImpl.setBody(mbMessage.getBody());
19030                    mbMessageImpl.setFormat(mbMessage.getFormat());
19031                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19032                    mbMessageImpl.setPriority(mbMessage.getPriority());
19033                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19034                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19035                    mbMessageImpl.setStatus(mbMessage.getStatus());
19036                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19037                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19038                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19039    
19040                    return mbMessageImpl;
19041            }
19042    
19043            /**
19044             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19045             *
19046             * @param primaryKey the primary key of the message-boards message
19047             * @return the message-boards message
19048             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19049             */
19050            @Override
19051            public MBMessage findByPrimaryKey(Serializable primaryKey)
19052                    throws NoSuchMessageException {
19053                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19054    
19055                    if (mbMessage == null) {
19056                            if (_log.isWarnEnabled()) {
19057                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19058                            }
19059    
19060                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19061                                    primaryKey);
19062                    }
19063    
19064                    return mbMessage;
19065            }
19066    
19067            /**
19068             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19069             *
19070             * @param messageId the primary key of the message-boards message
19071             * @return the message-boards message
19072             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19073             */
19074            @Override
19075            public MBMessage findByPrimaryKey(long messageId)
19076                    throws NoSuchMessageException {
19077                    return findByPrimaryKey((Serializable)messageId);
19078            }
19079    
19080            /**
19081             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19082             *
19083             * @param primaryKey the primary key of the message-boards message
19084             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19085             */
19086            @Override
19087            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19088                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19089                                    MBMessageImpl.class, primaryKey);
19090    
19091                    if (mbMessage == _nullMBMessage) {
19092                            return null;
19093                    }
19094    
19095                    if (mbMessage == null) {
19096                            Session session = null;
19097    
19098                            try {
19099                                    session = openSession();
19100    
19101                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19102                                                    primaryKey);
19103    
19104                                    if (mbMessage != null) {
19105                                            cacheResult(mbMessage);
19106                                    }
19107                                    else {
19108                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19109                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19110                                    }
19111                            }
19112                            catch (Exception e) {
19113                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19114                                            MBMessageImpl.class, primaryKey);
19115    
19116                                    throw processException(e);
19117                            }
19118                            finally {
19119                                    closeSession(session);
19120                            }
19121                    }
19122    
19123                    return mbMessage;
19124            }
19125    
19126            /**
19127             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19128             *
19129             * @param messageId the primary key of the message-boards message
19130             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19131             */
19132            @Override
19133            public MBMessage fetchByPrimaryKey(long messageId) {
19134                    return fetchByPrimaryKey((Serializable)messageId);
19135            }
19136    
19137            @Override
19138            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19139                    Set<Serializable> primaryKeys) {
19140                    if (primaryKeys.isEmpty()) {
19141                            return Collections.emptyMap();
19142                    }
19143    
19144                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19145    
19146                    if (primaryKeys.size() == 1) {
19147                            Iterator<Serializable> iterator = primaryKeys.iterator();
19148    
19149                            Serializable primaryKey = iterator.next();
19150    
19151                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19152    
19153                            if (mbMessage != null) {
19154                                    map.put(primaryKey, mbMessage);
19155                            }
19156    
19157                            return map;
19158                    }
19159    
19160                    Set<Serializable> uncachedPrimaryKeys = null;
19161    
19162                    for (Serializable primaryKey : primaryKeys) {
19163                            MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19164                                            MBMessageImpl.class, primaryKey);
19165    
19166                            if (mbMessage == null) {
19167                                    if (uncachedPrimaryKeys == null) {
19168                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19169                                    }
19170    
19171                                    uncachedPrimaryKeys.add(primaryKey);
19172                            }
19173                            else {
19174                                    map.put(primaryKey, mbMessage);
19175                            }
19176                    }
19177    
19178                    if (uncachedPrimaryKeys == null) {
19179                            return map;
19180                    }
19181    
19182                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19183                                    1);
19184    
19185                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19186    
19187                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19188                            query.append(String.valueOf(primaryKey));
19189    
19190                            query.append(StringPool.COMMA);
19191                    }
19192    
19193                    query.setIndex(query.index() - 1);
19194    
19195                    query.append(StringPool.CLOSE_PARENTHESIS);
19196    
19197                    String sql = query.toString();
19198    
19199                    Session session = null;
19200    
19201                    try {
19202                            session = openSession();
19203    
19204                            Query q = session.createQuery(sql);
19205    
19206                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19207                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19208    
19209                                    cacheResult(mbMessage);
19210    
19211                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19212                            }
19213    
19214                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19215                                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19216                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
19217                            }
19218                    }
19219                    catch (Exception e) {
19220                            throw processException(e);
19221                    }
19222                    finally {
19223                            closeSession(session);
19224                    }
19225    
19226                    return map;
19227            }
19228    
19229            /**
19230             * Returns all the message-boards messages.
19231             *
19232             * @return the message-boards messages
19233             */
19234            @Override
19235            public List<MBMessage> findAll() {
19236                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19237            }
19238    
19239            /**
19240             * Returns a range of all the message-boards messages.
19241             *
19242             * <p>
19243             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19244             * </p>
19245             *
19246             * @param start the lower bound of the range of message-boards messages
19247             * @param end the upper bound of the range of message-boards messages (not inclusive)
19248             * @return the range of message-boards messages
19249             */
19250            @Override
19251            public List<MBMessage> findAll(int start, int end) {
19252                    return findAll(start, end, null);
19253            }
19254    
19255            /**
19256             * Returns an ordered range of all the message-boards messages.
19257             *
19258             * <p>
19259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19260             * </p>
19261             *
19262             * @param start the lower bound of the range of message-boards messages
19263             * @param end the upper bound of the range of message-boards messages (not inclusive)
19264             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19265             * @return the ordered range of message-boards messages
19266             */
19267            @Override
19268            public List<MBMessage> findAll(int start, int end,
19269                    OrderByComparator<MBMessage> orderByComparator) {
19270                    boolean pagination = true;
19271                    FinderPath finderPath = null;
19272                    Object[] finderArgs = null;
19273    
19274                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19275                                    (orderByComparator == null)) {
19276                            pagination = false;
19277                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19278                            finderArgs = FINDER_ARGS_EMPTY;
19279                    }
19280                    else {
19281                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19282                            finderArgs = new Object[] { start, end, orderByComparator };
19283                    }
19284    
19285                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19286                                    finderArgs, this);
19287    
19288                    if (list == null) {
19289                            StringBundler query = null;
19290                            String sql = null;
19291    
19292                            if (orderByComparator != null) {
19293                                    query = new StringBundler(2 +
19294                                                    (orderByComparator.getOrderByFields().length * 3));
19295    
19296                                    query.append(_SQL_SELECT_MBMESSAGE);
19297    
19298                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19299                                            orderByComparator);
19300    
19301                                    sql = query.toString();
19302                            }
19303                            else {
19304                                    sql = _SQL_SELECT_MBMESSAGE;
19305    
19306                                    if (pagination) {
19307                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
19308                                    }
19309                            }
19310    
19311                            Session session = null;
19312    
19313                            try {
19314                                    session = openSession();
19315    
19316                                    Query q = session.createQuery(sql);
19317    
19318                                    if (!pagination) {
19319                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19320                                                            start, end, false);
19321    
19322                                            Collections.sort(list);
19323    
19324                                            list = Collections.unmodifiableList(list);
19325                                    }
19326                                    else {
19327                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19328                                                            start, end);
19329                                    }
19330    
19331                                    cacheResult(list);
19332    
19333                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19334                            }
19335                            catch (Exception e) {
19336                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19337    
19338                                    throw processException(e);
19339                            }
19340                            finally {
19341                                    closeSession(session);
19342                            }
19343                    }
19344    
19345                    return list;
19346            }
19347    
19348            /**
19349             * Removes all the message-boards messages from the database.
19350             *
19351             */
19352            @Override
19353            public void removeAll() {
19354                    for (MBMessage mbMessage : findAll()) {
19355                            remove(mbMessage);
19356                    }
19357            }
19358    
19359            /**
19360             * Returns the number of message-boards messages.
19361             *
19362             * @return the number of message-boards messages
19363             */
19364            @Override
19365            public int countAll() {
19366                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19367                                    FINDER_ARGS_EMPTY, this);
19368    
19369                    if (count == null) {
19370                            Session session = null;
19371    
19372                            try {
19373                                    session = openSession();
19374    
19375                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
19376    
19377                                    count = (Long)q.uniqueResult();
19378    
19379                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19380                                            FINDER_ARGS_EMPTY, count);
19381                            }
19382                            catch (Exception e) {
19383                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19384                                            FINDER_ARGS_EMPTY);
19385    
19386                                    throw processException(e);
19387                            }
19388                            finally {
19389                                    closeSession(session);
19390                            }
19391                    }
19392    
19393                    return count.intValue();
19394            }
19395    
19396            @Override
19397            protected Set<String> getBadColumnNames() {
19398                    return _badColumnNames;
19399            }
19400    
19401            /**
19402             * Initializes the message-boards message persistence.
19403             */
19404            public void afterPropertiesSet() {
19405            }
19406    
19407            public void destroy() {
19408                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
19409                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19410                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19411                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19412            }
19413    
19414            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19415            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
19416            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19417            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19418            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19419            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19420            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19421            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19422                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19423            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19424                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19425            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19426            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19427            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19428            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19429            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19430            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19431            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19432            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19433            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
19434                                    "uuid"
19435                            });
19436            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
19437                            @Override
19438                            public Object clone() {
19439                                    return this;
19440                            }
19441    
19442                            @Override
19443                            public CacheModel<MBMessage> toCacheModel() {
19444                                    return _nullMBMessageCacheModel;
19445                            }
19446                    };
19447    
19448            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19449                            @Override
19450                            public MBMessage toEntityModel() {
19451                                    return _nullMBMessage;
19452                            }
19453                    };
19454    }