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.EntityCache;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCache;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.SQLQuery;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.SystemException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.sanitizer.Sanitizer;
033    import com.liferay.portal.kernel.sanitizer.SanitizerException;
034    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
035    import com.liferay.portal.kernel.util.ArrayUtil;
036    import com.liferay.portal.kernel.util.ContentTypes;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.kernel.util.Validator;
044    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
045    import com.liferay.portal.model.CacheModel;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.ServiceContext;
049    import com.liferay.portal.service.ServiceContextThreadLocal;
050    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051    
052    import com.liferay.portlet.messageboards.NoSuchMessageException;
053    import com.liferay.portlet.messageboards.model.MBMessage;
054    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
055    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
056    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
057    
058    import java.io.Serializable;
059    
060    import java.util.Arrays;
061    import java.util.Collections;
062    import java.util.Date;
063    import java.util.HashMap;
064    import java.util.HashSet;
065    import java.util.Iterator;
066    import java.util.List;
067    import java.util.Map;
068    import java.util.Set;
069    
070    /**
071     * The persistence implementation for the message-boards message service.
072     *
073     * <p>
074     * Caching information and settings can be found in <code>portal.properties</code>
075     * </p>
076     *
077     * @author Brian Wing Shun Chan
078     * @see MBMessagePersistence
079     * @see com.liferay.portlet.messageboards.service.persistence.MBMessageUtil
080     * @generated
081     */
082    @ProviderType
083    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
084            implements MBMessagePersistence {
085            /*
086             * NOTE FOR DEVELOPERS:
087             *
088             * 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.
089             */
090            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
091            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
092                    ".List1";
093            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
094                    ".List2";
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
099                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
101            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
104            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
105                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
107                            new String[] {
108                                    String.class.getName(),
109                                    
110                            Integer.class.getName(), Integer.class.getName(),
111                                    OrderByComparator.class.getName()
112                            });
113            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
114                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
116                            new String[] { String.class.getName() },
117                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
118                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
119            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
120                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
122                            new String[] { String.class.getName() });
123    
124            /**
125             * Returns all the message-boards messages where uuid = &#63;.
126             *
127             * @param uuid the uuid
128             * @return the matching message-boards messages
129             */
130            @Override
131            public List<MBMessage> findByUuid(String uuid) {
132                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
133            }
134    
135            /**
136             * Returns a range of all the message-boards messages where uuid = &#63;.
137             *
138             * <p>
139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
140             * </p>
141             *
142             * @param uuid the uuid
143             * @param start the lower bound of the range of message-boards messages
144             * @param end the upper bound of the range of message-boards messages (not inclusive)
145             * @return the range of matching message-boards messages
146             */
147            @Override
148            public List<MBMessage> findByUuid(String uuid, int start, int end) {
149                    return findByUuid(uuid, start, end, null);
150            }
151    
152            /**
153             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
154             *
155             * <p>
156             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
157             * </p>
158             *
159             * @param uuid the uuid
160             * @param start the lower bound of the range of message-boards messages
161             * @param end the upper bound of the range of message-boards messages (not inclusive)
162             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
163             * @return the ordered range of matching message-boards messages
164             */
165            @Override
166            public List<MBMessage> findByUuid(String uuid, int start, int end,
167                    OrderByComparator<MBMessage> orderByComparator) {
168                    return findByUuid(uuid, start, end, orderByComparator, true);
169            }
170    
171            /**
172             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
173             *
174             * <p>
175             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
176             * </p>
177             *
178             * @param uuid the uuid
179             * @param start the lower bound of the range of message-boards messages
180             * @param end the upper bound of the range of message-boards messages (not inclusive)
181             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
182             * @param retrieveFromCache whether to retrieve from the finder cache
183             * @return the ordered range of matching message-boards messages
184             */
185            @Override
186            public List<MBMessage> findByUuid(String uuid, int start, int end,
187                    OrderByComparator<MBMessage> orderByComparator,
188                    boolean retrieveFromCache) {
189                    boolean pagination = true;
190                    FinderPath finderPath = null;
191                    Object[] finderArgs = null;
192    
193                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
194                                    (orderByComparator == null)) {
195                            pagination = false;
196                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
197                            finderArgs = new Object[] { uuid };
198                    }
199                    else {
200                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
201                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
202                    }
203    
204                    List<MBMessage> list = null;
205    
206                    if (retrieveFromCache) {
207                            list = (List<MBMessage>)finderCache.getResult(finderPath,
208                                            finderArgs, this);
209    
210                            if ((list != null) && !list.isEmpty()) {
211                                    for (MBMessage mbMessage : list) {
212                                            if (!Validator.equals(uuid, mbMessage.getUuid())) {
213                                                    list = null;
214    
215                                                    break;
216                                            }
217                                    }
218                            }
219                    }
220    
221                    if (list == null) {
222                            StringBundler query = null;
223    
224                            if (orderByComparator != null) {
225                                    query = new StringBundler(3 +
226                                                    (orderByComparator.getOrderByFields().length * 3));
227                            }
228                            else {
229                                    query = new StringBundler(3);
230                            }
231    
232                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
233    
234                            boolean bindUuid = false;
235    
236                            if (uuid == null) {
237                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
238                            }
239                            else if (uuid.equals(StringPool.BLANK)) {
240                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
241                            }
242                            else {
243                                    bindUuid = true;
244    
245                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
246                            }
247    
248                            if (orderByComparator != null) {
249                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
250                                            orderByComparator);
251                            }
252                            else
253                             if (pagination) {
254                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
255                            }
256    
257                            String sql = query.toString();
258    
259                            Session session = null;
260    
261                            try {
262                                    session = openSession();
263    
264                                    Query q = session.createQuery(sql);
265    
266                                    QueryPos qPos = QueryPos.getInstance(q);
267    
268                                    if (bindUuid) {
269                                            qPos.add(uuid);
270                                    }
271    
272                                    if (!pagination) {
273                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
274                                                            start, end, false);
275    
276                                            Collections.sort(list);
277    
278                                            list = Collections.unmodifiableList(list);
279                                    }
280                                    else {
281                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
282                                                            start, end);
283                                    }
284    
285                                    cacheResult(list);
286    
287                                    finderCache.putResult(finderPath, finderArgs, list);
288                            }
289                            catch (Exception e) {
290                                    finderCache.removeResult(finderPath, finderArgs);
291    
292                                    throw processException(e);
293                            }
294                            finally {
295                                    closeSession(session);
296                            }
297                    }
298    
299                    return list;
300            }
301    
302            /**
303             * Returns the first message-boards message in the ordered set where uuid = &#63;.
304             *
305             * @param uuid the uuid
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching message-boards message
308             * @throws NoSuchMessageException if a matching message-boards message could not be found
309             */
310            @Override
311            public MBMessage findByUuid_First(String uuid,
312                    OrderByComparator<MBMessage> orderByComparator)
313                    throws NoSuchMessageException {
314                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
315    
316                    if (mbMessage != null) {
317                            return mbMessage;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("uuid=");
325                    msg.append(uuid);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchMessageException(msg.toString());
330            }
331    
332            /**
333             * Returns the first message-boards message in the ordered set where uuid = &#63;.
334             *
335             * @param uuid the uuid
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
338             */
339            @Override
340            public MBMessage fetchByUuid_First(String uuid,
341                    OrderByComparator<MBMessage> orderByComparator) {
342                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
343    
344                    if (!list.isEmpty()) {
345                            return list.get(0);
346                    }
347    
348                    return null;
349            }
350    
351            /**
352             * Returns the last message-boards message in the ordered set where uuid = &#63;.
353             *
354             * @param uuid the uuid
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the last matching message-boards message
357             * @throws NoSuchMessageException if a matching message-boards message could not be found
358             */
359            @Override
360            public MBMessage findByUuid_Last(String uuid,
361                    OrderByComparator<MBMessage> orderByComparator)
362                    throws NoSuchMessageException {
363                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
364    
365                    if (mbMessage != null) {
366                            return mbMessage;
367                    }
368    
369                    StringBundler msg = new StringBundler(4);
370    
371                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
372    
373                    msg.append("uuid=");
374                    msg.append(uuid);
375    
376                    msg.append(StringPool.CLOSE_CURLY_BRACE);
377    
378                    throw new NoSuchMessageException(msg.toString());
379            }
380    
381            /**
382             * Returns the last message-boards message in the ordered set where uuid = &#63;.
383             *
384             * @param uuid the uuid
385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
386             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
387             */
388            @Override
389            public MBMessage fetchByUuid_Last(String uuid,
390                    OrderByComparator<MBMessage> orderByComparator) {
391                    int count = countByUuid(uuid);
392    
393                    if (count == 0) {
394                            return null;
395                    }
396    
397                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
398                                    orderByComparator);
399    
400                    if (!list.isEmpty()) {
401                            return list.get(0);
402                    }
403    
404                    return null;
405            }
406    
407            /**
408             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
409             *
410             * @param messageId the primary key of the current message-boards message
411             * @param uuid the uuid
412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
413             * @return the previous, current, and next message-boards message
414             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
415             */
416            @Override
417            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
418                    OrderByComparator<MBMessage> orderByComparator)
419                    throws NoSuchMessageException {
420                    MBMessage mbMessage = findByPrimaryKey(messageId);
421    
422                    Session session = null;
423    
424                    try {
425                            session = openSession();
426    
427                            MBMessage[] array = new MBMessageImpl[3];
428    
429                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
430                                            orderByComparator, true);
431    
432                            array[1] = mbMessage;
433    
434                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
435                                            orderByComparator, false);
436    
437                            return array;
438                    }
439                    catch (Exception e) {
440                            throw processException(e);
441                    }
442                    finally {
443                            closeSession(session);
444                    }
445            }
446    
447            protected MBMessage getByUuid_PrevAndNext(Session session,
448                    MBMessage mbMessage, String uuid,
449                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
450                    StringBundler query = null;
451    
452                    if (orderByComparator != null) {
453                            query = new StringBundler(6 +
454                                            (orderByComparator.getOrderByFields().length * 6));
455                    }
456                    else {
457                            query = new StringBundler(3);
458                    }
459    
460                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
461    
462                    boolean bindUuid = false;
463    
464                    if (uuid == null) {
465                            query.append(_FINDER_COLUMN_UUID_UUID_1);
466                    }
467                    else if (uuid.equals(StringPool.BLANK)) {
468                            query.append(_FINDER_COLUMN_UUID_UUID_3);
469                    }
470                    else {
471                            bindUuid = true;
472    
473                            query.append(_FINDER_COLUMN_UUID_UUID_2);
474                    }
475    
476                    if (orderByComparator != null) {
477                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
478    
479                            if (orderByConditionFields.length > 0) {
480                                    query.append(WHERE_AND);
481                            }
482    
483                            for (int i = 0; i < orderByConditionFields.length; i++) {
484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
485                                    query.append(orderByConditionFields[i]);
486    
487                                    if ((i + 1) < orderByConditionFields.length) {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
490                                            }
491                                            else {
492                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
493                                            }
494                                    }
495                                    else {
496                                            if (orderByComparator.isAscending() ^ previous) {
497                                                    query.append(WHERE_GREATER_THAN);
498                                            }
499                                            else {
500                                                    query.append(WHERE_LESSER_THAN);
501                                            }
502                                    }
503                            }
504    
505                            query.append(ORDER_BY_CLAUSE);
506    
507                            String[] orderByFields = orderByComparator.getOrderByFields();
508    
509                            for (int i = 0; i < orderByFields.length; i++) {
510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
511                                    query.append(orderByFields[i]);
512    
513                                    if ((i + 1) < orderByFields.length) {
514                                            if (orderByComparator.isAscending() ^ previous) {
515                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
516                                            }
517                                            else {
518                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
519                                            }
520                                    }
521                                    else {
522                                            if (orderByComparator.isAscending() ^ previous) {
523                                                    query.append(ORDER_BY_ASC);
524                                            }
525                                            else {
526                                                    query.append(ORDER_BY_DESC);
527                                            }
528                                    }
529                            }
530                    }
531                    else {
532                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
533                    }
534    
535                    String sql = query.toString();
536    
537                    Query q = session.createQuery(sql);
538    
539                    q.setFirstResult(0);
540                    q.setMaxResults(2);
541    
542                    QueryPos qPos = QueryPos.getInstance(q);
543    
544                    if (bindUuid) {
545                            qPos.add(uuid);
546                    }
547    
548                    if (orderByComparator != null) {
549                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
550    
551                            for (Object value : values) {
552                                    qPos.add(value);
553                            }
554                    }
555    
556                    List<MBMessage> list = q.list();
557    
558                    if (list.size() == 2) {
559                            return list.get(1);
560                    }
561                    else {
562                            return null;
563                    }
564            }
565    
566            /**
567             * Removes all the message-boards messages where uuid = &#63; from the database.
568             *
569             * @param uuid the uuid
570             */
571            @Override
572            public void removeByUuid(String uuid) {
573                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
574                                    QueryUtil.ALL_POS, null)) {
575                            remove(mbMessage);
576                    }
577            }
578    
579            /**
580             * Returns the number of message-boards messages where uuid = &#63;.
581             *
582             * @param uuid the uuid
583             * @return the number of matching message-boards messages
584             */
585            @Override
586            public int countByUuid(String uuid) {
587                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
588    
589                    Object[] finderArgs = new Object[] { uuid };
590    
591                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
592    
593                    if (count == null) {
594                            StringBundler query = new StringBundler(2);
595    
596                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
597    
598                            boolean bindUuid = false;
599    
600                            if (uuid == null) {
601                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
602                            }
603                            else if (uuid.equals(StringPool.BLANK)) {
604                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
605                            }
606                            else {
607                                    bindUuid = true;
608    
609                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
610                            }
611    
612                            String sql = query.toString();
613    
614                            Session session = null;
615    
616                            try {
617                                    session = openSession();
618    
619                                    Query q = session.createQuery(sql);
620    
621                                    QueryPos qPos = QueryPos.getInstance(q);
622    
623                                    if (bindUuid) {
624                                            qPos.add(uuid);
625                                    }
626    
627                                    count = (Long)q.uniqueResult();
628    
629                                    finderCache.putResult(finderPath, finderArgs, count);
630                            }
631                            catch (Exception e) {
632                                    finderCache.removeResult(finderPath, finderArgs);
633    
634                                    throw processException(e);
635                            }
636                            finally {
637                                    closeSession(session);
638                            }
639                    }
640    
641                    return count.intValue();
642            }
643    
644            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
645            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
646            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
647            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
648                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
649                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
650                            new String[] { String.class.getName(), Long.class.getName() },
651                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
652                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
653            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
656                            new String[] { String.class.getName(), Long.class.getName() });
657    
658            /**
659             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
660             *
661             * @param uuid the uuid
662             * @param groupId the group ID
663             * @return the matching message-boards message
664             * @throws NoSuchMessageException if a matching message-boards message could not be found
665             */
666            @Override
667            public MBMessage findByUUID_G(String uuid, long groupId)
668                    throws NoSuchMessageException {
669                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
670    
671                    if (mbMessage == null) {
672                            StringBundler msg = new StringBundler(6);
673    
674                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
675    
676                            msg.append("uuid=");
677                            msg.append(uuid);
678    
679                            msg.append(", groupId=");
680                            msg.append(groupId);
681    
682                            msg.append(StringPool.CLOSE_CURLY_BRACE);
683    
684                            if (_log.isWarnEnabled()) {
685                                    _log.warn(msg.toString());
686                            }
687    
688                            throw new NoSuchMessageException(msg.toString());
689                    }
690    
691                    return mbMessage;
692            }
693    
694            /**
695             * 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.
696             *
697             * @param uuid the uuid
698             * @param groupId the group ID
699             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
700             */
701            @Override
702            public MBMessage fetchByUUID_G(String uuid, long groupId) {
703                    return fetchByUUID_G(uuid, groupId, true);
704            }
705    
706            /**
707             * 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.
708             *
709             * @param uuid the uuid
710             * @param groupId the group ID
711             * @param retrieveFromCache whether to retrieve from the finder cache
712             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
713             */
714            @Override
715            public MBMessage fetchByUUID_G(String uuid, long groupId,
716                    boolean retrieveFromCache) {
717                    Object[] finderArgs = new Object[] { uuid, groupId };
718    
719                    Object result = null;
720    
721                    if (retrieveFromCache) {
722                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
723                                            finderArgs, this);
724                    }
725    
726                    if (result instanceof MBMessage) {
727                            MBMessage mbMessage = (MBMessage)result;
728    
729                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
730                                            (groupId != mbMessage.getGroupId())) {
731                                    result = null;
732                            }
733                    }
734    
735                    if (result == null) {
736                            StringBundler query = new StringBundler(4);
737    
738                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
739    
740                            boolean bindUuid = false;
741    
742                            if (uuid == null) {
743                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
744                            }
745                            else if (uuid.equals(StringPool.BLANK)) {
746                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
747                            }
748                            else {
749                                    bindUuid = true;
750    
751                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
752                            }
753    
754                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    if (bindUuid) {
768                                            qPos.add(uuid);
769                                    }
770    
771                                    qPos.add(groupId);
772    
773                                    List<MBMessage> list = q.list();
774    
775                                    if (list.isEmpty()) {
776                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
777                                                    finderArgs, list);
778                                    }
779                                    else {
780                                            MBMessage mbMessage = list.get(0);
781    
782                                            result = mbMessage;
783    
784                                            cacheResult(mbMessage);
785    
786                                            if ((mbMessage.getUuid() == null) ||
787                                                            !mbMessage.getUuid().equals(uuid) ||
788                                                            (mbMessage.getGroupId() != groupId)) {
789                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
790                                                            finderArgs, mbMessage);
791                                            }
792                                    }
793                            }
794                            catch (Exception e) {
795                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
796    
797                                    throw processException(e);
798                            }
799                            finally {
800                                    closeSession(session);
801                            }
802                    }
803    
804                    if (result instanceof List<?>) {
805                            return null;
806                    }
807                    else {
808                            return (MBMessage)result;
809                    }
810            }
811    
812            /**
813             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
814             *
815             * @param uuid the uuid
816             * @param groupId the group ID
817             * @return the message-boards message that was removed
818             */
819            @Override
820            public MBMessage removeByUUID_G(String uuid, long groupId)
821                    throws NoSuchMessageException {
822                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
823    
824                    return remove(mbMessage);
825            }
826    
827            /**
828             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
829             *
830             * @param uuid the uuid
831             * @param groupId the group ID
832             * @return the number of matching message-boards messages
833             */
834            @Override
835            public int countByUUID_G(String uuid, long groupId) {
836                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
837    
838                    Object[] finderArgs = new Object[] { uuid, groupId };
839    
840                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
841    
842                    if (count == null) {
843                            StringBundler query = new StringBundler(3);
844    
845                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
846    
847                            boolean bindUuid = false;
848    
849                            if (uuid == null) {
850                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
851                            }
852                            else if (uuid.equals(StringPool.BLANK)) {
853                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
854                            }
855                            else {
856                                    bindUuid = true;
857    
858                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
859                            }
860    
861                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
862    
863                            String sql = query.toString();
864    
865                            Session session = null;
866    
867                            try {
868                                    session = openSession();
869    
870                                    Query q = session.createQuery(sql);
871    
872                                    QueryPos qPos = QueryPos.getInstance(q);
873    
874                                    if (bindUuid) {
875                                            qPos.add(uuid);
876                                    }
877    
878                                    qPos.add(groupId);
879    
880                                    count = (Long)q.uniqueResult();
881    
882                                    finderCache.putResult(finderPath, finderArgs, count);
883                            }
884                            catch (Exception e) {
885                                    finderCache.removeResult(finderPath, finderArgs);
886    
887                                    throw processException(e);
888                            }
889                            finally {
890                                    closeSession(session);
891                            }
892                    }
893    
894                    return count.intValue();
895            }
896    
897            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
898            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
899            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
900            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
901            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
902                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
903                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
904                            new String[] {
905                                    String.class.getName(), Long.class.getName(),
906                                    
907                            Integer.class.getName(), Integer.class.getName(),
908                                    OrderByComparator.class.getName()
909                            });
910            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
911                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
912                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
913                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
914                            new String[] { String.class.getName(), Long.class.getName() },
915                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
916                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
917                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
918            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
919                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
920                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
921                            new String[] { String.class.getName(), Long.class.getName() });
922    
923            /**
924             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
925             *
926             * @param uuid the uuid
927             * @param companyId the company ID
928             * @return the matching message-boards messages
929             */
930            @Override
931            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
932                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
933                            QueryUtil.ALL_POS, null);
934            }
935    
936            /**
937             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
938             *
939             * <p>
940             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
941             * </p>
942             *
943             * @param uuid the uuid
944             * @param companyId the company ID
945             * @param start the lower bound of the range of message-boards messages
946             * @param end the upper bound of the range of message-boards messages (not inclusive)
947             * @return the range of matching message-boards messages
948             */
949            @Override
950            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
951                    int end) {
952                    return findByUuid_C(uuid, companyId, start, end, null);
953            }
954    
955            /**
956             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
957             *
958             * <p>
959             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
960             * </p>
961             *
962             * @param uuid the uuid
963             * @param companyId the company ID
964             * @param start the lower bound of the range of message-boards messages
965             * @param end the upper bound of the range of message-boards messages (not inclusive)
966             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
967             * @return the ordered range of matching message-boards messages
968             */
969            @Override
970            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
971                    int end, OrderByComparator<MBMessage> orderByComparator) {
972                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
973            }
974    
975            /**
976             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
977             *
978             * <p>
979             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
980             * </p>
981             *
982             * @param uuid the uuid
983             * @param companyId the company ID
984             * @param start the lower bound of the range of message-boards messages
985             * @param end the upper bound of the range of message-boards messages (not inclusive)
986             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
987             * @param retrieveFromCache whether to retrieve from the finder cache
988             * @return the ordered range of matching message-boards messages
989             */
990            @Override
991            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
992                    int end, OrderByComparator<MBMessage> orderByComparator,
993                    boolean retrieveFromCache) {
994                    boolean pagination = true;
995                    FinderPath finderPath = null;
996                    Object[] finderArgs = null;
997    
998                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
999                                    (orderByComparator == null)) {
1000                            pagination = false;
1001                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1002                            finderArgs = new Object[] { uuid, companyId };
1003                    }
1004                    else {
1005                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1006                            finderArgs = new Object[] {
1007                                            uuid, companyId,
1008                                            
1009                                            start, end, orderByComparator
1010                                    };
1011                    }
1012    
1013                    List<MBMessage> list = null;
1014    
1015                    if (retrieveFromCache) {
1016                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1017                                            finderArgs, this);
1018    
1019                            if ((list != null) && !list.isEmpty()) {
1020                                    for (MBMessage mbMessage : list) {
1021                                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
1022                                                            (companyId != mbMessage.getCompanyId())) {
1023                                                    list = null;
1024    
1025                                                    break;
1026                                            }
1027                                    }
1028                            }
1029                    }
1030    
1031                    if (list == null) {
1032                            StringBundler query = null;
1033    
1034                            if (orderByComparator != null) {
1035                                    query = new StringBundler(4 +
1036                                                    (orderByComparator.getOrderByFields().length * 3));
1037                            }
1038                            else {
1039                                    query = new StringBundler(4);
1040                            }
1041    
1042                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1043    
1044                            boolean bindUuid = false;
1045    
1046                            if (uuid == null) {
1047                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1048                            }
1049                            else if (uuid.equals(StringPool.BLANK)) {
1050                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1051                            }
1052                            else {
1053                                    bindUuid = true;
1054    
1055                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1056                            }
1057    
1058                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1059    
1060                            if (orderByComparator != null) {
1061                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1062                                            orderByComparator);
1063                            }
1064                            else
1065                             if (pagination) {
1066                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1067                            }
1068    
1069                            String sql = query.toString();
1070    
1071                            Session session = null;
1072    
1073                            try {
1074                                    session = openSession();
1075    
1076                                    Query q = session.createQuery(sql);
1077    
1078                                    QueryPos qPos = QueryPos.getInstance(q);
1079    
1080                                    if (bindUuid) {
1081                                            qPos.add(uuid);
1082                                    }
1083    
1084                                    qPos.add(companyId);
1085    
1086                                    if (!pagination) {
1087                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1088                                                            start, end, false);
1089    
1090                                            Collections.sort(list);
1091    
1092                                            list = Collections.unmodifiableList(list);
1093                                    }
1094                                    else {
1095                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1096                                                            start, end);
1097                                    }
1098    
1099                                    cacheResult(list);
1100    
1101                                    finderCache.putResult(finderPath, finderArgs, list);
1102                            }
1103                            catch (Exception e) {
1104                                    finderCache.removeResult(finderPath, finderArgs);
1105    
1106                                    throw processException(e);
1107                            }
1108                            finally {
1109                                    closeSession(session);
1110                            }
1111                    }
1112    
1113                    return list;
1114            }
1115    
1116            /**
1117             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1118             *
1119             * @param uuid the uuid
1120             * @param companyId the company ID
1121             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1122             * @return the first matching message-boards message
1123             * @throws NoSuchMessageException if a matching message-boards message could not be found
1124             */
1125            @Override
1126            public MBMessage findByUuid_C_First(String uuid, long companyId,
1127                    OrderByComparator<MBMessage> orderByComparator)
1128                    throws NoSuchMessageException {
1129                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1130                                    orderByComparator);
1131    
1132                    if (mbMessage != null) {
1133                            return mbMessage;
1134                    }
1135    
1136                    StringBundler msg = new StringBundler(6);
1137    
1138                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139    
1140                    msg.append("uuid=");
1141                    msg.append(uuid);
1142    
1143                    msg.append(", companyId=");
1144                    msg.append(companyId);
1145    
1146                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1147    
1148                    throw new NoSuchMessageException(msg.toString());
1149            }
1150    
1151            /**
1152             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1153             *
1154             * @param uuid the uuid
1155             * @param companyId the company ID
1156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1157             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1158             */
1159            @Override
1160            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1161                    OrderByComparator<MBMessage> orderByComparator) {
1162                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1163                                    orderByComparator);
1164    
1165                    if (!list.isEmpty()) {
1166                            return list.get(0);
1167                    }
1168    
1169                    return null;
1170            }
1171    
1172            /**
1173             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1174             *
1175             * @param uuid the uuid
1176             * @param companyId the company ID
1177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1178             * @return the last matching message-boards message
1179             * @throws NoSuchMessageException if a matching message-boards message could not be found
1180             */
1181            @Override
1182            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1183                    OrderByComparator<MBMessage> orderByComparator)
1184                    throws NoSuchMessageException {
1185                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1186                                    orderByComparator);
1187    
1188                    if (mbMessage != null) {
1189                            return mbMessage;
1190                    }
1191    
1192                    StringBundler msg = new StringBundler(6);
1193    
1194                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1195    
1196                    msg.append("uuid=");
1197                    msg.append(uuid);
1198    
1199                    msg.append(", companyId=");
1200                    msg.append(companyId);
1201    
1202                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1203    
1204                    throw new NoSuchMessageException(msg.toString());
1205            }
1206    
1207            /**
1208             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1209             *
1210             * @param uuid the uuid
1211             * @param companyId the company ID
1212             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1213             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1214             */
1215            @Override
1216            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1217                    OrderByComparator<MBMessage> orderByComparator) {
1218                    int count = countByUuid_C(uuid, companyId);
1219    
1220                    if (count == 0) {
1221                            return null;
1222                    }
1223    
1224                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1225                                    orderByComparator);
1226    
1227                    if (!list.isEmpty()) {
1228                            return list.get(0);
1229                    }
1230    
1231                    return null;
1232            }
1233    
1234            /**
1235             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1236             *
1237             * @param messageId the primary key of the current message-boards message
1238             * @param uuid the uuid
1239             * @param companyId the company ID
1240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1241             * @return the previous, current, and next message-boards message
1242             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1243             */
1244            @Override
1245            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1246                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1247                    throws NoSuchMessageException {
1248                    MBMessage mbMessage = findByPrimaryKey(messageId);
1249    
1250                    Session session = null;
1251    
1252                    try {
1253                            session = openSession();
1254    
1255                            MBMessage[] array = new MBMessageImpl[3];
1256    
1257                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1258                                            companyId, orderByComparator, true);
1259    
1260                            array[1] = mbMessage;
1261    
1262                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1263                                            companyId, orderByComparator, false);
1264    
1265                            return array;
1266                    }
1267                    catch (Exception e) {
1268                            throw processException(e);
1269                    }
1270                    finally {
1271                            closeSession(session);
1272                    }
1273            }
1274    
1275            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1276                    MBMessage mbMessage, String uuid, long companyId,
1277                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1278                    StringBundler query = null;
1279    
1280                    if (orderByComparator != null) {
1281                            query = new StringBundler(6 +
1282                                            (orderByComparator.getOrderByFields().length * 6));
1283                    }
1284                    else {
1285                            query = new StringBundler(3);
1286                    }
1287    
1288                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1289    
1290                    boolean bindUuid = false;
1291    
1292                    if (uuid == null) {
1293                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1294                    }
1295                    else if (uuid.equals(StringPool.BLANK)) {
1296                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1297                    }
1298                    else {
1299                            bindUuid = true;
1300    
1301                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1302                    }
1303    
1304                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1305    
1306                    if (orderByComparator != null) {
1307                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1308    
1309                            if (orderByConditionFields.length > 0) {
1310                                    query.append(WHERE_AND);
1311                            }
1312    
1313                            for (int i = 0; i < orderByConditionFields.length; i++) {
1314                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1315                                    query.append(orderByConditionFields[i]);
1316    
1317                                    if ((i + 1) < orderByConditionFields.length) {
1318                                            if (orderByComparator.isAscending() ^ previous) {
1319                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1320                                            }
1321                                            else {
1322                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1323                                            }
1324                                    }
1325                                    else {
1326                                            if (orderByComparator.isAscending() ^ previous) {
1327                                                    query.append(WHERE_GREATER_THAN);
1328                                            }
1329                                            else {
1330                                                    query.append(WHERE_LESSER_THAN);
1331                                            }
1332                                    }
1333                            }
1334    
1335                            query.append(ORDER_BY_CLAUSE);
1336    
1337                            String[] orderByFields = orderByComparator.getOrderByFields();
1338    
1339                            for (int i = 0; i < orderByFields.length; i++) {
1340                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1341                                    query.append(orderByFields[i]);
1342    
1343                                    if ((i + 1) < orderByFields.length) {
1344                                            if (orderByComparator.isAscending() ^ previous) {
1345                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1346                                            }
1347                                            else {
1348                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1349                                            }
1350                                    }
1351                                    else {
1352                                            if (orderByComparator.isAscending() ^ previous) {
1353                                                    query.append(ORDER_BY_ASC);
1354                                            }
1355                                            else {
1356                                                    query.append(ORDER_BY_DESC);
1357                                            }
1358                                    }
1359                            }
1360                    }
1361                    else {
1362                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1363                    }
1364    
1365                    String sql = query.toString();
1366    
1367                    Query q = session.createQuery(sql);
1368    
1369                    q.setFirstResult(0);
1370                    q.setMaxResults(2);
1371    
1372                    QueryPos qPos = QueryPos.getInstance(q);
1373    
1374                    if (bindUuid) {
1375                            qPos.add(uuid);
1376                    }
1377    
1378                    qPos.add(companyId);
1379    
1380                    if (orderByComparator != null) {
1381                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1382    
1383                            for (Object value : values) {
1384                                    qPos.add(value);
1385                            }
1386                    }
1387    
1388                    List<MBMessage> list = q.list();
1389    
1390                    if (list.size() == 2) {
1391                            return list.get(1);
1392                    }
1393                    else {
1394                            return null;
1395                    }
1396            }
1397    
1398            /**
1399             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1400             *
1401             * @param uuid the uuid
1402             * @param companyId the company ID
1403             */
1404            @Override
1405            public void removeByUuid_C(String uuid, long companyId) {
1406                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1407                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1408                            remove(mbMessage);
1409                    }
1410            }
1411    
1412            /**
1413             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1414             *
1415             * @param uuid the uuid
1416             * @param companyId the company ID
1417             * @return the number of matching message-boards messages
1418             */
1419            @Override
1420            public int countByUuid_C(String uuid, long companyId) {
1421                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1422    
1423                    Object[] finderArgs = new Object[] { uuid, companyId };
1424    
1425                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1426    
1427                    if (count == null) {
1428                            StringBundler query = new StringBundler(3);
1429    
1430                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1431    
1432                            boolean bindUuid = false;
1433    
1434                            if (uuid == null) {
1435                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1436                            }
1437                            else if (uuid.equals(StringPool.BLANK)) {
1438                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1439                            }
1440                            else {
1441                                    bindUuid = true;
1442    
1443                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1444                            }
1445    
1446                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1447    
1448                            String sql = query.toString();
1449    
1450                            Session session = null;
1451    
1452                            try {
1453                                    session = openSession();
1454    
1455                                    Query q = session.createQuery(sql);
1456    
1457                                    QueryPos qPos = QueryPos.getInstance(q);
1458    
1459                                    if (bindUuid) {
1460                                            qPos.add(uuid);
1461                                    }
1462    
1463                                    qPos.add(companyId);
1464    
1465                                    count = (Long)q.uniqueResult();
1466    
1467                                    finderCache.putResult(finderPath, finderArgs, count);
1468                            }
1469                            catch (Exception e) {
1470                                    finderCache.removeResult(finderPath, finderArgs);
1471    
1472                                    throw processException(e);
1473                            }
1474                            finally {
1475                                    closeSession(session);
1476                            }
1477                    }
1478    
1479                    return count.intValue();
1480            }
1481    
1482            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1483            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1484            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1485            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1486            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1487                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1488                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1489                            new String[] {
1490                                    Long.class.getName(),
1491                                    
1492                            Integer.class.getName(), Integer.class.getName(),
1493                                    OrderByComparator.class.getName()
1494                            });
1495            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1496                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1497                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1498                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1499                            new String[] { Long.class.getName() },
1500                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1501                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1502            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1503                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1504                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1505                            new String[] { Long.class.getName() });
1506    
1507            /**
1508             * Returns all the message-boards messages where groupId = &#63;.
1509             *
1510             * @param groupId the group ID
1511             * @return the matching message-boards messages
1512             */
1513            @Override
1514            public List<MBMessage> findByGroupId(long groupId) {
1515                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1516            }
1517    
1518            /**
1519             * Returns a range of all the message-boards messages where groupId = &#63;.
1520             *
1521             * <p>
1522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1523             * </p>
1524             *
1525             * @param groupId the group ID
1526             * @param start the lower bound of the range of message-boards messages
1527             * @param end the upper bound of the range of message-boards messages (not inclusive)
1528             * @return the range of matching message-boards messages
1529             */
1530            @Override
1531            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1532                    return findByGroupId(groupId, start, end, null);
1533            }
1534    
1535            /**
1536             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1537             *
1538             * <p>
1539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1540             * </p>
1541             *
1542             * @param groupId the group ID
1543             * @param start the lower bound of the range of message-boards messages
1544             * @param end the upper bound of the range of message-boards messages (not inclusive)
1545             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1546             * @return the ordered range of matching message-boards messages
1547             */
1548            @Override
1549            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1550                    OrderByComparator<MBMessage> orderByComparator) {
1551                    return findByGroupId(groupId, start, end, orderByComparator, true);
1552            }
1553    
1554            /**
1555             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1556             *
1557             * <p>
1558             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1559             * </p>
1560             *
1561             * @param groupId the group ID
1562             * @param start the lower bound of the range of message-boards messages
1563             * @param end the upper bound of the range of message-boards messages (not inclusive)
1564             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1565             * @param retrieveFromCache whether to retrieve from the finder cache
1566             * @return the ordered range of matching message-boards messages
1567             */
1568            @Override
1569            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1570                    OrderByComparator<MBMessage> orderByComparator,
1571                    boolean retrieveFromCache) {
1572                    boolean pagination = true;
1573                    FinderPath finderPath = null;
1574                    Object[] finderArgs = null;
1575    
1576                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1577                                    (orderByComparator == null)) {
1578                            pagination = false;
1579                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1580                            finderArgs = new Object[] { groupId };
1581                    }
1582                    else {
1583                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1584                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1585                    }
1586    
1587                    List<MBMessage> list = null;
1588    
1589                    if (retrieveFromCache) {
1590                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1591                                            finderArgs, this);
1592    
1593                            if ((list != null) && !list.isEmpty()) {
1594                                    for (MBMessage mbMessage : list) {
1595                                            if ((groupId != mbMessage.getGroupId())) {
1596                                                    list = null;
1597    
1598                                                    break;
1599                                            }
1600                                    }
1601                            }
1602                    }
1603    
1604                    if (list == null) {
1605                            StringBundler query = null;
1606    
1607                            if (orderByComparator != null) {
1608                                    query = new StringBundler(3 +
1609                                                    (orderByComparator.getOrderByFields().length * 3));
1610                            }
1611                            else {
1612                                    query = new StringBundler(3);
1613                            }
1614    
1615                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1616    
1617                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1618    
1619                            if (orderByComparator != null) {
1620                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1621                                            orderByComparator);
1622                            }
1623                            else
1624                             if (pagination) {
1625                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1626                            }
1627    
1628                            String sql = query.toString();
1629    
1630                            Session session = null;
1631    
1632                            try {
1633                                    session = openSession();
1634    
1635                                    Query q = session.createQuery(sql);
1636    
1637                                    QueryPos qPos = QueryPos.getInstance(q);
1638    
1639                                    qPos.add(groupId);
1640    
1641                                    if (!pagination) {
1642                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1643                                                            start, end, false);
1644    
1645                                            Collections.sort(list);
1646    
1647                                            list = Collections.unmodifiableList(list);
1648                                    }
1649                                    else {
1650                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1651                                                            start, end);
1652                                    }
1653    
1654                                    cacheResult(list);
1655    
1656                                    finderCache.putResult(finderPath, finderArgs, list);
1657                            }
1658                            catch (Exception e) {
1659                                    finderCache.removeResult(finderPath, finderArgs);
1660    
1661                                    throw processException(e);
1662                            }
1663                            finally {
1664                                    closeSession(session);
1665                            }
1666                    }
1667    
1668                    return list;
1669            }
1670    
1671            /**
1672             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1673             *
1674             * @param groupId the group ID
1675             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1676             * @return the first matching message-boards message
1677             * @throws NoSuchMessageException if a matching message-boards message could not be found
1678             */
1679            @Override
1680            public MBMessage findByGroupId_First(long groupId,
1681                    OrderByComparator<MBMessage> orderByComparator)
1682                    throws NoSuchMessageException {
1683                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1684    
1685                    if (mbMessage != null) {
1686                            return mbMessage;
1687                    }
1688    
1689                    StringBundler msg = new StringBundler(4);
1690    
1691                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692    
1693                    msg.append("groupId=");
1694                    msg.append(groupId);
1695    
1696                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1697    
1698                    throw new NoSuchMessageException(msg.toString());
1699            }
1700    
1701            /**
1702             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1703             *
1704             * @param groupId the group ID
1705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1706             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1707             */
1708            @Override
1709            public MBMessage fetchByGroupId_First(long groupId,
1710                    OrderByComparator<MBMessage> orderByComparator) {
1711                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1712    
1713                    if (!list.isEmpty()) {
1714                            return list.get(0);
1715                    }
1716    
1717                    return null;
1718            }
1719    
1720            /**
1721             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1722             *
1723             * @param groupId the group ID
1724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1725             * @return the last matching message-boards message
1726             * @throws NoSuchMessageException if a matching message-boards message could not be found
1727             */
1728            @Override
1729            public MBMessage findByGroupId_Last(long groupId,
1730                    OrderByComparator<MBMessage> orderByComparator)
1731                    throws NoSuchMessageException {
1732                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1733    
1734                    if (mbMessage != null) {
1735                            return mbMessage;
1736                    }
1737    
1738                    StringBundler msg = new StringBundler(4);
1739    
1740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1741    
1742                    msg.append("groupId=");
1743                    msg.append(groupId);
1744    
1745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1746    
1747                    throw new NoSuchMessageException(msg.toString());
1748            }
1749    
1750            /**
1751             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1752             *
1753             * @param groupId the group ID
1754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1755             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1756             */
1757            @Override
1758            public MBMessage fetchByGroupId_Last(long groupId,
1759                    OrderByComparator<MBMessage> orderByComparator) {
1760                    int count = countByGroupId(groupId);
1761    
1762                    if (count == 0) {
1763                            return null;
1764                    }
1765    
1766                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1767                                    orderByComparator);
1768    
1769                    if (!list.isEmpty()) {
1770                            return list.get(0);
1771                    }
1772    
1773                    return null;
1774            }
1775    
1776            /**
1777             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1778             *
1779             * @param messageId the primary key of the current message-boards message
1780             * @param groupId the group ID
1781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1782             * @return the previous, current, and next message-boards message
1783             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1784             */
1785            @Override
1786            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1787                    OrderByComparator<MBMessage> orderByComparator)
1788                    throws NoSuchMessageException {
1789                    MBMessage mbMessage = findByPrimaryKey(messageId);
1790    
1791                    Session session = null;
1792    
1793                    try {
1794                            session = openSession();
1795    
1796                            MBMessage[] array = new MBMessageImpl[3];
1797    
1798                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1799                                            orderByComparator, true);
1800    
1801                            array[1] = mbMessage;
1802    
1803                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1804                                            orderByComparator, false);
1805    
1806                            return array;
1807                    }
1808                    catch (Exception e) {
1809                            throw processException(e);
1810                    }
1811                    finally {
1812                            closeSession(session);
1813                    }
1814            }
1815    
1816            protected MBMessage getByGroupId_PrevAndNext(Session session,
1817                    MBMessage mbMessage, long groupId,
1818                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1819                    StringBundler query = null;
1820    
1821                    if (orderByComparator != null) {
1822                            query = new StringBundler(6 +
1823                                            (orderByComparator.getOrderByFields().length * 6));
1824                    }
1825                    else {
1826                            query = new StringBundler(3);
1827                    }
1828    
1829                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1830    
1831                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1832    
1833                    if (orderByComparator != null) {
1834                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1835    
1836                            if (orderByConditionFields.length > 0) {
1837                                    query.append(WHERE_AND);
1838                            }
1839    
1840                            for (int i = 0; i < orderByConditionFields.length; i++) {
1841                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1842                                    query.append(orderByConditionFields[i]);
1843    
1844                                    if ((i + 1) < orderByConditionFields.length) {
1845                                            if (orderByComparator.isAscending() ^ previous) {
1846                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1847                                            }
1848                                            else {
1849                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1850                                            }
1851                                    }
1852                                    else {
1853                                            if (orderByComparator.isAscending() ^ previous) {
1854                                                    query.append(WHERE_GREATER_THAN);
1855                                            }
1856                                            else {
1857                                                    query.append(WHERE_LESSER_THAN);
1858                                            }
1859                                    }
1860                            }
1861    
1862                            query.append(ORDER_BY_CLAUSE);
1863    
1864                            String[] orderByFields = orderByComparator.getOrderByFields();
1865    
1866                            for (int i = 0; i < orderByFields.length; i++) {
1867                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1868                                    query.append(orderByFields[i]);
1869    
1870                                    if ((i + 1) < orderByFields.length) {
1871                                            if (orderByComparator.isAscending() ^ previous) {
1872                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1873                                            }
1874                                            else {
1875                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1876                                            }
1877                                    }
1878                                    else {
1879                                            if (orderByComparator.isAscending() ^ previous) {
1880                                                    query.append(ORDER_BY_ASC);
1881                                            }
1882                                            else {
1883                                                    query.append(ORDER_BY_DESC);
1884                                            }
1885                                    }
1886                            }
1887                    }
1888                    else {
1889                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1890                    }
1891    
1892                    String sql = query.toString();
1893    
1894                    Query q = session.createQuery(sql);
1895    
1896                    q.setFirstResult(0);
1897                    q.setMaxResults(2);
1898    
1899                    QueryPos qPos = QueryPos.getInstance(q);
1900    
1901                    qPos.add(groupId);
1902    
1903                    if (orderByComparator != null) {
1904                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1905    
1906                            for (Object value : values) {
1907                                    qPos.add(value);
1908                            }
1909                    }
1910    
1911                    List<MBMessage> list = q.list();
1912    
1913                    if (list.size() == 2) {
1914                            return list.get(1);
1915                    }
1916                    else {
1917                            return null;
1918                    }
1919            }
1920    
1921            /**
1922             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1923             *
1924             * @param groupId the group ID
1925             * @return the matching message-boards messages that the user has permission to view
1926             */
1927            @Override
1928            public List<MBMessage> filterFindByGroupId(long groupId) {
1929                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1930                            QueryUtil.ALL_POS, null);
1931            }
1932    
1933            /**
1934             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1935             *
1936             * <p>
1937             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1938             * </p>
1939             *
1940             * @param groupId the group ID
1941             * @param start the lower bound of the range of message-boards messages
1942             * @param end the upper bound of the range of message-boards messages (not inclusive)
1943             * @return the range of matching message-boards messages that the user has permission to view
1944             */
1945            @Override
1946            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1947                    return filterFindByGroupId(groupId, start, end, null);
1948            }
1949    
1950            /**
1951             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1952             *
1953             * <p>
1954             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1955             * </p>
1956             *
1957             * @param groupId the group ID
1958             * @param start the lower bound of the range of message-boards messages
1959             * @param end the upper bound of the range of message-boards messages (not inclusive)
1960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1961             * @return the ordered range of matching message-boards messages that the user has permission to view
1962             */
1963            @Override
1964            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1965                    int end, OrderByComparator<MBMessage> orderByComparator) {
1966                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1967                            return findByGroupId(groupId, start, end, orderByComparator);
1968                    }
1969    
1970                    StringBundler query = null;
1971    
1972                    if (orderByComparator != null) {
1973                            query = new StringBundler(3 +
1974                                            (orderByComparator.getOrderByFields().length * 3));
1975                    }
1976                    else {
1977                            query = new StringBundler(3);
1978                    }
1979    
1980                    if (getDB().isSupportsInlineDistinct()) {
1981                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1982                    }
1983                    else {
1984                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1985                    }
1986    
1987                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1988    
1989                    if (!getDB().isSupportsInlineDistinct()) {
1990                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1991                    }
1992    
1993                    if (orderByComparator != null) {
1994                            if (getDB().isSupportsInlineDistinct()) {
1995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1996                                            orderByComparator, true);
1997                            }
1998                            else {
1999                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2000                                            orderByComparator, true);
2001                            }
2002                    }
2003                    else {
2004                            if (getDB().isSupportsInlineDistinct()) {
2005                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2006                            }
2007                            else {
2008                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2009                            }
2010                    }
2011    
2012                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2013                                    MBMessage.class.getName(),
2014                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2015    
2016                    Session session = null;
2017    
2018                    try {
2019                            session = openSession();
2020    
2021                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2022    
2023                            if (getDB().isSupportsInlineDistinct()) {
2024                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2025                            }
2026                            else {
2027                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2028                            }
2029    
2030                            QueryPos qPos = QueryPos.getInstance(q);
2031    
2032                            qPos.add(groupId);
2033    
2034                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2035                    }
2036                    catch (Exception e) {
2037                            throw processException(e);
2038                    }
2039                    finally {
2040                            closeSession(session);
2041                    }
2042            }
2043    
2044            /**
2045             * 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;.
2046             *
2047             * @param messageId the primary key of the current message-boards message
2048             * @param groupId the group ID
2049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2050             * @return the previous, current, and next message-boards message
2051             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2052             */
2053            @Override
2054            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2055                    long groupId, OrderByComparator<MBMessage> orderByComparator)
2056                    throws NoSuchMessageException {
2057                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2058                            return findByGroupId_PrevAndNext(messageId, groupId,
2059                                    orderByComparator);
2060                    }
2061    
2062                    MBMessage mbMessage = findByPrimaryKey(messageId);
2063    
2064                    Session session = null;
2065    
2066                    try {
2067                            session = openSession();
2068    
2069                            MBMessage[] array = new MBMessageImpl[3];
2070    
2071                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2072                                            groupId, orderByComparator, true);
2073    
2074                            array[1] = mbMessage;
2075    
2076                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2077                                            groupId, orderByComparator, false);
2078    
2079                            return array;
2080                    }
2081                    catch (Exception e) {
2082                            throw processException(e);
2083                    }
2084                    finally {
2085                            closeSession(session);
2086                    }
2087            }
2088    
2089            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2090                    MBMessage mbMessage, long groupId,
2091                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2092                    StringBundler query = null;
2093    
2094                    if (orderByComparator != null) {
2095                            query = new StringBundler(6 +
2096                                            (orderByComparator.getOrderByFields().length * 6));
2097                    }
2098                    else {
2099                            query = new StringBundler(3);
2100                    }
2101    
2102                    if (getDB().isSupportsInlineDistinct()) {
2103                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2104                    }
2105                    else {
2106                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2107                    }
2108    
2109                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2110    
2111                    if (!getDB().isSupportsInlineDistinct()) {
2112                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2113                    }
2114    
2115                    if (orderByComparator != null) {
2116                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2117    
2118                            if (orderByConditionFields.length > 0) {
2119                                    query.append(WHERE_AND);
2120                            }
2121    
2122                            for (int i = 0; i < orderByConditionFields.length; i++) {
2123                                    if (getDB().isSupportsInlineDistinct()) {
2124                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2125                                    }
2126                                    else {
2127                                            query.append(_ORDER_BY_ENTITY_TABLE);
2128                                    }
2129    
2130                                    query.append(orderByConditionFields[i]);
2131    
2132                                    if ((i + 1) < orderByConditionFields.length) {
2133                                            if (orderByComparator.isAscending() ^ previous) {
2134                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2135                                            }
2136                                            else {
2137                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2138                                            }
2139                                    }
2140                                    else {
2141                                            if (orderByComparator.isAscending() ^ previous) {
2142                                                    query.append(WHERE_GREATER_THAN);
2143                                            }
2144                                            else {
2145                                                    query.append(WHERE_LESSER_THAN);
2146                                            }
2147                                    }
2148                            }
2149    
2150                            query.append(ORDER_BY_CLAUSE);
2151    
2152                            String[] orderByFields = orderByComparator.getOrderByFields();
2153    
2154                            for (int i = 0; i < orderByFields.length; i++) {
2155                                    if (getDB().isSupportsInlineDistinct()) {
2156                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2157                                    }
2158                                    else {
2159                                            query.append(_ORDER_BY_ENTITY_TABLE);
2160                                    }
2161    
2162                                    query.append(orderByFields[i]);
2163    
2164                                    if ((i + 1) < orderByFields.length) {
2165                                            if (orderByComparator.isAscending() ^ previous) {
2166                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2167                                            }
2168                                            else {
2169                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2170                                            }
2171                                    }
2172                                    else {
2173                                            if (orderByComparator.isAscending() ^ previous) {
2174                                                    query.append(ORDER_BY_ASC);
2175                                            }
2176                                            else {
2177                                                    query.append(ORDER_BY_DESC);
2178                                            }
2179                                    }
2180                            }
2181                    }
2182                    else {
2183                            if (getDB().isSupportsInlineDistinct()) {
2184                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2185                            }
2186                            else {
2187                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2188                            }
2189                    }
2190    
2191                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2192                                    MBMessage.class.getName(),
2193                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2194    
2195                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2196    
2197                    q.setFirstResult(0);
2198                    q.setMaxResults(2);
2199    
2200                    if (getDB().isSupportsInlineDistinct()) {
2201                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2202                    }
2203                    else {
2204                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2205                    }
2206    
2207                    QueryPos qPos = QueryPos.getInstance(q);
2208    
2209                    qPos.add(groupId);
2210    
2211                    if (orderByComparator != null) {
2212                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2213    
2214                            for (Object value : values) {
2215                                    qPos.add(value);
2216                            }
2217                    }
2218    
2219                    List<MBMessage> list = q.list();
2220    
2221                    if (list.size() == 2) {
2222                            return list.get(1);
2223                    }
2224                    else {
2225                            return null;
2226                    }
2227            }
2228    
2229            /**
2230             * Removes all the message-boards messages where groupId = &#63; from the database.
2231             *
2232             * @param groupId the group ID
2233             */
2234            @Override
2235            public void removeByGroupId(long groupId) {
2236                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2237                                    QueryUtil.ALL_POS, null)) {
2238                            remove(mbMessage);
2239                    }
2240            }
2241    
2242            /**
2243             * Returns the number of message-boards messages where groupId = &#63;.
2244             *
2245             * @param groupId the group ID
2246             * @return the number of matching message-boards messages
2247             */
2248            @Override
2249            public int countByGroupId(long groupId) {
2250                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2251    
2252                    Object[] finderArgs = new Object[] { groupId };
2253    
2254                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2255    
2256                    if (count == null) {
2257                            StringBundler query = new StringBundler(2);
2258    
2259                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2260    
2261                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2262    
2263                            String sql = query.toString();
2264    
2265                            Session session = null;
2266    
2267                            try {
2268                                    session = openSession();
2269    
2270                                    Query q = session.createQuery(sql);
2271    
2272                                    QueryPos qPos = QueryPos.getInstance(q);
2273    
2274                                    qPos.add(groupId);
2275    
2276                                    count = (Long)q.uniqueResult();
2277    
2278                                    finderCache.putResult(finderPath, finderArgs, count);
2279                            }
2280                            catch (Exception e) {
2281                                    finderCache.removeResult(finderPath, finderArgs);
2282    
2283                                    throw processException(e);
2284                            }
2285                            finally {
2286                                    closeSession(session);
2287                            }
2288                    }
2289    
2290                    return count.intValue();
2291            }
2292    
2293            /**
2294             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2295             *
2296             * @param groupId the group ID
2297             * @return the number of matching message-boards messages that the user has permission to view
2298             */
2299            @Override
2300            public int filterCountByGroupId(long groupId) {
2301                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2302                            return countByGroupId(groupId);
2303                    }
2304    
2305                    StringBundler query = new StringBundler(2);
2306    
2307                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2308    
2309                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2310    
2311                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2312                                    MBMessage.class.getName(),
2313                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2314    
2315                    Session session = null;
2316    
2317                    try {
2318                            session = openSession();
2319    
2320                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2321    
2322                            q.addScalar(COUNT_COLUMN_NAME,
2323                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2324    
2325                            QueryPos qPos = QueryPos.getInstance(q);
2326    
2327                            qPos.add(groupId);
2328    
2329                            Long count = (Long)q.uniqueResult();
2330    
2331                            return count.intValue();
2332                    }
2333                    catch (Exception e) {
2334                            throw processException(e);
2335                    }
2336                    finally {
2337                            closeSession(session);
2338                    }
2339            }
2340    
2341            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2342            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2343                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2344                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2345                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2346                            new String[] {
2347                                    Long.class.getName(),
2348                                    
2349                            Integer.class.getName(), Integer.class.getName(),
2350                                    OrderByComparator.class.getName()
2351                            });
2352            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2353                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2354                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2355                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2356                            new String[] { Long.class.getName() },
2357                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2358                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2359            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2360                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2361                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2362                            new String[] { Long.class.getName() });
2363    
2364            /**
2365             * Returns all the message-boards messages where companyId = &#63;.
2366             *
2367             * @param companyId the company ID
2368             * @return the matching message-boards messages
2369             */
2370            @Override
2371            public List<MBMessage> findByCompanyId(long companyId) {
2372                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2373                            null);
2374            }
2375    
2376            /**
2377             * Returns a range of all the message-boards messages where companyId = &#63;.
2378             *
2379             * <p>
2380             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2381             * </p>
2382             *
2383             * @param companyId the company ID
2384             * @param start the lower bound of the range of message-boards messages
2385             * @param end the upper bound of the range of message-boards messages (not inclusive)
2386             * @return the range of matching message-boards messages
2387             */
2388            @Override
2389            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2390                    return findByCompanyId(companyId, start, end, null);
2391            }
2392    
2393            /**
2394             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2395             *
2396             * <p>
2397             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2398             * </p>
2399             *
2400             * @param companyId the company ID
2401             * @param start the lower bound of the range of message-boards messages
2402             * @param end the upper bound of the range of message-boards messages (not inclusive)
2403             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2404             * @return the ordered range of matching message-boards messages
2405             */
2406            @Override
2407            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2408                    OrderByComparator<MBMessage> orderByComparator) {
2409                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2410            }
2411    
2412            /**
2413             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2414             *
2415             * <p>
2416             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2417             * </p>
2418             *
2419             * @param companyId the company ID
2420             * @param start the lower bound of the range of message-boards messages
2421             * @param end the upper bound of the range of message-boards messages (not inclusive)
2422             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2423             * @param retrieveFromCache whether to retrieve from the finder cache
2424             * @return the ordered range of matching message-boards messages
2425             */
2426            @Override
2427            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2428                    OrderByComparator<MBMessage> orderByComparator,
2429                    boolean retrieveFromCache) {
2430                    boolean pagination = true;
2431                    FinderPath finderPath = null;
2432                    Object[] finderArgs = null;
2433    
2434                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2435                                    (orderByComparator == null)) {
2436                            pagination = false;
2437                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2438                            finderArgs = new Object[] { companyId };
2439                    }
2440                    else {
2441                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2442                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2443                    }
2444    
2445                    List<MBMessage> list = null;
2446    
2447                    if (retrieveFromCache) {
2448                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2449                                            finderArgs, this);
2450    
2451                            if ((list != null) && !list.isEmpty()) {
2452                                    for (MBMessage mbMessage : list) {
2453                                            if ((companyId != mbMessage.getCompanyId())) {
2454                                                    list = null;
2455    
2456                                                    break;
2457                                            }
2458                                    }
2459                            }
2460                    }
2461    
2462                    if (list == null) {
2463                            StringBundler query = null;
2464    
2465                            if (orderByComparator != null) {
2466                                    query = new StringBundler(3 +
2467                                                    (orderByComparator.getOrderByFields().length * 3));
2468                            }
2469                            else {
2470                                    query = new StringBundler(3);
2471                            }
2472    
2473                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2474    
2475                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2476    
2477                            if (orderByComparator != null) {
2478                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2479                                            orderByComparator);
2480                            }
2481                            else
2482                             if (pagination) {
2483                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2484                            }
2485    
2486                            String sql = query.toString();
2487    
2488                            Session session = null;
2489    
2490                            try {
2491                                    session = openSession();
2492    
2493                                    Query q = session.createQuery(sql);
2494    
2495                                    QueryPos qPos = QueryPos.getInstance(q);
2496    
2497                                    qPos.add(companyId);
2498    
2499                                    if (!pagination) {
2500                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2501                                                            start, end, false);
2502    
2503                                            Collections.sort(list);
2504    
2505                                            list = Collections.unmodifiableList(list);
2506                                    }
2507                                    else {
2508                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2509                                                            start, end);
2510                                    }
2511    
2512                                    cacheResult(list);
2513    
2514                                    finderCache.putResult(finderPath, finderArgs, list);
2515                            }
2516                            catch (Exception e) {
2517                                    finderCache.removeResult(finderPath, finderArgs);
2518    
2519                                    throw processException(e);
2520                            }
2521                            finally {
2522                                    closeSession(session);
2523                            }
2524                    }
2525    
2526                    return list;
2527            }
2528    
2529            /**
2530             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2531             *
2532             * @param companyId the company ID
2533             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2534             * @return the first matching message-boards message
2535             * @throws NoSuchMessageException if a matching message-boards message could not be found
2536             */
2537            @Override
2538            public MBMessage findByCompanyId_First(long companyId,
2539                    OrderByComparator<MBMessage> orderByComparator)
2540                    throws NoSuchMessageException {
2541                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2542                                    orderByComparator);
2543    
2544                    if (mbMessage != null) {
2545                            return mbMessage;
2546                    }
2547    
2548                    StringBundler msg = new StringBundler(4);
2549    
2550                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2551    
2552                    msg.append("companyId=");
2553                    msg.append(companyId);
2554    
2555                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2556    
2557                    throw new NoSuchMessageException(msg.toString());
2558            }
2559    
2560            /**
2561             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2562             *
2563             * @param companyId the company ID
2564             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2565             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2566             */
2567            @Override
2568            public MBMessage fetchByCompanyId_First(long companyId,
2569                    OrderByComparator<MBMessage> orderByComparator) {
2570                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2571                                    orderByComparator);
2572    
2573                    if (!list.isEmpty()) {
2574                            return list.get(0);
2575                    }
2576    
2577                    return null;
2578            }
2579    
2580            /**
2581             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2582             *
2583             * @param companyId the company ID
2584             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2585             * @return the last matching message-boards message
2586             * @throws NoSuchMessageException if a matching message-boards message could not be found
2587             */
2588            @Override
2589            public MBMessage findByCompanyId_Last(long companyId,
2590                    OrderByComparator<MBMessage> orderByComparator)
2591                    throws NoSuchMessageException {
2592                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2593    
2594                    if (mbMessage != null) {
2595                            return mbMessage;
2596                    }
2597    
2598                    StringBundler msg = new StringBundler(4);
2599    
2600                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2601    
2602                    msg.append("companyId=");
2603                    msg.append(companyId);
2604    
2605                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2606    
2607                    throw new NoSuchMessageException(msg.toString());
2608            }
2609    
2610            /**
2611             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2612             *
2613             * @param companyId the company ID
2614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2615             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2616             */
2617            @Override
2618            public MBMessage fetchByCompanyId_Last(long companyId,
2619                    OrderByComparator<MBMessage> orderByComparator) {
2620                    int count = countByCompanyId(companyId);
2621    
2622                    if (count == 0) {
2623                            return null;
2624                    }
2625    
2626                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2627                                    orderByComparator);
2628    
2629                    if (!list.isEmpty()) {
2630                            return list.get(0);
2631                    }
2632    
2633                    return null;
2634            }
2635    
2636            /**
2637             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2638             *
2639             * @param messageId the primary key of the current message-boards message
2640             * @param companyId the company ID
2641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2642             * @return the previous, current, and next message-boards message
2643             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2644             */
2645            @Override
2646            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2647                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2648                    throws NoSuchMessageException {
2649                    MBMessage mbMessage = findByPrimaryKey(messageId);
2650    
2651                    Session session = null;
2652    
2653                    try {
2654                            session = openSession();
2655    
2656                            MBMessage[] array = new MBMessageImpl[3];
2657    
2658                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2659                                            companyId, orderByComparator, true);
2660    
2661                            array[1] = mbMessage;
2662    
2663                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2664                                            companyId, orderByComparator, false);
2665    
2666                            return array;
2667                    }
2668                    catch (Exception e) {
2669                            throw processException(e);
2670                    }
2671                    finally {
2672                            closeSession(session);
2673                    }
2674            }
2675    
2676            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2677                    MBMessage mbMessage, long companyId,
2678                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2679                    StringBundler query = null;
2680    
2681                    if (orderByComparator != null) {
2682                            query = new StringBundler(6 +
2683                                            (orderByComparator.getOrderByFields().length * 6));
2684                    }
2685                    else {
2686                            query = new StringBundler(3);
2687                    }
2688    
2689                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2690    
2691                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2692    
2693                    if (orderByComparator != null) {
2694                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2695    
2696                            if (orderByConditionFields.length > 0) {
2697                                    query.append(WHERE_AND);
2698                            }
2699    
2700                            for (int i = 0; i < orderByConditionFields.length; i++) {
2701                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2702                                    query.append(orderByConditionFields[i]);
2703    
2704                                    if ((i + 1) < orderByConditionFields.length) {
2705                                            if (orderByComparator.isAscending() ^ previous) {
2706                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2707                                            }
2708                                            else {
2709                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2710                                            }
2711                                    }
2712                                    else {
2713                                            if (orderByComparator.isAscending() ^ previous) {
2714                                                    query.append(WHERE_GREATER_THAN);
2715                                            }
2716                                            else {
2717                                                    query.append(WHERE_LESSER_THAN);
2718                                            }
2719                                    }
2720                            }
2721    
2722                            query.append(ORDER_BY_CLAUSE);
2723    
2724                            String[] orderByFields = orderByComparator.getOrderByFields();
2725    
2726                            for (int i = 0; i < orderByFields.length; i++) {
2727                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2728                                    query.append(orderByFields[i]);
2729    
2730                                    if ((i + 1) < orderByFields.length) {
2731                                            if (orderByComparator.isAscending() ^ previous) {
2732                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2733                                            }
2734                                            else {
2735                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2736                                            }
2737                                    }
2738                                    else {
2739                                            if (orderByComparator.isAscending() ^ previous) {
2740                                                    query.append(ORDER_BY_ASC);
2741                                            }
2742                                            else {
2743                                                    query.append(ORDER_BY_DESC);
2744                                            }
2745                                    }
2746                            }
2747                    }
2748                    else {
2749                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2750                    }
2751    
2752                    String sql = query.toString();
2753    
2754                    Query q = session.createQuery(sql);
2755    
2756                    q.setFirstResult(0);
2757                    q.setMaxResults(2);
2758    
2759                    QueryPos qPos = QueryPos.getInstance(q);
2760    
2761                    qPos.add(companyId);
2762    
2763                    if (orderByComparator != null) {
2764                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2765    
2766                            for (Object value : values) {
2767                                    qPos.add(value);
2768                            }
2769                    }
2770    
2771                    List<MBMessage> list = q.list();
2772    
2773                    if (list.size() == 2) {
2774                            return list.get(1);
2775                    }
2776                    else {
2777                            return null;
2778                    }
2779            }
2780    
2781            /**
2782             * Removes all the message-boards messages where companyId = &#63; from the database.
2783             *
2784             * @param companyId the company ID
2785             */
2786            @Override
2787            public void removeByCompanyId(long companyId) {
2788                    for (MBMessage mbMessage : findByCompanyId(companyId,
2789                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2790                            remove(mbMessage);
2791                    }
2792            }
2793    
2794            /**
2795             * Returns the number of message-boards messages where companyId = &#63;.
2796             *
2797             * @param companyId the company ID
2798             * @return the number of matching message-boards messages
2799             */
2800            @Override
2801            public int countByCompanyId(long companyId) {
2802                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2803    
2804                    Object[] finderArgs = new Object[] { companyId };
2805    
2806                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2807    
2808                    if (count == null) {
2809                            StringBundler query = new StringBundler(2);
2810    
2811                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2812    
2813                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2814    
2815                            String sql = query.toString();
2816    
2817                            Session session = null;
2818    
2819                            try {
2820                                    session = openSession();
2821    
2822                                    Query q = session.createQuery(sql);
2823    
2824                                    QueryPos qPos = QueryPos.getInstance(q);
2825    
2826                                    qPos.add(companyId);
2827    
2828                                    count = (Long)q.uniqueResult();
2829    
2830                                    finderCache.putResult(finderPath, finderArgs, count);
2831                            }
2832                            catch (Exception e) {
2833                                    finderCache.removeResult(finderPath, finderArgs);
2834    
2835                                    throw processException(e);
2836                            }
2837                            finally {
2838                                    closeSession(session);
2839                            }
2840                    }
2841    
2842                    return count.intValue();
2843            }
2844    
2845            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2846            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2847                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2848                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2849                            new String[] {
2850                                    Long.class.getName(),
2851                                    
2852                            Integer.class.getName(), Integer.class.getName(),
2853                                    OrderByComparator.class.getName()
2854                            });
2855            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2856                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2857                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2858                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2859                            new String[] { Long.class.getName() },
2860                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2861                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2862            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2863                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2864                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2865                            new String[] { Long.class.getName() });
2866    
2867            /**
2868             * Returns all the message-boards messages where userId = &#63;.
2869             *
2870             * @param userId the user ID
2871             * @return the matching message-boards messages
2872             */
2873            @Override
2874            public List<MBMessage> findByUserId(long userId) {
2875                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2876            }
2877    
2878            /**
2879             * Returns a range of all the message-boards messages where userId = &#63;.
2880             *
2881             * <p>
2882             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2883             * </p>
2884             *
2885             * @param userId the user ID
2886             * @param start the lower bound of the range of message-boards messages
2887             * @param end the upper bound of the range of message-boards messages (not inclusive)
2888             * @return the range of matching message-boards messages
2889             */
2890            @Override
2891            public List<MBMessage> findByUserId(long userId, int start, int end) {
2892                    return findByUserId(userId, start, end, null);
2893            }
2894    
2895            /**
2896             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2897             *
2898             * <p>
2899             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2900             * </p>
2901             *
2902             * @param userId the user ID
2903             * @param start the lower bound of the range of message-boards messages
2904             * @param end the upper bound of the range of message-boards messages (not inclusive)
2905             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2906             * @return the ordered range of matching message-boards messages
2907             */
2908            @Override
2909            public List<MBMessage> findByUserId(long userId, int start, int end,
2910                    OrderByComparator<MBMessage> orderByComparator) {
2911                    return findByUserId(userId, start, end, orderByComparator, true);
2912            }
2913    
2914            /**
2915             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2916             *
2917             * <p>
2918             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2919             * </p>
2920             *
2921             * @param userId the user ID
2922             * @param start the lower bound of the range of message-boards messages
2923             * @param end the upper bound of the range of message-boards messages (not inclusive)
2924             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2925             * @param retrieveFromCache whether to retrieve from the finder cache
2926             * @return the ordered range of matching message-boards messages
2927             */
2928            @Override
2929            public List<MBMessage> findByUserId(long userId, int start, int end,
2930                    OrderByComparator<MBMessage> orderByComparator,
2931                    boolean retrieveFromCache) {
2932                    boolean pagination = true;
2933                    FinderPath finderPath = null;
2934                    Object[] finderArgs = null;
2935    
2936                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2937                                    (orderByComparator == null)) {
2938                            pagination = false;
2939                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2940                            finderArgs = new Object[] { userId };
2941                    }
2942                    else {
2943                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2944                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2945                    }
2946    
2947                    List<MBMessage> list = null;
2948    
2949                    if (retrieveFromCache) {
2950                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2951                                            finderArgs, this);
2952    
2953                            if ((list != null) && !list.isEmpty()) {
2954                                    for (MBMessage mbMessage : list) {
2955                                            if ((userId != mbMessage.getUserId())) {
2956                                                    list = null;
2957    
2958                                                    break;
2959                                            }
2960                                    }
2961                            }
2962                    }
2963    
2964                    if (list == null) {
2965                            StringBundler query = null;
2966    
2967                            if (orderByComparator != null) {
2968                                    query = new StringBundler(3 +
2969                                                    (orderByComparator.getOrderByFields().length * 3));
2970                            }
2971                            else {
2972                                    query = new StringBundler(3);
2973                            }
2974    
2975                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2976    
2977                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2978    
2979                            if (orderByComparator != null) {
2980                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2981                                            orderByComparator);
2982                            }
2983                            else
2984                             if (pagination) {
2985                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2986                            }
2987    
2988                            String sql = query.toString();
2989    
2990                            Session session = null;
2991    
2992                            try {
2993                                    session = openSession();
2994    
2995                                    Query q = session.createQuery(sql);
2996    
2997                                    QueryPos qPos = QueryPos.getInstance(q);
2998    
2999                                    qPos.add(userId);
3000    
3001                                    if (!pagination) {
3002                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3003                                                            start, end, false);
3004    
3005                                            Collections.sort(list);
3006    
3007                                            list = Collections.unmodifiableList(list);
3008                                    }
3009                                    else {
3010                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3011                                                            start, end);
3012                                    }
3013    
3014                                    cacheResult(list);
3015    
3016                                    finderCache.putResult(finderPath, finderArgs, list);
3017                            }
3018                            catch (Exception e) {
3019                                    finderCache.removeResult(finderPath, finderArgs);
3020    
3021                                    throw processException(e);
3022                            }
3023                            finally {
3024                                    closeSession(session);
3025                            }
3026                    }
3027    
3028                    return list;
3029            }
3030    
3031            /**
3032             * Returns the first message-boards message in the ordered set where userId = &#63;.
3033             *
3034             * @param userId the user ID
3035             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3036             * @return the first matching message-boards message
3037             * @throws NoSuchMessageException if a matching message-boards message could not be found
3038             */
3039            @Override
3040            public MBMessage findByUserId_First(long userId,
3041                    OrderByComparator<MBMessage> orderByComparator)
3042                    throws NoSuchMessageException {
3043                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3044    
3045                    if (mbMessage != null) {
3046                            return mbMessage;
3047                    }
3048    
3049                    StringBundler msg = new StringBundler(4);
3050    
3051                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3052    
3053                    msg.append("userId=");
3054                    msg.append(userId);
3055    
3056                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3057    
3058                    throw new NoSuchMessageException(msg.toString());
3059            }
3060    
3061            /**
3062             * Returns the first message-boards message in the ordered set where userId = &#63;.
3063             *
3064             * @param userId the user ID
3065             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3066             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3067             */
3068            @Override
3069            public MBMessage fetchByUserId_First(long userId,
3070                    OrderByComparator<MBMessage> orderByComparator) {
3071                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3072    
3073                    if (!list.isEmpty()) {
3074                            return list.get(0);
3075                    }
3076    
3077                    return null;
3078            }
3079    
3080            /**
3081             * Returns the last message-boards message in the ordered set where userId = &#63;.
3082             *
3083             * @param userId the user ID
3084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3085             * @return the last matching message-boards message
3086             * @throws NoSuchMessageException if a matching message-boards message could not be found
3087             */
3088            @Override
3089            public MBMessage findByUserId_Last(long userId,
3090                    OrderByComparator<MBMessage> orderByComparator)
3091                    throws NoSuchMessageException {
3092                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3093    
3094                    if (mbMessage != null) {
3095                            return mbMessage;
3096                    }
3097    
3098                    StringBundler msg = new StringBundler(4);
3099    
3100                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3101    
3102                    msg.append("userId=");
3103                    msg.append(userId);
3104    
3105                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3106    
3107                    throw new NoSuchMessageException(msg.toString());
3108            }
3109    
3110            /**
3111             * Returns the last message-boards message in the ordered set where userId = &#63;.
3112             *
3113             * @param userId the user ID
3114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3115             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3116             */
3117            @Override
3118            public MBMessage fetchByUserId_Last(long userId,
3119                    OrderByComparator<MBMessage> orderByComparator) {
3120                    int count = countByUserId(userId);
3121    
3122                    if (count == 0) {
3123                            return null;
3124                    }
3125    
3126                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3127                                    orderByComparator);
3128    
3129                    if (!list.isEmpty()) {
3130                            return list.get(0);
3131                    }
3132    
3133                    return null;
3134            }
3135    
3136            /**
3137             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3138             *
3139             * @param messageId the primary key of the current message-boards message
3140             * @param userId the user ID
3141             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3142             * @return the previous, current, and next message-boards message
3143             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3144             */
3145            @Override
3146            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3147                    OrderByComparator<MBMessage> orderByComparator)
3148                    throws NoSuchMessageException {
3149                    MBMessage mbMessage = findByPrimaryKey(messageId);
3150    
3151                    Session session = null;
3152    
3153                    try {
3154                            session = openSession();
3155    
3156                            MBMessage[] array = new MBMessageImpl[3];
3157    
3158                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3159                                            orderByComparator, true);
3160    
3161                            array[1] = mbMessage;
3162    
3163                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3164                                            orderByComparator, false);
3165    
3166                            return array;
3167                    }
3168                    catch (Exception e) {
3169                            throw processException(e);
3170                    }
3171                    finally {
3172                            closeSession(session);
3173                    }
3174            }
3175    
3176            protected MBMessage getByUserId_PrevAndNext(Session session,
3177                    MBMessage mbMessage, long userId,
3178                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3179                    StringBundler query = null;
3180    
3181                    if (orderByComparator != null) {
3182                            query = new StringBundler(6 +
3183                                            (orderByComparator.getOrderByFields().length * 6));
3184                    }
3185                    else {
3186                            query = new StringBundler(3);
3187                    }
3188    
3189                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3190    
3191                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3192    
3193                    if (orderByComparator != null) {
3194                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3195    
3196                            if (orderByConditionFields.length > 0) {
3197                                    query.append(WHERE_AND);
3198                            }
3199    
3200                            for (int i = 0; i < orderByConditionFields.length; i++) {
3201                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3202                                    query.append(orderByConditionFields[i]);
3203    
3204                                    if ((i + 1) < orderByConditionFields.length) {
3205                                            if (orderByComparator.isAscending() ^ previous) {
3206                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3207                                            }
3208                                            else {
3209                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3210                                            }
3211                                    }
3212                                    else {
3213                                            if (orderByComparator.isAscending() ^ previous) {
3214                                                    query.append(WHERE_GREATER_THAN);
3215                                            }
3216                                            else {
3217                                                    query.append(WHERE_LESSER_THAN);
3218                                            }
3219                                    }
3220                            }
3221    
3222                            query.append(ORDER_BY_CLAUSE);
3223    
3224                            String[] orderByFields = orderByComparator.getOrderByFields();
3225    
3226                            for (int i = 0; i < orderByFields.length; i++) {
3227                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3228                                    query.append(orderByFields[i]);
3229    
3230                                    if ((i + 1) < orderByFields.length) {
3231                                            if (orderByComparator.isAscending() ^ previous) {
3232                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3233                                            }
3234                                            else {
3235                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3236                                            }
3237                                    }
3238                                    else {
3239                                            if (orderByComparator.isAscending() ^ previous) {
3240                                                    query.append(ORDER_BY_ASC);
3241                                            }
3242                                            else {
3243                                                    query.append(ORDER_BY_DESC);
3244                                            }
3245                                    }
3246                            }
3247                    }
3248                    else {
3249                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3250                    }
3251    
3252                    String sql = query.toString();
3253    
3254                    Query q = session.createQuery(sql);
3255    
3256                    q.setFirstResult(0);
3257                    q.setMaxResults(2);
3258    
3259                    QueryPos qPos = QueryPos.getInstance(q);
3260    
3261                    qPos.add(userId);
3262    
3263                    if (orderByComparator != null) {
3264                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3265    
3266                            for (Object value : values) {
3267                                    qPos.add(value);
3268                            }
3269                    }
3270    
3271                    List<MBMessage> list = q.list();
3272    
3273                    if (list.size() == 2) {
3274                            return list.get(1);
3275                    }
3276                    else {
3277                            return null;
3278                    }
3279            }
3280    
3281            /**
3282             * Removes all the message-boards messages where userId = &#63; from the database.
3283             *
3284             * @param userId the user ID
3285             */
3286            @Override
3287            public void removeByUserId(long userId) {
3288                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3289                                    QueryUtil.ALL_POS, null)) {
3290                            remove(mbMessage);
3291                    }
3292            }
3293    
3294            /**
3295             * Returns the number of message-boards messages where userId = &#63;.
3296             *
3297             * @param userId the user ID
3298             * @return the number of matching message-boards messages
3299             */
3300            @Override
3301            public int countByUserId(long userId) {
3302                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3303    
3304                    Object[] finderArgs = new Object[] { userId };
3305    
3306                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3307    
3308                    if (count == null) {
3309                            StringBundler query = new StringBundler(2);
3310    
3311                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3312    
3313                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3314    
3315                            String sql = query.toString();
3316    
3317                            Session session = null;
3318    
3319                            try {
3320                                    session = openSession();
3321    
3322                                    Query q = session.createQuery(sql);
3323    
3324                                    QueryPos qPos = QueryPos.getInstance(q);
3325    
3326                                    qPos.add(userId);
3327    
3328                                    count = (Long)q.uniqueResult();
3329    
3330                                    finderCache.putResult(finderPath, finderArgs, count);
3331                            }
3332                            catch (Exception e) {
3333                                    finderCache.removeResult(finderPath, finderArgs);
3334    
3335                                    throw processException(e);
3336                            }
3337                            finally {
3338                                    closeSession(session);
3339                            }
3340                    }
3341    
3342                    return count.intValue();
3343            }
3344    
3345            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3346            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3347                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3348                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3349                            new String[] {
3350                                    Long.class.getName(),
3351                                    
3352                            Integer.class.getName(), Integer.class.getName(),
3353                                    OrderByComparator.class.getName()
3354                            });
3355            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3356                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3357                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3358                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3359                            new String[] { Long.class.getName() },
3360                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3361                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3362            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3363                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3364                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3365                            new String[] { Long.class.getName() });
3366    
3367            /**
3368             * Returns all the message-boards messages where threadId = &#63;.
3369             *
3370             * @param threadId the thread ID
3371             * @return the matching message-boards messages
3372             */
3373            @Override
3374            public List<MBMessage> findByThreadId(long threadId) {
3375                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3376                            null);
3377            }
3378    
3379            /**
3380             * Returns a range of all the message-boards messages where threadId = &#63;.
3381             *
3382             * <p>
3383             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3384             * </p>
3385             *
3386             * @param threadId the thread ID
3387             * @param start the lower bound of the range of message-boards messages
3388             * @param end the upper bound of the range of message-boards messages (not inclusive)
3389             * @return the range of matching message-boards messages
3390             */
3391            @Override
3392            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3393                    return findByThreadId(threadId, start, end, null);
3394            }
3395    
3396            /**
3397             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3398             *
3399             * <p>
3400             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3401             * </p>
3402             *
3403             * @param threadId the thread ID
3404             * @param start the lower bound of the range of message-boards messages
3405             * @param end the upper bound of the range of message-boards messages (not inclusive)
3406             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3407             * @return the ordered range of matching message-boards messages
3408             */
3409            @Override
3410            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3411                    OrderByComparator<MBMessage> orderByComparator) {
3412                    return findByThreadId(threadId, start, end, orderByComparator, true);
3413            }
3414    
3415            /**
3416             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3417             *
3418             * <p>
3419             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3420             * </p>
3421             *
3422             * @param threadId the thread ID
3423             * @param start the lower bound of the range of message-boards messages
3424             * @param end the upper bound of the range of message-boards messages (not inclusive)
3425             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3426             * @param retrieveFromCache whether to retrieve from the finder cache
3427             * @return the ordered range of matching message-boards messages
3428             */
3429            @Override
3430            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3431                    OrderByComparator<MBMessage> orderByComparator,
3432                    boolean retrieveFromCache) {
3433                    boolean pagination = true;
3434                    FinderPath finderPath = null;
3435                    Object[] finderArgs = null;
3436    
3437                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3438                                    (orderByComparator == null)) {
3439                            pagination = false;
3440                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3441                            finderArgs = new Object[] { threadId };
3442                    }
3443                    else {
3444                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3445                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3446                    }
3447    
3448                    List<MBMessage> list = null;
3449    
3450                    if (retrieveFromCache) {
3451                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3452                                            finderArgs, this);
3453    
3454                            if ((list != null) && !list.isEmpty()) {
3455                                    for (MBMessage mbMessage : list) {
3456                                            if ((threadId != mbMessage.getThreadId())) {
3457                                                    list = null;
3458    
3459                                                    break;
3460                                            }
3461                                    }
3462                            }
3463                    }
3464    
3465                    if (list == null) {
3466                            StringBundler query = null;
3467    
3468                            if (orderByComparator != null) {
3469                                    query = new StringBundler(3 +
3470                                                    (orderByComparator.getOrderByFields().length * 3));
3471                            }
3472                            else {
3473                                    query = new StringBundler(3);
3474                            }
3475    
3476                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3477    
3478                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3479    
3480                            if (orderByComparator != null) {
3481                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3482                                            orderByComparator);
3483                            }
3484                            else
3485                             if (pagination) {
3486                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3487                            }
3488    
3489                            String sql = query.toString();
3490    
3491                            Session session = null;
3492    
3493                            try {
3494                                    session = openSession();
3495    
3496                                    Query q = session.createQuery(sql);
3497    
3498                                    QueryPos qPos = QueryPos.getInstance(q);
3499    
3500                                    qPos.add(threadId);
3501    
3502                                    if (!pagination) {
3503                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3504                                                            start, end, false);
3505    
3506                                            Collections.sort(list);
3507    
3508                                            list = Collections.unmodifiableList(list);
3509                                    }
3510                                    else {
3511                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3512                                                            start, end);
3513                                    }
3514    
3515                                    cacheResult(list);
3516    
3517                                    finderCache.putResult(finderPath, finderArgs, list);
3518                            }
3519                            catch (Exception e) {
3520                                    finderCache.removeResult(finderPath, finderArgs);
3521    
3522                                    throw processException(e);
3523                            }
3524                            finally {
3525                                    closeSession(session);
3526                            }
3527                    }
3528    
3529                    return list;
3530            }
3531    
3532            /**
3533             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3534             *
3535             * @param threadId the thread ID
3536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3537             * @return the first matching message-boards message
3538             * @throws NoSuchMessageException if a matching message-boards message could not be found
3539             */
3540            @Override
3541            public MBMessage findByThreadId_First(long threadId,
3542                    OrderByComparator<MBMessage> orderByComparator)
3543                    throws NoSuchMessageException {
3544                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3545    
3546                    if (mbMessage != null) {
3547                            return mbMessage;
3548                    }
3549    
3550                    StringBundler msg = new StringBundler(4);
3551    
3552                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3553    
3554                    msg.append("threadId=");
3555                    msg.append(threadId);
3556    
3557                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3558    
3559                    throw new NoSuchMessageException(msg.toString());
3560            }
3561    
3562            /**
3563             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3564             *
3565             * @param threadId the thread ID
3566             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3567             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3568             */
3569            @Override
3570            public MBMessage fetchByThreadId_First(long threadId,
3571                    OrderByComparator<MBMessage> orderByComparator) {
3572                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3573    
3574                    if (!list.isEmpty()) {
3575                            return list.get(0);
3576                    }
3577    
3578                    return null;
3579            }
3580    
3581            /**
3582             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3583             *
3584             * @param threadId the thread ID
3585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3586             * @return the last matching message-boards message
3587             * @throws NoSuchMessageException if a matching message-boards message could not be found
3588             */
3589            @Override
3590            public MBMessage findByThreadId_Last(long threadId,
3591                    OrderByComparator<MBMessage> orderByComparator)
3592                    throws NoSuchMessageException {
3593                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3594    
3595                    if (mbMessage != null) {
3596                            return mbMessage;
3597                    }
3598    
3599                    StringBundler msg = new StringBundler(4);
3600    
3601                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3602    
3603                    msg.append("threadId=");
3604                    msg.append(threadId);
3605    
3606                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3607    
3608                    throw new NoSuchMessageException(msg.toString());
3609            }
3610    
3611            /**
3612             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3613             *
3614             * @param threadId the thread ID
3615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3616             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3617             */
3618            @Override
3619            public MBMessage fetchByThreadId_Last(long threadId,
3620                    OrderByComparator<MBMessage> orderByComparator) {
3621                    int count = countByThreadId(threadId);
3622    
3623                    if (count == 0) {
3624                            return null;
3625                    }
3626    
3627                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3628                                    orderByComparator);
3629    
3630                    if (!list.isEmpty()) {
3631                            return list.get(0);
3632                    }
3633    
3634                    return null;
3635            }
3636    
3637            /**
3638             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3639             *
3640             * @param messageId the primary key of the current message-boards message
3641             * @param threadId the thread ID
3642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3643             * @return the previous, current, and next message-boards message
3644             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3645             */
3646            @Override
3647            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3648                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3649                    throws NoSuchMessageException {
3650                    MBMessage mbMessage = findByPrimaryKey(messageId);
3651    
3652                    Session session = null;
3653    
3654                    try {
3655                            session = openSession();
3656    
3657                            MBMessage[] array = new MBMessageImpl[3];
3658    
3659                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3660                                            orderByComparator, true);
3661    
3662                            array[1] = mbMessage;
3663    
3664                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3665                                            orderByComparator, false);
3666    
3667                            return array;
3668                    }
3669                    catch (Exception e) {
3670                            throw processException(e);
3671                    }
3672                    finally {
3673                            closeSession(session);
3674                    }
3675            }
3676    
3677            protected MBMessage getByThreadId_PrevAndNext(Session session,
3678                    MBMessage mbMessage, long threadId,
3679                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3680                    StringBundler query = null;
3681    
3682                    if (orderByComparator != null) {
3683                            query = new StringBundler(6 +
3684                                            (orderByComparator.getOrderByFields().length * 6));
3685                    }
3686                    else {
3687                            query = new StringBundler(3);
3688                    }
3689    
3690                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3691    
3692                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3693    
3694                    if (orderByComparator != null) {
3695                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3696    
3697                            if (orderByConditionFields.length > 0) {
3698                                    query.append(WHERE_AND);
3699                            }
3700    
3701                            for (int i = 0; i < orderByConditionFields.length; i++) {
3702                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3703                                    query.append(orderByConditionFields[i]);
3704    
3705                                    if ((i + 1) < orderByConditionFields.length) {
3706                                            if (orderByComparator.isAscending() ^ previous) {
3707                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3708                                            }
3709                                            else {
3710                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3711                                            }
3712                                    }
3713                                    else {
3714                                            if (orderByComparator.isAscending() ^ previous) {
3715                                                    query.append(WHERE_GREATER_THAN);
3716                                            }
3717                                            else {
3718                                                    query.append(WHERE_LESSER_THAN);
3719                                            }
3720                                    }
3721                            }
3722    
3723                            query.append(ORDER_BY_CLAUSE);
3724    
3725                            String[] orderByFields = orderByComparator.getOrderByFields();
3726    
3727                            for (int i = 0; i < orderByFields.length; i++) {
3728                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3729                                    query.append(orderByFields[i]);
3730    
3731                                    if ((i + 1) < orderByFields.length) {
3732                                            if (orderByComparator.isAscending() ^ previous) {
3733                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3734                                            }
3735                                            else {
3736                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3737                                            }
3738                                    }
3739                                    else {
3740                                            if (orderByComparator.isAscending() ^ previous) {
3741                                                    query.append(ORDER_BY_ASC);
3742                                            }
3743                                            else {
3744                                                    query.append(ORDER_BY_DESC);
3745                                            }
3746                                    }
3747                            }
3748                    }
3749                    else {
3750                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3751                    }
3752    
3753                    String sql = query.toString();
3754    
3755                    Query q = session.createQuery(sql);
3756    
3757                    q.setFirstResult(0);
3758                    q.setMaxResults(2);
3759    
3760                    QueryPos qPos = QueryPos.getInstance(q);
3761    
3762                    qPos.add(threadId);
3763    
3764                    if (orderByComparator != null) {
3765                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3766    
3767                            for (Object value : values) {
3768                                    qPos.add(value);
3769                            }
3770                    }
3771    
3772                    List<MBMessage> list = q.list();
3773    
3774                    if (list.size() == 2) {
3775                            return list.get(1);
3776                    }
3777                    else {
3778                            return null;
3779                    }
3780            }
3781    
3782            /**
3783             * Removes all the message-boards messages where threadId = &#63; from the database.
3784             *
3785             * @param threadId the thread ID
3786             */
3787            @Override
3788            public void removeByThreadId(long threadId) {
3789                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3790                                    QueryUtil.ALL_POS, null)) {
3791                            remove(mbMessage);
3792                    }
3793            }
3794    
3795            /**
3796             * Returns the number of message-boards messages where threadId = &#63;.
3797             *
3798             * @param threadId the thread ID
3799             * @return the number of matching message-boards messages
3800             */
3801            @Override
3802            public int countByThreadId(long threadId) {
3803                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3804    
3805                    Object[] finderArgs = new Object[] { threadId };
3806    
3807                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3808    
3809                    if (count == null) {
3810                            StringBundler query = new StringBundler(2);
3811    
3812                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3813    
3814                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3815    
3816                            String sql = query.toString();
3817    
3818                            Session session = null;
3819    
3820                            try {
3821                                    session = openSession();
3822    
3823                                    Query q = session.createQuery(sql);
3824    
3825                                    QueryPos qPos = QueryPos.getInstance(q);
3826    
3827                                    qPos.add(threadId);
3828    
3829                                    count = (Long)q.uniqueResult();
3830    
3831                                    finderCache.putResult(finderPath, finderArgs, count);
3832                            }
3833                            catch (Exception e) {
3834                                    finderCache.removeResult(finderPath, finderArgs);
3835    
3836                                    throw processException(e);
3837                            }
3838                            finally {
3839                                    closeSession(session);
3840                            }
3841                    }
3842    
3843                    return count.intValue();
3844            }
3845    
3846            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3847            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3848                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3849                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3850                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3851                            new String[] {
3852                                    Long.class.getName(),
3853                                    
3854                            Integer.class.getName(), Integer.class.getName(),
3855                                    OrderByComparator.class.getName()
3856                            });
3857            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3858                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3859                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3860                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3861                            new String[] { Long.class.getName() },
3862                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3863                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3864            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3865                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3866                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3867                            new String[] { Long.class.getName() });
3868    
3869            /**
3870             * Returns all the message-boards messages where threadId = &#63;.
3871             *
3872             * @param threadId the thread ID
3873             * @return the matching message-boards messages
3874             */
3875            @Override
3876            public List<MBMessage> findByThreadReplies(long threadId) {
3877                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3878                            QueryUtil.ALL_POS, null);
3879            }
3880    
3881            /**
3882             * Returns a range of all the message-boards messages where threadId = &#63;.
3883             *
3884             * <p>
3885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3886             * </p>
3887             *
3888             * @param threadId the thread ID
3889             * @param start the lower bound of the range of message-boards messages
3890             * @param end the upper bound of the range of message-boards messages (not inclusive)
3891             * @return the range of matching message-boards messages
3892             */
3893            @Override
3894            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3895                    return findByThreadReplies(threadId, start, end, null);
3896            }
3897    
3898            /**
3899             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3900             *
3901             * <p>
3902             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3903             * </p>
3904             *
3905             * @param threadId the thread ID
3906             * @param start the lower bound of the range of message-boards messages
3907             * @param end the upper bound of the range of message-boards messages (not inclusive)
3908             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3909             * @return the ordered range of matching message-boards messages
3910             */
3911            @Override
3912            public List<MBMessage> findByThreadReplies(long threadId, int start,
3913                    int end, OrderByComparator<MBMessage> orderByComparator) {
3914                    return findByThreadReplies(threadId, start, end, orderByComparator, true);
3915            }
3916    
3917            /**
3918             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3919             *
3920             * <p>
3921             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3922             * </p>
3923             *
3924             * @param threadId the thread ID
3925             * @param start the lower bound of the range of message-boards messages
3926             * @param end the upper bound of the range of message-boards messages (not inclusive)
3927             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3928             * @param retrieveFromCache whether to retrieve from the finder cache
3929             * @return the ordered range of matching message-boards messages
3930             */
3931            @Override
3932            public List<MBMessage> findByThreadReplies(long threadId, int start,
3933                    int end, OrderByComparator<MBMessage> orderByComparator,
3934                    boolean retrieveFromCache) {
3935                    boolean pagination = true;
3936                    FinderPath finderPath = null;
3937                    Object[] finderArgs = null;
3938    
3939                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3940                                    (orderByComparator == null)) {
3941                            pagination = false;
3942                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3943                            finderArgs = new Object[] { threadId };
3944                    }
3945                    else {
3946                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3947                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3948                    }
3949    
3950                    List<MBMessage> list = null;
3951    
3952                    if (retrieveFromCache) {
3953                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3954                                            finderArgs, this);
3955    
3956                            if ((list != null) && !list.isEmpty()) {
3957                                    for (MBMessage mbMessage : list) {
3958                                            if ((threadId != mbMessage.getThreadId())) {
3959                                                    list = null;
3960    
3961                                                    break;
3962                                            }
3963                                    }
3964                            }
3965                    }
3966    
3967                    if (list == null) {
3968                            StringBundler query = null;
3969    
3970                            if (orderByComparator != null) {
3971                                    query = new StringBundler(3 +
3972                                                    (orderByComparator.getOrderByFields().length * 3));
3973                            }
3974                            else {
3975                                    query = new StringBundler(3);
3976                            }
3977    
3978                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3979    
3980                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3981    
3982                            if (orderByComparator != null) {
3983                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3984                                            orderByComparator);
3985                            }
3986                            else
3987                             if (pagination) {
3988                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3989                            }
3990    
3991                            String sql = query.toString();
3992    
3993                            Session session = null;
3994    
3995                            try {
3996                                    session = openSession();
3997    
3998                                    Query q = session.createQuery(sql);
3999    
4000                                    QueryPos qPos = QueryPos.getInstance(q);
4001    
4002                                    qPos.add(threadId);
4003    
4004                                    if (!pagination) {
4005                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4006                                                            start, end, false);
4007    
4008                                            Collections.sort(list);
4009    
4010                                            list = Collections.unmodifiableList(list);
4011                                    }
4012                                    else {
4013                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4014                                                            start, end);
4015                                    }
4016    
4017                                    cacheResult(list);
4018    
4019                                    finderCache.putResult(finderPath, finderArgs, list);
4020                            }
4021                            catch (Exception e) {
4022                                    finderCache.removeResult(finderPath, finderArgs);
4023    
4024                                    throw processException(e);
4025                            }
4026                            finally {
4027                                    closeSession(session);
4028                            }
4029                    }
4030    
4031                    return list;
4032            }
4033    
4034            /**
4035             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4036             *
4037             * @param threadId the thread ID
4038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4039             * @return the first matching message-boards message
4040             * @throws NoSuchMessageException if a matching message-boards message could not be found
4041             */
4042            @Override
4043            public MBMessage findByThreadReplies_First(long threadId,
4044                    OrderByComparator<MBMessage> orderByComparator)
4045                    throws NoSuchMessageException {
4046                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4047                                    orderByComparator);
4048    
4049                    if (mbMessage != null) {
4050                            return mbMessage;
4051                    }
4052    
4053                    StringBundler msg = new StringBundler(4);
4054    
4055                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4056    
4057                    msg.append("threadId=");
4058                    msg.append(threadId);
4059    
4060                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4061    
4062                    throw new NoSuchMessageException(msg.toString());
4063            }
4064    
4065            /**
4066             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4067             *
4068             * @param threadId the thread ID
4069             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4070             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4071             */
4072            @Override
4073            public MBMessage fetchByThreadReplies_First(long threadId,
4074                    OrderByComparator<MBMessage> orderByComparator) {
4075                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4076                                    orderByComparator);
4077    
4078                    if (!list.isEmpty()) {
4079                            return list.get(0);
4080                    }
4081    
4082                    return null;
4083            }
4084    
4085            /**
4086             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4087             *
4088             * @param threadId the thread ID
4089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4090             * @return the last matching message-boards message
4091             * @throws NoSuchMessageException if a matching message-boards message could not be found
4092             */
4093            @Override
4094            public MBMessage findByThreadReplies_Last(long threadId,
4095                    OrderByComparator<MBMessage> orderByComparator)
4096                    throws NoSuchMessageException {
4097                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4098                                    orderByComparator);
4099    
4100                    if (mbMessage != null) {
4101                            return mbMessage;
4102                    }
4103    
4104                    StringBundler msg = new StringBundler(4);
4105    
4106                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4107    
4108                    msg.append("threadId=");
4109                    msg.append(threadId);
4110    
4111                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4112    
4113                    throw new NoSuchMessageException(msg.toString());
4114            }
4115    
4116            /**
4117             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4118             *
4119             * @param threadId the thread ID
4120             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4121             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4122             */
4123            @Override
4124            public MBMessage fetchByThreadReplies_Last(long threadId,
4125                    OrderByComparator<MBMessage> orderByComparator) {
4126                    int count = countByThreadReplies(threadId);
4127    
4128                    if (count == 0) {
4129                            return null;
4130                    }
4131    
4132                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4133                                    orderByComparator);
4134    
4135                    if (!list.isEmpty()) {
4136                            return list.get(0);
4137                    }
4138    
4139                    return null;
4140            }
4141    
4142            /**
4143             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4144             *
4145             * @param messageId the primary key of the current message-boards message
4146             * @param threadId the thread ID
4147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4148             * @return the previous, current, and next message-boards message
4149             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4150             */
4151            @Override
4152            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4153                    long threadId, OrderByComparator<MBMessage> orderByComparator)
4154                    throws NoSuchMessageException {
4155                    MBMessage mbMessage = findByPrimaryKey(messageId);
4156    
4157                    Session session = null;
4158    
4159                    try {
4160                            session = openSession();
4161    
4162                            MBMessage[] array = new MBMessageImpl[3];
4163    
4164                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4165                                            threadId, orderByComparator, true);
4166    
4167                            array[1] = mbMessage;
4168    
4169                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4170                                            threadId, orderByComparator, false);
4171    
4172                            return array;
4173                    }
4174                    catch (Exception e) {
4175                            throw processException(e);
4176                    }
4177                    finally {
4178                            closeSession(session);
4179                    }
4180            }
4181    
4182            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4183                    MBMessage mbMessage, long threadId,
4184                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4185                    StringBundler query = null;
4186    
4187                    if (orderByComparator != null) {
4188                            query = new StringBundler(6 +
4189                                            (orderByComparator.getOrderByFields().length * 6));
4190                    }
4191                    else {
4192                            query = new StringBundler(3);
4193                    }
4194    
4195                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4196    
4197                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4198    
4199                    if (orderByComparator != null) {
4200                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4201    
4202                            if (orderByConditionFields.length > 0) {
4203                                    query.append(WHERE_AND);
4204                            }
4205    
4206                            for (int i = 0; i < orderByConditionFields.length; i++) {
4207                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4208                                    query.append(orderByConditionFields[i]);
4209    
4210                                    if ((i + 1) < orderByConditionFields.length) {
4211                                            if (orderByComparator.isAscending() ^ previous) {
4212                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4213                                            }
4214                                            else {
4215                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4216                                            }
4217                                    }
4218                                    else {
4219                                            if (orderByComparator.isAscending() ^ previous) {
4220                                                    query.append(WHERE_GREATER_THAN);
4221                                            }
4222                                            else {
4223                                                    query.append(WHERE_LESSER_THAN);
4224                                            }
4225                                    }
4226                            }
4227    
4228                            query.append(ORDER_BY_CLAUSE);
4229    
4230                            String[] orderByFields = orderByComparator.getOrderByFields();
4231    
4232                            for (int i = 0; i < orderByFields.length; i++) {
4233                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4234                                    query.append(orderByFields[i]);
4235    
4236                                    if ((i + 1) < orderByFields.length) {
4237                                            if (orderByComparator.isAscending() ^ previous) {
4238                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4239                                            }
4240                                            else {
4241                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4242                                            }
4243                                    }
4244                                    else {
4245                                            if (orderByComparator.isAscending() ^ previous) {
4246                                                    query.append(ORDER_BY_ASC);
4247                                            }
4248                                            else {
4249                                                    query.append(ORDER_BY_DESC);
4250                                            }
4251                                    }
4252                            }
4253                    }
4254                    else {
4255                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4256                    }
4257    
4258                    String sql = query.toString();
4259    
4260                    Query q = session.createQuery(sql);
4261    
4262                    q.setFirstResult(0);
4263                    q.setMaxResults(2);
4264    
4265                    QueryPos qPos = QueryPos.getInstance(q);
4266    
4267                    qPos.add(threadId);
4268    
4269                    if (orderByComparator != null) {
4270                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4271    
4272                            for (Object value : values) {
4273                                    qPos.add(value);
4274                            }
4275                    }
4276    
4277                    List<MBMessage> list = q.list();
4278    
4279                    if (list.size() == 2) {
4280                            return list.get(1);
4281                    }
4282                    else {
4283                            return null;
4284                    }
4285            }
4286    
4287            /**
4288             * Removes all the message-boards messages where threadId = &#63; from the database.
4289             *
4290             * @param threadId the thread ID
4291             */
4292            @Override
4293            public void removeByThreadReplies(long threadId) {
4294                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4295                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4296                            remove(mbMessage);
4297                    }
4298            }
4299    
4300            /**
4301             * Returns the number of message-boards messages where threadId = &#63;.
4302             *
4303             * @param threadId the thread ID
4304             * @return the number of matching message-boards messages
4305             */
4306            @Override
4307            public int countByThreadReplies(long threadId) {
4308                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4309    
4310                    Object[] finderArgs = new Object[] { threadId };
4311    
4312                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4313    
4314                    if (count == null) {
4315                            StringBundler query = new StringBundler(2);
4316    
4317                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4318    
4319                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4320    
4321                            String sql = query.toString();
4322    
4323                            Session session = null;
4324    
4325                            try {
4326                                    session = openSession();
4327    
4328                                    Query q = session.createQuery(sql);
4329    
4330                                    QueryPos qPos = QueryPos.getInstance(q);
4331    
4332                                    qPos.add(threadId);
4333    
4334                                    count = (Long)q.uniqueResult();
4335    
4336                                    finderCache.putResult(finderPath, finderArgs, count);
4337                            }
4338                            catch (Exception e) {
4339                                    finderCache.removeResult(finderPath, finderArgs);
4340    
4341                                    throw processException(e);
4342                            }
4343                            finally {
4344                                    closeSession(session);
4345                            }
4346                    }
4347    
4348                    return count.intValue();
4349            }
4350    
4351            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4352            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4353                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4354                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4355                            new String[] {
4356                                    Long.class.getName(), Long.class.getName(),
4357                                    
4358                            Integer.class.getName(), Integer.class.getName(),
4359                                    OrderByComparator.class.getName()
4360                            });
4361            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4362                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4363                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4364                            new String[] { Long.class.getName(), Long.class.getName() },
4365                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4366                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4367                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4368            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4369                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4370                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4371                            new String[] { Long.class.getName(), Long.class.getName() });
4372    
4373            /**
4374             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4375             *
4376             * @param groupId the group ID
4377             * @param userId the user ID
4378             * @return the matching message-boards messages
4379             */
4380            @Override
4381            public List<MBMessage> findByG_U(long groupId, long userId) {
4382                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4383                            null);
4384            }
4385    
4386            /**
4387             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4388             *
4389             * <p>
4390             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4391             * </p>
4392             *
4393             * @param groupId the group ID
4394             * @param userId the user ID
4395             * @param start the lower bound of the range of message-boards messages
4396             * @param end the upper bound of the range of message-boards messages (not inclusive)
4397             * @return the range of matching message-boards messages
4398             */
4399            @Override
4400            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4401                    int end) {
4402                    return findByG_U(groupId, userId, start, end, null);
4403            }
4404    
4405            /**
4406             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4407             *
4408             * <p>
4409             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4410             * </p>
4411             *
4412             * @param groupId the group ID
4413             * @param userId the user ID
4414             * @param start the lower bound of the range of message-boards messages
4415             * @param end the upper bound of the range of message-boards messages (not inclusive)
4416             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4417             * @return the ordered range of matching message-boards messages
4418             */
4419            @Override
4420            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4421                    int end, OrderByComparator<MBMessage> orderByComparator) {
4422                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
4423            }
4424    
4425            /**
4426             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4427             *
4428             * <p>
4429             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4430             * </p>
4431             *
4432             * @param groupId the group ID
4433             * @param userId the user ID
4434             * @param start the lower bound of the range of message-boards messages
4435             * @param end the upper bound of the range of message-boards messages (not inclusive)
4436             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4437             * @param retrieveFromCache whether to retrieve from the finder cache
4438             * @return the ordered range of matching message-boards messages
4439             */
4440            @Override
4441            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4442                    int end, OrderByComparator<MBMessage> orderByComparator,
4443                    boolean retrieveFromCache) {
4444                    boolean pagination = true;
4445                    FinderPath finderPath = null;
4446                    Object[] finderArgs = null;
4447    
4448                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4449                                    (orderByComparator == null)) {
4450                            pagination = false;
4451                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4452                            finderArgs = new Object[] { groupId, userId };
4453                    }
4454                    else {
4455                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4456                            finderArgs = new Object[] {
4457                                            groupId, userId,
4458                                            
4459                                            start, end, orderByComparator
4460                                    };
4461                    }
4462    
4463                    List<MBMessage> list = null;
4464    
4465                    if (retrieveFromCache) {
4466                            list = (List<MBMessage>)finderCache.getResult(finderPath,
4467                                            finderArgs, this);
4468    
4469                            if ((list != null) && !list.isEmpty()) {
4470                                    for (MBMessage mbMessage : list) {
4471                                            if ((groupId != mbMessage.getGroupId()) ||
4472                                                            (userId != mbMessage.getUserId())) {
4473                                                    list = null;
4474    
4475                                                    break;
4476                                            }
4477                                    }
4478                            }
4479                    }
4480    
4481                    if (list == null) {
4482                            StringBundler query = null;
4483    
4484                            if (orderByComparator != null) {
4485                                    query = new StringBundler(4 +
4486                                                    (orderByComparator.getOrderByFields().length * 3));
4487                            }
4488                            else {
4489                                    query = new StringBundler(4);
4490                            }
4491    
4492                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4493    
4494                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4495    
4496                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4497    
4498                            if (orderByComparator != null) {
4499                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4500                                            orderByComparator);
4501                            }
4502                            else
4503                             if (pagination) {
4504                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4505                            }
4506    
4507                            String sql = query.toString();
4508    
4509                            Session session = null;
4510    
4511                            try {
4512                                    session = openSession();
4513    
4514                                    Query q = session.createQuery(sql);
4515    
4516                                    QueryPos qPos = QueryPos.getInstance(q);
4517    
4518                                    qPos.add(groupId);
4519    
4520                                    qPos.add(userId);
4521    
4522                                    if (!pagination) {
4523                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4524                                                            start, end, false);
4525    
4526                                            Collections.sort(list);
4527    
4528                                            list = Collections.unmodifiableList(list);
4529                                    }
4530                                    else {
4531                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4532                                                            start, end);
4533                                    }
4534    
4535                                    cacheResult(list);
4536    
4537                                    finderCache.putResult(finderPath, finderArgs, list);
4538                            }
4539                            catch (Exception e) {
4540                                    finderCache.removeResult(finderPath, finderArgs);
4541    
4542                                    throw processException(e);
4543                            }
4544                            finally {
4545                                    closeSession(session);
4546                            }
4547                    }
4548    
4549                    return list;
4550            }
4551    
4552            /**
4553             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4554             *
4555             * @param groupId the group ID
4556             * @param userId the user ID
4557             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4558             * @return the first matching message-boards message
4559             * @throws NoSuchMessageException if a matching message-boards message could not be found
4560             */
4561            @Override
4562            public MBMessage findByG_U_First(long groupId, long userId,
4563                    OrderByComparator<MBMessage> orderByComparator)
4564                    throws NoSuchMessageException {
4565                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4566                                    orderByComparator);
4567    
4568                    if (mbMessage != null) {
4569                            return mbMessage;
4570                    }
4571    
4572                    StringBundler msg = new StringBundler(6);
4573    
4574                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4575    
4576                    msg.append("groupId=");
4577                    msg.append(groupId);
4578    
4579                    msg.append(", userId=");
4580                    msg.append(userId);
4581    
4582                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4583    
4584                    throw new NoSuchMessageException(msg.toString());
4585            }
4586    
4587            /**
4588             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4589             *
4590             * @param groupId the group ID
4591             * @param userId the user ID
4592             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4593             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4594             */
4595            @Override
4596            public MBMessage fetchByG_U_First(long groupId, long userId,
4597                    OrderByComparator<MBMessage> orderByComparator) {
4598                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4599                                    orderByComparator);
4600    
4601                    if (!list.isEmpty()) {
4602                            return list.get(0);
4603                    }
4604    
4605                    return null;
4606            }
4607    
4608            /**
4609             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4610             *
4611             * @param groupId the group ID
4612             * @param userId the user ID
4613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4614             * @return the last matching message-boards message
4615             * @throws NoSuchMessageException if a matching message-boards message could not be found
4616             */
4617            @Override
4618            public MBMessage findByG_U_Last(long groupId, long userId,
4619                    OrderByComparator<MBMessage> orderByComparator)
4620                    throws NoSuchMessageException {
4621                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4622    
4623                    if (mbMessage != null) {
4624                            return mbMessage;
4625                    }
4626    
4627                    StringBundler msg = new StringBundler(6);
4628    
4629                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4630    
4631                    msg.append("groupId=");
4632                    msg.append(groupId);
4633    
4634                    msg.append(", userId=");
4635                    msg.append(userId);
4636    
4637                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4638    
4639                    throw new NoSuchMessageException(msg.toString());
4640            }
4641    
4642            /**
4643             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4644             *
4645             * @param groupId the group ID
4646             * @param userId the user ID
4647             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4648             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4649             */
4650            @Override
4651            public MBMessage fetchByG_U_Last(long groupId, long userId,
4652                    OrderByComparator<MBMessage> orderByComparator) {
4653                    int count = countByG_U(groupId, userId);
4654    
4655                    if (count == 0) {
4656                            return null;
4657                    }
4658    
4659                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4660                                    orderByComparator);
4661    
4662                    if (!list.isEmpty()) {
4663                            return list.get(0);
4664                    }
4665    
4666                    return null;
4667            }
4668    
4669            /**
4670             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4671             *
4672             * @param messageId the primary key of the current message-boards message
4673             * @param groupId the group ID
4674             * @param userId the user ID
4675             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4676             * @return the previous, current, and next message-boards message
4677             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4678             */
4679            @Override
4680            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4681                    long userId, OrderByComparator<MBMessage> orderByComparator)
4682                    throws NoSuchMessageException {
4683                    MBMessage mbMessage = findByPrimaryKey(messageId);
4684    
4685                    Session session = null;
4686    
4687                    try {
4688                            session = openSession();
4689    
4690                            MBMessage[] array = new MBMessageImpl[3];
4691    
4692                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4693                                            userId, orderByComparator, true);
4694    
4695                            array[1] = mbMessage;
4696    
4697                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4698                                            userId, orderByComparator, false);
4699    
4700                            return array;
4701                    }
4702                    catch (Exception e) {
4703                            throw processException(e);
4704                    }
4705                    finally {
4706                            closeSession(session);
4707                    }
4708            }
4709    
4710            protected MBMessage getByG_U_PrevAndNext(Session session,
4711                    MBMessage mbMessage, long groupId, long userId,
4712                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4713                    StringBundler query = null;
4714    
4715                    if (orderByComparator != null) {
4716                            query = new StringBundler(6 +
4717                                            (orderByComparator.getOrderByFields().length * 6));
4718                    }
4719                    else {
4720                            query = new StringBundler(3);
4721                    }
4722    
4723                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4724    
4725                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4726    
4727                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4728    
4729                    if (orderByComparator != null) {
4730                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4731    
4732                            if (orderByConditionFields.length > 0) {
4733                                    query.append(WHERE_AND);
4734                            }
4735    
4736                            for (int i = 0; i < orderByConditionFields.length; i++) {
4737                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4738                                    query.append(orderByConditionFields[i]);
4739    
4740                                    if ((i + 1) < orderByConditionFields.length) {
4741                                            if (orderByComparator.isAscending() ^ previous) {
4742                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4743                                            }
4744                                            else {
4745                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4746                                            }
4747                                    }
4748                                    else {
4749                                            if (orderByComparator.isAscending() ^ previous) {
4750                                                    query.append(WHERE_GREATER_THAN);
4751                                            }
4752                                            else {
4753                                                    query.append(WHERE_LESSER_THAN);
4754                                            }
4755                                    }
4756                            }
4757    
4758                            query.append(ORDER_BY_CLAUSE);
4759    
4760                            String[] orderByFields = orderByComparator.getOrderByFields();
4761    
4762                            for (int i = 0; i < orderByFields.length; i++) {
4763                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4764                                    query.append(orderByFields[i]);
4765    
4766                                    if ((i + 1) < orderByFields.length) {
4767                                            if (orderByComparator.isAscending() ^ previous) {
4768                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4769                                            }
4770                                            else {
4771                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4772                                            }
4773                                    }
4774                                    else {
4775                                            if (orderByComparator.isAscending() ^ previous) {
4776                                                    query.append(ORDER_BY_ASC);
4777                                            }
4778                                            else {
4779                                                    query.append(ORDER_BY_DESC);
4780                                            }
4781                                    }
4782                            }
4783                    }
4784                    else {
4785                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4786                    }
4787    
4788                    String sql = query.toString();
4789    
4790                    Query q = session.createQuery(sql);
4791    
4792                    q.setFirstResult(0);
4793                    q.setMaxResults(2);
4794    
4795                    QueryPos qPos = QueryPos.getInstance(q);
4796    
4797                    qPos.add(groupId);
4798    
4799                    qPos.add(userId);
4800    
4801                    if (orderByComparator != null) {
4802                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4803    
4804                            for (Object value : values) {
4805                                    qPos.add(value);
4806                            }
4807                    }
4808    
4809                    List<MBMessage> list = q.list();
4810    
4811                    if (list.size() == 2) {
4812                            return list.get(1);
4813                    }
4814                    else {
4815                            return null;
4816                    }
4817            }
4818    
4819            /**
4820             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4821             *
4822             * @param groupId the group ID
4823             * @param userId the user ID
4824             * @return the matching message-boards messages that the user has permission to view
4825             */
4826            @Override
4827            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4828                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4829                            QueryUtil.ALL_POS, null);
4830            }
4831    
4832            /**
4833             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4834             *
4835             * <p>
4836             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4837             * </p>
4838             *
4839             * @param groupId the group ID
4840             * @param userId the user ID
4841             * @param start the lower bound of the range of message-boards messages
4842             * @param end the upper bound of the range of message-boards messages (not inclusive)
4843             * @return the range of matching message-boards messages that the user has permission to view
4844             */
4845            @Override
4846            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4847                    int start, int end) {
4848                    return filterFindByG_U(groupId, userId, start, end, null);
4849            }
4850    
4851            /**
4852             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4853             *
4854             * <p>
4855             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4856             * </p>
4857             *
4858             * @param groupId the group ID
4859             * @param userId the user ID
4860             * @param start the lower bound of the range of message-boards messages
4861             * @param end the upper bound of the range of message-boards messages (not inclusive)
4862             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4863             * @return the ordered range of matching message-boards messages that the user has permission to view
4864             */
4865            @Override
4866            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4867                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4868                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4869                            return findByG_U(groupId, userId, start, end, orderByComparator);
4870                    }
4871    
4872                    StringBundler query = null;
4873    
4874                    if (orderByComparator != null) {
4875                            query = new StringBundler(4 +
4876                                            (orderByComparator.getOrderByFields().length * 3));
4877                    }
4878                    else {
4879                            query = new StringBundler(4);
4880                    }
4881    
4882                    if (getDB().isSupportsInlineDistinct()) {
4883                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4884                    }
4885                    else {
4886                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4887                    }
4888    
4889                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4890    
4891                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4892    
4893                    if (!getDB().isSupportsInlineDistinct()) {
4894                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4895                    }
4896    
4897                    if (orderByComparator != null) {
4898                            if (getDB().isSupportsInlineDistinct()) {
4899                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4900                                            orderByComparator, true);
4901                            }
4902                            else {
4903                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4904                                            orderByComparator, true);
4905                            }
4906                    }
4907                    else {
4908                            if (getDB().isSupportsInlineDistinct()) {
4909                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4910                            }
4911                            else {
4912                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4913                            }
4914                    }
4915    
4916                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4917                                    MBMessage.class.getName(),
4918                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4919    
4920                    Session session = null;
4921    
4922                    try {
4923                            session = openSession();
4924    
4925                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4926    
4927                            if (getDB().isSupportsInlineDistinct()) {
4928                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4929                            }
4930                            else {
4931                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4932                            }
4933    
4934                            QueryPos qPos = QueryPos.getInstance(q);
4935    
4936                            qPos.add(groupId);
4937    
4938                            qPos.add(userId);
4939    
4940                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4941                    }
4942                    catch (Exception e) {
4943                            throw processException(e);
4944                    }
4945                    finally {
4946                            closeSession(session);
4947                    }
4948            }
4949    
4950            /**
4951             * 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;.
4952             *
4953             * @param messageId the primary key of the current message-boards message
4954             * @param groupId the group ID
4955             * @param userId the user ID
4956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4957             * @return the previous, current, and next message-boards message
4958             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4959             */
4960            @Override
4961            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4962                    long groupId, long userId,
4963                    OrderByComparator<MBMessage> orderByComparator)
4964                    throws NoSuchMessageException {
4965                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4966                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4967                                    orderByComparator);
4968                    }
4969    
4970                    MBMessage mbMessage = findByPrimaryKey(messageId);
4971    
4972                    Session session = null;
4973    
4974                    try {
4975                            session = openSession();
4976    
4977                            MBMessage[] array = new MBMessageImpl[3];
4978    
4979                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4980                                            userId, orderByComparator, true);
4981    
4982                            array[1] = mbMessage;
4983    
4984                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4985                                            userId, orderByComparator, false);
4986    
4987                            return array;
4988                    }
4989                    catch (Exception e) {
4990                            throw processException(e);
4991                    }
4992                    finally {
4993                            closeSession(session);
4994                    }
4995            }
4996    
4997            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4998                    MBMessage mbMessage, long groupId, long userId,
4999                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5000                    StringBundler query = null;
5001    
5002                    if (orderByComparator != null) {
5003                            query = new StringBundler(6 +
5004                                            (orderByComparator.getOrderByFields().length * 6));
5005                    }
5006                    else {
5007                            query = new StringBundler(3);
5008                    }
5009    
5010                    if (getDB().isSupportsInlineDistinct()) {
5011                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5012                    }
5013                    else {
5014                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5015                    }
5016    
5017                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5018    
5019                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5020    
5021                    if (!getDB().isSupportsInlineDistinct()) {
5022                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5023                    }
5024    
5025                    if (orderByComparator != null) {
5026                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5027    
5028                            if (orderByConditionFields.length > 0) {
5029                                    query.append(WHERE_AND);
5030                            }
5031    
5032                            for (int i = 0; i < orderByConditionFields.length; i++) {
5033                                    if (getDB().isSupportsInlineDistinct()) {
5034                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5035                                    }
5036                                    else {
5037                                            query.append(_ORDER_BY_ENTITY_TABLE);
5038                                    }
5039    
5040                                    query.append(orderByConditionFields[i]);
5041    
5042                                    if ((i + 1) < orderByConditionFields.length) {
5043                                            if (orderByComparator.isAscending() ^ previous) {
5044                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5045                                            }
5046                                            else {
5047                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5048                                            }
5049                                    }
5050                                    else {
5051                                            if (orderByComparator.isAscending() ^ previous) {
5052                                                    query.append(WHERE_GREATER_THAN);
5053                                            }
5054                                            else {
5055                                                    query.append(WHERE_LESSER_THAN);
5056                                            }
5057                                    }
5058                            }
5059    
5060                            query.append(ORDER_BY_CLAUSE);
5061    
5062                            String[] orderByFields = orderByComparator.getOrderByFields();
5063    
5064                            for (int i = 0; i < orderByFields.length; i++) {
5065                                    if (getDB().isSupportsInlineDistinct()) {
5066                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5067                                    }
5068                                    else {
5069                                            query.append(_ORDER_BY_ENTITY_TABLE);
5070                                    }
5071    
5072                                    query.append(orderByFields[i]);
5073    
5074                                    if ((i + 1) < orderByFields.length) {
5075                                            if (orderByComparator.isAscending() ^ previous) {
5076                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5077                                            }
5078                                            else {
5079                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5080                                            }
5081                                    }
5082                                    else {
5083                                            if (orderByComparator.isAscending() ^ previous) {
5084                                                    query.append(ORDER_BY_ASC);
5085                                            }
5086                                            else {
5087                                                    query.append(ORDER_BY_DESC);
5088                                            }
5089                                    }
5090                            }
5091                    }
5092                    else {
5093                            if (getDB().isSupportsInlineDistinct()) {
5094                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5095                            }
5096                            else {
5097                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5098                            }
5099                    }
5100    
5101                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5102                                    MBMessage.class.getName(),
5103                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5104    
5105                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5106    
5107                    q.setFirstResult(0);
5108                    q.setMaxResults(2);
5109    
5110                    if (getDB().isSupportsInlineDistinct()) {
5111                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5112                    }
5113                    else {
5114                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5115                    }
5116    
5117                    QueryPos qPos = QueryPos.getInstance(q);
5118    
5119                    qPos.add(groupId);
5120    
5121                    qPos.add(userId);
5122    
5123                    if (orderByComparator != null) {
5124                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5125    
5126                            for (Object value : values) {
5127                                    qPos.add(value);
5128                            }
5129                    }
5130    
5131                    List<MBMessage> list = q.list();
5132    
5133                    if (list.size() == 2) {
5134                            return list.get(1);
5135                    }
5136                    else {
5137                            return null;
5138                    }
5139            }
5140    
5141            /**
5142             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5143             *
5144             * @param groupId the group ID
5145             * @param userId the user ID
5146             */
5147            @Override
5148            public void removeByG_U(long groupId, long userId) {
5149                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5150                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5151                            remove(mbMessage);
5152                    }
5153            }
5154    
5155            /**
5156             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5157             *
5158             * @param groupId the group ID
5159             * @param userId the user ID
5160             * @return the number of matching message-boards messages
5161             */
5162            @Override
5163            public int countByG_U(long groupId, long userId) {
5164                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5165    
5166                    Object[] finderArgs = new Object[] { groupId, userId };
5167    
5168                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5169    
5170                    if (count == null) {
5171                            StringBundler query = new StringBundler(3);
5172    
5173                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5174    
5175                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5176    
5177                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5178    
5179                            String sql = query.toString();
5180    
5181                            Session session = null;
5182    
5183                            try {
5184                                    session = openSession();
5185    
5186                                    Query q = session.createQuery(sql);
5187    
5188                                    QueryPos qPos = QueryPos.getInstance(q);
5189    
5190                                    qPos.add(groupId);
5191    
5192                                    qPos.add(userId);
5193    
5194                                    count = (Long)q.uniqueResult();
5195    
5196                                    finderCache.putResult(finderPath, finderArgs, count);
5197                            }
5198                            catch (Exception e) {
5199                                    finderCache.removeResult(finderPath, finderArgs);
5200    
5201                                    throw processException(e);
5202                            }
5203                            finally {
5204                                    closeSession(session);
5205                            }
5206                    }
5207    
5208                    return count.intValue();
5209            }
5210    
5211            /**
5212             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5213             *
5214             * @param groupId the group ID
5215             * @param userId the user ID
5216             * @return the number of matching message-boards messages that the user has permission to view
5217             */
5218            @Override
5219            public int filterCountByG_U(long groupId, long userId) {
5220                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5221                            return countByG_U(groupId, userId);
5222                    }
5223    
5224                    StringBundler query = new StringBundler(3);
5225    
5226                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5227    
5228                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5229    
5230                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5231    
5232                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5233                                    MBMessage.class.getName(),
5234                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5235    
5236                    Session session = null;
5237    
5238                    try {
5239                            session = openSession();
5240    
5241                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5242    
5243                            q.addScalar(COUNT_COLUMN_NAME,
5244                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5245    
5246                            QueryPos qPos = QueryPos.getInstance(q);
5247    
5248                            qPos.add(groupId);
5249    
5250                            qPos.add(userId);
5251    
5252                            Long count = (Long)q.uniqueResult();
5253    
5254                            return count.intValue();
5255                    }
5256                    catch (Exception e) {
5257                            throw processException(e);
5258                    }
5259                    finally {
5260                            closeSession(session);
5261                    }
5262            }
5263    
5264            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5265            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5266            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5267                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5268                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5269                            new String[] {
5270                                    Long.class.getName(), Long.class.getName(),
5271                                    
5272                            Integer.class.getName(), Integer.class.getName(),
5273                                    OrderByComparator.class.getName()
5274                            });
5275            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5276                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5277                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5278                            new String[] { Long.class.getName(), Long.class.getName() },
5279                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5280                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5281                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5282            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5283                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5284                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5285                            new String[] { Long.class.getName(), Long.class.getName() });
5286    
5287            /**
5288             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5289             *
5290             * @param groupId the group ID
5291             * @param categoryId the category ID
5292             * @return the matching message-boards messages
5293             */
5294            @Override
5295            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5296                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5297                            QueryUtil.ALL_POS, null);
5298            }
5299    
5300            /**
5301             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5302             *
5303             * <p>
5304             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5305             * </p>
5306             *
5307             * @param groupId the group ID
5308             * @param categoryId the category ID
5309             * @param start the lower bound of the range of message-boards messages
5310             * @param end the upper bound of the range of message-boards messages (not inclusive)
5311             * @return the range of matching message-boards messages
5312             */
5313            @Override
5314            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5315                    int end) {
5316                    return findByG_C(groupId, categoryId, start, end, null);
5317            }
5318    
5319            /**
5320             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5321             *
5322             * <p>
5323             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5324             * </p>
5325             *
5326             * @param groupId the group ID
5327             * @param categoryId the category ID
5328             * @param start the lower bound of the range of message-boards messages
5329             * @param end the upper bound of the range of message-boards messages (not inclusive)
5330             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5331             * @return the ordered range of matching message-boards messages
5332             */
5333            @Override
5334            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5335                    int end, OrderByComparator<MBMessage> orderByComparator) {
5336                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
5337                            true);
5338            }
5339    
5340            /**
5341             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5342             *
5343             * <p>
5344             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5345             * </p>
5346             *
5347             * @param groupId the group ID
5348             * @param categoryId the category ID
5349             * @param start the lower bound of the range of message-boards messages
5350             * @param end the upper bound of the range of message-boards messages (not inclusive)
5351             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5352             * @param retrieveFromCache whether to retrieve from the finder cache
5353             * @return the ordered range of matching message-boards messages
5354             */
5355            @Override
5356            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5357                    int end, OrderByComparator<MBMessage> orderByComparator,
5358                    boolean retrieveFromCache) {
5359                    boolean pagination = true;
5360                    FinderPath finderPath = null;
5361                    Object[] finderArgs = null;
5362    
5363                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5364                                    (orderByComparator == null)) {
5365                            pagination = false;
5366                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5367                            finderArgs = new Object[] { groupId, categoryId };
5368                    }
5369                    else {
5370                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5371                            finderArgs = new Object[] {
5372                                            groupId, categoryId,
5373                                            
5374                                            start, end, orderByComparator
5375                                    };
5376                    }
5377    
5378                    List<MBMessage> list = null;
5379    
5380                    if (retrieveFromCache) {
5381                            list = (List<MBMessage>)finderCache.getResult(finderPath,
5382                                            finderArgs, this);
5383    
5384                            if ((list != null) && !list.isEmpty()) {
5385                                    for (MBMessage mbMessage : list) {
5386                                            if ((groupId != mbMessage.getGroupId()) ||
5387                                                            (categoryId != mbMessage.getCategoryId())) {
5388                                                    list = null;
5389    
5390                                                    break;
5391                                            }
5392                                    }
5393                            }
5394                    }
5395    
5396                    if (list == null) {
5397                            StringBundler query = null;
5398    
5399                            if (orderByComparator != null) {
5400                                    query = new StringBundler(4 +
5401                                                    (orderByComparator.getOrderByFields().length * 3));
5402                            }
5403                            else {
5404                                    query = new StringBundler(4);
5405                            }
5406    
5407                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5408    
5409                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5410    
5411                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5412    
5413                            if (orderByComparator != null) {
5414                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5415                                            orderByComparator);
5416                            }
5417                            else
5418                             if (pagination) {
5419                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5420                            }
5421    
5422                            String sql = query.toString();
5423    
5424                            Session session = null;
5425    
5426                            try {
5427                                    session = openSession();
5428    
5429                                    Query q = session.createQuery(sql);
5430    
5431                                    QueryPos qPos = QueryPos.getInstance(q);
5432    
5433                                    qPos.add(groupId);
5434    
5435                                    qPos.add(categoryId);
5436    
5437                                    if (!pagination) {
5438                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5439                                                            start, end, false);
5440    
5441                                            Collections.sort(list);
5442    
5443                                            list = Collections.unmodifiableList(list);
5444                                    }
5445                                    else {
5446                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5447                                                            start, end);
5448                                    }
5449    
5450                                    cacheResult(list);
5451    
5452                                    finderCache.putResult(finderPath, finderArgs, list);
5453                            }
5454                            catch (Exception e) {
5455                                    finderCache.removeResult(finderPath, finderArgs);
5456    
5457                                    throw processException(e);
5458                            }
5459                            finally {
5460                                    closeSession(session);
5461                            }
5462                    }
5463    
5464                    return list;
5465            }
5466    
5467            /**
5468             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5469             *
5470             * @param groupId the group ID
5471             * @param categoryId the category ID
5472             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5473             * @return the first matching message-boards message
5474             * @throws NoSuchMessageException if a matching message-boards message could not be found
5475             */
5476            @Override
5477            public MBMessage findByG_C_First(long groupId, long categoryId,
5478                    OrderByComparator<MBMessage> orderByComparator)
5479                    throws NoSuchMessageException {
5480                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5481                                    orderByComparator);
5482    
5483                    if (mbMessage != null) {
5484                            return mbMessage;
5485                    }
5486    
5487                    StringBundler msg = new StringBundler(6);
5488    
5489                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5490    
5491                    msg.append("groupId=");
5492                    msg.append(groupId);
5493    
5494                    msg.append(", categoryId=");
5495                    msg.append(categoryId);
5496    
5497                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5498    
5499                    throw new NoSuchMessageException(msg.toString());
5500            }
5501    
5502            /**
5503             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5504             *
5505             * @param groupId the group ID
5506             * @param categoryId the category ID
5507             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5508             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5509             */
5510            @Override
5511            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5512                    OrderByComparator<MBMessage> orderByComparator) {
5513                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5514                                    orderByComparator);
5515    
5516                    if (!list.isEmpty()) {
5517                            return list.get(0);
5518                    }
5519    
5520                    return null;
5521            }
5522    
5523            /**
5524             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5525             *
5526             * @param groupId the group ID
5527             * @param categoryId the category ID
5528             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5529             * @return the last matching message-boards message
5530             * @throws NoSuchMessageException if a matching message-boards message could not be found
5531             */
5532            @Override
5533            public MBMessage findByG_C_Last(long groupId, long categoryId,
5534                    OrderByComparator<MBMessage> orderByComparator)
5535                    throws NoSuchMessageException {
5536                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5537                                    orderByComparator);
5538    
5539                    if (mbMessage != null) {
5540                            return mbMessage;
5541                    }
5542    
5543                    StringBundler msg = new StringBundler(6);
5544    
5545                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5546    
5547                    msg.append("groupId=");
5548                    msg.append(groupId);
5549    
5550                    msg.append(", categoryId=");
5551                    msg.append(categoryId);
5552    
5553                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5554    
5555                    throw new NoSuchMessageException(msg.toString());
5556            }
5557    
5558            /**
5559             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5560             *
5561             * @param groupId the group ID
5562             * @param categoryId the category ID
5563             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5564             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5565             */
5566            @Override
5567            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5568                    OrderByComparator<MBMessage> orderByComparator) {
5569                    int count = countByG_C(groupId, categoryId);
5570    
5571                    if (count == 0) {
5572                            return null;
5573                    }
5574    
5575                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5576                                    orderByComparator);
5577    
5578                    if (!list.isEmpty()) {
5579                            return list.get(0);
5580                    }
5581    
5582                    return null;
5583            }
5584    
5585            /**
5586             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5587             *
5588             * @param messageId the primary key of the current message-boards message
5589             * @param groupId the group ID
5590             * @param categoryId the category ID
5591             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5592             * @return the previous, current, and next message-boards message
5593             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5594             */
5595            @Override
5596            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5597                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5598                    throws NoSuchMessageException {
5599                    MBMessage mbMessage = findByPrimaryKey(messageId);
5600    
5601                    Session session = null;
5602    
5603                    try {
5604                            session = openSession();
5605    
5606                            MBMessage[] array = new MBMessageImpl[3];
5607    
5608                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5609                                            categoryId, orderByComparator, true);
5610    
5611                            array[1] = mbMessage;
5612    
5613                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5614                                            categoryId, orderByComparator, false);
5615    
5616                            return array;
5617                    }
5618                    catch (Exception e) {
5619                            throw processException(e);
5620                    }
5621                    finally {
5622                            closeSession(session);
5623                    }
5624            }
5625    
5626            protected MBMessage getByG_C_PrevAndNext(Session session,
5627                    MBMessage mbMessage, long groupId, long categoryId,
5628                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5629                    StringBundler query = null;
5630    
5631                    if (orderByComparator != null) {
5632                            query = new StringBundler(6 +
5633                                            (orderByComparator.getOrderByFields().length * 6));
5634                    }
5635                    else {
5636                            query = new StringBundler(3);
5637                    }
5638    
5639                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5640    
5641                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5642    
5643                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5644    
5645                    if (orderByComparator != null) {
5646                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5647    
5648                            if (orderByConditionFields.length > 0) {
5649                                    query.append(WHERE_AND);
5650                            }
5651    
5652                            for (int i = 0; i < orderByConditionFields.length; i++) {
5653                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5654                                    query.append(orderByConditionFields[i]);
5655    
5656                                    if ((i + 1) < orderByConditionFields.length) {
5657                                            if (orderByComparator.isAscending() ^ previous) {
5658                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5659                                            }
5660                                            else {
5661                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5662                                            }
5663                                    }
5664                                    else {
5665                                            if (orderByComparator.isAscending() ^ previous) {
5666                                                    query.append(WHERE_GREATER_THAN);
5667                                            }
5668                                            else {
5669                                                    query.append(WHERE_LESSER_THAN);
5670                                            }
5671                                    }
5672                            }
5673    
5674                            query.append(ORDER_BY_CLAUSE);
5675    
5676                            String[] orderByFields = orderByComparator.getOrderByFields();
5677    
5678                            for (int i = 0; i < orderByFields.length; i++) {
5679                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5680                                    query.append(orderByFields[i]);
5681    
5682                                    if ((i + 1) < orderByFields.length) {
5683                                            if (orderByComparator.isAscending() ^ previous) {
5684                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5685                                            }
5686                                            else {
5687                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5688                                            }
5689                                    }
5690                                    else {
5691                                            if (orderByComparator.isAscending() ^ previous) {
5692                                                    query.append(ORDER_BY_ASC);
5693                                            }
5694                                            else {
5695                                                    query.append(ORDER_BY_DESC);
5696                                            }
5697                                    }
5698                            }
5699                    }
5700                    else {
5701                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5702                    }
5703    
5704                    String sql = query.toString();
5705    
5706                    Query q = session.createQuery(sql);
5707    
5708                    q.setFirstResult(0);
5709                    q.setMaxResults(2);
5710    
5711                    QueryPos qPos = QueryPos.getInstance(q);
5712    
5713                    qPos.add(groupId);
5714    
5715                    qPos.add(categoryId);
5716    
5717                    if (orderByComparator != null) {
5718                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5719    
5720                            for (Object value : values) {
5721                                    qPos.add(value);
5722                            }
5723                    }
5724    
5725                    List<MBMessage> list = q.list();
5726    
5727                    if (list.size() == 2) {
5728                            return list.get(1);
5729                    }
5730                    else {
5731                            return null;
5732                    }
5733            }
5734    
5735            /**
5736             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5737             *
5738             * @param groupId the group ID
5739             * @param categoryId the category ID
5740             * @return the matching message-boards messages that the user has permission to view
5741             */
5742            @Override
5743            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5744                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5745                            QueryUtil.ALL_POS, null);
5746            }
5747    
5748            /**
5749             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5750             *
5751             * <p>
5752             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5753             * </p>
5754             *
5755             * @param groupId the group ID
5756             * @param categoryId the category ID
5757             * @param start the lower bound of the range of message-boards messages
5758             * @param end the upper bound of the range of message-boards messages (not inclusive)
5759             * @return the range of matching message-boards messages that the user has permission to view
5760             */
5761            @Override
5762            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5763                    int start, int end) {
5764                    return filterFindByG_C(groupId, categoryId, start, end, null);
5765            }
5766    
5767            /**
5768             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5769             *
5770             * <p>
5771             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5772             * </p>
5773             *
5774             * @param groupId the group ID
5775             * @param categoryId the category ID
5776             * @param start the lower bound of the range of message-boards messages
5777             * @param end the upper bound of the range of message-boards messages (not inclusive)
5778             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5779             * @return the ordered range of matching message-boards messages that the user has permission to view
5780             */
5781            @Override
5782            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5783                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5784                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5785                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5786                    }
5787    
5788                    StringBundler query = null;
5789    
5790                    if (orderByComparator != null) {
5791                            query = new StringBundler(4 +
5792                                            (orderByComparator.getOrderByFields().length * 3));
5793                    }
5794                    else {
5795                            query = new StringBundler(4);
5796                    }
5797    
5798                    if (getDB().isSupportsInlineDistinct()) {
5799                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5800                    }
5801                    else {
5802                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5803                    }
5804    
5805                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5806    
5807                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5808    
5809                    if (!getDB().isSupportsInlineDistinct()) {
5810                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5811                    }
5812    
5813                    if (orderByComparator != null) {
5814                            if (getDB().isSupportsInlineDistinct()) {
5815                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5816                                            orderByComparator, true);
5817                            }
5818                            else {
5819                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5820                                            orderByComparator, true);
5821                            }
5822                    }
5823                    else {
5824                            if (getDB().isSupportsInlineDistinct()) {
5825                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5826                            }
5827                            else {
5828                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5829                            }
5830                    }
5831    
5832                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5833                                    MBMessage.class.getName(),
5834                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5835    
5836                    Session session = null;
5837    
5838                    try {
5839                            session = openSession();
5840    
5841                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5842    
5843                            if (getDB().isSupportsInlineDistinct()) {
5844                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5845                            }
5846                            else {
5847                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5848                            }
5849    
5850                            QueryPos qPos = QueryPos.getInstance(q);
5851    
5852                            qPos.add(groupId);
5853    
5854                            qPos.add(categoryId);
5855    
5856                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5857                    }
5858                    catch (Exception e) {
5859                            throw processException(e);
5860                    }
5861                    finally {
5862                            closeSession(session);
5863                    }
5864            }
5865    
5866            /**
5867             * 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;.
5868             *
5869             * @param messageId the primary key of the current message-boards message
5870             * @param groupId the group ID
5871             * @param categoryId the category ID
5872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5873             * @return the previous, current, and next message-boards message
5874             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5875             */
5876            @Override
5877            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5878                    long groupId, long categoryId,
5879                    OrderByComparator<MBMessage> orderByComparator)
5880                    throws NoSuchMessageException {
5881                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5882                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5883                                    orderByComparator);
5884                    }
5885    
5886                    MBMessage mbMessage = findByPrimaryKey(messageId);
5887    
5888                    Session session = null;
5889    
5890                    try {
5891                            session = openSession();
5892    
5893                            MBMessage[] array = new MBMessageImpl[3];
5894    
5895                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5896                                            categoryId, orderByComparator, true);
5897    
5898                            array[1] = mbMessage;
5899    
5900                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5901                                            categoryId, orderByComparator, false);
5902    
5903                            return array;
5904                    }
5905                    catch (Exception e) {
5906                            throw processException(e);
5907                    }
5908                    finally {
5909                            closeSession(session);
5910                    }
5911            }
5912    
5913            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5914                    MBMessage mbMessage, long groupId, long categoryId,
5915                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5916                    StringBundler query = null;
5917    
5918                    if (orderByComparator != null) {
5919                            query = new StringBundler(6 +
5920                                            (orderByComparator.getOrderByFields().length * 6));
5921                    }
5922                    else {
5923                            query = new StringBundler(3);
5924                    }
5925    
5926                    if (getDB().isSupportsInlineDistinct()) {
5927                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5928                    }
5929                    else {
5930                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5931                    }
5932    
5933                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5934    
5935                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5936    
5937                    if (!getDB().isSupportsInlineDistinct()) {
5938                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5939                    }
5940    
5941                    if (orderByComparator != null) {
5942                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5943    
5944                            if (orderByConditionFields.length > 0) {
5945                                    query.append(WHERE_AND);
5946                            }
5947    
5948                            for (int i = 0; i < orderByConditionFields.length; i++) {
5949                                    if (getDB().isSupportsInlineDistinct()) {
5950                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5951                                    }
5952                                    else {
5953                                            query.append(_ORDER_BY_ENTITY_TABLE);
5954                                    }
5955    
5956                                    query.append(orderByConditionFields[i]);
5957    
5958                                    if ((i + 1) < orderByConditionFields.length) {
5959                                            if (orderByComparator.isAscending() ^ previous) {
5960                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5961                                            }
5962                                            else {
5963                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5964                                            }
5965                                    }
5966                                    else {
5967                                            if (orderByComparator.isAscending() ^ previous) {
5968                                                    query.append(WHERE_GREATER_THAN);
5969                                            }
5970                                            else {
5971                                                    query.append(WHERE_LESSER_THAN);
5972                                            }
5973                                    }
5974                            }
5975    
5976                            query.append(ORDER_BY_CLAUSE);
5977    
5978                            String[] orderByFields = orderByComparator.getOrderByFields();
5979    
5980                            for (int i = 0; i < orderByFields.length; i++) {
5981                                    if (getDB().isSupportsInlineDistinct()) {
5982                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5983                                    }
5984                                    else {
5985                                            query.append(_ORDER_BY_ENTITY_TABLE);
5986                                    }
5987    
5988                                    query.append(orderByFields[i]);
5989    
5990                                    if ((i + 1) < orderByFields.length) {
5991                                            if (orderByComparator.isAscending() ^ previous) {
5992                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5993                                            }
5994                                            else {
5995                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5996                                            }
5997                                    }
5998                                    else {
5999                                            if (orderByComparator.isAscending() ^ previous) {
6000                                                    query.append(ORDER_BY_ASC);
6001                                            }
6002                                            else {
6003                                                    query.append(ORDER_BY_DESC);
6004                                            }
6005                                    }
6006                            }
6007                    }
6008                    else {
6009                            if (getDB().isSupportsInlineDistinct()) {
6010                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6011                            }
6012                            else {
6013                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6014                            }
6015                    }
6016    
6017                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6018                                    MBMessage.class.getName(),
6019                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6020    
6021                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6022    
6023                    q.setFirstResult(0);
6024                    q.setMaxResults(2);
6025    
6026                    if (getDB().isSupportsInlineDistinct()) {
6027                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6028                    }
6029                    else {
6030                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6031                    }
6032    
6033                    QueryPos qPos = QueryPos.getInstance(q);
6034    
6035                    qPos.add(groupId);
6036    
6037                    qPos.add(categoryId);
6038    
6039                    if (orderByComparator != null) {
6040                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6041    
6042                            for (Object value : values) {
6043                                    qPos.add(value);
6044                            }
6045                    }
6046    
6047                    List<MBMessage> list = q.list();
6048    
6049                    if (list.size() == 2) {
6050                            return list.get(1);
6051                    }
6052                    else {
6053                            return null;
6054                    }
6055            }
6056    
6057            /**
6058             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
6059             *
6060             * @param groupId the group ID
6061             * @param categoryId the category ID
6062             */
6063            @Override
6064            public void removeByG_C(long groupId, long categoryId) {
6065                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
6066                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6067                            remove(mbMessage);
6068                    }
6069            }
6070    
6071            /**
6072             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
6073             *
6074             * @param groupId the group ID
6075             * @param categoryId the category ID
6076             * @return the number of matching message-boards messages
6077             */
6078            @Override
6079            public int countByG_C(long groupId, long categoryId) {
6080                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6081    
6082                    Object[] finderArgs = new Object[] { groupId, categoryId };
6083    
6084                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6085    
6086                    if (count == null) {
6087                            StringBundler query = new StringBundler(3);
6088    
6089                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6090    
6091                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6092    
6093                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6094    
6095                            String sql = query.toString();
6096    
6097                            Session session = null;
6098    
6099                            try {
6100                                    session = openSession();
6101    
6102                                    Query q = session.createQuery(sql);
6103    
6104                                    QueryPos qPos = QueryPos.getInstance(q);
6105    
6106                                    qPos.add(groupId);
6107    
6108                                    qPos.add(categoryId);
6109    
6110                                    count = (Long)q.uniqueResult();
6111    
6112                                    finderCache.putResult(finderPath, finderArgs, count);
6113                            }
6114                            catch (Exception e) {
6115                                    finderCache.removeResult(finderPath, finderArgs);
6116    
6117                                    throw processException(e);
6118                            }
6119                            finally {
6120                                    closeSession(session);
6121                            }
6122                    }
6123    
6124                    return count.intValue();
6125            }
6126    
6127            /**
6128             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6129             *
6130             * @param groupId the group ID
6131             * @param categoryId the category ID
6132             * @return the number of matching message-boards messages that the user has permission to view
6133             */
6134            @Override
6135            public int filterCountByG_C(long groupId, long categoryId) {
6136                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6137                            return countByG_C(groupId, categoryId);
6138                    }
6139    
6140                    StringBundler query = new StringBundler(3);
6141    
6142                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6143    
6144                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6145    
6146                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6147    
6148                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6149                                    MBMessage.class.getName(),
6150                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6151    
6152                    Session session = null;
6153    
6154                    try {
6155                            session = openSession();
6156    
6157                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6158    
6159                            q.addScalar(COUNT_COLUMN_NAME,
6160                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6161    
6162                            QueryPos qPos = QueryPos.getInstance(q);
6163    
6164                            qPos.add(groupId);
6165    
6166                            qPos.add(categoryId);
6167    
6168                            Long count = (Long)q.uniqueResult();
6169    
6170                            return count.intValue();
6171                    }
6172                    catch (Exception e) {
6173                            throw processException(e);
6174                    }
6175                    finally {
6176                            closeSession(session);
6177                    }
6178            }
6179    
6180            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6181            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6182            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6183                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6184                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6185                            new String[] {
6186                                    Long.class.getName(), Integer.class.getName(),
6187                                    
6188                            Integer.class.getName(), Integer.class.getName(),
6189                                    OrderByComparator.class.getName()
6190                            });
6191            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6192                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6193                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6194                            new String[] { Long.class.getName(), Integer.class.getName() },
6195                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6196                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6197                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6198            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6199                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6201                            new String[] { Long.class.getName(), Integer.class.getName() });
6202    
6203            /**
6204             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6205             *
6206             * @param groupId the group ID
6207             * @param status the status
6208             * @return the matching message-boards messages
6209             */
6210            @Override
6211            public List<MBMessage> findByG_S(long groupId, int status) {
6212                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6213                            null);
6214            }
6215    
6216            /**
6217             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6218             *
6219             * <p>
6220             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6221             * </p>
6222             *
6223             * @param groupId the group ID
6224             * @param status the status
6225             * @param start the lower bound of the range of message-boards messages
6226             * @param end the upper bound of the range of message-boards messages (not inclusive)
6227             * @return the range of matching message-boards messages
6228             */
6229            @Override
6230            public List<MBMessage> findByG_S(long groupId, int status, int start,
6231                    int end) {
6232                    return findByG_S(groupId, status, start, end, null);
6233            }
6234    
6235            /**
6236             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6237             *
6238             * <p>
6239             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6240             * </p>
6241             *
6242             * @param groupId the group ID
6243             * @param status the status
6244             * @param start the lower bound of the range of message-boards messages
6245             * @param end the upper bound of the range of message-boards messages (not inclusive)
6246             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6247             * @return the ordered range of matching message-boards messages
6248             */
6249            @Override
6250            public List<MBMessage> findByG_S(long groupId, int status, int start,
6251                    int end, OrderByComparator<MBMessage> orderByComparator) {
6252                    return findByG_S(groupId, status, start, end, orderByComparator, true);
6253            }
6254    
6255            /**
6256             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6257             *
6258             * <p>
6259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6260             * </p>
6261             *
6262             * @param groupId the group ID
6263             * @param status the status
6264             * @param start the lower bound of the range of message-boards messages
6265             * @param end the upper bound of the range of message-boards messages (not inclusive)
6266             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6267             * @param retrieveFromCache whether to retrieve from the finder cache
6268             * @return the ordered range of matching message-boards messages
6269             */
6270            @Override
6271            public List<MBMessage> findByG_S(long groupId, int status, int start,
6272                    int end, OrderByComparator<MBMessage> orderByComparator,
6273                    boolean retrieveFromCache) {
6274                    boolean pagination = true;
6275                    FinderPath finderPath = null;
6276                    Object[] finderArgs = null;
6277    
6278                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6279                                    (orderByComparator == null)) {
6280                            pagination = false;
6281                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6282                            finderArgs = new Object[] { groupId, status };
6283                    }
6284                    else {
6285                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6286                            finderArgs = new Object[] {
6287                                            groupId, status,
6288                                            
6289                                            start, end, orderByComparator
6290                                    };
6291                    }
6292    
6293                    List<MBMessage> list = null;
6294    
6295                    if (retrieveFromCache) {
6296                            list = (List<MBMessage>)finderCache.getResult(finderPath,
6297                                            finderArgs, this);
6298    
6299                            if ((list != null) && !list.isEmpty()) {
6300                                    for (MBMessage mbMessage : list) {
6301                                            if ((groupId != mbMessage.getGroupId()) ||
6302                                                            (status != mbMessage.getStatus())) {
6303                                                    list = null;
6304    
6305                                                    break;
6306                                            }
6307                                    }
6308                            }
6309                    }
6310    
6311                    if (list == null) {
6312                            StringBundler query = null;
6313    
6314                            if (orderByComparator != null) {
6315                                    query = new StringBundler(4 +
6316                                                    (orderByComparator.getOrderByFields().length * 3));
6317                            }
6318                            else {
6319                                    query = new StringBundler(4);
6320                            }
6321    
6322                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6323    
6324                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6325    
6326                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6327    
6328                            if (orderByComparator != null) {
6329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6330                                            orderByComparator);
6331                            }
6332                            else
6333                             if (pagination) {
6334                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6335                            }
6336    
6337                            String sql = query.toString();
6338    
6339                            Session session = null;
6340    
6341                            try {
6342                                    session = openSession();
6343    
6344                                    Query q = session.createQuery(sql);
6345    
6346                                    QueryPos qPos = QueryPos.getInstance(q);
6347    
6348                                    qPos.add(groupId);
6349    
6350                                    qPos.add(status);
6351    
6352                                    if (!pagination) {
6353                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6354                                                            start, end, false);
6355    
6356                                            Collections.sort(list);
6357    
6358                                            list = Collections.unmodifiableList(list);
6359                                    }
6360                                    else {
6361                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6362                                                            start, end);
6363                                    }
6364    
6365                                    cacheResult(list);
6366    
6367                                    finderCache.putResult(finderPath, finderArgs, list);
6368                            }
6369                            catch (Exception e) {
6370                                    finderCache.removeResult(finderPath, finderArgs);
6371    
6372                                    throw processException(e);
6373                            }
6374                            finally {
6375                                    closeSession(session);
6376                            }
6377                    }
6378    
6379                    return list;
6380            }
6381    
6382            /**
6383             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6384             *
6385             * @param groupId the group ID
6386             * @param status the status
6387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6388             * @return the first matching message-boards message
6389             * @throws NoSuchMessageException if a matching message-boards message could not be found
6390             */
6391            @Override
6392            public MBMessage findByG_S_First(long groupId, int status,
6393                    OrderByComparator<MBMessage> orderByComparator)
6394                    throws NoSuchMessageException {
6395                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6396                                    orderByComparator);
6397    
6398                    if (mbMessage != null) {
6399                            return mbMessage;
6400                    }
6401    
6402                    StringBundler msg = new StringBundler(6);
6403    
6404                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6405    
6406                    msg.append("groupId=");
6407                    msg.append(groupId);
6408    
6409                    msg.append(", status=");
6410                    msg.append(status);
6411    
6412                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6413    
6414                    throw new NoSuchMessageException(msg.toString());
6415            }
6416    
6417            /**
6418             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6419             *
6420             * @param groupId the group ID
6421             * @param status the status
6422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6423             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6424             */
6425            @Override
6426            public MBMessage fetchByG_S_First(long groupId, int status,
6427                    OrderByComparator<MBMessage> orderByComparator) {
6428                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6429                                    orderByComparator);
6430    
6431                    if (!list.isEmpty()) {
6432                            return list.get(0);
6433                    }
6434    
6435                    return null;
6436            }
6437    
6438            /**
6439             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6440             *
6441             * @param groupId the group ID
6442             * @param status the status
6443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6444             * @return the last matching message-boards message
6445             * @throws NoSuchMessageException if a matching message-boards message could not be found
6446             */
6447            @Override
6448            public MBMessage findByG_S_Last(long groupId, int status,
6449                    OrderByComparator<MBMessage> orderByComparator)
6450                    throws NoSuchMessageException {
6451                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6452    
6453                    if (mbMessage != null) {
6454                            return mbMessage;
6455                    }
6456    
6457                    StringBundler msg = new StringBundler(6);
6458    
6459                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6460    
6461                    msg.append("groupId=");
6462                    msg.append(groupId);
6463    
6464                    msg.append(", status=");
6465                    msg.append(status);
6466    
6467                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6468    
6469                    throw new NoSuchMessageException(msg.toString());
6470            }
6471    
6472            /**
6473             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6474             *
6475             * @param groupId the group ID
6476             * @param status the status
6477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6478             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6479             */
6480            @Override
6481            public MBMessage fetchByG_S_Last(long groupId, int status,
6482                    OrderByComparator<MBMessage> orderByComparator) {
6483                    int count = countByG_S(groupId, status);
6484    
6485                    if (count == 0) {
6486                            return null;
6487                    }
6488    
6489                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6490                                    orderByComparator);
6491    
6492                    if (!list.isEmpty()) {
6493                            return list.get(0);
6494                    }
6495    
6496                    return null;
6497            }
6498    
6499            /**
6500             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6501             *
6502             * @param messageId the primary key of the current message-boards message
6503             * @param groupId the group ID
6504             * @param status the status
6505             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6506             * @return the previous, current, and next message-boards message
6507             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6508             */
6509            @Override
6510            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6511                    int status, OrderByComparator<MBMessage> orderByComparator)
6512                    throws NoSuchMessageException {
6513                    MBMessage mbMessage = findByPrimaryKey(messageId);
6514    
6515                    Session session = null;
6516    
6517                    try {
6518                            session = openSession();
6519    
6520                            MBMessage[] array = new MBMessageImpl[3];
6521    
6522                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6523                                            status, orderByComparator, true);
6524    
6525                            array[1] = mbMessage;
6526    
6527                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6528                                            status, orderByComparator, false);
6529    
6530                            return array;
6531                    }
6532                    catch (Exception e) {
6533                            throw processException(e);
6534                    }
6535                    finally {
6536                            closeSession(session);
6537                    }
6538            }
6539    
6540            protected MBMessage getByG_S_PrevAndNext(Session session,
6541                    MBMessage mbMessage, long groupId, int status,
6542                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6543                    StringBundler query = null;
6544    
6545                    if (orderByComparator != null) {
6546                            query = new StringBundler(6 +
6547                                            (orderByComparator.getOrderByFields().length * 6));
6548                    }
6549                    else {
6550                            query = new StringBundler(3);
6551                    }
6552    
6553                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6554    
6555                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6556    
6557                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6558    
6559                    if (orderByComparator != null) {
6560                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6561    
6562                            if (orderByConditionFields.length > 0) {
6563                                    query.append(WHERE_AND);
6564                            }
6565    
6566                            for (int i = 0; i < orderByConditionFields.length; i++) {
6567                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6568                                    query.append(orderByConditionFields[i]);
6569    
6570                                    if ((i + 1) < orderByConditionFields.length) {
6571                                            if (orderByComparator.isAscending() ^ previous) {
6572                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6573                                            }
6574                                            else {
6575                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6576                                            }
6577                                    }
6578                                    else {
6579                                            if (orderByComparator.isAscending() ^ previous) {
6580                                                    query.append(WHERE_GREATER_THAN);
6581                                            }
6582                                            else {
6583                                                    query.append(WHERE_LESSER_THAN);
6584                                            }
6585                                    }
6586                            }
6587    
6588                            query.append(ORDER_BY_CLAUSE);
6589    
6590                            String[] orderByFields = orderByComparator.getOrderByFields();
6591    
6592                            for (int i = 0; i < orderByFields.length; i++) {
6593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6594                                    query.append(orderByFields[i]);
6595    
6596                                    if ((i + 1) < orderByFields.length) {
6597                                            if (orderByComparator.isAscending() ^ previous) {
6598                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6599                                            }
6600                                            else {
6601                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6602                                            }
6603                                    }
6604                                    else {
6605                                            if (orderByComparator.isAscending() ^ previous) {
6606                                                    query.append(ORDER_BY_ASC);
6607                                            }
6608                                            else {
6609                                                    query.append(ORDER_BY_DESC);
6610                                            }
6611                                    }
6612                            }
6613                    }
6614                    else {
6615                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6616                    }
6617    
6618                    String sql = query.toString();
6619    
6620                    Query q = session.createQuery(sql);
6621    
6622                    q.setFirstResult(0);
6623                    q.setMaxResults(2);
6624    
6625                    QueryPos qPos = QueryPos.getInstance(q);
6626    
6627                    qPos.add(groupId);
6628    
6629                    qPos.add(status);
6630    
6631                    if (orderByComparator != null) {
6632                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6633    
6634                            for (Object value : values) {
6635                                    qPos.add(value);
6636                            }
6637                    }
6638    
6639                    List<MBMessage> list = q.list();
6640    
6641                    if (list.size() == 2) {
6642                            return list.get(1);
6643                    }
6644                    else {
6645                            return null;
6646                    }
6647            }
6648    
6649            /**
6650             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6651             *
6652             * @param groupId the group ID
6653             * @param status the status
6654             * @return the matching message-boards messages that the user has permission to view
6655             */
6656            @Override
6657            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6658                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6659                            QueryUtil.ALL_POS, null);
6660            }
6661    
6662            /**
6663             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6664             *
6665             * <p>
6666             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6667             * </p>
6668             *
6669             * @param groupId the group ID
6670             * @param status the status
6671             * @param start the lower bound of the range of message-boards messages
6672             * @param end the upper bound of the range of message-boards messages (not inclusive)
6673             * @return the range of matching message-boards messages that the user has permission to view
6674             */
6675            @Override
6676            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6677                    int end) {
6678                    return filterFindByG_S(groupId, status, start, end, null);
6679            }
6680    
6681            /**
6682             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6683             *
6684             * <p>
6685             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6686             * </p>
6687             *
6688             * @param groupId the group ID
6689             * @param status the status
6690             * @param start the lower bound of the range of message-boards messages
6691             * @param end the upper bound of the range of message-boards messages (not inclusive)
6692             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6693             * @return the ordered range of matching message-boards messages that the user has permission to view
6694             */
6695            @Override
6696            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6697                    int end, OrderByComparator<MBMessage> orderByComparator) {
6698                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6699                            return findByG_S(groupId, status, start, end, orderByComparator);
6700                    }
6701    
6702                    StringBundler query = null;
6703    
6704                    if (orderByComparator != null) {
6705                            query = new StringBundler(4 +
6706                                            (orderByComparator.getOrderByFields().length * 3));
6707                    }
6708                    else {
6709                            query = new StringBundler(4);
6710                    }
6711    
6712                    if (getDB().isSupportsInlineDistinct()) {
6713                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6714                    }
6715                    else {
6716                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6717                    }
6718    
6719                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6720    
6721                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6722    
6723                    if (!getDB().isSupportsInlineDistinct()) {
6724                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6725                    }
6726    
6727                    if (orderByComparator != null) {
6728                            if (getDB().isSupportsInlineDistinct()) {
6729                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6730                                            orderByComparator, true);
6731                            }
6732                            else {
6733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6734                                            orderByComparator, true);
6735                            }
6736                    }
6737                    else {
6738                            if (getDB().isSupportsInlineDistinct()) {
6739                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6740                            }
6741                            else {
6742                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6743                            }
6744                    }
6745    
6746                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6747                                    MBMessage.class.getName(),
6748                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6749    
6750                    Session session = null;
6751    
6752                    try {
6753                            session = openSession();
6754    
6755                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6756    
6757                            if (getDB().isSupportsInlineDistinct()) {
6758                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6759                            }
6760                            else {
6761                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6762                            }
6763    
6764                            QueryPos qPos = QueryPos.getInstance(q);
6765    
6766                            qPos.add(groupId);
6767    
6768                            qPos.add(status);
6769    
6770                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6771                    }
6772                    catch (Exception e) {
6773                            throw processException(e);
6774                    }
6775                    finally {
6776                            closeSession(session);
6777                    }
6778            }
6779    
6780            /**
6781             * 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;.
6782             *
6783             * @param messageId the primary key of the current message-boards message
6784             * @param groupId the group ID
6785             * @param status the status
6786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6787             * @return the previous, current, and next message-boards message
6788             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6789             */
6790            @Override
6791            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6792                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6793                    throws NoSuchMessageException {
6794                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6795                            return findByG_S_PrevAndNext(messageId, groupId, status,
6796                                    orderByComparator);
6797                    }
6798    
6799                    MBMessage mbMessage = findByPrimaryKey(messageId);
6800    
6801                    Session session = null;
6802    
6803                    try {
6804                            session = openSession();
6805    
6806                            MBMessage[] array = new MBMessageImpl[3];
6807    
6808                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6809                                            status, orderByComparator, true);
6810    
6811                            array[1] = mbMessage;
6812    
6813                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6814                                            status, orderByComparator, false);
6815    
6816                            return array;
6817                    }
6818                    catch (Exception e) {
6819                            throw processException(e);
6820                    }
6821                    finally {
6822                            closeSession(session);
6823                    }
6824            }
6825    
6826            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6827                    MBMessage mbMessage, long groupId, int status,
6828                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6829                    StringBundler query = null;
6830    
6831                    if (orderByComparator != null) {
6832                            query = new StringBundler(6 +
6833                                            (orderByComparator.getOrderByFields().length * 6));
6834                    }
6835                    else {
6836                            query = new StringBundler(3);
6837                    }
6838    
6839                    if (getDB().isSupportsInlineDistinct()) {
6840                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6841                    }
6842                    else {
6843                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6844                    }
6845    
6846                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6847    
6848                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6849    
6850                    if (!getDB().isSupportsInlineDistinct()) {
6851                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6852                    }
6853    
6854                    if (orderByComparator != null) {
6855                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6856    
6857                            if (orderByConditionFields.length > 0) {
6858                                    query.append(WHERE_AND);
6859                            }
6860    
6861                            for (int i = 0; i < orderByConditionFields.length; i++) {
6862                                    if (getDB().isSupportsInlineDistinct()) {
6863                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6864                                    }
6865                                    else {
6866                                            query.append(_ORDER_BY_ENTITY_TABLE);
6867                                    }
6868    
6869                                    query.append(orderByConditionFields[i]);
6870    
6871                                    if ((i + 1) < orderByConditionFields.length) {
6872                                            if (orderByComparator.isAscending() ^ previous) {
6873                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6874                                            }
6875                                            else {
6876                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6877                                            }
6878                                    }
6879                                    else {
6880                                            if (orderByComparator.isAscending() ^ previous) {
6881                                                    query.append(WHERE_GREATER_THAN);
6882                                            }
6883                                            else {
6884                                                    query.append(WHERE_LESSER_THAN);
6885                                            }
6886                                    }
6887                            }
6888    
6889                            query.append(ORDER_BY_CLAUSE);
6890    
6891                            String[] orderByFields = orderByComparator.getOrderByFields();
6892    
6893                            for (int i = 0; i < orderByFields.length; i++) {
6894                                    if (getDB().isSupportsInlineDistinct()) {
6895                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6896                                    }
6897                                    else {
6898                                            query.append(_ORDER_BY_ENTITY_TABLE);
6899                                    }
6900    
6901                                    query.append(orderByFields[i]);
6902    
6903                                    if ((i + 1) < orderByFields.length) {
6904                                            if (orderByComparator.isAscending() ^ previous) {
6905                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6906                                            }
6907                                            else {
6908                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6909                                            }
6910                                    }
6911                                    else {
6912                                            if (orderByComparator.isAscending() ^ previous) {
6913                                                    query.append(ORDER_BY_ASC);
6914                                            }
6915                                            else {
6916                                                    query.append(ORDER_BY_DESC);
6917                                            }
6918                                    }
6919                            }
6920                    }
6921                    else {
6922                            if (getDB().isSupportsInlineDistinct()) {
6923                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6924                            }
6925                            else {
6926                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6927                            }
6928                    }
6929    
6930                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6931                                    MBMessage.class.getName(),
6932                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6933    
6934                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6935    
6936                    q.setFirstResult(0);
6937                    q.setMaxResults(2);
6938    
6939                    if (getDB().isSupportsInlineDistinct()) {
6940                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6941                    }
6942                    else {
6943                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6944                    }
6945    
6946                    QueryPos qPos = QueryPos.getInstance(q);
6947    
6948                    qPos.add(groupId);
6949    
6950                    qPos.add(status);
6951    
6952                    if (orderByComparator != null) {
6953                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6954    
6955                            for (Object value : values) {
6956                                    qPos.add(value);
6957                            }
6958                    }
6959    
6960                    List<MBMessage> list = q.list();
6961    
6962                    if (list.size() == 2) {
6963                            return list.get(1);
6964                    }
6965                    else {
6966                            return null;
6967                    }
6968            }
6969    
6970            /**
6971             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6972             *
6973             * @param groupId the group ID
6974             * @param status the status
6975             */
6976            @Override
6977            public void removeByG_S(long groupId, int status) {
6978                    for (MBMessage mbMessage : findByG_S(groupId, status,
6979                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6980                            remove(mbMessage);
6981                    }
6982            }
6983    
6984            /**
6985             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6986             *
6987             * @param groupId the group ID
6988             * @param status the status
6989             * @return the number of matching message-boards messages
6990             */
6991            @Override
6992            public int countByG_S(long groupId, int status) {
6993                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6994    
6995                    Object[] finderArgs = new Object[] { groupId, status };
6996    
6997                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6998    
6999                    if (count == null) {
7000                            StringBundler query = new StringBundler(3);
7001    
7002                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7003    
7004                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7005    
7006                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
7007    
7008                            String sql = query.toString();
7009    
7010                            Session session = null;
7011    
7012                            try {
7013                                    session = openSession();
7014    
7015                                    Query q = session.createQuery(sql);
7016    
7017                                    QueryPos qPos = QueryPos.getInstance(q);
7018    
7019                                    qPos.add(groupId);
7020    
7021                                    qPos.add(status);
7022    
7023                                    count = (Long)q.uniqueResult();
7024    
7025                                    finderCache.putResult(finderPath, finderArgs, count);
7026                            }
7027                            catch (Exception e) {
7028                                    finderCache.removeResult(finderPath, finderArgs);
7029    
7030                                    throw processException(e);
7031                            }
7032                            finally {
7033                                    closeSession(session);
7034                            }
7035                    }
7036    
7037                    return count.intValue();
7038            }
7039    
7040            /**
7041             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
7042             *
7043             * @param groupId the group ID
7044             * @param status the status
7045             * @return the number of matching message-boards messages that the user has permission to view
7046             */
7047            @Override
7048            public int filterCountByG_S(long groupId, int status) {
7049                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7050                            return countByG_S(groupId, status);
7051                    }
7052    
7053                    StringBundler query = new StringBundler(3);
7054    
7055                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
7056    
7057                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7058    
7059                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
7060    
7061                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7062                                    MBMessage.class.getName(),
7063                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7064    
7065                    Session session = null;
7066    
7067                    try {
7068                            session = openSession();
7069    
7070                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7071    
7072                            q.addScalar(COUNT_COLUMN_NAME,
7073                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7074    
7075                            QueryPos qPos = QueryPos.getInstance(q);
7076    
7077                            qPos.add(groupId);
7078    
7079                            qPos.add(status);
7080    
7081                            Long count = (Long)q.uniqueResult();
7082    
7083                            return count.intValue();
7084                    }
7085                    catch (Exception e) {
7086                            throw processException(e);
7087                    }
7088                    finally {
7089                            closeSession(session);
7090                    }
7091            }
7092    
7093            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
7094            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7098                            new String[] {
7099                                    Long.class.getName(), Integer.class.getName(),
7100                                    
7101                            Integer.class.getName(), Integer.class.getName(),
7102                                    OrderByComparator.class.getName()
7103                            });
7104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7105                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7107                            new String[] { Long.class.getName(), Integer.class.getName() },
7108                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7109                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7110                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7111            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7112                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7114                            new String[] { Long.class.getName(), Integer.class.getName() });
7115    
7116            /**
7117             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7118             *
7119             * @param companyId the company ID
7120             * @param status the status
7121             * @return the matching message-boards messages
7122             */
7123            @Override
7124            public List<MBMessage> findByC_S(long companyId, int status) {
7125                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7126                            QueryUtil.ALL_POS, null);
7127            }
7128    
7129            /**
7130             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7131             *
7132             * <p>
7133             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7134             * </p>
7135             *
7136             * @param companyId the company ID
7137             * @param status the status
7138             * @param start the lower bound of the range of message-boards messages
7139             * @param end the upper bound of the range of message-boards messages (not inclusive)
7140             * @return the range of matching message-boards messages
7141             */
7142            @Override
7143            public List<MBMessage> findByC_S(long companyId, int status, int start,
7144                    int end) {
7145                    return findByC_S(companyId, status, start, end, null);
7146            }
7147    
7148            /**
7149             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7150             *
7151             * <p>
7152             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7153             * </p>
7154             *
7155             * @param companyId the company ID
7156             * @param status the status
7157             * @param start the lower bound of the range of message-boards messages
7158             * @param end the upper bound of the range of message-boards messages (not inclusive)
7159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7160             * @return the ordered range of matching message-boards messages
7161             */
7162            @Override
7163            public List<MBMessage> findByC_S(long companyId, int status, int start,
7164                    int end, OrderByComparator<MBMessage> orderByComparator) {
7165                    return findByC_S(companyId, status, start, end, orderByComparator, true);
7166            }
7167    
7168            /**
7169             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7170             *
7171             * <p>
7172             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7173             * </p>
7174             *
7175             * @param companyId the company ID
7176             * @param status the status
7177             * @param start the lower bound of the range of message-boards messages
7178             * @param end the upper bound of the range of message-boards messages (not inclusive)
7179             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7180             * @param retrieveFromCache whether to retrieve from the finder cache
7181             * @return the ordered range of matching message-boards messages
7182             */
7183            @Override
7184            public List<MBMessage> findByC_S(long companyId, int status, int start,
7185                    int end, OrderByComparator<MBMessage> orderByComparator,
7186                    boolean retrieveFromCache) {
7187                    boolean pagination = true;
7188                    FinderPath finderPath = null;
7189                    Object[] finderArgs = null;
7190    
7191                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7192                                    (orderByComparator == null)) {
7193                            pagination = false;
7194                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7195                            finderArgs = new Object[] { companyId, status };
7196                    }
7197                    else {
7198                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7199                            finderArgs = new Object[] {
7200                                            companyId, status,
7201                                            
7202                                            start, end, orderByComparator
7203                                    };
7204                    }
7205    
7206                    List<MBMessage> list = null;
7207    
7208                    if (retrieveFromCache) {
7209                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7210                                            finderArgs, this);
7211    
7212                            if ((list != null) && !list.isEmpty()) {
7213                                    for (MBMessage mbMessage : list) {
7214                                            if ((companyId != mbMessage.getCompanyId()) ||
7215                                                            (status != mbMessage.getStatus())) {
7216                                                    list = null;
7217    
7218                                                    break;
7219                                            }
7220                                    }
7221                            }
7222                    }
7223    
7224                    if (list == null) {
7225                            StringBundler query = null;
7226    
7227                            if (orderByComparator != null) {
7228                                    query = new StringBundler(4 +
7229                                                    (orderByComparator.getOrderByFields().length * 3));
7230                            }
7231                            else {
7232                                    query = new StringBundler(4);
7233                            }
7234    
7235                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7236    
7237                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7238    
7239                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7240    
7241                            if (orderByComparator != null) {
7242                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7243                                            orderByComparator);
7244                            }
7245                            else
7246                             if (pagination) {
7247                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7248                            }
7249    
7250                            String sql = query.toString();
7251    
7252                            Session session = null;
7253    
7254                            try {
7255                                    session = openSession();
7256    
7257                                    Query q = session.createQuery(sql);
7258    
7259                                    QueryPos qPos = QueryPos.getInstance(q);
7260    
7261                                    qPos.add(companyId);
7262    
7263                                    qPos.add(status);
7264    
7265                                    if (!pagination) {
7266                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7267                                                            start, end, false);
7268    
7269                                            Collections.sort(list);
7270    
7271                                            list = Collections.unmodifiableList(list);
7272                                    }
7273                                    else {
7274                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7275                                                            start, end);
7276                                    }
7277    
7278                                    cacheResult(list);
7279    
7280                                    finderCache.putResult(finderPath, finderArgs, list);
7281                            }
7282                            catch (Exception e) {
7283                                    finderCache.removeResult(finderPath, finderArgs);
7284    
7285                                    throw processException(e);
7286                            }
7287                            finally {
7288                                    closeSession(session);
7289                            }
7290                    }
7291    
7292                    return list;
7293            }
7294    
7295            /**
7296             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7297             *
7298             * @param companyId the company ID
7299             * @param status the status
7300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7301             * @return the first matching message-boards message
7302             * @throws NoSuchMessageException if a matching message-boards message could not be found
7303             */
7304            @Override
7305            public MBMessage findByC_S_First(long companyId, int status,
7306                    OrderByComparator<MBMessage> orderByComparator)
7307                    throws NoSuchMessageException {
7308                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7309                                    orderByComparator);
7310    
7311                    if (mbMessage != null) {
7312                            return mbMessage;
7313                    }
7314    
7315                    StringBundler msg = new StringBundler(6);
7316    
7317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7318    
7319                    msg.append("companyId=");
7320                    msg.append(companyId);
7321    
7322                    msg.append(", status=");
7323                    msg.append(status);
7324    
7325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7326    
7327                    throw new NoSuchMessageException(msg.toString());
7328            }
7329    
7330            /**
7331             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7332             *
7333             * @param companyId the company ID
7334             * @param status the status
7335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7336             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7337             */
7338            @Override
7339            public MBMessage fetchByC_S_First(long companyId, int status,
7340                    OrderByComparator<MBMessage> orderByComparator) {
7341                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7342                                    orderByComparator);
7343    
7344                    if (!list.isEmpty()) {
7345                            return list.get(0);
7346                    }
7347    
7348                    return null;
7349            }
7350    
7351            /**
7352             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7353             *
7354             * @param companyId the company ID
7355             * @param status the status
7356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7357             * @return the last matching message-boards message
7358             * @throws NoSuchMessageException if a matching message-boards message could not be found
7359             */
7360            @Override
7361            public MBMessage findByC_S_Last(long companyId, int status,
7362                    OrderByComparator<MBMessage> orderByComparator)
7363                    throws NoSuchMessageException {
7364                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7365                                    orderByComparator);
7366    
7367                    if (mbMessage != null) {
7368                            return mbMessage;
7369                    }
7370    
7371                    StringBundler msg = new StringBundler(6);
7372    
7373                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7374    
7375                    msg.append("companyId=");
7376                    msg.append(companyId);
7377    
7378                    msg.append(", status=");
7379                    msg.append(status);
7380    
7381                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7382    
7383                    throw new NoSuchMessageException(msg.toString());
7384            }
7385    
7386            /**
7387             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7388             *
7389             * @param companyId the company ID
7390             * @param status the status
7391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7392             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7393             */
7394            @Override
7395            public MBMessage fetchByC_S_Last(long companyId, int status,
7396                    OrderByComparator<MBMessage> orderByComparator) {
7397                    int count = countByC_S(companyId, status);
7398    
7399                    if (count == 0) {
7400                            return null;
7401                    }
7402    
7403                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7404                                    orderByComparator);
7405    
7406                    if (!list.isEmpty()) {
7407                            return list.get(0);
7408                    }
7409    
7410                    return null;
7411            }
7412    
7413            /**
7414             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7415             *
7416             * @param messageId the primary key of the current message-boards message
7417             * @param companyId the company ID
7418             * @param status the status
7419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7420             * @return the previous, current, and next message-boards message
7421             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7422             */
7423            @Override
7424            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7425                    int status, OrderByComparator<MBMessage> orderByComparator)
7426                    throws NoSuchMessageException {
7427                    MBMessage mbMessage = findByPrimaryKey(messageId);
7428    
7429                    Session session = null;
7430    
7431                    try {
7432                            session = openSession();
7433    
7434                            MBMessage[] array = new MBMessageImpl[3];
7435    
7436                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7437                                            status, orderByComparator, true);
7438    
7439                            array[1] = mbMessage;
7440    
7441                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7442                                            status, orderByComparator, false);
7443    
7444                            return array;
7445                    }
7446                    catch (Exception e) {
7447                            throw processException(e);
7448                    }
7449                    finally {
7450                            closeSession(session);
7451                    }
7452            }
7453    
7454            protected MBMessage getByC_S_PrevAndNext(Session session,
7455                    MBMessage mbMessage, long companyId, int status,
7456                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7457                    StringBundler query = null;
7458    
7459                    if (orderByComparator != null) {
7460                            query = new StringBundler(6 +
7461                                            (orderByComparator.getOrderByFields().length * 6));
7462                    }
7463                    else {
7464                            query = new StringBundler(3);
7465                    }
7466    
7467                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7468    
7469                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7470    
7471                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7472    
7473                    if (orderByComparator != null) {
7474                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7475    
7476                            if (orderByConditionFields.length > 0) {
7477                                    query.append(WHERE_AND);
7478                            }
7479    
7480                            for (int i = 0; i < orderByConditionFields.length; i++) {
7481                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7482                                    query.append(orderByConditionFields[i]);
7483    
7484                                    if ((i + 1) < orderByConditionFields.length) {
7485                                            if (orderByComparator.isAscending() ^ previous) {
7486                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7487                                            }
7488                                            else {
7489                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7490                                            }
7491                                    }
7492                                    else {
7493                                            if (orderByComparator.isAscending() ^ previous) {
7494                                                    query.append(WHERE_GREATER_THAN);
7495                                            }
7496                                            else {
7497                                                    query.append(WHERE_LESSER_THAN);
7498                                            }
7499                                    }
7500                            }
7501    
7502                            query.append(ORDER_BY_CLAUSE);
7503    
7504                            String[] orderByFields = orderByComparator.getOrderByFields();
7505    
7506                            for (int i = 0; i < orderByFields.length; i++) {
7507                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7508                                    query.append(orderByFields[i]);
7509    
7510                                    if ((i + 1) < orderByFields.length) {
7511                                            if (orderByComparator.isAscending() ^ previous) {
7512                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7513                                            }
7514                                            else {
7515                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7516                                            }
7517                                    }
7518                                    else {
7519                                            if (orderByComparator.isAscending() ^ previous) {
7520                                                    query.append(ORDER_BY_ASC);
7521                                            }
7522                                            else {
7523                                                    query.append(ORDER_BY_DESC);
7524                                            }
7525                                    }
7526                            }
7527                    }
7528                    else {
7529                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7530                    }
7531    
7532                    String sql = query.toString();
7533    
7534                    Query q = session.createQuery(sql);
7535    
7536                    q.setFirstResult(0);
7537                    q.setMaxResults(2);
7538    
7539                    QueryPos qPos = QueryPos.getInstance(q);
7540    
7541                    qPos.add(companyId);
7542    
7543                    qPos.add(status);
7544    
7545                    if (orderByComparator != null) {
7546                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7547    
7548                            for (Object value : values) {
7549                                    qPos.add(value);
7550                            }
7551                    }
7552    
7553                    List<MBMessage> list = q.list();
7554    
7555                    if (list.size() == 2) {
7556                            return list.get(1);
7557                    }
7558                    else {
7559                            return null;
7560                    }
7561            }
7562    
7563            /**
7564             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7565             *
7566             * @param companyId the company ID
7567             * @param status the status
7568             */
7569            @Override
7570            public void removeByC_S(long companyId, int status) {
7571                    for (MBMessage mbMessage : findByC_S(companyId, status,
7572                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7573                            remove(mbMessage);
7574                    }
7575            }
7576    
7577            /**
7578             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7579             *
7580             * @param companyId the company ID
7581             * @param status the status
7582             * @return the number of matching message-boards messages
7583             */
7584            @Override
7585            public int countByC_S(long companyId, int status) {
7586                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7587    
7588                    Object[] finderArgs = new Object[] { companyId, status };
7589    
7590                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7591    
7592                    if (count == null) {
7593                            StringBundler query = new StringBundler(3);
7594    
7595                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7596    
7597                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7598    
7599                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7600    
7601                            String sql = query.toString();
7602    
7603                            Session session = null;
7604    
7605                            try {
7606                                    session = openSession();
7607    
7608                                    Query q = session.createQuery(sql);
7609    
7610                                    QueryPos qPos = QueryPos.getInstance(q);
7611    
7612                                    qPos.add(companyId);
7613    
7614                                    qPos.add(status);
7615    
7616                                    count = (Long)q.uniqueResult();
7617    
7618                                    finderCache.putResult(finderPath, finderArgs, count);
7619                            }
7620                            catch (Exception e) {
7621                                    finderCache.removeResult(finderPath, finderArgs);
7622    
7623                                    throw processException(e);
7624                            }
7625                            finally {
7626                                    closeSession(session);
7627                            }
7628                    }
7629    
7630                    return count.intValue();
7631            }
7632    
7633            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7634            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7635            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7636                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7637                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7638                            new String[] {
7639                                    Long.class.getName(), Long.class.getName(),
7640                                    
7641                            Integer.class.getName(), Integer.class.getName(),
7642                                    OrderByComparator.class.getName()
7643                            });
7644            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7645                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7646                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7647                            new String[] { Long.class.getName(), Long.class.getName() },
7648                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7649                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7650                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7651            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7652                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7653                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7654                            new String[] { Long.class.getName(), Long.class.getName() });
7655            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7656                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7657                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7658                            new String[] { Long.class.getName(), Long.class.getName() });
7659    
7660            /**
7661             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7662             *
7663             * @param userId the user ID
7664             * @param classNameId the class name ID
7665             * @return the matching message-boards messages
7666             */
7667            @Override
7668            public List<MBMessage> findByU_C(long userId, long classNameId) {
7669                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7670                            QueryUtil.ALL_POS, null);
7671            }
7672    
7673            /**
7674             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7675             *
7676             * <p>
7677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7678             * </p>
7679             *
7680             * @param userId the user ID
7681             * @param classNameId the class name ID
7682             * @param start the lower bound of the range of message-boards messages
7683             * @param end the upper bound of the range of message-boards messages (not inclusive)
7684             * @return the range of matching message-boards messages
7685             */
7686            @Override
7687            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7688                    int end) {
7689                    return findByU_C(userId, classNameId, start, end, null);
7690            }
7691    
7692            /**
7693             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7694             *
7695             * <p>
7696             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7697             * </p>
7698             *
7699             * @param userId the user ID
7700             * @param classNameId the class name ID
7701             * @param start the lower bound of the range of message-boards messages
7702             * @param end the upper bound of the range of message-boards messages (not inclusive)
7703             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7704             * @return the ordered range of matching message-boards messages
7705             */
7706            @Override
7707            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7708                    int end, OrderByComparator<MBMessage> orderByComparator) {
7709                    return findByU_C(userId, classNameId, start, end, orderByComparator,
7710                            true);
7711            }
7712    
7713            /**
7714             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7715             *
7716             * <p>
7717             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7718             * </p>
7719             *
7720             * @param userId the user ID
7721             * @param classNameId the class name ID
7722             * @param start the lower bound of the range of message-boards messages
7723             * @param end the upper bound of the range of message-boards messages (not inclusive)
7724             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7725             * @param retrieveFromCache whether to retrieve from the finder cache
7726             * @return the ordered range of matching message-boards messages
7727             */
7728            @Override
7729            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7730                    int end, OrderByComparator<MBMessage> orderByComparator,
7731                    boolean retrieveFromCache) {
7732                    boolean pagination = true;
7733                    FinderPath finderPath = null;
7734                    Object[] finderArgs = null;
7735    
7736                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7737                                    (orderByComparator == null)) {
7738                            pagination = false;
7739                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7740                            finderArgs = new Object[] { userId, classNameId };
7741                    }
7742                    else {
7743                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7744                            finderArgs = new Object[] {
7745                                            userId, classNameId,
7746                                            
7747                                            start, end, orderByComparator
7748                                    };
7749                    }
7750    
7751                    List<MBMessage> list = null;
7752    
7753                    if (retrieveFromCache) {
7754                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7755                                            finderArgs, this);
7756    
7757                            if ((list != null) && !list.isEmpty()) {
7758                                    for (MBMessage mbMessage : list) {
7759                                            if ((userId != mbMessage.getUserId()) ||
7760                                                            (classNameId != mbMessage.getClassNameId())) {
7761                                                    list = null;
7762    
7763                                                    break;
7764                                            }
7765                                    }
7766                            }
7767                    }
7768    
7769                    if (list == null) {
7770                            StringBundler query = null;
7771    
7772                            if (orderByComparator != null) {
7773                                    query = new StringBundler(4 +
7774                                                    (orderByComparator.getOrderByFields().length * 3));
7775                            }
7776                            else {
7777                                    query = new StringBundler(4);
7778                            }
7779    
7780                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7781    
7782                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7783    
7784                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7785    
7786                            if (orderByComparator != null) {
7787                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7788                                            orderByComparator);
7789                            }
7790                            else
7791                             if (pagination) {
7792                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7793                            }
7794    
7795                            String sql = query.toString();
7796    
7797                            Session session = null;
7798    
7799                            try {
7800                                    session = openSession();
7801    
7802                                    Query q = session.createQuery(sql);
7803    
7804                                    QueryPos qPos = QueryPos.getInstance(q);
7805    
7806                                    qPos.add(userId);
7807    
7808                                    qPos.add(classNameId);
7809    
7810                                    if (!pagination) {
7811                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7812                                                            start, end, false);
7813    
7814                                            Collections.sort(list);
7815    
7816                                            list = Collections.unmodifiableList(list);
7817                                    }
7818                                    else {
7819                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7820                                                            start, end);
7821                                    }
7822    
7823                                    cacheResult(list);
7824    
7825                                    finderCache.putResult(finderPath, finderArgs, list);
7826                            }
7827                            catch (Exception e) {
7828                                    finderCache.removeResult(finderPath, finderArgs);
7829    
7830                                    throw processException(e);
7831                            }
7832                            finally {
7833                                    closeSession(session);
7834                            }
7835                    }
7836    
7837                    return list;
7838            }
7839    
7840            /**
7841             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7842             *
7843             * @param userId the user ID
7844             * @param classNameId the class name ID
7845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7846             * @return the first matching message-boards message
7847             * @throws NoSuchMessageException if a matching message-boards message could not be found
7848             */
7849            @Override
7850            public MBMessage findByU_C_First(long userId, long classNameId,
7851                    OrderByComparator<MBMessage> orderByComparator)
7852                    throws NoSuchMessageException {
7853                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7854                                    orderByComparator);
7855    
7856                    if (mbMessage != null) {
7857                            return mbMessage;
7858                    }
7859    
7860                    StringBundler msg = new StringBundler(6);
7861    
7862                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7863    
7864                    msg.append("userId=");
7865                    msg.append(userId);
7866    
7867                    msg.append(", classNameId=");
7868                    msg.append(classNameId);
7869    
7870                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7871    
7872                    throw new NoSuchMessageException(msg.toString());
7873            }
7874    
7875            /**
7876             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7877             *
7878             * @param userId the user ID
7879             * @param classNameId the class name ID
7880             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7881             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7882             */
7883            @Override
7884            public MBMessage fetchByU_C_First(long userId, long classNameId,
7885                    OrderByComparator<MBMessage> orderByComparator) {
7886                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7887                                    orderByComparator);
7888    
7889                    if (!list.isEmpty()) {
7890                            return list.get(0);
7891                    }
7892    
7893                    return null;
7894            }
7895    
7896            /**
7897             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7898             *
7899             * @param userId the user ID
7900             * @param classNameId the class name ID
7901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7902             * @return the last matching message-boards message
7903             * @throws NoSuchMessageException if a matching message-boards message could not be found
7904             */
7905            @Override
7906            public MBMessage findByU_C_Last(long userId, long classNameId,
7907                    OrderByComparator<MBMessage> orderByComparator)
7908                    throws NoSuchMessageException {
7909                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7910                                    orderByComparator);
7911    
7912                    if (mbMessage != null) {
7913                            return mbMessage;
7914                    }
7915    
7916                    StringBundler msg = new StringBundler(6);
7917    
7918                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7919    
7920                    msg.append("userId=");
7921                    msg.append(userId);
7922    
7923                    msg.append(", classNameId=");
7924                    msg.append(classNameId);
7925    
7926                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7927    
7928                    throw new NoSuchMessageException(msg.toString());
7929            }
7930    
7931            /**
7932             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7933             *
7934             * @param userId the user ID
7935             * @param classNameId the class name ID
7936             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7937             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7938             */
7939            @Override
7940            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7941                    OrderByComparator<MBMessage> orderByComparator) {
7942                    int count = countByU_C(userId, classNameId);
7943    
7944                    if (count == 0) {
7945                            return null;
7946                    }
7947    
7948                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7949                                    orderByComparator);
7950    
7951                    if (!list.isEmpty()) {
7952                            return list.get(0);
7953                    }
7954    
7955                    return null;
7956            }
7957    
7958            /**
7959             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7960             *
7961             * @param messageId the primary key of the current message-boards message
7962             * @param userId the user ID
7963             * @param classNameId the class name ID
7964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7965             * @return the previous, current, and next message-boards message
7966             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7967             */
7968            @Override
7969            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7970                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7971                    throws NoSuchMessageException {
7972                    MBMessage mbMessage = findByPrimaryKey(messageId);
7973    
7974                    Session session = null;
7975    
7976                    try {
7977                            session = openSession();
7978    
7979                            MBMessage[] array = new MBMessageImpl[3];
7980    
7981                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7982                                            classNameId, orderByComparator, true);
7983    
7984                            array[1] = mbMessage;
7985    
7986                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7987                                            classNameId, orderByComparator, false);
7988    
7989                            return array;
7990                    }
7991                    catch (Exception e) {
7992                            throw processException(e);
7993                    }
7994                    finally {
7995                            closeSession(session);
7996                    }
7997            }
7998    
7999            protected MBMessage getByU_C_PrevAndNext(Session session,
8000                    MBMessage mbMessage, long userId, long classNameId,
8001                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8002                    StringBundler query = null;
8003    
8004                    if (orderByComparator != null) {
8005                            query = new StringBundler(6 +
8006                                            (orderByComparator.getOrderByFields().length * 6));
8007                    }
8008                    else {
8009                            query = new StringBundler(3);
8010                    }
8011    
8012                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8013    
8014                    query.append(_FINDER_COLUMN_U_C_USERID_2);
8015    
8016                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8017    
8018                    if (orderByComparator != null) {
8019                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8020    
8021                            if (orderByConditionFields.length > 0) {
8022                                    query.append(WHERE_AND);
8023                            }
8024    
8025                            for (int i = 0; i < orderByConditionFields.length; i++) {
8026                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8027                                    query.append(orderByConditionFields[i]);
8028    
8029                                    if ((i + 1) < orderByConditionFields.length) {
8030                                            if (orderByComparator.isAscending() ^ previous) {
8031                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8032                                            }
8033                                            else {
8034                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8035                                            }
8036                                    }
8037                                    else {
8038                                            if (orderByComparator.isAscending() ^ previous) {
8039                                                    query.append(WHERE_GREATER_THAN);
8040                                            }
8041                                            else {
8042                                                    query.append(WHERE_LESSER_THAN);
8043                                            }
8044                                    }
8045                            }
8046    
8047                            query.append(ORDER_BY_CLAUSE);
8048    
8049                            String[] orderByFields = orderByComparator.getOrderByFields();
8050    
8051                            for (int i = 0; i < orderByFields.length; i++) {
8052                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8053                                    query.append(orderByFields[i]);
8054    
8055                                    if ((i + 1) < orderByFields.length) {
8056                                            if (orderByComparator.isAscending() ^ previous) {
8057                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8058                                            }
8059                                            else {
8060                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8061                                            }
8062                                    }
8063                                    else {
8064                                            if (orderByComparator.isAscending() ^ previous) {
8065                                                    query.append(ORDER_BY_ASC);
8066                                            }
8067                                            else {
8068                                                    query.append(ORDER_BY_DESC);
8069                                            }
8070                                    }
8071                            }
8072                    }
8073                    else {
8074                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8075                    }
8076    
8077                    String sql = query.toString();
8078    
8079                    Query q = session.createQuery(sql);
8080    
8081                    q.setFirstResult(0);
8082                    q.setMaxResults(2);
8083    
8084                    QueryPos qPos = QueryPos.getInstance(q);
8085    
8086                    qPos.add(userId);
8087    
8088                    qPos.add(classNameId);
8089    
8090                    if (orderByComparator != null) {
8091                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8092    
8093                            for (Object value : values) {
8094                                    qPos.add(value);
8095                            }
8096                    }
8097    
8098                    List<MBMessage> list = q.list();
8099    
8100                    if (list.size() == 2) {
8101                            return list.get(1);
8102                    }
8103                    else {
8104                            return null;
8105                    }
8106            }
8107    
8108            /**
8109             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8110             *
8111             * <p>
8112             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8113             * </p>
8114             *
8115             * @param userId the user ID
8116             * @param classNameIds the class name IDs
8117             * @return the matching message-boards messages
8118             */
8119            @Override
8120            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
8121                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
8122                            QueryUtil.ALL_POS, null);
8123            }
8124    
8125            /**
8126             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8127             *
8128             * <p>
8129             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8130             * </p>
8131             *
8132             * @param userId the user ID
8133             * @param classNameIds the class name IDs
8134             * @param start the lower bound of the range of message-boards messages
8135             * @param end the upper bound of the range of message-boards messages (not inclusive)
8136             * @return the range of matching message-boards messages
8137             */
8138            @Override
8139            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8140                    int start, int end) {
8141                    return findByU_C(userId, classNameIds, start, end, null);
8142            }
8143    
8144            /**
8145             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8146             *
8147             * <p>
8148             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8149             * </p>
8150             *
8151             * @param userId the user ID
8152             * @param classNameIds the class name IDs
8153             * @param start the lower bound of the range of message-boards messages
8154             * @param end the upper bound of the range of message-boards messages (not inclusive)
8155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8156             * @return the ordered range of matching message-boards messages
8157             */
8158            @Override
8159            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8160                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8161                    return findByU_C(userId, classNameIds, start, end, orderByComparator,
8162                            true);
8163            }
8164    
8165            /**
8166             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;, optionally using the finder cache.
8167             *
8168             * <p>
8169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the 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.
8170             * </p>
8171             *
8172             * @param userId the user ID
8173             * @param classNameId the class name ID
8174             * @param start the lower bound of the range of message-boards messages
8175             * @param end the upper bound of the range of message-boards messages (not inclusive)
8176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8177             * @param retrieveFromCache whether to retrieve from the finder cache
8178             * @return the ordered range of matching message-boards messages
8179             */
8180            @Override
8181            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8182                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
8183                    boolean retrieveFromCache) {
8184                    if (classNameIds == null) {
8185                            classNameIds = new long[0];
8186                    }
8187                    else if (classNameIds.length > 1) {
8188                            classNameIds = ArrayUtil.unique(classNameIds);
8189    
8190                            Arrays.sort(classNameIds);
8191                    }
8192    
8193                    if (classNameIds.length == 1) {
8194                            return findByU_C(userId, classNameIds[0], start, end,
8195                                    orderByComparator);
8196                    }
8197    
8198                    boolean pagination = true;
8199                    Object[] finderArgs = null;
8200    
8201                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8202                                    (orderByComparator == null)) {
8203                            pagination = false;
8204                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8205                    }
8206                    else {
8207                            finderArgs = new Object[] {
8208                                            userId, StringUtil.merge(classNameIds),
8209                                            
8210                                            start, end, orderByComparator
8211                                    };
8212                    }
8213    
8214                    List<MBMessage> list = null;
8215    
8216                    if (retrieveFromCache) {
8217                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8218                                            finderArgs, this);
8219    
8220                            if ((list != null) && !list.isEmpty()) {
8221                                    for (MBMessage mbMessage : list) {
8222                                            if ((userId != mbMessage.getUserId()) ||
8223                                                            !ArrayUtil.contains(classNameIds,
8224                                                                    mbMessage.getClassNameId())) {
8225                                                    list = null;
8226    
8227                                                    break;
8228                                            }
8229                                    }
8230                            }
8231                    }
8232    
8233                    if (list == null) {
8234                            StringBundler query = new StringBundler();
8235    
8236                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8237    
8238                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8239    
8240                            if (classNameIds.length > 0) {
8241                                    query.append(StringPool.OPEN_PARENTHESIS);
8242    
8243                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8244    
8245                                    query.append(StringUtil.merge(classNameIds));
8246    
8247                                    query.append(StringPool.CLOSE_PARENTHESIS);
8248    
8249                                    query.append(StringPool.CLOSE_PARENTHESIS);
8250                            }
8251    
8252                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8253                                                    1)), query.index() - 1);
8254    
8255                            if (orderByComparator != null) {
8256                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8257                                            orderByComparator);
8258                            }
8259                            else
8260                             if (pagination) {
8261                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8262                            }
8263    
8264                            String sql = query.toString();
8265    
8266                            Session session = null;
8267    
8268                            try {
8269                                    session = openSession();
8270    
8271                                    Query q = session.createQuery(sql);
8272    
8273                                    QueryPos qPos = QueryPos.getInstance(q);
8274    
8275                                    qPos.add(userId);
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                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8293                                            finderArgs, list);
8294                            }
8295                            catch (Exception e) {
8296                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8297                                            finderArgs);
8298    
8299                                    throw processException(e);
8300                            }
8301                            finally {
8302                                    closeSession(session);
8303                            }
8304                    }
8305    
8306                    return list;
8307            }
8308    
8309            /**
8310             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8311             *
8312             * @param userId the user ID
8313             * @param classNameId the class name ID
8314             */
8315            @Override
8316            public void removeByU_C(long userId, long classNameId) {
8317                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8318                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8319                            remove(mbMessage);
8320                    }
8321            }
8322    
8323            /**
8324             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8325             *
8326             * @param userId the user ID
8327             * @param classNameId the class name ID
8328             * @return the number of matching message-boards messages
8329             */
8330            @Override
8331            public int countByU_C(long userId, long classNameId) {
8332                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8333    
8334                    Object[] finderArgs = new Object[] { userId, classNameId };
8335    
8336                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8337    
8338                    if (count == null) {
8339                            StringBundler query = new StringBundler(3);
8340    
8341                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8342    
8343                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8344    
8345                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8346    
8347                            String sql = query.toString();
8348    
8349                            Session session = null;
8350    
8351                            try {
8352                                    session = openSession();
8353    
8354                                    Query q = session.createQuery(sql);
8355    
8356                                    QueryPos qPos = QueryPos.getInstance(q);
8357    
8358                                    qPos.add(userId);
8359    
8360                                    qPos.add(classNameId);
8361    
8362                                    count = (Long)q.uniqueResult();
8363    
8364                                    finderCache.putResult(finderPath, finderArgs, count);
8365                            }
8366                            catch (Exception e) {
8367                                    finderCache.removeResult(finderPath, finderArgs);
8368    
8369                                    throw processException(e);
8370                            }
8371                            finally {
8372                                    closeSession(session);
8373                            }
8374                    }
8375    
8376                    return count.intValue();
8377            }
8378    
8379            /**
8380             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8381             *
8382             * @param userId the user ID
8383             * @param classNameIds the class name IDs
8384             * @return the number of matching message-boards messages
8385             */
8386            @Override
8387            public int countByU_C(long userId, long[] classNameIds) {
8388                    if (classNameIds == null) {
8389                            classNameIds = new long[0];
8390                    }
8391                    else if (classNameIds.length > 1) {
8392                            classNameIds = ArrayUtil.unique(classNameIds);
8393    
8394                            Arrays.sort(classNameIds);
8395                    }
8396    
8397                    Object[] finderArgs = new Object[] {
8398                                    userId, StringUtil.merge(classNameIds)
8399                            };
8400    
8401                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8402                                    finderArgs, this);
8403    
8404                    if (count == null) {
8405                            StringBundler query = new StringBundler();
8406    
8407                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8408    
8409                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8410    
8411                            if (classNameIds.length > 0) {
8412                                    query.append(StringPool.OPEN_PARENTHESIS);
8413    
8414                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8415    
8416                                    query.append(StringUtil.merge(classNameIds));
8417    
8418                                    query.append(StringPool.CLOSE_PARENTHESIS);
8419    
8420                                    query.append(StringPool.CLOSE_PARENTHESIS);
8421                            }
8422    
8423                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8424                                                    1)), query.index() - 1);
8425    
8426                            String sql = query.toString();
8427    
8428                            Session session = null;
8429    
8430                            try {
8431                                    session = openSession();
8432    
8433                                    Query q = session.createQuery(sql);
8434    
8435                                    QueryPos qPos = QueryPos.getInstance(q);
8436    
8437                                    qPos.add(userId);
8438    
8439                                    count = (Long)q.uniqueResult();
8440    
8441                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8442                                            finderArgs, count);
8443                            }
8444                            catch (Exception e) {
8445                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8446                                            finderArgs);
8447    
8448                                    throw processException(e);
8449                            }
8450                            finally {
8451                                    closeSession(session);
8452                            }
8453                    }
8454    
8455                    return count.intValue();
8456            }
8457    
8458            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8459            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8460            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8461            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8462                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8463                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8464                            new String[] {
8465                                    Long.class.getName(), Long.class.getName(),
8466                                    
8467                            Integer.class.getName(), Integer.class.getName(),
8468                                    OrderByComparator.class.getName()
8469                            });
8470            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8471                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8472                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8473                            new String[] { Long.class.getName(), Long.class.getName() },
8474                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8475                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8476                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8477            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8478                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8479                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8480                            new String[] { Long.class.getName(), Long.class.getName() });
8481    
8482            /**
8483             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8484             *
8485             * @param classNameId the class name ID
8486             * @param classPK the class p k
8487             * @return the matching message-boards messages
8488             */
8489            @Override
8490            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8491                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8492                            QueryUtil.ALL_POS, null);
8493            }
8494    
8495            /**
8496             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8497             *
8498             * <p>
8499             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8500             * </p>
8501             *
8502             * @param classNameId the class name ID
8503             * @param classPK the class p k
8504             * @param start the lower bound of the range of message-boards messages
8505             * @param end the upper bound of the range of message-boards messages (not inclusive)
8506             * @return the range of matching message-boards messages
8507             */
8508            @Override
8509            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8510                    int end) {
8511                    return findByC_C(classNameId, classPK, start, end, null);
8512            }
8513    
8514            /**
8515             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8516             *
8517             * <p>
8518             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8519             * </p>
8520             *
8521             * @param classNameId the class name ID
8522             * @param classPK the class p k
8523             * @param start the lower bound of the range of message-boards messages
8524             * @param end the upper bound of the range of message-boards messages (not inclusive)
8525             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8526             * @return the ordered range of matching message-boards messages
8527             */
8528            @Override
8529            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8530                    int end, OrderByComparator<MBMessage> orderByComparator) {
8531                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
8532                            true);
8533            }
8534    
8535            /**
8536             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8537             *
8538             * <p>
8539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8540             * </p>
8541             *
8542             * @param classNameId the class name ID
8543             * @param classPK the class p k
8544             * @param start the lower bound of the range of message-boards messages
8545             * @param end the upper bound of the range of message-boards messages (not inclusive)
8546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8547             * @param retrieveFromCache whether to retrieve from the finder cache
8548             * @return the ordered range of matching message-boards messages
8549             */
8550            @Override
8551            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8552                    int end, OrderByComparator<MBMessage> orderByComparator,
8553                    boolean retrieveFromCache) {
8554                    boolean pagination = true;
8555                    FinderPath finderPath = null;
8556                    Object[] finderArgs = null;
8557    
8558                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8559                                    (orderByComparator == null)) {
8560                            pagination = false;
8561                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8562                            finderArgs = new Object[] { classNameId, classPK };
8563                    }
8564                    else {
8565                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8566                            finderArgs = new Object[] {
8567                                            classNameId, classPK,
8568                                            
8569                                            start, end, orderByComparator
8570                                    };
8571                    }
8572    
8573                    List<MBMessage> list = null;
8574    
8575                    if (retrieveFromCache) {
8576                            list = (List<MBMessage>)finderCache.getResult(finderPath,
8577                                            finderArgs, this);
8578    
8579                            if ((list != null) && !list.isEmpty()) {
8580                                    for (MBMessage mbMessage : list) {
8581                                            if ((classNameId != mbMessage.getClassNameId()) ||
8582                                                            (classPK != mbMessage.getClassPK())) {
8583                                                    list = null;
8584    
8585                                                    break;
8586                                            }
8587                                    }
8588                            }
8589                    }
8590    
8591                    if (list == null) {
8592                            StringBundler query = null;
8593    
8594                            if (orderByComparator != null) {
8595                                    query = new StringBundler(4 +
8596                                                    (orderByComparator.getOrderByFields().length * 3));
8597                            }
8598                            else {
8599                                    query = new StringBundler(4);
8600                            }
8601    
8602                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8603    
8604                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8605    
8606                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8607    
8608                            if (orderByComparator != null) {
8609                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8610                                            orderByComparator);
8611                            }
8612                            else
8613                             if (pagination) {
8614                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8615                            }
8616    
8617                            String sql = query.toString();
8618    
8619                            Session session = null;
8620    
8621                            try {
8622                                    session = openSession();
8623    
8624                                    Query q = session.createQuery(sql);
8625    
8626                                    QueryPos qPos = QueryPos.getInstance(q);
8627    
8628                                    qPos.add(classNameId);
8629    
8630                                    qPos.add(classPK);
8631    
8632                                    if (!pagination) {
8633                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8634                                                            start, end, false);
8635    
8636                                            Collections.sort(list);
8637    
8638                                            list = Collections.unmodifiableList(list);
8639                                    }
8640                                    else {
8641                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8642                                                            start, end);
8643                                    }
8644    
8645                                    cacheResult(list);
8646    
8647                                    finderCache.putResult(finderPath, finderArgs, list);
8648                            }
8649                            catch (Exception e) {
8650                                    finderCache.removeResult(finderPath, finderArgs);
8651    
8652                                    throw processException(e);
8653                            }
8654                            finally {
8655                                    closeSession(session);
8656                            }
8657                    }
8658    
8659                    return list;
8660            }
8661    
8662            /**
8663             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8664             *
8665             * @param classNameId the class name ID
8666             * @param classPK the class p k
8667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8668             * @return the first matching message-boards message
8669             * @throws NoSuchMessageException if a matching message-boards message could not be found
8670             */
8671            @Override
8672            public MBMessage findByC_C_First(long classNameId, long classPK,
8673                    OrderByComparator<MBMessage> orderByComparator)
8674                    throws NoSuchMessageException {
8675                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8676                                    orderByComparator);
8677    
8678                    if (mbMessage != null) {
8679                            return mbMessage;
8680                    }
8681    
8682                    StringBundler msg = new StringBundler(6);
8683    
8684                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8685    
8686                    msg.append("classNameId=");
8687                    msg.append(classNameId);
8688    
8689                    msg.append(", classPK=");
8690                    msg.append(classPK);
8691    
8692                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8693    
8694                    throw new NoSuchMessageException(msg.toString());
8695            }
8696    
8697            /**
8698             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8699             *
8700             * @param classNameId the class name ID
8701             * @param classPK the class p k
8702             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8703             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8704             */
8705            @Override
8706            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8707                    OrderByComparator<MBMessage> orderByComparator) {
8708                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8709                                    orderByComparator);
8710    
8711                    if (!list.isEmpty()) {
8712                            return list.get(0);
8713                    }
8714    
8715                    return null;
8716            }
8717    
8718            /**
8719             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8720             *
8721             * @param classNameId the class name ID
8722             * @param classPK the class p k
8723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8724             * @return the last matching message-boards message
8725             * @throws NoSuchMessageException if a matching message-boards message could not be found
8726             */
8727            @Override
8728            public MBMessage findByC_C_Last(long classNameId, long classPK,
8729                    OrderByComparator<MBMessage> orderByComparator)
8730                    throws NoSuchMessageException {
8731                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8732                                    orderByComparator);
8733    
8734                    if (mbMessage != null) {
8735                            return mbMessage;
8736                    }
8737    
8738                    StringBundler msg = new StringBundler(6);
8739    
8740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8741    
8742                    msg.append("classNameId=");
8743                    msg.append(classNameId);
8744    
8745                    msg.append(", classPK=");
8746                    msg.append(classPK);
8747    
8748                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8749    
8750                    throw new NoSuchMessageException(msg.toString());
8751            }
8752    
8753            /**
8754             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8755             *
8756             * @param classNameId the class name ID
8757             * @param classPK the class p k
8758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8759             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8760             */
8761            @Override
8762            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8763                    OrderByComparator<MBMessage> orderByComparator) {
8764                    int count = countByC_C(classNameId, classPK);
8765    
8766                    if (count == 0) {
8767                            return null;
8768                    }
8769    
8770                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8771                                    count, orderByComparator);
8772    
8773                    if (!list.isEmpty()) {
8774                            return list.get(0);
8775                    }
8776    
8777                    return null;
8778            }
8779    
8780            /**
8781             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8782             *
8783             * @param messageId the primary key of the current message-boards message
8784             * @param classNameId the class name ID
8785             * @param classPK the class p k
8786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8787             * @return the previous, current, and next message-boards message
8788             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8789             */
8790            @Override
8791            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8792                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8793                    throws NoSuchMessageException {
8794                    MBMessage mbMessage = findByPrimaryKey(messageId);
8795    
8796                    Session session = null;
8797    
8798                    try {
8799                            session = openSession();
8800    
8801                            MBMessage[] array = new MBMessageImpl[3];
8802    
8803                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8804                                            classPK, orderByComparator, true);
8805    
8806                            array[1] = mbMessage;
8807    
8808                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8809                                            classPK, orderByComparator, false);
8810    
8811                            return array;
8812                    }
8813                    catch (Exception e) {
8814                            throw processException(e);
8815                    }
8816                    finally {
8817                            closeSession(session);
8818                    }
8819            }
8820    
8821            protected MBMessage getByC_C_PrevAndNext(Session session,
8822                    MBMessage mbMessage, long classNameId, long classPK,
8823                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8824                    StringBundler query = null;
8825    
8826                    if (orderByComparator != null) {
8827                            query = new StringBundler(6 +
8828                                            (orderByComparator.getOrderByFields().length * 6));
8829                    }
8830                    else {
8831                            query = new StringBundler(3);
8832                    }
8833    
8834                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8835    
8836                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8837    
8838                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8839    
8840                    if (orderByComparator != null) {
8841                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8842    
8843                            if (orderByConditionFields.length > 0) {
8844                                    query.append(WHERE_AND);
8845                            }
8846    
8847                            for (int i = 0; i < orderByConditionFields.length; i++) {
8848                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8849                                    query.append(orderByConditionFields[i]);
8850    
8851                                    if ((i + 1) < orderByConditionFields.length) {
8852                                            if (orderByComparator.isAscending() ^ previous) {
8853                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8854                                            }
8855                                            else {
8856                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8857                                            }
8858                                    }
8859                                    else {
8860                                            if (orderByComparator.isAscending() ^ previous) {
8861                                                    query.append(WHERE_GREATER_THAN);
8862                                            }
8863                                            else {
8864                                                    query.append(WHERE_LESSER_THAN);
8865                                            }
8866                                    }
8867                            }
8868    
8869                            query.append(ORDER_BY_CLAUSE);
8870    
8871                            String[] orderByFields = orderByComparator.getOrderByFields();
8872    
8873                            for (int i = 0; i < orderByFields.length; i++) {
8874                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8875                                    query.append(orderByFields[i]);
8876    
8877                                    if ((i + 1) < orderByFields.length) {
8878                                            if (orderByComparator.isAscending() ^ previous) {
8879                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8880                                            }
8881                                            else {
8882                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8883                                            }
8884                                    }
8885                                    else {
8886                                            if (orderByComparator.isAscending() ^ previous) {
8887                                                    query.append(ORDER_BY_ASC);
8888                                            }
8889                                            else {
8890                                                    query.append(ORDER_BY_DESC);
8891                                            }
8892                                    }
8893                            }
8894                    }
8895                    else {
8896                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8897                    }
8898    
8899                    String sql = query.toString();
8900    
8901                    Query q = session.createQuery(sql);
8902    
8903                    q.setFirstResult(0);
8904                    q.setMaxResults(2);
8905    
8906                    QueryPos qPos = QueryPos.getInstance(q);
8907    
8908                    qPos.add(classNameId);
8909    
8910                    qPos.add(classPK);
8911    
8912                    if (orderByComparator != null) {
8913                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8914    
8915                            for (Object value : values) {
8916                                    qPos.add(value);
8917                            }
8918                    }
8919    
8920                    List<MBMessage> list = q.list();
8921    
8922                    if (list.size() == 2) {
8923                            return list.get(1);
8924                    }
8925                    else {
8926                            return null;
8927                    }
8928            }
8929    
8930            /**
8931             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8932             *
8933             * @param classNameId the class name ID
8934             * @param classPK the class p k
8935             */
8936            @Override
8937            public void removeByC_C(long classNameId, long classPK) {
8938                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8939                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8940                            remove(mbMessage);
8941                    }
8942            }
8943    
8944            /**
8945             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8946             *
8947             * @param classNameId the class name ID
8948             * @param classPK the class p k
8949             * @return the number of matching message-boards messages
8950             */
8951            @Override
8952            public int countByC_C(long classNameId, long classPK) {
8953                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8954    
8955                    Object[] finderArgs = new Object[] { classNameId, classPK };
8956    
8957                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8958    
8959                    if (count == null) {
8960                            StringBundler query = new StringBundler(3);
8961    
8962                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8963    
8964                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8965    
8966                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8967    
8968                            String sql = query.toString();
8969    
8970                            Session session = null;
8971    
8972                            try {
8973                                    session = openSession();
8974    
8975                                    Query q = session.createQuery(sql);
8976    
8977                                    QueryPos qPos = QueryPos.getInstance(q);
8978    
8979                                    qPos.add(classNameId);
8980    
8981                                    qPos.add(classPK);
8982    
8983                                    count = (Long)q.uniqueResult();
8984    
8985                                    finderCache.putResult(finderPath, finderArgs, count);
8986                            }
8987                            catch (Exception e) {
8988                                    finderCache.removeResult(finderPath, finderArgs);
8989    
8990                                    throw processException(e);
8991                            }
8992                            finally {
8993                                    closeSession(session);
8994                            }
8995                    }
8996    
8997                    return count.intValue();
8998            }
8999    
9000            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
9001            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
9002            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9003                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9004                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
9005                            new String[] {
9006                                    Long.class.getName(), Long.class.getName(),
9007                                    
9008                            Integer.class.getName(), Integer.class.getName(),
9009                                    OrderByComparator.class.getName()
9010                            });
9011            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9012                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9013                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
9014                            new String[] { Long.class.getName(), Long.class.getName() },
9015                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9016                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
9017                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9018            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9019                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9020                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
9021                            new String[] { Long.class.getName(), Long.class.getName() });
9022    
9023            /**
9024             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9025             *
9026             * @param threadId the thread ID
9027             * @param parentMessageId the parent message ID
9028             * @return the matching message-boards messages
9029             */
9030            @Override
9031            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
9032                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
9033                            QueryUtil.ALL_POS, null);
9034            }
9035    
9036            /**
9037             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9038             *
9039             * <p>
9040             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9041             * </p>
9042             *
9043             * @param threadId the thread ID
9044             * @param parentMessageId the parent message ID
9045             * @param start the lower bound of the range of message-boards messages
9046             * @param end the upper bound of the range of message-boards messages (not inclusive)
9047             * @return the range of matching message-boards messages
9048             */
9049            @Override
9050            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9051                    int start, int end) {
9052                    return findByT_P(threadId, parentMessageId, start, end, null);
9053            }
9054    
9055            /**
9056             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9057             *
9058             * <p>
9059             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9060             * </p>
9061             *
9062             * @param threadId the thread ID
9063             * @param parentMessageId the parent message ID
9064             * @param start the lower bound of the range of message-boards messages
9065             * @param end the upper bound of the range of message-boards messages (not inclusive)
9066             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9067             * @return the ordered range of matching message-boards messages
9068             */
9069            @Override
9070            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9071                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
9072                    return findByT_P(threadId, parentMessageId, start, end,
9073                            orderByComparator, true);
9074            }
9075    
9076            /**
9077             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9078             *
9079             * <p>
9080             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9081             * </p>
9082             *
9083             * @param threadId the thread ID
9084             * @param parentMessageId the parent message ID
9085             * @param start the lower bound of the range of message-boards messages
9086             * @param end the upper bound of the range of message-boards messages (not inclusive)
9087             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9088             * @param retrieveFromCache whether to retrieve from the finder cache
9089             * @return the ordered range of matching message-boards messages
9090             */
9091            @Override
9092            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9093                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
9094                    boolean retrieveFromCache) {
9095                    boolean pagination = true;
9096                    FinderPath finderPath = null;
9097                    Object[] finderArgs = null;
9098    
9099                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9100                                    (orderByComparator == null)) {
9101                            pagination = false;
9102                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
9103                            finderArgs = new Object[] { threadId, parentMessageId };
9104                    }
9105                    else {
9106                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
9107                            finderArgs = new Object[] {
9108                                            threadId, parentMessageId,
9109                                            
9110                                            start, end, orderByComparator
9111                                    };
9112                    }
9113    
9114                    List<MBMessage> list = null;
9115    
9116                    if (retrieveFromCache) {
9117                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9118                                            finderArgs, this);
9119    
9120                            if ((list != null) && !list.isEmpty()) {
9121                                    for (MBMessage mbMessage : list) {
9122                                            if ((threadId != mbMessage.getThreadId()) ||
9123                                                            (parentMessageId != mbMessage.getParentMessageId())) {
9124                                                    list = null;
9125    
9126                                                    break;
9127                                            }
9128                                    }
9129                            }
9130                    }
9131    
9132                    if (list == null) {
9133                            StringBundler query = null;
9134    
9135                            if (orderByComparator != null) {
9136                                    query = new StringBundler(4 +
9137                                                    (orderByComparator.getOrderByFields().length * 3));
9138                            }
9139                            else {
9140                                    query = new StringBundler(4);
9141                            }
9142    
9143                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9144    
9145                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9146    
9147                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9148    
9149                            if (orderByComparator != null) {
9150                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9151                                            orderByComparator);
9152                            }
9153                            else
9154                             if (pagination) {
9155                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9156                            }
9157    
9158                            String sql = query.toString();
9159    
9160                            Session session = null;
9161    
9162                            try {
9163                                    session = openSession();
9164    
9165                                    Query q = session.createQuery(sql);
9166    
9167                                    QueryPos qPos = QueryPos.getInstance(q);
9168    
9169                                    qPos.add(threadId);
9170    
9171                                    qPos.add(parentMessageId);
9172    
9173                                    if (!pagination) {
9174                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9175                                                            start, end, false);
9176    
9177                                            Collections.sort(list);
9178    
9179                                            list = Collections.unmodifiableList(list);
9180                                    }
9181                                    else {
9182                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9183                                                            start, end);
9184                                    }
9185    
9186                                    cacheResult(list);
9187    
9188                                    finderCache.putResult(finderPath, finderArgs, list);
9189                            }
9190                            catch (Exception e) {
9191                                    finderCache.removeResult(finderPath, finderArgs);
9192    
9193                                    throw processException(e);
9194                            }
9195                            finally {
9196                                    closeSession(session);
9197                            }
9198                    }
9199    
9200                    return list;
9201            }
9202    
9203            /**
9204             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9205             *
9206             * @param threadId the thread ID
9207             * @param parentMessageId the parent message ID
9208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9209             * @return the first matching message-boards message
9210             * @throws NoSuchMessageException if a matching message-boards message could not be found
9211             */
9212            @Override
9213            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9214                    OrderByComparator<MBMessage> orderByComparator)
9215                    throws NoSuchMessageException {
9216                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9217                                    orderByComparator);
9218    
9219                    if (mbMessage != null) {
9220                            return mbMessage;
9221                    }
9222    
9223                    StringBundler msg = new StringBundler(6);
9224    
9225                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9226    
9227                    msg.append("threadId=");
9228                    msg.append(threadId);
9229    
9230                    msg.append(", parentMessageId=");
9231                    msg.append(parentMessageId);
9232    
9233                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9234    
9235                    throw new NoSuchMessageException(msg.toString());
9236            }
9237    
9238            /**
9239             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9240             *
9241             * @param threadId the thread ID
9242             * @param parentMessageId the parent message ID
9243             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9244             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9245             */
9246            @Override
9247            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9248                    OrderByComparator<MBMessage> orderByComparator) {
9249                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9250                                    orderByComparator);
9251    
9252                    if (!list.isEmpty()) {
9253                            return list.get(0);
9254                    }
9255    
9256                    return null;
9257            }
9258    
9259            /**
9260             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9261             *
9262             * @param threadId the thread ID
9263             * @param parentMessageId the parent message ID
9264             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9265             * @return the last matching message-boards message
9266             * @throws NoSuchMessageException if a matching message-boards message could not be found
9267             */
9268            @Override
9269            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9270                    OrderByComparator<MBMessage> orderByComparator)
9271                    throws NoSuchMessageException {
9272                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9273                                    orderByComparator);
9274    
9275                    if (mbMessage != null) {
9276                            return mbMessage;
9277                    }
9278    
9279                    StringBundler msg = new StringBundler(6);
9280    
9281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9282    
9283                    msg.append("threadId=");
9284                    msg.append(threadId);
9285    
9286                    msg.append(", parentMessageId=");
9287                    msg.append(parentMessageId);
9288    
9289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9290    
9291                    throw new NoSuchMessageException(msg.toString());
9292            }
9293    
9294            /**
9295             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9296             *
9297             * @param threadId the thread ID
9298             * @param parentMessageId the parent message ID
9299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9300             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9301             */
9302            @Override
9303            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9304                    OrderByComparator<MBMessage> orderByComparator) {
9305                    int count = countByT_P(threadId, parentMessageId);
9306    
9307                    if (count == 0) {
9308                            return null;
9309                    }
9310    
9311                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9312                                    count, orderByComparator);
9313    
9314                    if (!list.isEmpty()) {
9315                            return list.get(0);
9316                    }
9317    
9318                    return null;
9319            }
9320    
9321            /**
9322             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9323             *
9324             * @param messageId the primary key of the current message-boards message
9325             * @param threadId the thread ID
9326             * @param parentMessageId the parent message ID
9327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9328             * @return the previous, current, and next message-boards message
9329             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9330             */
9331            @Override
9332            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9333                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
9334                    throws NoSuchMessageException {
9335                    MBMessage mbMessage = findByPrimaryKey(messageId);
9336    
9337                    Session session = null;
9338    
9339                    try {
9340                            session = openSession();
9341    
9342                            MBMessage[] array = new MBMessageImpl[3];
9343    
9344                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9345                                            parentMessageId, orderByComparator, true);
9346    
9347                            array[1] = mbMessage;
9348    
9349                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9350                                            parentMessageId, orderByComparator, false);
9351    
9352                            return array;
9353                    }
9354                    catch (Exception e) {
9355                            throw processException(e);
9356                    }
9357                    finally {
9358                            closeSession(session);
9359                    }
9360            }
9361    
9362            protected MBMessage getByT_P_PrevAndNext(Session session,
9363                    MBMessage mbMessage, long threadId, long parentMessageId,
9364                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9365                    StringBundler query = null;
9366    
9367                    if (orderByComparator != null) {
9368                            query = new StringBundler(6 +
9369                                            (orderByComparator.getOrderByFields().length * 6));
9370                    }
9371                    else {
9372                            query = new StringBundler(3);
9373                    }
9374    
9375                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9376    
9377                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9378    
9379                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9380    
9381                    if (orderByComparator != null) {
9382                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9383    
9384                            if (orderByConditionFields.length > 0) {
9385                                    query.append(WHERE_AND);
9386                            }
9387    
9388                            for (int i = 0; i < orderByConditionFields.length; i++) {
9389                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9390                                    query.append(orderByConditionFields[i]);
9391    
9392                                    if ((i + 1) < orderByConditionFields.length) {
9393                                            if (orderByComparator.isAscending() ^ previous) {
9394                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9395                                            }
9396                                            else {
9397                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9398                                            }
9399                                    }
9400                                    else {
9401                                            if (orderByComparator.isAscending() ^ previous) {
9402                                                    query.append(WHERE_GREATER_THAN);
9403                                            }
9404                                            else {
9405                                                    query.append(WHERE_LESSER_THAN);
9406                                            }
9407                                    }
9408                            }
9409    
9410                            query.append(ORDER_BY_CLAUSE);
9411    
9412                            String[] orderByFields = orderByComparator.getOrderByFields();
9413    
9414                            for (int i = 0; i < orderByFields.length; i++) {
9415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9416                                    query.append(orderByFields[i]);
9417    
9418                                    if ((i + 1) < orderByFields.length) {
9419                                            if (orderByComparator.isAscending() ^ previous) {
9420                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9421                                            }
9422                                            else {
9423                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9424                                            }
9425                                    }
9426                                    else {
9427                                            if (orderByComparator.isAscending() ^ previous) {
9428                                                    query.append(ORDER_BY_ASC);
9429                                            }
9430                                            else {
9431                                                    query.append(ORDER_BY_DESC);
9432                                            }
9433                                    }
9434                            }
9435                    }
9436                    else {
9437                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9438                    }
9439    
9440                    String sql = query.toString();
9441    
9442                    Query q = session.createQuery(sql);
9443    
9444                    q.setFirstResult(0);
9445                    q.setMaxResults(2);
9446    
9447                    QueryPos qPos = QueryPos.getInstance(q);
9448    
9449                    qPos.add(threadId);
9450    
9451                    qPos.add(parentMessageId);
9452    
9453                    if (orderByComparator != null) {
9454                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9455    
9456                            for (Object value : values) {
9457                                    qPos.add(value);
9458                            }
9459                    }
9460    
9461                    List<MBMessage> list = q.list();
9462    
9463                    if (list.size() == 2) {
9464                            return list.get(1);
9465                    }
9466                    else {
9467                            return null;
9468                    }
9469            }
9470    
9471            /**
9472             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9473             *
9474             * @param threadId the thread ID
9475             * @param parentMessageId the parent message ID
9476             */
9477            @Override
9478            public void removeByT_P(long threadId, long parentMessageId) {
9479                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9480                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9481                            remove(mbMessage);
9482                    }
9483            }
9484    
9485            /**
9486             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9487             *
9488             * @param threadId the thread ID
9489             * @param parentMessageId the parent message ID
9490             * @return the number of matching message-boards messages
9491             */
9492            @Override
9493            public int countByT_P(long threadId, long parentMessageId) {
9494                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9495    
9496                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9497    
9498                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9499    
9500                    if (count == null) {
9501                            StringBundler query = new StringBundler(3);
9502    
9503                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9504    
9505                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9506    
9507                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9508    
9509                            String sql = query.toString();
9510    
9511                            Session session = null;
9512    
9513                            try {
9514                                    session = openSession();
9515    
9516                                    Query q = session.createQuery(sql);
9517    
9518                                    QueryPos qPos = QueryPos.getInstance(q);
9519    
9520                                    qPos.add(threadId);
9521    
9522                                    qPos.add(parentMessageId);
9523    
9524                                    count = (Long)q.uniqueResult();
9525    
9526                                    finderCache.putResult(finderPath, finderArgs, count);
9527                            }
9528                            catch (Exception e) {
9529                                    finderCache.removeResult(finderPath, finderArgs);
9530    
9531                                    throw processException(e);
9532                            }
9533                            finally {
9534                                    closeSession(session);
9535                            }
9536                    }
9537    
9538                    return count.intValue();
9539            }
9540    
9541            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9542            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9543            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9544                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9545                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9546                            new String[] {
9547                                    Long.class.getName(), Boolean.class.getName(),
9548                                    
9549                            Integer.class.getName(), Integer.class.getName(),
9550                                    OrderByComparator.class.getName()
9551                            });
9552            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9553                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9554                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9555                            new String[] { Long.class.getName(), Boolean.class.getName() },
9556                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9557                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9558                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9559            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9560                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9561                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9562                            new String[] { Long.class.getName(), Boolean.class.getName() });
9563    
9564            /**
9565             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9566             *
9567             * @param threadId the thread ID
9568             * @param answer the answer
9569             * @return the matching message-boards messages
9570             */
9571            @Override
9572            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9573                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9574                            QueryUtil.ALL_POS, null);
9575            }
9576    
9577            /**
9578             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9579             *
9580             * <p>
9581             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9582             * </p>
9583             *
9584             * @param threadId the thread ID
9585             * @param answer the answer
9586             * @param start the lower bound of the range of message-boards messages
9587             * @param end the upper bound of the range of message-boards messages (not inclusive)
9588             * @return the range of matching message-boards messages
9589             */
9590            @Override
9591            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9592                    int end) {
9593                    return findByT_A(threadId, answer, start, end, null);
9594            }
9595    
9596            /**
9597             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9598             *
9599             * <p>
9600             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9601             * </p>
9602             *
9603             * @param threadId the thread ID
9604             * @param answer the answer
9605             * @param start the lower bound of the range of message-boards messages
9606             * @param end the upper bound of the range of message-boards messages (not inclusive)
9607             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9608             * @return the ordered range of matching message-boards messages
9609             */
9610            @Override
9611            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9612                    int end, OrderByComparator<MBMessage> orderByComparator) {
9613                    return findByT_A(threadId, answer, start, end, orderByComparator, true);
9614            }
9615    
9616            /**
9617             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9618             *
9619             * <p>
9620             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9621             * </p>
9622             *
9623             * @param threadId the thread ID
9624             * @param answer the answer
9625             * @param start the lower bound of the range of message-boards messages
9626             * @param end the upper bound of the range of message-boards messages (not inclusive)
9627             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9628             * @param retrieveFromCache whether to retrieve from the finder cache
9629             * @return the ordered range of matching message-boards messages
9630             */
9631            @Override
9632            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9633                    int end, OrderByComparator<MBMessage> orderByComparator,
9634                    boolean retrieveFromCache) {
9635                    boolean pagination = true;
9636                    FinderPath finderPath = null;
9637                    Object[] finderArgs = null;
9638    
9639                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9640                                    (orderByComparator == null)) {
9641                            pagination = false;
9642                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9643                            finderArgs = new Object[] { threadId, answer };
9644                    }
9645                    else {
9646                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9647                            finderArgs = new Object[] {
9648                                            threadId, answer,
9649                                            
9650                                            start, end, orderByComparator
9651                                    };
9652                    }
9653    
9654                    List<MBMessage> list = null;
9655    
9656                    if (retrieveFromCache) {
9657                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9658                                            finderArgs, this);
9659    
9660                            if ((list != null) && !list.isEmpty()) {
9661                                    for (MBMessage mbMessage : list) {
9662                                            if ((threadId != mbMessage.getThreadId()) ||
9663                                                            (answer != mbMessage.getAnswer())) {
9664                                                    list = null;
9665    
9666                                                    break;
9667                                            }
9668                                    }
9669                            }
9670                    }
9671    
9672                    if (list == null) {
9673                            StringBundler query = null;
9674    
9675                            if (orderByComparator != null) {
9676                                    query = new StringBundler(4 +
9677                                                    (orderByComparator.getOrderByFields().length * 3));
9678                            }
9679                            else {
9680                                    query = new StringBundler(4);
9681                            }
9682    
9683                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9684    
9685                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9686    
9687                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9688    
9689                            if (orderByComparator != null) {
9690                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9691                                            orderByComparator);
9692                            }
9693                            else
9694                             if (pagination) {
9695                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9696                            }
9697    
9698                            String sql = query.toString();
9699    
9700                            Session session = null;
9701    
9702                            try {
9703                                    session = openSession();
9704    
9705                                    Query q = session.createQuery(sql);
9706    
9707                                    QueryPos qPos = QueryPos.getInstance(q);
9708    
9709                                    qPos.add(threadId);
9710    
9711                                    qPos.add(answer);
9712    
9713                                    if (!pagination) {
9714                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9715                                                            start, end, false);
9716    
9717                                            Collections.sort(list);
9718    
9719                                            list = Collections.unmodifiableList(list);
9720                                    }
9721                                    else {
9722                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9723                                                            start, end);
9724                                    }
9725    
9726                                    cacheResult(list);
9727    
9728                                    finderCache.putResult(finderPath, finderArgs, list);
9729                            }
9730                            catch (Exception e) {
9731                                    finderCache.removeResult(finderPath, finderArgs);
9732    
9733                                    throw processException(e);
9734                            }
9735                            finally {
9736                                    closeSession(session);
9737                            }
9738                    }
9739    
9740                    return list;
9741            }
9742    
9743            /**
9744             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9745             *
9746             * @param threadId the thread ID
9747             * @param answer the answer
9748             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9749             * @return the first matching message-boards message
9750             * @throws NoSuchMessageException if a matching message-boards message could not be found
9751             */
9752            @Override
9753            public MBMessage findByT_A_First(long threadId, boolean answer,
9754                    OrderByComparator<MBMessage> orderByComparator)
9755                    throws NoSuchMessageException {
9756                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9757                                    orderByComparator);
9758    
9759                    if (mbMessage != null) {
9760                            return mbMessage;
9761                    }
9762    
9763                    StringBundler msg = new StringBundler(6);
9764    
9765                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9766    
9767                    msg.append("threadId=");
9768                    msg.append(threadId);
9769    
9770                    msg.append(", answer=");
9771                    msg.append(answer);
9772    
9773                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9774    
9775                    throw new NoSuchMessageException(msg.toString());
9776            }
9777    
9778            /**
9779             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9780             *
9781             * @param threadId the thread ID
9782             * @param answer the answer
9783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9784             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9785             */
9786            @Override
9787            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9788                    OrderByComparator<MBMessage> orderByComparator) {
9789                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9790                                    orderByComparator);
9791    
9792                    if (!list.isEmpty()) {
9793                            return list.get(0);
9794                    }
9795    
9796                    return null;
9797            }
9798    
9799            /**
9800             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9801             *
9802             * @param threadId the thread ID
9803             * @param answer the answer
9804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9805             * @return the last matching message-boards message
9806             * @throws NoSuchMessageException if a matching message-boards message could not be found
9807             */
9808            @Override
9809            public MBMessage findByT_A_Last(long threadId, boolean answer,
9810                    OrderByComparator<MBMessage> orderByComparator)
9811                    throws NoSuchMessageException {
9812                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9813                                    orderByComparator);
9814    
9815                    if (mbMessage != null) {
9816                            return mbMessage;
9817                    }
9818    
9819                    StringBundler msg = new StringBundler(6);
9820    
9821                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9822    
9823                    msg.append("threadId=");
9824                    msg.append(threadId);
9825    
9826                    msg.append(", answer=");
9827                    msg.append(answer);
9828    
9829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9830    
9831                    throw new NoSuchMessageException(msg.toString());
9832            }
9833    
9834            /**
9835             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9836             *
9837             * @param threadId the thread ID
9838             * @param answer the answer
9839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9840             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9841             */
9842            @Override
9843            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9844                    OrderByComparator<MBMessage> orderByComparator) {
9845                    int count = countByT_A(threadId, answer);
9846    
9847                    if (count == 0) {
9848                            return null;
9849                    }
9850    
9851                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9852                                    orderByComparator);
9853    
9854                    if (!list.isEmpty()) {
9855                            return list.get(0);
9856                    }
9857    
9858                    return null;
9859            }
9860    
9861            /**
9862             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9863             *
9864             * @param messageId the primary key of the current message-boards message
9865             * @param threadId the thread ID
9866             * @param answer the answer
9867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9868             * @return the previous, current, and next message-boards message
9869             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9870             */
9871            @Override
9872            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9873                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9874                    throws NoSuchMessageException {
9875                    MBMessage mbMessage = findByPrimaryKey(messageId);
9876    
9877                    Session session = null;
9878    
9879                    try {
9880                            session = openSession();
9881    
9882                            MBMessage[] array = new MBMessageImpl[3];
9883    
9884                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9885                                            answer, orderByComparator, true);
9886    
9887                            array[1] = mbMessage;
9888    
9889                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9890                                            answer, orderByComparator, false);
9891    
9892                            return array;
9893                    }
9894                    catch (Exception e) {
9895                            throw processException(e);
9896                    }
9897                    finally {
9898                            closeSession(session);
9899                    }
9900            }
9901    
9902            protected MBMessage getByT_A_PrevAndNext(Session session,
9903                    MBMessage mbMessage, long threadId, boolean answer,
9904                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9905                    StringBundler query = null;
9906    
9907                    if (orderByComparator != null) {
9908                            query = new StringBundler(6 +
9909                                            (orderByComparator.getOrderByFields().length * 6));
9910                    }
9911                    else {
9912                            query = new StringBundler(3);
9913                    }
9914    
9915                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9916    
9917                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9918    
9919                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9920    
9921                    if (orderByComparator != null) {
9922                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9923    
9924                            if (orderByConditionFields.length > 0) {
9925                                    query.append(WHERE_AND);
9926                            }
9927    
9928                            for (int i = 0; i < orderByConditionFields.length; i++) {
9929                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9930                                    query.append(orderByConditionFields[i]);
9931    
9932                                    if ((i + 1) < orderByConditionFields.length) {
9933                                            if (orderByComparator.isAscending() ^ previous) {
9934                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9935                                            }
9936                                            else {
9937                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9938                                            }
9939                                    }
9940                                    else {
9941                                            if (orderByComparator.isAscending() ^ previous) {
9942                                                    query.append(WHERE_GREATER_THAN);
9943                                            }
9944                                            else {
9945                                                    query.append(WHERE_LESSER_THAN);
9946                                            }
9947                                    }
9948                            }
9949    
9950                            query.append(ORDER_BY_CLAUSE);
9951    
9952                            String[] orderByFields = orderByComparator.getOrderByFields();
9953    
9954                            for (int i = 0; i < orderByFields.length; i++) {
9955                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9956                                    query.append(orderByFields[i]);
9957    
9958                                    if ((i + 1) < orderByFields.length) {
9959                                            if (orderByComparator.isAscending() ^ previous) {
9960                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9961                                            }
9962                                            else {
9963                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9964                                            }
9965                                    }
9966                                    else {
9967                                            if (orderByComparator.isAscending() ^ previous) {
9968                                                    query.append(ORDER_BY_ASC);
9969                                            }
9970                                            else {
9971                                                    query.append(ORDER_BY_DESC);
9972                                            }
9973                                    }
9974                            }
9975                    }
9976                    else {
9977                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9978                    }
9979    
9980                    String sql = query.toString();
9981    
9982                    Query q = session.createQuery(sql);
9983    
9984                    q.setFirstResult(0);
9985                    q.setMaxResults(2);
9986    
9987                    QueryPos qPos = QueryPos.getInstance(q);
9988    
9989                    qPos.add(threadId);
9990    
9991                    qPos.add(answer);
9992    
9993                    if (orderByComparator != null) {
9994                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9995    
9996                            for (Object value : values) {
9997                                    qPos.add(value);
9998                            }
9999                    }
10000    
10001                    List<MBMessage> list = q.list();
10002    
10003                    if (list.size() == 2) {
10004                            return list.get(1);
10005                    }
10006                    else {
10007                            return null;
10008                    }
10009            }
10010    
10011            /**
10012             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
10013             *
10014             * @param threadId the thread ID
10015             * @param answer the answer
10016             */
10017            @Override
10018            public void removeByT_A(long threadId, boolean answer) {
10019                    for (MBMessage mbMessage : findByT_A(threadId, answer,
10020                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10021                            remove(mbMessage);
10022                    }
10023            }
10024    
10025            /**
10026             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
10027             *
10028             * @param threadId the thread ID
10029             * @param answer the answer
10030             * @return the number of matching message-boards messages
10031             */
10032            @Override
10033            public int countByT_A(long threadId, boolean answer) {
10034                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
10035    
10036                    Object[] finderArgs = new Object[] { threadId, answer };
10037    
10038                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10039    
10040                    if (count == null) {
10041                            StringBundler query = new StringBundler(3);
10042    
10043                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10044    
10045                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
10046    
10047                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
10048    
10049                            String sql = query.toString();
10050    
10051                            Session session = null;
10052    
10053                            try {
10054                                    session = openSession();
10055    
10056                                    Query q = session.createQuery(sql);
10057    
10058                                    QueryPos qPos = QueryPos.getInstance(q);
10059    
10060                                    qPos.add(threadId);
10061    
10062                                    qPos.add(answer);
10063    
10064                                    count = (Long)q.uniqueResult();
10065    
10066                                    finderCache.putResult(finderPath, finderArgs, count);
10067                            }
10068                            catch (Exception e) {
10069                                    finderCache.removeResult(finderPath, finderArgs);
10070    
10071                                    throw processException(e);
10072                            }
10073                            finally {
10074                                    closeSession(session);
10075                            }
10076                    }
10077    
10078                    return count.intValue();
10079            }
10080    
10081            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
10082            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
10083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10084                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
10086                            new String[] {
10087                                    Long.class.getName(), Integer.class.getName(),
10088                                    
10089                            Integer.class.getName(), Integer.class.getName(),
10090                                    OrderByComparator.class.getName()
10091                            });
10092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10093                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
10095                            new String[] { Long.class.getName(), Integer.class.getName() },
10096                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10097                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10098                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10099            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10100                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
10102                            new String[] { Long.class.getName(), Integer.class.getName() });
10103    
10104            /**
10105             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10106             *
10107             * @param threadId the thread ID
10108             * @param status the status
10109             * @return the matching message-boards messages
10110             */
10111            @Override
10112            public List<MBMessage> findByT_S(long threadId, int status) {
10113                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
10114                            QueryUtil.ALL_POS, null);
10115            }
10116    
10117            /**
10118             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10119             *
10120             * <p>
10121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10122             * </p>
10123             *
10124             * @param threadId the thread ID
10125             * @param status the status
10126             * @param start the lower bound of the range of message-boards messages
10127             * @param end the upper bound of the range of message-boards messages (not inclusive)
10128             * @return the range of matching message-boards messages
10129             */
10130            @Override
10131            public List<MBMessage> findByT_S(long threadId, int status, int start,
10132                    int end) {
10133                    return findByT_S(threadId, status, start, end, null);
10134            }
10135    
10136            /**
10137             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10138             *
10139             * <p>
10140             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10141             * </p>
10142             *
10143             * @param threadId the thread ID
10144             * @param status the status
10145             * @param start the lower bound of the range of message-boards messages
10146             * @param end the upper bound of the range of message-boards messages (not inclusive)
10147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10148             * @return the ordered range of matching message-boards messages
10149             */
10150            @Override
10151            public List<MBMessage> findByT_S(long threadId, int status, int start,
10152                    int end, OrderByComparator<MBMessage> orderByComparator) {
10153                    return findByT_S(threadId, status, start, end, orderByComparator, true);
10154            }
10155    
10156            /**
10157             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10158             *
10159             * <p>
10160             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10161             * </p>
10162             *
10163             * @param threadId the thread ID
10164             * @param status the status
10165             * @param start the lower bound of the range of message-boards messages
10166             * @param end the upper bound of the range of message-boards messages (not inclusive)
10167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10168             * @param retrieveFromCache whether to retrieve from the finder cache
10169             * @return the ordered range of matching message-boards messages
10170             */
10171            @Override
10172            public List<MBMessage> findByT_S(long threadId, int status, int start,
10173                    int end, OrderByComparator<MBMessage> orderByComparator,
10174                    boolean retrieveFromCache) {
10175                    boolean pagination = true;
10176                    FinderPath finderPath = null;
10177                    Object[] finderArgs = null;
10178    
10179                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10180                                    (orderByComparator == null)) {
10181                            pagination = false;
10182                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10183                            finderArgs = new Object[] { threadId, status };
10184                    }
10185                    else {
10186                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10187                            finderArgs = new Object[] {
10188                                            threadId, status,
10189                                            
10190                                            start, end, orderByComparator
10191                                    };
10192                    }
10193    
10194                    List<MBMessage> list = null;
10195    
10196                    if (retrieveFromCache) {
10197                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10198                                            finderArgs, this);
10199    
10200                            if ((list != null) && !list.isEmpty()) {
10201                                    for (MBMessage mbMessage : list) {
10202                                            if ((threadId != mbMessage.getThreadId()) ||
10203                                                            (status != mbMessage.getStatus())) {
10204                                                    list = null;
10205    
10206                                                    break;
10207                                            }
10208                                    }
10209                            }
10210                    }
10211    
10212                    if (list == null) {
10213                            StringBundler query = null;
10214    
10215                            if (orderByComparator != null) {
10216                                    query = new StringBundler(4 +
10217                                                    (orderByComparator.getOrderByFields().length * 3));
10218                            }
10219                            else {
10220                                    query = new StringBundler(4);
10221                            }
10222    
10223                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10224    
10225                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10226    
10227                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10228    
10229                            if (orderByComparator != null) {
10230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10231                                            orderByComparator);
10232                            }
10233                            else
10234                             if (pagination) {
10235                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10236                            }
10237    
10238                            String sql = query.toString();
10239    
10240                            Session session = null;
10241    
10242                            try {
10243                                    session = openSession();
10244    
10245                                    Query q = session.createQuery(sql);
10246    
10247                                    QueryPos qPos = QueryPos.getInstance(q);
10248    
10249                                    qPos.add(threadId);
10250    
10251                                    qPos.add(status);
10252    
10253                                    if (!pagination) {
10254                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10255                                                            start, end, false);
10256    
10257                                            Collections.sort(list);
10258    
10259                                            list = Collections.unmodifiableList(list);
10260                                    }
10261                                    else {
10262                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10263                                                            start, end);
10264                                    }
10265    
10266                                    cacheResult(list);
10267    
10268                                    finderCache.putResult(finderPath, finderArgs, list);
10269                            }
10270                            catch (Exception e) {
10271                                    finderCache.removeResult(finderPath, finderArgs);
10272    
10273                                    throw processException(e);
10274                            }
10275                            finally {
10276                                    closeSession(session);
10277                            }
10278                    }
10279    
10280                    return list;
10281            }
10282    
10283            /**
10284             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10285             *
10286             * @param threadId the thread ID
10287             * @param status the status
10288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10289             * @return the first matching message-boards message
10290             * @throws NoSuchMessageException if a matching message-boards message could not be found
10291             */
10292            @Override
10293            public MBMessage findByT_S_First(long threadId, int status,
10294                    OrderByComparator<MBMessage> orderByComparator)
10295                    throws NoSuchMessageException {
10296                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10297                                    orderByComparator);
10298    
10299                    if (mbMessage != null) {
10300                            return mbMessage;
10301                    }
10302    
10303                    StringBundler msg = new StringBundler(6);
10304    
10305                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10306    
10307                    msg.append("threadId=");
10308                    msg.append(threadId);
10309    
10310                    msg.append(", status=");
10311                    msg.append(status);
10312    
10313                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10314    
10315                    throw new NoSuchMessageException(msg.toString());
10316            }
10317    
10318            /**
10319             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10320             *
10321             * @param threadId the thread ID
10322             * @param status the status
10323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10324             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10325             */
10326            @Override
10327            public MBMessage fetchByT_S_First(long threadId, int status,
10328                    OrderByComparator<MBMessage> orderByComparator) {
10329                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10330                                    orderByComparator);
10331    
10332                    if (!list.isEmpty()) {
10333                            return list.get(0);
10334                    }
10335    
10336                    return null;
10337            }
10338    
10339            /**
10340             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10341             *
10342             * @param threadId the thread ID
10343             * @param status the status
10344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10345             * @return the last matching message-boards message
10346             * @throws NoSuchMessageException if a matching message-boards message could not be found
10347             */
10348            @Override
10349            public MBMessage findByT_S_Last(long threadId, int status,
10350                    OrderByComparator<MBMessage> orderByComparator)
10351                    throws NoSuchMessageException {
10352                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10353                                    orderByComparator);
10354    
10355                    if (mbMessage != null) {
10356                            return mbMessage;
10357                    }
10358    
10359                    StringBundler msg = new StringBundler(6);
10360    
10361                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10362    
10363                    msg.append("threadId=");
10364                    msg.append(threadId);
10365    
10366                    msg.append(", status=");
10367                    msg.append(status);
10368    
10369                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10370    
10371                    throw new NoSuchMessageException(msg.toString());
10372            }
10373    
10374            /**
10375             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10376             *
10377             * @param threadId the thread ID
10378             * @param status the status
10379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10380             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10381             */
10382            @Override
10383            public MBMessage fetchByT_S_Last(long threadId, int status,
10384                    OrderByComparator<MBMessage> orderByComparator) {
10385                    int count = countByT_S(threadId, status);
10386    
10387                    if (count == 0) {
10388                            return null;
10389                    }
10390    
10391                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10392                                    orderByComparator);
10393    
10394                    if (!list.isEmpty()) {
10395                            return list.get(0);
10396                    }
10397    
10398                    return null;
10399            }
10400    
10401            /**
10402             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10403             *
10404             * @param messageId the primary key of the current message-boards message
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 previous, current, and next message-boards message
10409             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10410             */
10411            @Override
10412            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10413                    int status, OrderByComparator<MBMessage> orderByComparator)
10414                    throws NoSuchMessageException {
10415                    MBMessage mbMessage = findByPrimaryKey(messageId);
10416    
10417                    Session session = null;
10418    
10419                    try {
10420                            session = openSession();
10421    
10422                            MBMessage[] array = new MBMessageImpl[3];
10423    
10424                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10425                                            status, orderByComparator, true);
10426    
10427                            array[1] = mbMessage;
10428    
10429                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10430                                            status, orderByComparator, false);
10431    
10432                            return array;
10433                    }
10434                    catch (Exception e) {
10435                            throw processException(e);
10436                    }
10437                    finally {
10438                            closeSession(session);
10439                    }
10440            }
10441    
10442            protected MBMessage getByT_S_PrevAndNext(Session session,
10443                    MBMessage mbMessage, long threadId, int status,
10444                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10445                    StringBundler query = null;
10446    
10447                    if (orderByComparator != null) {
10448                            query = new StringBundler(6 +
10449                                            (orderByComparator.getOrderByFields().length * 6));
10450                    }
10451                    else {
10452                            query = new StringBundler(3);
10453                    }
10454    
10455                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10456    
10457                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10458    
10459                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10460    
10461                    if (orderByComparator != null) {
10462                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10463    
10464                            if (orderByConditionFields.length > 0) {
10465                                    query.append(WHERE_AND);
10466                            }
10467    
10468                            for (int i = 0; i < orderByConditionFields.length; i++) {
10469                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10470                                    query.append(orderByConditionFields[i]);
10471    
10472                                    if ((i + 1) < orderByConditionFields.length) {
10473                                            if (orderByComparator.isAscending() ^ previous) {
10474                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10475                                            }
10476                                            else {
10477                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10478                                            }
10479                                    }
10480                                    else {
10481                                            if (orderByComparator.isAscending() ^ previous) {
10482                                                    query.append(WHERE_GREATER_THAN);
10483                                            }
10484                                            else {
10485                                                    query.append(WHERE_LESSER_THAN);
10486                                            }
10487                                    }
10488                            }
10489    
10490                            query.append(ORDER_BY_CLAUSE);
10491    
10492                            String[] orderByFields = orderByComparator.getOrderByFields();
10493    
10494                            for (int i = 0; i < orderByFields.length; i++) {
10495                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10496                                    query.append(orderByFields[i]);
10497    
10498                                    if ((i + 1) < orderByFields.length) {
10499                                            if (orderByComparator.isAscending() ^ previous) {
10500                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10501                                            }
10502                                            else {
10503                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10504                                            }
10505                                    }
10506                                    else {
10507                                            if (orderByComparator.isAscending() ^ previous) {
10508                                                    query.append(ORDER_BY_ASC);
10509                                            }
10510                                            else {
10511                                                    query.append(ORDER_BY_DESC);
10512                                            }
10513                                    }
10514                            }
10515                    }
10516                    else {
10517                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10518                    }
10519    
10520                    String sql = query.toString();
10521    
10522                    Query q = session.createQuery(sql);
10523    
10524                    q.setFirstResult(0);
10525                    q.setMaxResults(2);
10526    
10527                    QueryPos qPos = QueryPos.getInstance(q);
10528    
10529                    qPos.add(threadId);
10530    
10531                    qPos.add(status);
10532    
10533                    if (orderByComparator != null) {
10534                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10535    
10536                            for (Object value : values) {
10537                                    qPos.add(value);
10538                            }
10539                    }
10540    
10541                    List<MBMessage> list = q.list();
10542    
10543                    if (list.size() == 2) {
10544                            return list.get(1);
10545                    }
10546                    else {
10547                            return null;
10548                    }
10549            }
10550    
10551            /**
10552             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10553             *
10554             * @param threadId the thread ID
10555             * @param status the status
10556             */
10557            @Override
10558            public void removeByT_S(long threadId, int status) {
10559                    for (MBMessage mbMessage : findByT_S(threadId, status,
10560                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10561                            remove(mbMessage);
10562                    }
10563            }
10564    
10565            /**
10566             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10567             *
10568             * @param threadId the thread ID
10569             * @param status the status
10570             * @return the number of matching message-boards messages
10571             */
10572            @Override
10573            public int countByT_S(long threadId, int status) {
10574                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10575    
10576                    Object[] finderArgs = new Object[] { threadId, status };
10577    
10578                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10579    
10580                    if (count == null) {
10581                            StringBundler query = new StringBundler(3);
10582    
10583                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10584    
10585                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10586    
10587                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10588    
10589                            String sql = query.toString();
10590    
10591                            Session session = null;
10592    
10593                            try {
10594                                    session = openSession();
10595    
10596                                    Query q = session.createQuery(sql);
10597    
10598                                    QueryPos qPos = QueryPos.getInstance(q);
10599    
10600                                    qPos.add(threadId);
10601    
10602                                    qPos.add(status);
10603    
10604                                    count = (Long)q.uniqueResult();
10605    
10606                                    finderCache.putResult(finderPath, finderArgs, count);
10607                            }
10608                            catch (Exception e) {
10609                                    finderCache.removeResult(finderPath, finderArgs);
10610    
10611                                    throw processException(e);
10612                            }
10613                            finally {
10614                                    closeSession(session);
10615                            }
10616                    }
10617    
10618                    return count.intValue();
10619            }
10620    
10621            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10622            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10623            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10624                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10625                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10626                            new String[] {
10627                                    Long.class.getName(), Integer.class.getName(),
10628                                    
10629                            Integer.class.getName(), Integer.class.getName(),
10630                                    OrderByComparator.class.getName()
10631                            });
10632            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10633                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10634                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10635                            new String[] { Long.class.getName(), Integer.class.getName() },
10636                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10637                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10638                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10639            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10640                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10641                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10642                            new String[] { Long.class.getName(), Integer.class.getName() });
10643    
10644            /**
10645             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10646             *
10647             * @param threadId the thread ID
10648             * @param status the status
10649             * @return the matching message-boards messages
10650             */
10651            @Override
10652            public List<MBMessage> findByTR_S(long threadId, int status) {
10653                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10654                            QueryUtil.ALL_POS, null);
10655            }
10656    
10657            /**
10658             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10659             *
10660             * <p>
10661             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10662             * </p>
10663             *
10664             * @param threadId the thread ID
10665             * @param status the status
10666             * @param start the lower bound of the range of message-boards messages
10667             * @param end the upper bound of the range of message-boards messages (not inclusive)
10668             * @return the range of matching message-boards messages
10669             */
10670            @Override
10671            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10672                    int end) {
10673                    return findByTR_S(threadId, status, start, end, null);
10674            }
10675    
10676            /**
10677             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10678             *
10679             * <p>
10680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10681             * </p>
10682             *
10683             * @param threadId the thread ID
10684             * @param status the status
10685             * @param start the lower bound of the range of message-boards messages
10686             * @param end the upper bound of the range of message-boards messages (not inclusive)
10687             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10688             * @return the ordered range of matching message-boards messages
10689             */
10690            @Override
10691            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10692                    int end, OrderByComparator<MBMessage> orderByComparator) {
10693                    return findByTR_S(threadId, status, start, end, orderByComparator, true);
10694            }
10695    
10696            /**
10697             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10698             *
10699             * <p>
10700             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10701             * </p>
10702             *
10703             * @param threadId the thread ID
10704             * @param status the status
10705             * @param start the lower bound of the range of message-boards messages
10706             * @param end the upper bound of the range of message-boards messages (not inclusive)
10707             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10708             * @param retrieveFromCache whether to retrieve from the finder cache
10709             * @return the ordered range of matching message-boards messages
10710             */
10711            @Override
10712            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10713                    int end, OrderByComparator<MBMessage> orderByComparator,
10714                    boolean retrieveFromCache) {
10715                    boolean pagination = true;
10716                    FinderPath finderPath = null;
10717                    Object[] finderArgs = null;
10718    
10719                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10720                                    (orderByComparator == null)) {
10721                            pagination = false;
10722                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10723                            finderArgs = new Object[] { threadId, status };
10724                    }
10725                    else {
10726                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10727                            finderArgs = new Object[] {
10728                                            threadId, status,
10729                                            
10730                                            start, end, orderByComparator
10731                                    };
10732                    }
10733    
10734                    List<MBMessage> list = null;
10735    
10736                    if (retrieveFromCache) {
10737                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10738                                            finderArgs, this);
10739    
10740                            if ((list != null) && !list.isEmpty()) {
10741                                    for (MBMessage mbMessage : list) {
10742                                            if ((threadId != mbMessage.getThreadId()) ||
10743                                                            (status != mbMessage.getStatus())) {
10744                                                    list = null;
10745    
10746                                                    break;
10747                                            }
10748                                    }
10749                            }
10750                    }
10751    
10752                    if (list == null) {
10753                            StringBundler query = null;
10754    
10755                            if (orderByComparator != null) {
10756                                    query = new StringBundler(4 +
10757                                                    (orderByComparator.getOrderByFields().length * 3));
10758                            }
10759                            else {
10760                                    query = new StringBundler(4);
10761                            }
10762    
10763                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10764    
10765                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10766    
10767                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10768    
10769                            if (orderByComparator != null) {
10770                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10771                                            orderByComparator);
10772                            }
10773                            else
10774                             if (pagination) {
10775                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10776                            }
10777    
10778                            String sql = query.toString();
10779    
10780                            Session session = null;
10781    
10782                            try {
10783                                    session = openSession();
10784    
10785                                    Query q = session.createQuery(sql);
10786    
10787                                    QueryPos qPos = QueryPos.getInstance(q);
10788    
10789                                    qPos.add(threadId);
10790    
10791                                    qPos.add(status);
10792    
10793                                    if (!pagination) {
10794                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10795                                                            start, end, false);
10796    
10797                                            Collections.sort(list);
10798    
10799                                            list = Collections.unmodifiableList(list);
10800                                    }
10801                                    else {
10802                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10803                                                            start, end);
10804                                    }
10805    
10806                                    cacheResult(list);
10807    
10808                                    finderCache.putResult(finderPath, finderArgs, list);
10809                            }
10810                            catch (Exception e) {
10811                                    finderCache.removeResult(finderPath, finderArgs);
10812    
10813                                    throw processException(e);
10814                            }
10815                            finally {
10816                                    closeSession(session);
10817                            }
10818                    }
10819    
10820                    return list;
10821            }
10822    
10823            /**
10824             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10825             *
10826             * @param threadId the thread ID
10827             * @param status the status
10828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10829             * @return the first matching message-boards message
10830             * @throws NoSuchMessageException if a matching message-boards message could not be found
10831             */
10832            @Override
10833            public MBMessage findByTR_S_First(long threadId, int status,
10834                    OrderByComparator<MBMessage> orderByComparator)
10835                    throws NoSuchMessageException {
10836                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10837                                    orderByComparator);
10838    
10839                    if (mbMessage != null) {
10840                            return mbMessage;
10841                    }
10842    
10843                    StringBundler msg = new StringBundler(6);
10844    
10845                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10846    
10847                    msg.append("threadId=");
10848                    msg.append(threadId);
10849    
10850                    msg.append(", status=");
10851                    msg.append(status);
10852    
10853                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10854    
10855                    throw new NoSuchMessageException(msg.toString());
10856            }
10857    
10858            /**
10859             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10860             *
10861             * @param threadId the thread ID
10862             * @param status the status
10863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10864             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10865             */
10866            @Override
10867            public MBMessage fetchByTR_S_First(long threadId, int status,
10868                    OrderByComparator<MBMessage> orderByComparator) {
10869                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10870                                    orderByComparator);
10871    
10872                    if (!list.isEmpty()) {
10873                            return list.get(0);
10874                    }
10875    
10876                    return null;
10877            }
10878    
10879            /**
10880             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10881             *
10882             * @param threadId the thread ID
10883             * @param status the status
10884             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10885             * @return the last matching message-boards message
10886             * @throws NoSuchMessageException if a matching message-boards message could not be found
10887             */
10888            @Override
10889            public MBMessage findByTR_S_Last(long threadId, int status,
10890                    OrderByComparator<MBMessage> orderByComparator)
10891                    throws NoSuchMessageException {
10892                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10893                                    orderByComparator);
10894    
10895                    if (mbMessage != null) {
10896                            return mbMessage;
10897                    }
10898    
10899                    StringBundler msg = new StringBundler(6);
10900    
10901                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10902    
10903                    msg.append("threadId=");
10904                    msg.append(threadId);
10905    
10906                    msg.append(", status=");
10907                    msg.append(status);
10908    
10909                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10910    
10911                    throw new NoSuchMessageException(msg.toString());
10912            }
10913    
10914            /**
10915             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10916             *
10917             * @param threadId the thread ID
10918             * @param status the status
10919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10920             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10921             */
10922            @Override
10923            public MBMessage fetchByTR_S_Last(long threadId, int status,
10924                    OrderByComparator<MBMessage> orderByComparator) {
10925                    int count = countByTR_S(threadId, status);
10926    
10927                    if (count == 0) {
10928                            return null;
10929                    }
10930    
10931                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10932                                    orderByComparator);
10933    
10934                    if (!list.isEmpty()) {
10935                            return list.get(0);
10936                    }
10937    
10938                    return null;
10939            }
10940    
10941            /**
10942             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10943             *
10944             * @param messageId the primary key of the current message-boards message
10945             * @param threadId the thread ID
10946             * @param status the status
10947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10948             * @return the previous, current, and next message-boards message
10949             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10950             */
10951            @Override
10952            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10953                    int status, OrderByComparator<MBMessage> orderByComparator)
10954                    throws NoSuchMessageException {
10955                    MBMessage mbMessage = findByPrimaryKey(messageId);
10956    
10957                    Session session = null;
10958    
10959                    try {
10960                            session = openSession();
10961    
10962                            MBMessage[] array = new MBMessageImpl[3];
10963    
10964                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10965                                            status, orderByComparator, true);
10966    
10967                            array[1] = mbMessage;
10968    
10969                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10970                                            status, orderByComparator, false);
10971    
10972                            return array;
10973                    }
10974                    catch (Exception e) {
10975                            throw processException(e);
10976                    }
10977                    finally {
10978                            closeSession(session);
10979                    }
10980            }
10981    
10982            protected MBMessage getByTR_S_PrevAndNext(Session session,
10983                    MBMessage mbMessage, long threadId, int status,
10984                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10985                    StringBundler query = null;
10986    
10987                    if (orderByComparator != null) {
10988                            query = new StringBundler(6 +
10989                                            (orderByComparator.getOrderByFields().length * 6));
10990                    }
10991                    else {
10992                            query = new StringBundler(3);
10993                    }
10994    
10995                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10996    
10997                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10998    
10999                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11000    
11001                    if (orderByComparator != null) {
11002                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11003    
11004                            if (orderByConditionFields.length > 0) {
11005                                    query.append(WHERE_AND);
11006                            }
11007    
11008                            for (int i = 0; i < orderByConditionFields.length; i++) {
11009                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11010                                    query.append(orderByConditionFields[i]);
11011    
11012                                    if ((i + 1) < orderByConditionFields.length) {
11013                                            if (orderByComparator.isAscending() ^ previous) {
11014                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11015                                            }
11016                                            else {
11017                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11018                                            }
11019                                    }
11020                                    else {
11021                                            if (orderByComparator.isAscending() ^ previous) {
11022                                                    query.append(WHERE_GREATER_THAN);
11023                                            }
11024                                            else {
11025                                                    query.append(WHERE_LESSER_THAN);
11026                                            }
11027                                    }
11028                            }
11029    
11030                            query.append(ORDER_BY_CLAUSE);
11031    
11032                            String[] orderByFields = orderByComparator.getOrderByFields();
11033    
11034                            for (int i = 0; i < orderByFields.length; i++) {
11035                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11036                                    query.append(orderByFields[i]);
11037    
11038                                    if ((i + 1) < orderByFields.length) {
11039                                            if (orderByComparator.isAscending() ^ previous) {
11040                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11041                                            }
11042                                            else {
11043                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11044                                            }
11045                                    }
11046                                    else {
11047                                            if (orderByComparator.isAscending() ^ previous) {
11048                                                    query.append(ORDER_BY_ASC);
11049                                            }
11050                                            else {
11051                                                    query.append(ORDER_BY_DESC);
11052                                            }
11053                                    }
11054                            }
11055                    }
11056                    else {
11057                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11058                    }
11059    
11060                    String sql = query.toString();
11061    
11062                    Query q = session.createQuery(sql);
11063    
11064                    q.setFirstResult(0);
11065                    q.setMaxResults(2);
11066    
11067                    QueryPos qPos = QueryPos.getInstance(q);
11068    
11069                    qPos.add(threadId);
11070    
11071                    qPos.add(status);
11072    
11073                    if (orderByComparator != null) {
11074                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11075    
11076                            for (Object value : values) {
11077                                    qPos.add(value);
11078                            }
11079                    }
11080    
11081                    List<MBMessage> list = q.list();
11082    
11083                    if (list.size() == 2) {
11084                            return list.get(1);
11085                    }
11086                    else {
11087                            return null;
11088                    }
11089            }
11090    
11091            /**
11092             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
11093             *
11094             * @param threadId the thread ID
11095             * @param status the status
11096             */
11097            @Override
11098            public void removeByTR_S(long threadId, int status) {
11099                    for (MBMessage mbMessage : findByTR_S(threadId, status,
11100                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11101                            remove(mbMessage);
11102                    }
11103            }
11104    
11105            /**
11106             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
11107             *
11108             * @param threadId the thread ID
11109             * @param status the status
11110             * @return the number of matching message-boards messages
11111             */
11112            @Override
11113            public int countByTR_S(long threadId, int status) {
11114                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
11115    
11116                    Object[] finderArgs = new Object[] { threadId, status };
11117    
11118                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
11119    
11120                    if (count == null) {
11121                            StringBundler query = new StringBundler(3);
11122    
11123                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11124    
11125                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11126    
11127                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11128    
11129                            String sql = query.toString();
11130    
11131                            Session session = null;
11132    
11133                            try {
11134                                    session = openSession();
11135    
11136                                    Query q = session.createQuery(sql);
11137    
11138                                    QueryPos qPos = QueryPos.getInstance(q);
11139    
11140                                    qPos.add(threadId);
11141    
11142                                    qPos.add(status);
11143    
11144                                    count = (Long)q.uniqueResult();
11145    
11146                                    finderCache.putResult(finderPath, finderArgs, count);
11147                            }
11148                            catch (Exception e) {
11149                                    finderCache.removeResult(finderPath, finderArgs);
11150    
11151                                    throw processException(e);
11152                            }
11153                            finally {
11154                                    closeSession(session);
11155                            }
11156                    }
11157    
11158                    return count.intValue();
11159            }
11160    
11161            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11162            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11163            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11164                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11165                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
11166                            new String[] {
11167                                    Long.class.getName(), Long.class.getName(),
11168                                    Integer.class.getName(),
11169                                    
11170                            Integer.class.getName(), Integer.class.getName(),
11171                                    OrderByComparator.class.getName()
11172                            });
11173            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11174                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11175                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
11176                            new String[] {
11177                                    Long.class.getName(), Long.class.getName(),
11178                                    Integer.class.getName()
11179                            },
11180                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11181                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
11182                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
11183                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11184            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11186                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
11187                            new String[] {
11188                                    Long.class.getName(), Long.class.getName(),
11189                                    Integer.class.getName()
11190                            });
11191    
11192            /**
11193             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11194             *
11195             * @param groupId the group ID
11196             * @param userId the user ID
11197             * @param status the status
11198             * @return the matching message-boards messages
11199             */
11200            @Override
11201            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
11202                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11203                            QueryUtil.ALL_POS, null);
11204            }
11205    
11206            /**
11207             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11208             *
11209             * <p>
11210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11211             * </p>
11212             *
11213             * @param groupId the group ID
11214             * @param userId the user ID
11215             * @param status the status
11216             * @param start the lower bound of the range of message-boards messages
11217             * @param end the upper bound of the range of message-boards messages (not inclusive)
11218             * @return the range of matching message-boards messages
11219             */
11220            @Override
11221            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11222                    int start, int end) {
11223                    return findByG_U_S(groupId, userId, status, start, end, null);
11224            }
11225    
11226            /**
11227             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11228             *
11229             * <p>
11230             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11231             * </p>
11232             *
11233             * @param groupId the group ID
11234             * @param userId the user ID
11235             * @param status the status
11236             * @param start the lower bound of the range of message-boards messages
11237             * @param end the upper bound of the range of message-boards messages (not inclusive)
11238             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11239             * @return the ordered range of matching message-boards messages
11240             */
11241            @Override
11242            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11243                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
11244                    return findByG_U_S(groupId, userId, status, start, end,
11245                            orderByComparator, true);
11246            }
11247    
11248            /**
11249             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11250             *
11251             * <p>
11252             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11253             * </p>
11254             *
11255             * @param groupId the group ID
11256             * @param userId the user ID
11257             * @param status the status
11258             * @param start the lower bound of the range of message-boards messages
11259             * @param end the upper bound of the range of message-boards messages (not inclusive)
11260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11261             * @param retrieveFromCache whether to retrieve from the finder cache
11262             * @return the ordered range of matching message-boards messages
11263             */
11264            @Override
11265            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11266                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
11267                    boolean retrieveFromCache) {
11268                    boolean pagination = true;
11269                    FinderPath finderPath = null;
11270                    Object[] finderArgs = null;
11271    
11272                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11273                                    (orderByComparator == null)) {
11274                            pagination = false;
11275                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11276                            finderArgs = new Object[] { groupId, userId, status };
11277                    }
11278                    else {
11279                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11280                            finderArgs = new Object[] {
11281                                            groupId, userId, status,
11282                                            
11283                                            start, end, orderByComparator
11284                                    };
11285                    }
11286    
11287                    List<MBMessage> list = null;
11288    
11289                    if (retrieveFromCache) {
11290                            list = (List<MBMessage>)finderCache.getResult(finderPath,
11291                                            finderArgs, this);
11292    
11293                            if ((list != null) && !list.isEmpty()) {
11294                                    for (MBMessage mbMessage : list) {
11295                                            if ((groupId != mbMessage.getGroupId()) ||
11296                                                            (userId != mbMessage.getUserId()) ||
11297                                                            (status != mbMessage.getStatus())) {
11298                                                    list = null;
11299    
11300                                                    break;
11301                                            }
11302                                    }
11303                            }
11304                    }
11305    
11306                    if (list == null) {
11307                            StringBundler query = null;
11308    
11309                            if (orderByComparator != null) {
11310                                    query = new StringBundler(5 +
11311                                                    (orderByComparator.getOrderByFields().length * 3));
11312                            }
11313                            else {
11314                                    query = new StringBundler(5);
11315                            }
11316    
11317                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11318    
11319                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11320    
11321                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11322    
11323                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11324    
11325                            if (orderByComparator != null) {
11326                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11327                                            orderByComparator);
11328                            }
11329                            else
11330                             if (pagination) {
11331                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11332                            }
11333    
11334                            String sql = query.toString();
11335    
11336                            Session session = null;
11337    
11338                            try {
11339                                    session = openSession();
11340    
11341                                    Query q = session.createQuery(sql);
11342    
11343                                    QueryPos qPos = QueryPos.getInstance(q);
11344    
11345                                    qPos.add(groupId);
11346    
11347                                    qPos.add(userId);
11348    
11349                                    qPos.add(status);
11350    
11351                                    if (!pagination) {
11352                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11353                                                            start, end, false);
11354    
11355                                            Collections.sort(list);
11356    
11357                                            list = Collections.unmodifiableList(list);
11358                                    }
11359                                    else {
11360                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11361                                                            start, end);
11362                                    }
11363    
11364                                    cacheResult(list);
11365    
11366                                    finderCache.putResult(finderPath, finderArgs, list);
11367                            }
11368                            catch (Exception e) {
11369                                    finderCache.removeResult(finderPath, finderArgs);
11370    
11371                                    throw processException(e);
11372                            }
11373                            finally {
11374                                    closeSession(session);
11375                            }
11376                    }
11377    
11378                    return list;
11379            }
11380    
11381            /**
11382             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11383             *
11384             * @param groupId the group ID
11385             * @param userId the user ID
11386             * @param status the status
11387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11388             * @return the first matching message-boards message
11389             * @throws NoSuchMessageException if a matching message-boards message could not be found
11390             */
11391            @Override
11392            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11393                    OrderByComparator<MBMessage> orderByComparator)
11394                    throws NoSuchMessageException {
11395                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11396                                    orderByComparator);
11397    
11398                    if (mbMessage != null) {
11399                            return mbMessage;
11400                    }
11401    
11402                    StringBundler msg = new StringBundler(8);
11403    
11404                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11405    
11406                    msg.append("groupId=");
11407                    msg.append(groupId);
11408    
11409                    msg.append(", userId=");
11410                    msg.append(userId);
11411    
11412                    msg.append(", status=");
11413                    msg.append(status);
11414    
11415                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11416    
11417                    throw new NoSuchMessageException(msg.toString());
11418            }
11419    
11420            /**
11421             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11422             *
11423             * @param groupId the group ID
11424             * @param userId the user ID
11425             * @param status the status
11426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11427             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11428             */
11429            @Override
11430            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11431                    OrderByComparator<MBMessage> orderByComparator) {
11432                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11433                                    orderByComparator);
11434    
11435                    if (!list.isEmpty()) {
11436                            return list.get(0);
11437                    }
11438    
11439                    return null;
11440            }
11441    
11442            /**
11443             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11444             *
11445             * @param groupId the group ID
11446             * @param userId the user ID
11447             * @param status the status
11448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11449             * @return the last matching message-boards message
11450             * @throws NoSuchMessageException if a matching message-boards message could not be found
11451             */
11452            @Override
11453            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11454                    OrderByComparator<MBMessage> orderByComparator)
11455                    throws NoSuchMessageException {
11456                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11457                                    orderByComparator);
11458    
11459                    if (mbMessage != null) {
11460                            return mbMessage;
11461                    }
11462    
11463                    StringBundler msg = new StringBundler(8);
11464    
11465                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11466    
11467                    msg.append("groupId=");
11468                    msg.append(groupId);
11469    
11470                    msg.append(", userId=");
11471                    msg.append(userId);
11472    
11473                    msg.append(", status=");
11474                    msg.append(status);
11475    
11476                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11477    
11478                    throw new NoSuchMessageException(msg.toString());
11479            }
11480    
11481            /**
11482             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11483             *
11484             * @param groupId the group ID
11485             * @param userId the user ID
11486             * @param status the status
11487             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11488             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11489             */
11490            @Override
11491            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11492                    OrderByComparator<MBMessage> orderByComparator) {
11493                    int count = countByG_U_S(groupId, userId, status);
11494    
11495                    if (count == 0) {
11496                            return null;
11497                    }
11498    
11499                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11500                                    count, orderByComparator);
11501    
11502                    if (!list.isEmpty()) {
11503                            return list.get(0);
11504                    }
11505    
11506                    return null;
11507            }
11508    
11509            /**
11510             * 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;.
11511             *
11512             * @param messageId the primary key of the current message-boards message
11513             * @param groupId the group ID
11514             * @param userId the user ID
11515             * @param status the status
11516             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11517             * @return the previous, current, and next message-boards message
11518             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11519             */
11520            @Override
11521            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11522                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11523                    throws NoSuchMessageException {
11524                    MBMessage mbMessage = findByPrimaryKey(messageId);
11525    
11526                    Session session = null;
11527    
11528                    try {
11529                            session = openSession();
11530    
11531                            MBMessage[] array = new MBMessageImpl[3];
11532    
11533                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11534                                            userId, status, orderByComparator, true);
11535    
11536                            array[1] = mbMessage;
11537    
11538                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11539                                            userId, status, orderByComparator, false);
11540    
11541                            return array;
11542                    }
11543                    catch (Exception e) {
11544                            throw processException(e);
11545                    }
11546                    finally {
11547                            closeSession(session);
11548                    }
11549            }
11550    
11551            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11552                    MBMessage mbMessage, long groupId, long userId, int status,
11553                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11554                    StringBundler query = null;
11555    
11556                    if (orderByComparator != null) {
11557                            query = new StringBundler(6 +
11558                                            (orderByComparator.getOrderByFields().length * 6));
11559                    }
11560                    else {
11561                            query = new StringBundler(3);
11562                    }
11563    
11564                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11565    
11566                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11567    
11568                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11569    
11570                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11571    
11572                    if (orderByComparator != null) {
11573                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11574    
11575                            if (orderByConditionFields.length > 0) {
11576                                    query.append(WHERE_AND);
11577                            }
11578    
11579                            for (int i = 0; i < orderByConditionFields.length; i++) {
11580                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11581                                    query.append(orderByConditionFields[i]);
11582    
11583                                    if ((i + 1) < orderByConditionFields.length) {
11584                                            if (orderByComparator.isAscending() ^ previous) {
11585                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11586                                            }
11587                                            else {
11588                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11589                                            }
11590                                    }
11591                                    else {
11592                                            if (orderByComparator.isAscending() ^ previous) {
11593                                                    query.append(WHERE_GREATER_THAN);
11594                                            }
11595                                            else {
11596                                                    query.append(WHERE_LESSER_THAN);
11597                                            }
11598                                    }
11599                            }
11600    
11601                            query.append(ORDER_BY_CLAUSE);
11602    
11603                            String[] orderByFields = orderByComparator.getOrderByFields();
11604    
11605                            for (int i = 0; i < orderByFields.length; i++) {
11606                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11607                                    query.append(orderByFields[i]);
11608    
11609                                    if ((i + 1) < orderByFields.length) {
11610                                            if (orderByComparator.isAscending() ^ previous) {
11611                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11612                                            }
11613                                            else {
11614                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11615                                            }
11616                                    }
11617                                    else {
11618                                            if (orderByComparator.isAscending() ^ previous) {
11619                                                    query.append(ORDER_BY_ASC);
11620                                            }
11621                                            else {
11622                                                    query.append(ORDER_BY_DESC);
11623                                            }
11624                                    }
11625                            }
11626                    }
11627                    else {
11628                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11629                    }
11630    
11631                    String sql = query.toString();
11632    
11633                    Query q = session.createQuery(sql);
11634    
11635                    q.setFirstResult(0);
11636                    q.setMaxResults(2);
11637    
11638                    QueryPos qPos = QueryPos.getInstance(q);
11639    
11640                    qPos.add(groupId);
11641    
11642                    qPos.add(userId);
11643    
11644                    qPos.add(status);
11645    
11646                    if (orderByComparator != null) {
11647                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11648    
11649                            for (Object value : values) {
11650                                    qPos.add(value);
11651                            }
11652                    }
11653    
11654                    List<MBMessage> list = q.list();
11655    
11656                    if (list.size() == 2) {
11657                            return list.get(1);
11658                    }
11659                    else {
11660                            return null;
11661                    }
11662            }
11663    
11664            /**
11665             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11666             *
11667             * @param groupId the group ID
11668             * @param userId the user ID
11669             * @param status the status
11670             * @return the matching message-boards messages that the user has permission to view
11671             */
11672            @Override
11673            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11674                    int status) {
11675                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11676                            QueryUtil.ALL_POS, null);
11677            }
11678    
11679            /**
11680             * 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;.
11681             *
11682             * <p>
11683             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11684             * </p>
11685             *
11686             * @param groupId the group ID
11687             * @param userId the user ID
11688             * @param status the status
11689             * @param start the lower bound of the range of message-boards messages
11690             * @param end the upper bound of the range of message-boards messages (not inclusive)
11691             * @return the range of matching message-boards messages that the user has permission to view
11692             */
11693            @Override
11694            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11695                    int status, int start, int end) {
11696                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11697            }
11698    
11699            /**
11700             * 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;.
11701             *
11702             * <p>
11703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11704             * </p>
11705             *
11706             * @param groupId the group ID
11707             * @param userId the user ID
11708             * @param status the status
11709             * @param start the lower bound of the range of message-boards messages
11710             * @param end the upper bound of the range of message-boards messages (not inclusive)
11711             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11712             * @return the ordered range of matching message-boards messages that the user has permission to view
11713             */
11714            @Override
11715            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11716                    int status, int start, int end,
11717                    OrderByComparator<MBMessage> orderByComparator) {
11718                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11719                            return findByG_U_S(groupId, userId, status, start, end,
11720                                    orderByComparator);
11721                    }
11722    
11723                    StringBundler query = null;
11724    
11725                    if (orderByComparator != null) {
11726                            query = new StringBundler(5 +
11727                                            (orderByComparator.getOrderByFields().length * 3));
11728                    }
11729                    else {
11730                            query = new StringBundler(5);
11731                    }
11732    
11733                    if (getDB().isSupportsInlineDistinct()) {
11734                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11735                    }
11736                    else {
11737                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11738                    }
11739    
11740                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11741    
11742                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11743    
11744                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11745    
11746                    if (!getDB().isSupportsInlineDistinct()) {
11747                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11748                    }
11749    
11750                    if (orderByComparator != null) {
11751                            if (getDB().isSupportsInlineDistinct()) {
11752                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11753                                            orderByComparator, true);
11754                            }
11755                            else {
11756                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11757                                            orderByComparator, true);
11758                            }
11759                    }
11760                    else {
11761                            if (getDB().isSupportsInlineDistinct()) {
11762                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11763                            }
11764                            else {
11765                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11766                            }
11767                    }
11768    
11769                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11770                                    MBMessage.class.getName(),
11771                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11772    
11773                    Session session = null;
11774    
11775                    try {
11776                            session = openSession();
11777    
11778                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11779    
11780                            if (getDB().isSupportsInlineDistinct()) {
11781                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11782                            }
11783                            else {
11784                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11785                            }
11786    
11787                            QueryPos qPos = QueryPos.getInstance(q);
11788    
11789                            qPos.add(groupId);
11790    
11791                            qPos.add(userId);
11792    
11793                            qPos.add(status);
11794    
11795                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11796                    }
11797                    catch (Exception e) {
11798                            throw processException(e);
11799                    }
11800                    finally {
11801                            closeSession(session);
11802                    }
11803            }
11804    
11805            /**
11806             * 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;.
11807             *
11808             * @param messageId the primary key of the current message-boards message
11809             * @param groupId the group ID
11810             * @param userId the user ID
11811             * @param status the status
11812             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11813             * @return the previous, current, and next message-boards message
11814             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11815             */
11816            @Override
11817            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11818                    long groupId, long userId, int status,
11819                    OrderByComparator<MBMessage> orderByComparator)
11820                    throws NoSuchMessageException {
11821                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11822                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11823                                    orderByComparator);
11824                    }
11825    
11826                    MBMessage mbMessage = findByPrimaryKey(messageId);
11827    
11828                    Session session = null;
11829    
11830                    try {
11831                            session = openSession();
11832    
11833                            MBMessage[] array = new MBMessageImpl[3];
11834    
11835                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11836                                            groupId, userId, status, orderByComparator, true);
11837    
11838                            array[1] = mbMessage;
11839    
11840                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11841                                            groupId, userId, status, orderByComparator, false);
11842    
11843                            return array;
11844                    }
11845                    catch (Exception e) {
11846                            throw processException(e);
11847                    }
11848                    finally {
11849                            closeSession(session);
11850                    }
11851            }
11852    
11853            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11854                    MBMessage mbMessage, long groupId, long userId, int status,
11855                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11856                    StringBundler query = null;
11857    
11858                    if (orderByComparator != null) {
11859                            query = new StringBundler(6 +
11860                                            (orderByComparator.getOrderByFields().length * 6));
11861                    }
11862                    else {
11863                            query = new StringBundler(3);
11864                    }
11865    
11866                    if (getDB().isSupportsInlineDistinct()) {
11867                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11868                    }
11869                    else {
11870                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11871                    }
11872    
11873                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11874    
11875                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11876    
11877                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11878    
11879                    if (!getDB().isSupportsInlineDistinct()) {
11880                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11881                    }
11882    
11883                    if (orderByComparator != null) {
11884                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11885    
11886                            if (orderByConditionFields.length > 0) {
11887                                    query.append(WHERE_AND);
11888                            }
11889    
11890                            for (int i = 0; i < orderByConditionFields.length; i++) {
11891                                    if (getDB().isSupportsInlineDistinct()) {
11892                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11893                                    }
11894                                    else {
11895                                            query.append(_ORDER_BY_ENTITY_TABLE);
11896                                    }
11897    
11898                                    query.append(orderByConditionFields[i]);
11899    
11900                                    if ((i + 1) < orderByConditionFields.length) {
11901                                            if (orderByComparator.isAscending() ^ previous) {
11902                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11903                                            }
11904                                            else {
11905                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11906                                            }
11907                                    }
11908                                    else {
11909                                            if (orderByComparator.isAscending() ^ previous) {
11910                                                    query.append(WHERE_GREATER_THAN);
11911                                            }
11912                                            else {
11913                                                    query.append(WHERE_LESSER_THAN);
11914                                            }
11915                                    }
11916                            }
11917    
11918                            query.append(ORDER_BY_CLAUSE);
11919    
11920                            String[] orderByFields = orderByComparator.getOrderByFields();
11921    
11922                            for (int i = 0; i < orderByFields.length; i++) {
11923                                    if (getDB().isSupportsInlineDistinct()) {
11924                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11925                                    }
11926                                    else {
11927                                            query.append(_ORDER_BY_ENTITY_TABLE);
11928                                    }
11929    
11930                                    query.append(orderByFields[i]);
11931    
11932                                    if ((i + 1) < orderByFields.length) {
11933                                            if (orderByComparator.isAscending() ^ previous) {
11934                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11935                                            }
11936                                            else {
11937                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11938                                            }
11939                                    }
11940                                    else {
11941                                            if (orderByComparator.isAscending() ^ previous) {
11942                                                    query.append(ORDER_BY_ASC);
11943                                            }
11944                                            else {
11945                                                    query.append(ORDER_BY_DESC);
11946                                            }
11947                                    }
11948                            }
11949                    }
11950                    else {
11951                            if (getDB().isSupportsInlineDistinct()) {
11952                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11953                            }
11954                            else {
11955                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11956                            }
11957                    }
11958    
11959                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11960                                    MBMessage.class.getName(),
11961                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11962    
11963                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11964    
11965                    q.setFirstResult(0);
11966                    q.setMaxResults(2);
11967    
11968                    if (getDB().isSupportsInlineDistinct()) {
11969                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11970                    }
11971                    else {
11972                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11973                    }
11974    
11975                    QueryPos qPos = QueryPos.getInstance(q);
11976    
11977                    qPos.add(groupId);
11978    
11979                    qPos.add(userId);
11980    
11981                    qPos.add(status);
11982    
11983                    if (orderByComparator != null) {
11984                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11985    
11986                            for (Object value : values) {
11987                                    qPos.add(value);
11988                            }
11989                    }
11990    
11991                    List<MBMessage> list = q.list();
11992    
11993                    if (list.size() == 2) {
11994                            return list.get(1);
11995                    }
11996                    else {
11997                            return null;
11998                    }
11999            }
12000    
12001            /**
12002             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
12003             *
12004             * @param groupId the group ID
12005             * @param userId the user ID
12006             * @param status the status
12007             */
12008            @Override
12009            public void removeByG_U_S(long groupId, long userId, int status) {
12010                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
12011                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12012                            remove(mbMessage);
12013                    }
12014            }
12015    
12016            /**
12017             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
12018             *
12019             * @param groupId the group ID
12020             * @param userId the user ID
12021             * @param status the status
12022             * @return the number of matching message-boards messages
12023             */
12024            @Override
12025            public int countByG_U_S(long groupId, long userId, int status) {
12026                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
12027    
12028                    Object[] finderArgs = new Object[] { groupId, userId, status };
12029    
12030                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12031    
12032                    if (count == null) {
12033                            StringBundler query = new StringBundler(4);
12034    
12035                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12036    
12037                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12038    
12039                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12040    
12041                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12042    
12043                            String sql = query.toString();
12044    
12045                            Session session = null;
12046    
12047                            try {
12048                                    session = openSession();
12049    
12050                                    Query q = session.createQuery(sql);
12051    
12052                                    QueryPos qPos = QueryPos.getInstance(q);
12053    
12054                                    qPos.add(groupId);
12055    
12056                                    qPos.add(userId);
12057    
12058                                    qPos.add(status);
12059    
12060                                    count = (Long)q.uniqueResult();
12061    
12062                                    finderCache.putResult(finderPath, finderArgs, count);
12063                            }
12064                            catch (Exception e) {
12065                                    finderCache.removeResult(finderPath, finderArgs);
12066    
12067                                    throw processException(e);
12068                            }
12069                            finally {
12070                                    closeSession(session);
12071                            }
12072                    }
12073    
12074                    return count.intValue();
12075            }
12076    
12077            /**
12078             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
12079             *
12080             * @param groupId the group ID
12081             * @param userId the user ID
12082             * @param status the status
12083             * @return the number of matching message-boards messages that the user has permission to view
12084             */
12085            @Override
12086            public int filterCountByG_U_S(long groupId, long userId, int status) {
12087                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12088                            return countByG_U_S(groupId, userId, status);
12089                    }
12090    
12091                    StringBundler query = new StringBundler(4);
12092    
12093                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12094    
12095                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12096    
12097                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12098    
12099                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12100    
12101                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12102                                    MBMessage.class.getName(),
12103                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12104    
12105                    Session session = null;
12106    
12107                    try {
12108                            session = openSession();
12109    
12110                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12111    
12112                            q.addScalar(COUNT_COLUMN_NAME,
12113                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12114    
12115                            QueryPos qPos = QueryPos.getInstance(q);
12116    
12117                            qPos.add(groupId);
12118    
12119                            qPos.add(userId);
12120    
12121                            qPos.add(status);
12122    
12123                            Long count = (Long)q.uniqueResult();
12124    
12125                            return count.intValue();
12126                    }
12127                    catch (Exception e) {
12128                            throw processException(e);
12129                    }
12130                    finally {
12131                            closeSession(session);
12132                    }
12133            }
12134    
12135            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
12136            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
12137            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
12138            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12139                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12140                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
12141                            new String[] {
12142                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12143                                    
12144                            Integer.class.getName(), Integer.class.getName(),
12145                                    OrderByComparator.class.getName()
12146                            });
12147            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12148                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
12150                            new String[] {
12151                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12152                            },
12153                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12154                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12155                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
12156                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12157            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12158                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
12160                            new String[] {
12161                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12162                            });
12163    
12164            /**
12165             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12166             *
12167             * @param groupId the group ID
12168             * @param categoryId the category ID
12169             * @param threadId the thread ID
12170             * @return the matching message-boards messages
12171             */
12172            @Override
12173            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12174                    long threadId) {
12175                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
12176                            QueryUtil.ALL_POS, null);
12177            }
12178    
12179            /**
12180             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12181             *
12182             * <p>
12183             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12184             * </p>
12185             *
12186             * @param groupId the group ID
12187             * @param categoryId the category ID
12188             * @param threadId the thread ID
12189             * @param start the lower bound of the range of message-boards messages
12190             * @param end the upper bound of the range of message-boards messages (not inclusive)
12191             * @return the range of matching message-boards messages
12192             */
12193            @Override
12194            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12195                    long threadId, int start, int end) {
12196                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
12197            }
12198    
12199            /**
12200             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12201             *
12202             * <p>
12203             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12204             * </p>
12205             *
12206             * @param groupId the group ID
12207             * @param categoryId the category ID
12208             * @param threadId the thread ID
12209             * @param start the lower bound of the range of message-boards messages
12210             * @param end the upper bound of the range of message-boards messages (not inclusive)
12211             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12212             * @return the ordered range of matching message-boards messages
12213             */
12214            @Override
12215            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12216                    long threadId, int start, int end,
12217                    OrderByComparator<MBMessage> orderByComparator) {
12218                    return findByG_C_T(groupId, categoryId, threadId, start, end,
12219                            orderByComparator, true);
12220            }
12221    
12222            /**
12223             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12224             *
12225             * <p>
12226             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12227             * </p>
12228             *
12229             * @param groupId the group ID
12230             * @param categoryId the category ID
12231             * @param threadId the thread ID
12232             * @param start the lower bound of the range of message-boards messages
12233             * @param end the upper bound of the range of message-boards messages (not inclusive)
12234             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12235             * @param retrieveFromCache whether to retrieve from the finder cache
12236             * @return the ordered range of matching message-boards messages
12237             */
12238            @Override
12239            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12240                    long threadId, int start, int end,
12241                    OrderByComparator<MBMessage> orderByComparator,
12242                    boolean retrieveFromCache) {
12243                    boolean pagination = true;
12244                    FinderPath finderPath = null;
12245                    Object[] finderArgs = null;
12246    
12247                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12248                                    (orderByComparator == null)) {
12249                            pagination = false;
12250                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12251                            finderArgs = new Object[] { groupId, categoryId, threadId };
12252                    }
12253                    else {
12254                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12255                            finderArgs = new Object[] {
12256                                            groupId, categoryId, threadId,
12257                                            
12258                                            start, end, orderByComparator
12259                                    };
12260                    }
12261    
12262                    List<MBMessage> list = null;
12263    
12264                    if (retrieveFromCache) {
12265                            list = (List<MBMessage>)finderCache.getResult(finderPath,
12266                                            finderArgs, this);
12267    
12268                            if ((list != null) && !list.isEmpty()) {
12269                                    for (MBMessage mbMessage : list) {
12270                                            if ((groupId != mbMessage.getGroupId()) ||
12271                                                            (categoryId != mbMessage.getCategoryId()) ||
12272                                                            (threadId != mbMessage.getThreadId())) {
12273                                                    list = null;
12274    
12275                                                    break;
12276                                            }
12277                                    }
12278                            }
12279                    }
12280    
12281                    if (list == null) {
12282                            StringBundler query = null;
12283    
12284                            if (orderByComparator != null) {
12285                                    query = new StringBundler(5 +
12286                                                    (orderByComparator.getOrderByFields().length * 3));
12287                            }
12288                            else {
12289                                    query = new StringBundler(5);
12290                            }
12291    
12292                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12293    
12294                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12295    
12296                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12297    
12298                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12299    
12300                            if (orderByComparator != null) {
12301                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12302                                            orderByComparator);
12303                            }
12304                            else
12305                             if (pagination) {
12306                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12307                            }
12308    
12309                            String sql = query.toString();
12310    
12311                            Session session = null;
12312    
12313                            try {
12314                                    session = openSession();
12315    
12316                                    Query q = session.createQuery(sql);
12317    
12318                                    QueryPos qPos = QueryPos.getInstance(q);
12319    
12320                                    qPos.add(groupId);
12321    
12322                                    qPos.add(categoryId);
12323    
12324                                    qPos.add(threadId);
12325    
12326                                    if (!pagination) {
12327                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12328                                                            start, end, false);
12329    
12330                                            Collections.sort(list);
12331    
12332                                            list = Collections.unmodifiableList(list);
12333                                    }
12334                                    else {
12335                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12336                                                            start, end);
12337                                    }
12338    
12339                                    cacheResult(list);
12340    
12341                                    finderCache.putResult(finderPath, finderArgs, list);
12342                            }
12343                            catch (Exception e) {
12344                                    finderCache.removeResult(finderPath, finderArgs);
12345    
12346                                    throw processException(e);
12347                            }
12348                            finally {
12349                                    closeSession(session);
12350                            }
12351                    }
12352    
12353                    return list;
12354            }
12355    
12356            /**
12357             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12358             *
12359             * @param groupId the group ID
12360             * @param categoryId the category ID
12361             * @param threadId the thread ID
12362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12363             * @return the first matching message-boards message
12364             * @throws NoSuchMessageException if a matching message-boards message could not be found
12365             */
12366            @Override
12367            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12368                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12369                    throws NoSuchMessageException {
12370                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12371                                    orderByComparator);
12372    
12373                    if (mbMessage != null) {
12374                            return mbMessage;
12375                    }
12376    
12377                    StringBundler msg = new StringBundler(8);
12378    
12379                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12380    
12381                    msg.append("groupId=");
12382                    msg.append(groupId);
12383    
12384                    msg.append(", categoryId=");
12385                    msg.append(categoryId);
12386    
12387                    msg.append(", threadId=");
12388                    msg.append(threadId);
12389    
12390                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12391    
12392                    throw new NoSuchMessageException(msg.toString());
12393            }
12394    
12395            /**
12396             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12397             *
12398             * @param groupId the group ID
12399             * @param categoryId the category ID
12400             * @param threadId the thread ID
12401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12402             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12403             */
12404            @Override
12405            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12406                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12407                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12408                                    orderByComparator);
12409    
12410                    if (!list.isEmpty()) {
12411                            return list.get(0);
12412                    }
12413    
12414                    return null;
12415            }
12416    
12417            /**
12418             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12419             *
12420             * @param groupId the group ID
12421             * @param categoryId the category ID
12422             * @param threadId the thread ID
12423             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12424             * @return the last matching message-boards message
12425             * @throws NoSuchMessageException if a matching message-boards message could not be found
12426             */
12427            @Override
12428            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12429                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12430                    throws NoSuchMessageException {
12431                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12432                                    orderByComparator);
12433    
12434                    if (mbMessage != null) {
12435                            return mbMessage;
12436                    }
12437    
12438                    StringBundler msg = new StringBundler(8);
12439    
12440                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12441    
12442                    msg.append("groupId=");
12443                    msg.append(groupId);
12444    
12445                    msg.append(", categoryId=");
12446                    msg.append(categoryId);
12447    
12448                    msg.append(", threadId=");
12449                    msg.append(threadId);
12450    
12451                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12452    
12453                    throw new NoSuchMessageException(msg.toString());
12454            }
12455    
12456            /**
12457             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12458             *
12459             * @param groupId the group ID
12460             * @param categoryId the category ID
12461             * @param threadId the thread ID
12462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12463             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12464             */
12465            @Override
12466            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12467                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12468                    int count = countByG_C_T(groupId, categoryId, threadId);
12469    
12470                    if (count == 0) {
12471                            return null;
12472                    }
12473    
12474                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12475                                    count - 1, count, orderByComparator);
12476    
12477                    if (!list.isEmpty()) {
12478                            return list.get(0);
12479                    }
12480    
12481                    return null;
12482            }
12483    
12484            /**
12485             * 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;.
12486             *
12487             * @param messageId the primary key of the current message-boards message
12488             * @param groupId the group ID
12489             * @param categoryId the category ID
12490             * @param threadId the thread ID
12491             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12492             * @return the previous, current, and next message-boards message
12493             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12494             */
12495            @Override
12496            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12497                    long categoryId, long threadId,
12498                    OrderByComparator<MBMessage> orderByComparator)
12499                    throws NoSuchMessageException {
12500                    MBMessage mbMessage = findByPrimaryKey(messageId);
12501    
12502                    Session session = null;
12503    
12504                    try {
12505                            session = openSession();
12506    
12507                            MBMessage[] array = new MBMessageImpl[3];
12508    
12509                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12510                                            categoryId, threadId, orderByComparator, true);
12511    
12512                            array[1] = mbMessage;
12513    
12514                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12515                                            categoryId, threadId, orderByComparator, false);
12516    
12517                            return array;
12518                    }
12519                    catch (Exception e) {
12520                            throw processException(e);
12521                    }
12522                    finally {
12523                            closeSession(session);
12524                    }
12525            }
12526    
12527            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12528                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12529                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12530                    StringBundler query = null;
12531    
12532                    if (orderByComparator != null) {
12533                            query = new StringBundler(6 +
12534                                            (orderByComparator.getOrderByFields().length * 6));
12535                    }
12536                    else {
12537                            query = new StringBundler(3);
12538                    }
12539    
12540                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12541    
12542                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12543    
12544                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12545    
12546                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12547    
12548                    if (orderByComparator != null) {
12549                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12550    
12551                            if (orderByConditionFields.length > 0) {
12552                                    query.append(WHERE_AND);
12553                            }
12554    
12555                            for (int i = 0; i < orderByConditionFields.length; i++) {
12556                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12557                                    query.append(orderByConditionFields[i]);
12558    
12559                                    if ((i + 1) < orderByConditionFields.length) {
12560                                            if (orderByComparator.isAscending() ^ previous) {
12561                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12562                                            }
12563                                            else {
12564                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12565                                            }
12566                                    }
12567                                    else {
12568                                            if (orderByComparator.isAscending() ^ previous) {
12569                                                    query.append(WHERE_GREATER_THAN);
12570                                            }
12571                                            else {
12572                                                    query.append(WHERE_LESSER_THAN);
12573                                            }
12574                                    }
12575                            }
12576    
12577                            query.append(ORDER_BY_CLAUSE);
12578    
12579                            String[] orderByFields = orderByComparator.getOrderByFields();
12580    
12581                            for (int i = 0; i < orderByFields.length; i++) {
12582                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12583                                    query.append(orderByFields[i]);
12584    
12585                                    if ((i + 1) < orderByFields.length) {
12586                                            if (orderByComparator.isAscending() ^ previous) {
12587                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12588                                            }
12589                                            else {
12590                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12591                                            }
12592                                    }
12593                                    else {
12594                                            if (orderByComparator.isAscending() ^ previous) {
12595                                                    query.append(ORDER_BY_ASC);
12596                                            }
12597                                            else {
12598                                                    query.append(ORDER_BY_DESC);
12599                                            }
12600                                    }
12601                            }
12602                    }
12603                    else {
12604                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12605                    }
12606    
12607                    String sql = query.toString();
12608    
12609                    Query q = session.createQuery(sql);
12610    
12611                    q.setFirstResult(0);
12612                    q.setMaxResults(2);
12613    
12614                    QueryPos qPos = QueryPos.getInstance(q);
12615    
12616                    qPos.add(groupId);
12617    
12618                    qPos.add(categoryId);
12619    
12620                    qPos.add(threadId);
12621    
12622                    if (orderByComparator != null) {
12623                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12624    
12625                            for (Object value : values) {
12626                                    qPos.add(value);
12627                            }
12628                    }
12629    
12630                    List<MBMessage> list = q.list();
12631    
12632                    if (list.size() == 2) {
12633                            return list.get(1);
12634                    }
12635                    else {
12636                            return null;
12637                    }
12638            }
12639    
12640            /**
12641             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12642             *
12643             * @param groupId the group ID
12644             * @param categoryId the category ID
12645             * @param threadId the thread ID
12646             * @return the matching message-boards messages that the user has permission to view
12647             */
12648            @Override
12649            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12650                    long threadId) {
12651                    return filterFindByG_C_T(groupId, categoryId, threadId,
12652                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12653            }
12654    
12655            /**
12656             * 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;.
12657             *
12658             * <p>
12659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12660             * </p>
12661             *
12662             * @param groupId the group ID
12663             * @param categoryId the category ID
12664             * @param threadId the thread ID
12665             * @param start the lower bound of the range of message-boards messages
12666             * @param end the upper bound of the range of message-boards messages (not inclusive)
12667             * @return the range of matching message-boards messages that the user has permission to view
12668             */
12669            @Override
12670            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12671                    long threadId, int start, int end) {
12672                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12673            }
12674    
12675            /**
12676             * 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;.
12677             *
12678             * <p>
12679             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12680             * </p>
12681             *
12682             * @param groupId the group ID
12683             * @param categoryId the category ID
12684             * @param threadId the thread ID
12685             * @param start the lower bound of the range of message-boards messages
12686             * @param end the upper bound of the range of message-boards messages (not inclusive)
12687             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12688             * @return the ordered range of matching message-boards messages that the user has permission to view
12689             */
12690            @Override
12691            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12692                    long threadId, int start, int end,
12693                    OrderByComparator<MBMessage> orderByComparator) {
12694                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12695                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12696                                    orderByComparator);
12697                    }
12698    
12699                    StringBundler query = null;
12700    
12701                    if (orderByComparator != null) {
12702                            query = new StringBundler(5 +
12703                                            (orderByComparator.getOrderByFields().length * 3));
12704                    }
12705                    else {
12706                            query = new StringBundler(5);
12707                    }
12708    
12709                    if (getDB().isSupportsInlineDistinct()) {
12710                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12711                    }
12712                    else {
12713                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12714                    }
12715    
12716                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12717    
12718                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12719    
12720                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12721    
12722                    if (!getDB().isSupportsInlineDistinct()) {
12723                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12724                    }
12725    
12726                    if (orderByComparator != null) {
12727                            if (getDB().isSupportsInlineDistinct()) {
12728                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12729                                            orderByComparator, true);
12730                            }
12731                            else {
12732                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12733                                            orderByComparator, true);
12734                            }
12735                    }
12736                    else {
12737                            if (getDB().isSupportsInlineDistinct()) {
12738                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12739                            }
12740                            else {
12741                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12742                            }
12743                    }
12744    
12745                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12746                                    MBMessage.class.getName(),
12747                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12748    
12749                    Session session = null;
12750    
12751                    try {
12752                            session = openSession();
12753    
12754                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12755    
12756                            if (getDB().isSupportsInlineDistinct()) {
12757                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12758                            }
12759                            else {
12760                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12761                            }
12762    
12763                            QueryPos qPos = QueryPos.getInstance(q);
12764    
12765                            qPos.add(groupId);
12766    
12767                            qPos.add(categoryId);
12768    
12769                            qPos.add(threadId);
12770    
12771                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12772                    }
12773                    catch (Exception e) {
12774                            throw processException(e);
12775                    }
12776                    finally {
12777                            closeSession(session);
12778                    }
12779            }
12780    
12781            /**
12782             * 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;.
12783             *
12784             * @param messageId the primary key of the current message-boards message
12785             * @param groupId the group ID
12786             * @param categoryId the category ID
12787             * @param threadId the thread ID
12788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12789             * @return the previous, current, and next message-boards message
12790             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12791             */
12792            @Override
12793            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12794                    long groupId, long categoryId, long threadId,
12795                    OrderByComparator<MBMessage> orderByComparator)
12796                    throws NoSuchMessageException {
12797                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12798                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12799                                    threadId, orderByComparator);
12800                    }
12801    
12802                    MBMessage mbMessage = findByPrimaryKey(messageId);
12803    
12804                    Session session = null;
12805    
12806                    try {
12807                            session = openSession();
12808    
12809                            MBMessage[] array = new MBMessageImpl[3];
12810    
12811                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12812                                            groupId, categoryId, threadId, orderByComparator, true);
12813    
12814                            array[1] = mbMessage;
12815    
12816                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12817                                            groupId, categoryId, threadId, orderByComparator, false);
12818    
12819                            return array;
12820                    }
12821                    catch (Exception e) {
12822                            throw processException(e);
12823                    }
12824                    finally {
12825                            closeSession(session);
12826                    }
12827            }
12828    
12829            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12830                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12831                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12832                    StringBundler query = null;
12833    
12834                    if (orderByComparator != null) {
12835                            query = new StringBundler(6 +
12836                                            (orderByComparator.getOrderByFields().length * 6));
12837                    }
12838                    else {
12839                            query = new StringBundler(3);
12840                    }
12841    
12842                    if (getDB().isSupportsInlineDistinct()) {
12843                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12844                    }
12845                    else {
12846                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12847                    }
12848    
12849                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12850    
12851                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12852    
12853                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12854    
12855                    if (!getDB().isSupportsInlineDistinct()) {
12856                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12857                    }
12858    
12859                    if (orderByComparator != null) {
12860                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12861    
12862                            if (orderByConditionFields.length > 0) {
12863                                    query.append(WHERE_AND);
12864                            }
12865    
12866                            for (int i = 0; i < orderByConditionFields.length; i++) {
12867                                    if (getDB().isSupportsInlineDistinct()) {
12868                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12869                                    }
12870                                    else {
12871                                            query.append(_ORDER_BY_ENTITY_TABLE);
12872                                    }
12873    
12874                                    query.append(orderByConditionFields[i]);
12875    
12876                                    if ((i + 1) < orderByConditionFields.length) {
12877                                            if (orderByComparator.isAscending() ^ previous) {
12878                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12879                                            }
12880                                            else {
12881                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12882                                            }
12883                                    }
12884                                    else {
12885                                            if (orderByComparator.isAscending() ^ previous) {
12886                                                    query.append(WHERE_GREATER_THAN);
12887                                            }
12888                                            else {
12889                                                    query.append(WHERE_LESSER_THAN);
12890                                            }
12891                                    }
12892                            }
12893    
12894                            query.append(ORDER_BY_CLAUSE);
12895    
12896                            String[] orderByFields = orderByComparator.getOrderByFields();
12897    
12898                            for (int i = 0; i < orderByFields.length; i++) {
12899                                    if (getDB().isSupportsInlineDistinct()) {
12900                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12901                                    }
12902                                    else {
12903                                            query.append(_ORDER_BY_ENTITY_TABLE);
12904                                    }
12905    
12906                                    query.append(orderByFields[i]);
12907    
12908                                    if ((i + 1) < orderByFields.length) {
12909                                            if (orderByComparator.isAscending() ^ previous) {
12910                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12911                                            }
12912                                            else {
12913                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12914                                            }
12915                                    }
12916                                    else {
12917                                            if (orderByComparator.isAscending() ^ previous) {
12918                                                    query.append(ORDER_BY_ASC);
12919                                            }
12920                                            else {
12921                                                    query.append(ORDER_BY_DESC);
12922                                            }
12923                                    }
12924                            }
12925                    }
12926                    else {
12927                            if (getDB().isSupportsInlineDistinct()) {
12928                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12929                            }
12930                            else {
12931                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12932                            }
12933                    }
12934    
12935                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12936                                    MBMessage.class.getName(),
12937                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12938    
12939                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12940    
12941                    q.setFirstResult(0);
12942                    q.setMaxResults(2);
12943    
12944                    if (getDB().isSupportsInlineDistinct()) {
12945                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12946                    }
12947                    else {
12948                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12949                    }
12950    
12951                    QueryPos qPos = QueryPos.getInstance(q);
12952    
12953                    qPos.add(groupId);
12954    
12955                    qPos.add(categoryId);
12956    
12957                    qPos.add(threadId);
12958    
12959                    if (orderByComparator != null) {
12960                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12961    
12962                            for (Object value : values) {
12963                                    qPos.add(value);
12964                            }
12965                    }
12966    
12967                    List<MBMessage> list = q.list();
12968    
12969                    if (list.size() == 2) {
12970                            return list.get(1);
12971                    }
12972                    else {
12973                            return null;
12974                    }
12975            }
12976    
12977            /**
12978             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12979             *
12980             * @param groupId the group ID
12981             * @param categoryId the category ID
12982             * @param threadId the thread ID
12983             */
12984            @Override
12985            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
12986                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12987                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12988                            remove(mbMessage);
12989                    }
12990            }
12991    
12992            /**
12993             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12994             *
12995             * @param groupId the group ID
12996             * @param categoryId the category ID
12997             * @param threadId the thread ID
12998             * @return the number of matching message-boards messages
12999             */
13000            @Override
13001            public int countByG_C_T(long groupId, long categoryId, long threadId) {
13002                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
13003    
13004                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
13005    
13006                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13007    
13008                    if (count == null) {
13009                            StringBundler query = new StringBundler(4);
13010    
13011                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13012    
13013                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13014    
13015                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13016    
13017                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13018    
13019                            String sql = query.toString();
13020    
13021                            Session session = null;
13022    
13023                            try {
13024                                    session = openSession();
13025    
13026                                    Query q = session.createQuery(sql);
13027    
13028                                    QueryPos qPos = QueryPos.getInstance(q);
13029    
13030                                    qPos.add(groupId);
13031    
13032                                    qPos.add(categoryId);
13033    
13034                                    qPos.add(threadId);
13035    
13036                                    count = (Long)q.uniqueResult();
13037    
13038                                    finderCache.putResult(finderPath, finderArgs, count);
13039                            }
13040                            catch (Exception e) {
13041                                    finderCache.removeResult(finderPath, finderArgs);
13042    
13043                                    throw processException(e);
13044                            }
13045                            finally {
13046                                    closeSession(session);
13047                            }
13048                    }
13049    
13050                    return count.intValue();
13051            }
13052    
13053            /**
13054             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13055             *
13056             * @param groupId the group ID
13057             * @param categoryId the category ID
13058             * @param threadId the thread ID
13059             * @return the number of matching message-boards messages that the user has permission to view
13060             */
13061            @Override
13062            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
13063                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13064                            return countByG_C_T(groupId, categoryId, threadId);
13065                    }
13066    
13067                    StringBundler query = new StringBundler(4);
13068    
13069                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13070    
13071                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13072    
13073                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13074    
13075                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13076    
13077                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13078                                    MBMessage.class.getName(),
13079                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13080    
13081                    Session session = null;
13082    
13083                    try {
13084                            session = openSession();
13085    
13086                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13087    
13088                            q.addScalar(COUNT_COLUMN_NAME,
13089                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13090    
13091                            QueryPos qPos = QueryPos.getInstance(q);
13092    
13093                            qPos.add(groupId);
13094    
13095                            qPos.add(categoryId);
13096    
13097                            qPos.add(threadId);
13098    
13099                            Long count = (Long)q.uniqueResult();
13100    
13101                            return count.intValue();
13102                    }
13103                    catch (Exception e) {
13104                            throw processException(e);
13105                    }
13106                    finally {
13107                            closeSession(session);
13108                    }
13109            }
13110    
13111            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
13112            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13113            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
13114            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13116                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
13117                            new String[] {
13118                                    Long.class.getName(), Long.class.getName(),
13119                                    Integer.class.getName(),
13120                                    
13121                            Integer.class.getName(), Integer.class.getName(),
13122                                    OrderByComparator.class.getName()
13123                            });
13124            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13125                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
13127                            new String[] {
13128                                    Long.class.getName(), Long.class.getName(),
13129                                    Integer.class.getName()
13130                            },
13131                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
13132                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
13133                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
13134                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13135            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13136                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13137                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
13138                            new String[] {
13139                                    Long.class.getName(), Long.class.getName(),
13140                                    Integer.class.getName()
13141                            });
13142    
13143            /**
13144             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13145             *
13146             * @param groupId the group ID
13147             * @param categoryId the category ID
13148             * @param status the status
13149             * @return the matching message-boards messages
13150             */
13151            @Override
13152            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
13153                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
13154                            QueryUtil.ALL_POS, null);
13155            }
13156    
13157            /**
13158             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13159             *
13160             * <p>
13161             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13162             * </p>
13163             *
13164             * @param groupId the group ID
13165             * @param categoryId the category ID
13166             * @param status the status
13167             * @param start the lower bound of the range of message-boards messages
13168             * @param end the upper bound of the range of message-boards messages (not inclusive)
13169             * @return the range of matching message-boards messages
13170             */
13171            @Override
13172            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13173                    int status, int start, int end) {
13174                    return findByG_C_S(groupId, categoryId, status, start, end, null);
13175            }
13176    
13177            /**
13178             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13179             *
13180             * <p>
13181             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13182             * </p>
13183             *
13184             * @param groupId the group ID
13185             * @param categoryId the category ID
13186             * @param status the status
13187             * @param start the lower bound of the range of message-boards messages
13188             * @param end the upper bound of the range of message-boards messages (not inclusive)
13189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13190             * @return the ordered range of matching message-boards messages
13191             */
13192            @Override
13193            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13194                    int status, int start, int end,
13195                    OrderByComparator<MBMessage> orderByComparator) {
13196                    return findByG_C_S(groupId, categoryId, status, start, end,
13197                            orderByComparator, true);
13198            }
13199    
13200            /**
13201             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13202             *
13203             * <p>
13204             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13205             * </p>
13206             *
13207             * @param groupId the group ID
13208             * @param categoryId the category ID
13209             * @param status the status
13210             * @param start the lower bound of the range of message-boards messages
13211             * @param end the upper bound of the range of message-boards messages (not inclusive)
13212             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13213             * @param retrieveFromCache whether to retrieve from the finder cache
13214             * @return the ordered range of matching message-boards messages
13215             */
13216            @Override
13217            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13218                    int status, int start, int end,
13219                    OrderByComparator<MBMessage> orderByComparator,
13220                    boolean retrieveFromCache) {
13221                    boolean pagination = true;
13222                    FinderPath finderPath = null;
13223                    Object[] finderArgs = null;
13224    
13225                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13226                                    (orderByComparator == null)) {
13227                            pagination = false;
13228                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13229                            finderArgs = new Object[] { groupId, categoryId, status };
13230                    }
13231                    else {
13232                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13233                            finderArgs = new Object[] {
13234                                            groupId, categoryId, status,
13235                                            
13236                                            start, end, orderByComparator
13237                                    };
13238                    }
13239    
13240                    List<MBMessage> list = null;
13241    
13242                    if (retrieveFromCache) {
13243                            list = (List<MBMessage>)finderCache.getResult(finderPath,
13244                                            finderArgs, this);
13245    
13246                            if ((list != null) && !list.isEmpty()) {
13247                                    for (MBMessage mbMessage : list) {
13248                                            if ((groupId != mbMessage.getGroupId()) ||
13249                                                            (categoryId != mbMessage.getCategoryId()) ||
13250                                                            (status != mbMessage.getStatus())) {
13251                                                    list = null;
13252    
13253                                                    break;
13254                                            }
13255                                    }
13256                            }
13257                    }
13258    
13259                    if (list == null) {
13260                            StringBundler query = null;
13261    
13262                            if (orderByComparator != null) {
13263                                    query = new StringBundler(5 +
13264                                                    (orderByComparator.getOrderByFields().length * 3));
13265                            }
13266                            else {
13267                                    query = new StringBundler(5);
13268                            }
13269    
13270                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13271    
13272                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13273    
13274                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13275    
13276                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13277    
13278                            if (orderByComparator != null) {
13279                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13280                                            orderByComparator);
13281                            }
13282                            else
13283                             if (pagination) {
13284                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13285                            }
13286    
13287                            String sql = query.toString();
13288    
13289                            Session session = null;
13290    
13291                            try {
13292                                    session = openSession();
13293    
13294                                    Query q = session.createQuery(sql);
13295    
13296                                    QueryPos qPos = QueryPos.getInstance(q);
13297    
13298                                    qPos.add(groupId);
13299    
13300                                    qPos.add(categoryId);
13301    
13302                                    qPos.add(status);
13303    
13304                                    if (!pagination) {
13305                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13306                                                            start, end, false);
13307    
13308                                            Collections.sort(list);
13309    
13310                                            list = Collections.unmodifiableList(list);
13311                                    }
13312                                    else {
13313                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13314                                                            start, end);
13315                                    }
13316    
13317                                    cacheResult(list);
13318    
13319                                    finderCache.putResult(finderPath, finderArgs, list);
13320                            }
13321                            catch (Exception e) {
13322                                    finderCache.removeResult(finderPath, finderArgs);
13323    
13324                                    throw processException(e);
13325                            }
13326                            finally {
13327                                    closeSession(session);
13328                            }
13329                    }
13330    
13331                    return list;
13332            }
13333    
13334            /**
13335             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13336             *
13337             * @param groupId the group ID
13338             * @param categoryId the category ID
13339             * @param status the status
13340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13341             * @return the first matching message-boards message
13342             * @throws NoSuchMessageException if a matching message-boards message could not be found
13343             */
13344            @Override
13345            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13346                    int status, OrderByComparator<MBMessage> orderByComparator)
13347                    throws NoSuchMessageException {
13348                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13349                                    orderByComparator);
13350    
13351                    if (mbMessage != null) {
13352                            return mbMessage;
13353                    }
13354    
13355                    StringBundler msg = new StringBundler(8);
13356    
13357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13358    
13359                    msg.append("groupId=");
13360                    msg.append(groupId);
13361    
13362                    msg.append(", categoryId=");
13363                    msg.append(categoryId);
13364    
13365                    msg.append(", status=");
13366                    msg.append(status);
13367    
13368                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13369    
13370                    throw new NoSuchMessageException(msg.toString());
13371            }
13372    
13373            /**
13374             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13375             *
13376             * @param groupId the group ID
13377             * @param categoryId the category ID
13378             * @param status the status
13379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13380             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13381             */
13382            @Override
13383            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13384                    int status, OrderByComparator<MBMessage> orderByComparator) {
13385                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13386                                    orderByComparator);
13387    
13388                    if (!list.isEmpty()) {
13389                            return list.get(0);
13390                    }
13391    
13392                    return null;
13393            }
13394    
13395            /**
13396             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13397             *
13398             * @param groupId the group ID
13399             * @param categoryId the category ID
13400             * @param status the status
13401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13402             * @return the last matching message-boards message
13403             * @throws NoSuchMessageException if a matching message-boards message could not be found
13404             */
13405            @Override
13406            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13407                    int status, OrderByComparator<MBMessage> orderByComparator)
13408                    throws NoSuchMessageException {
13409                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13410                                    orderByComparator);
13411    
13412                    if (mbMessage != null) {
13413                            return mbMessage;
13414                    }
13415    
13416                    StringBundler msg = new StringBundler(8);
13417    
13418                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13419    
13420                    msg.append("groupId=");
13421                    msg.append(groupId);
13422    
13423                    msg.append(", categoryId=");
13424                    msg.append(categoryId);
13425    
13426                    msg.append(", status=");
13427                    msg.append(status);
13428    
13429                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13430    
13431                    throw new NoSuchMessageException(msg.toString());
13432            }
13433    
13434            /**
13435             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13436             *
13437             * @param groupId the group ID
13438             * @param categoryId the category ID
13439             * @param status the status
13440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13441             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13442             */
13443            @Override
13444            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13445                    int status, OrderByComparator<MBMessage> orderByComparator) {
13446                    int count = countByG_C_S(groupId, categoryId, status);
13447    
13448                    if (count == 0) {
13449                            return null;
13450                    }
13451    
13452                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13453                                    count - 1, count, orderByComparator);
13454    
13455                    if (!list.isEmpty()) {
13456                            return list.get(0);
13457                    }
13458    
13459                    return null;
13460            }
13461    
13462            /**
13463             * 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;.
13464             *
13465             * @param messageId the primary key of the current message-boards message
13466             * @param groupId the group ID
13467             * @param categoryId the category ID
13468             * @param status the status
13469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13470             * @return the previous, current, and next message-boards message
13471             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13472             */
13473            @Override
13474            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13475                    long categoryId, int status,
13476                    OrderByComparator<MBMessage> orderByComparator)
13477                    throws NoSuchMessageException {
13478                    MBMessage mbMessage = findByPrimaryKey(messageId);
13479    
13480                    Session session = null;
13481    
13482                    try {
13483                            session = openSession();
13484    
13485                            MBMessage[] array = new MBMessageImpl[3];
13486    
13487                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13488                                            categoryId, status, orderByComparator, true);
13489    
13490                            array[1] = mbMessage;
13491    
13492                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13493                                            categoryId, status, orderByComparator, false);
13494    
13495                            return array;
13496                    }
13497                    catch (Exception e) {
13498                            throw processException(e);
13499                    }
13500                    finally {
13501                            closeSession(session);
13502                    }
13503            }
13504    
13505            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13506                    MBMessage mbMessage, long groupId, long categoryId, int status,
13507                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13508                    StringBundler query = null;
13509    
13510                    if (orderByComparator != null) {
13511                            query = new StringBundler(6 +
13512                                            (orderByComparator.getOrderByFields().length * 6));
13513                    }
13514                    else {
13515                            query = new StringBundler(3);
13516                    }
13517    
13518                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13519    
13520                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13521    
13522                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13523    
13524                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13525    
13526                    if (orderByComparator != null) {
13527                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13528    
13529                            if (orderByConditionFields.length > 0) {
13530                                    query.append(WHERE_AND);
13531                            }
13532    
13533                            for (int i = 0; i < orderByConditionFields.length; i++) {
13534                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13535                                    query.append(orderByConditionFields[i]);
13536    
13537                                    if ((i + 1) < orderByConditionFields.length) {
13538                                            if (orderByComparator.isAscending() ^ previous) {
13539                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13540                                            }
13541                                            else {
13542                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13543                                            }
13544                                    }
13545                                    else {
13546                                            if (orderByComparator.isAscending() ^ previous) {
13547                                                    query.append(WHERE_GREATER_THAN);
13548                                            }
13549                                            else {
13550                                                    query.append(WHERE_LESSER_THAN);
13551                                            }
13552                                    }
13553                            }
13554    
13555                            query.append(ORDER_BY_CLAUSE);
13556    
13557                            String[] orderByFields = orderByComparator.getOrderByFields();
13558    
13559                            for (int i = 0; i < orderByFields.length; i++) {
13560                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13561                                    query.append(orderByFields[i]);
13562    
13563                                    if ((i + 1) < orderByFields.length) {
13564                                            if (orderByComparator.isAscending() ^ previous) {
13565                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13566                                            }
13567                                            else {
13568                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13569                                            }
13570                                    }
13571                                    else {
13572                                            if (orderByComparator.isAscending() ^ previous) {
13573                                                    query.append(ORDER_BY_ASC);
13574                                            }
13575                                            else {
13576                                                    query.append(ORDER_BY_DESC);
13577                                            }
13578                                    }
13579                            }
13580                    }
13581                    else {
13582                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13583                    }
13584    
13585                    String sql = query.toString();
13586    
13587                    Query q = session.createQuery(sql);
13588    
13589                    q.setFirstResult(0);
13590                    q.setMaxResults(2);
13591    
13592                    QueryPos qPos = QueryPos.getInstance(q);
13593    
13594                    qPos.add(groupId);
13595    
13596                    qPos.add(categoryId);
13597    
13598                    qPos.add(status);
13599    
13600                    if (orderByComparator != null) {
13601                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13602    
13603                            for (Object value : values) {
13604                                    qPos.add(value);
13605                            }
13606                    }
13607    
13608                    List<MBMessage> list = q.list();
13609    
13610                    if (list.size() == 2) {
13611                            return list.get(1);
13612                    }
13613                    else {
13614                            return null;
13615                    }
13616            }
13617    
13618            /**
13619             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13620             *
13621             * @param groupId the group ID
13622             * @param categoryId the category ID
13623             * @param status the status
13624             * @return the matching message-boards messages that the user has permission to view
13625             */
13626            @Override
13627            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13628                    int status) {
13629                    return filterFindByG_C_S(groupId, categoryId, status,
13630                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13631            }
13632    
13633            /**
13634             * 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;.
13635             *
13636             * <p>
13637             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13638             * </p>
13639             *
13640             * @param groupId the group ID
13641             * @param categoryId the category ID
13642             * @param status the status
13643             * @param start the lower bound of the range of message-boards messages
13644             * @param end the upper bound of the range of message-boards messages (not inclusive)
13645             * @return the range of matching message-boards messages that the user has permission to view
13646             */
13647            @Override
13648            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13649                    int status, int start, int end) {
13650                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13651            }
13652    
13653            /**
13654             * 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;.
13655             *
13656             * <p>
13657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13658             * </p>
13659             *
13660             * @param groupId the group ID
13661             * @param categoryId the category ID
13662             * @param status the status
13663             * @param start the lower bound of the range of message-boards messages
13664             * @param end the upper bound of the range of message-boards messages (not inclusive)
13665             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13666             * @return the ordered range of matching message-boards messages that the user has permission to view
13667             */
13668            @Override
13669            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13670                    int status, int start, int end,
13671                    OrderByComparator<MBMessage> orderByComparator) {
13672                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13673                            return findByG_C_S(groupId, categoryId, status, start, end,
13674                                    orderByComparator);
13675                    }
13676    
13677                    StringBundler query = null;
13678    
13679                    if (orderByComparator != null) {
13680                            query = new StringBundler(5 +
13681                                            (orderByComparator.getOrderByFields().length * 3));
13682                    }
13683                    else {
13684                            query = new StringBundler(5);
13685                    }
13686    
13687                    if (getDB().isSupportsInlineDistinct()) {
13688                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13689                    }
13690                    else {
13691                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13692                    }
13693    
13694                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13695    
13696                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13697    
13698                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13699    
13700                    if (!getDB().isSupportsInlineDistinct()) {
13701                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13702                    }
13703    
13704                    if (orderByComparator != null) {
13705                            if (getDB().isSupportsInlineDistinct()) {
13706                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13707                                            orderByComparator, true);
13708                            }
13709                            else {
13710                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13711                                            orderByComparator, true);
13712                            }
13713                    }
13714                    else {
13715                            if (getDB().isSupportsInlineDistinct()) {
13716                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13717                            }
13718                            else {
13719                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13720                            }
13721                    }
13722    
13723                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13724                                    MBMessage.class.getName(),
13725                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13726    
13727                    Session session = null;
13728    
13729                    try {
13730                            session = openSession();
13731    
13732                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13733    
13734                            if (getDB().isSupportsInlineDistinct()) {
13735                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13736                            }
13737                            else {
13738                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13739                            }
13740    
13741                            QueryPos qPos = QueryPos.getInstance(q);
13742    
13743                            qPos.add(groupId);
13744    
13745                            qPos.add(categoryId);
13746    
13747                            qPos.add(status);
13748    
13749                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13750                    }
13751                    catch (Exception e) {
13752                            throw processException(e);
13753                    }
13754                    finally {
13755                            closeSession(session);
13756                    }
13757            }
13758    
13759            /**
13760             * 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;.
13761             *
13762             * @param messageId the primary key of the current message-boards message
13763             * @param groupId the group ID
13764             * @param categoryId the category ID
13765             * @param status the status
13766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13767             * @return the previous, current, and next message-boards message
13768             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13769             */
13770            @Override
13771            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13772                    long groupId, long categoryId, int status,
13773                    OrderByComparator<MBMessage> orderByComparator)
13774                    throws NoSuchMessageException {
13775                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13776                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13777                                    status, orderByComparator);
13778                    }
13779    
13780                    MBMessage mbMessage = findByPrimaryKey(messageId);
13781    
13782                    Session session = null;
13783    
13784                    try {
13785                            session = openSession();
13786    
13787                            MBMessage[] array = new MBMessageImpl[3];
13788    
13789                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13790                                            groupId, categoryId, status, orderByComparator, true);
13791    
13792                            array[1] = mbMessage;
13793    
13794                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13795                                            groupId, categoryId, status, orderByComparator, false);
13796    
13797                            return array;
13798                    }
13799                    catch (Exception e) {
13800                            throw processException(e);
13801                    }
13802                    finally {
13803                            closeSession(session);
13804                    }
13805            }
13806    
13807            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13808                    MBMessage mbMessage, long groupId, long categoryId, int status,
13809                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13810                    StringBundler query = null;
13811    
13812                    if (orderByComparator != null) {
13813                            query = new StringBundler(6 +
13814                                            (orderByComparator.getOrderByFields().length * 6));
13815                    }
13816                    else {
13817                            query = new StringBundler(3);
13818                    }
13819    
13820                    if (getDB().isSupportsInlineDistinct()) {
13821                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13822                    }
13823                    else {
13824                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13825                    }
13826    
13827                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13828    
13829                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13830    
13831                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13832    
13833                    if (!getDB().isSupportsInlineDistinct()) {
13834                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13835                    }
13836    
13837                    if (orderByComparator != null) {
13838                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13839    
13840                            if (orderByConditionFields.length > 0) {
13841                                    query.append(WHERE_AND);
13842                            }
13843    
13844                            for (int i = 0; i < orderByConditionFields.length; i++) {
13845                                    if (getDB().isSupportsInlineDistinct()) {
13846                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13847                                    }
13848                                    else {
13849                                            query.append(_ORDER_BY_ENTITY_TABLE);
13850                                    }
13851    
13852                                    query.append(orderByConditionFields[i]);
13853    
13854                                    if ((i + 1) < orderByConditionFields.length) {
13855                                            if (orderByComparator.isAscending() ^ previous) {
13856                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13857                                            }
13858                                            else {
13859                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13860                                            }
13861                                    }
13862                                    else {
13863                                            if (orderByComparator.isAscending() ^ previous) {
13864                                                    query.append(WHERE_GREATER_THAN);
13865                                            }
13866                                            else {
13867                                                    query.append(WHERE_LESSER_THAN);
13868                                            }
13869                                    }
13870                            }
13871    
13872                            query.append(ORDER_BY_CLAUSE);
13873    
13874                            String[] orderByFields = orderByComparator.getOrderByFields();
13875    
13876                            for (int i = 0; i < orderByFields.length; i++) {
13877                                    if (getDB().isSupportsInlineDistinct()) {
13878                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13879                                    }
13880                                    else {
13881                                            query.append(_ORDER_BY_ENTITY_TABLE);
13882                                    }
13883    
13884                                    query.append(orderByFields[i]);
13885    
13886                                    if ((i + 1) < orderByFields.length) {
13887                                            if (orderByComparator.isAscending() ^ previous) {
13888                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13889                                            }
13890                                            else {
13891                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13892                                            }
13893                                    }
13894                                    else {
13895                                            if (orderByComparator.isAscending() ^ previous) {
13896                                                    query.append(ORDER_BY_ASC);
13897                                            }
13898                                            else {
13899                                                    query.append(ORDER_BY_DESC);
13900                                            }
13901                                    }
13902                            }
13903                    }
13904                    else {
13905                            if (getDB().isSupportsInlineDistinct()) {
13906                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13907                            }
13908                            else {
13909                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13910                            }
13911                    }
13912    
13913                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13914                                    MBMessage.class.getName(),
13915                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13916    
13917                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13918    
13919                    q.setFirstResult(0);
13920                    q.setMaxResults(2);
13921    
13922                    if (getDB().isSupportsInlineDistinct()) {
13923                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13924                    }
13925                    else {
13926                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13927                    }
13928    
13929                    QueryPos qPos = QueryPos.getInstance(q);
13930    
13931                    qPos.add(groupId);
13932    
13933                    qPos.add(categoryId);
13934    
13935                    qPos.add(status);
13936    
13937                    if (orderByComparator != null) {
13938                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13939    
13940                            for (Object value : values) {
13941                                    qPos.add(value);
13942                            }
13943                    }
13944    
13945                    List<MBMessage> list = q.list();
13946    
13947                    if (list.size() == 2) {
13948                            return list.get(1);
13949                    }
13950                    else {
13951                            return null;
13952                    }
13953            }
13954    
13955            /**
13956             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13957             *
13958             * @param groupId the group ID
13959             * @param categoryId the category ID
13960             * @param status the status
13961             */
13962            @Override
13963            public void removeByG_C_S(long groupId, long categoryId, int status) {
13964                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13965                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13966                            remove(mbMessage);
13967                    }
13968            }
13969    
13970            /**
13971             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13972             *
13973             * @param groupId the group ID
13974             * @param categoryId the category ID
13975             * @param status the status
13976             * @return the number of matching message-boards messages
13977             */
13978            @Override
13979            public int countByG_C_S(long groupId, long categoryId, int status) {
13980                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13981    
13982                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13983    
13984                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13985    
13986                    if (count == null) {
13987                            StringBundler query = new StringBundler(4);
13988    
13989                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13990    
13991                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13992    
13993                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13994    
13995                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13996    
13997                            String sql = query.toString();
13998    
13999                            Session session = null;
14000    
14001                            try {
14002                                    session = openSession();
14003    
14004                                    Query q = session.createQuery(sql);
14005    
14006                                    QueryPos qPos = QueryPos.getInstance(q);
14007    
14008                                    qPos.add(groupId);
14009    
14010                                    qPos.add(categoryId);
14011    
14012                                    qPos.add(status);
14013    
14014                                    count = (Long)q.uniqueResult();
14015    
14016                                    finderCache.putResult(finderPath, finderArgs, count);
14017                            }
14018                            catch (Exception e) {
14019                                    finderCache.removeResult(finderPath, finderArgs);
14020    
14021                                    throw processException(e);
14022                            }
14023                            finally {
14024                                    closeSession(session);
14025                            }
14026                    }
14027    
14028                    return count.intValue();
14029            }
14030    
14031            /**
14032             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
14033             *
14034             * @param groupId the group ID
14035             * @param categoryId the category ID
14036             * @param status the status
14037             * @return the number of matching message-boards messages that the user has permission to view
14038             */
14039            @Override
14040            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
14041                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14042                            return countByG_C_S(groupId, categoryId, status);
14043                    }
14044    
14045                    StringBundler query = new StringBundler(4);
14046    
14047                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
14048    
14049                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14050    
14051                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14052    
14053                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14054    
14055                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14056                                    MBMessage.class.getName(),
14057                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14058    
14059                    Session session = null;
14060    
14061                    try {
14062                            session = openSession();
14063    
14064                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
14065    
14066                            q.addScalar(COUNT_COLUMN_NAME,
14067                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14068    
14069                            QueryPos qPos = QueryPos.getInstance(q);
14070    
14071                            qPos.add(groupId);
14072    
14073                            qPos.add(categoryId);
14074    
14075                            qPos.add(status);
14076    
14077                            Long count = (Long)q.uniqueResult();
14078    
14079                            return count.intValue();
14080                    }
14081                    catch (Exception e) {
14082                            throw processException(e);
14083                    }
14084                    finally {
14085                            closeSession(session);
14086                    }
14087            }
14088    
14089            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
14090            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
14091            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
14092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14093                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
14095                            new String[] {
14096                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14097                                    
14098                            Integer.class.getName(), Integer.class.getName(),
14099                                    OrderByComparator.class.getName()
14100                            });
14101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
14104                            new String[] {
14105                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14106                            },
14107                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14108                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14109                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14110                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14111            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14112                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
14114                            new String[] {
14115                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14116                            });
14117    
14118            /**
14119             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14120             *
14121             * @param userId the user ID
14122             * @param classNameId the class name ID
14123             * @param classPK the class p k
14124             * @return the matching message-boards messages
14125             */
14126            @Override
14127            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14128                    long classPK) {
14129                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
14130                            QueryUtil.ALL_POS, null);
14131            }
14132    
14133            /**
14134             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14135             *
14136             * <p>
14137             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14138             * </p>
14139             *
14140             * @param userId the user ID
14141             * @param classNameId the class name ID
14142             * @param classPK the class p k
14143             * @param start the lower bound of the range of message-boards messages
14144             * @param end the upper bound of the range of message-boards messages (not inclusive)
14145             * @return the range of matching message-boards messages
14146             */
14147            @Override
14148            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14149                    long classPK, int start, int end) {
14150                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
14151            }
14152    
14153            /**
14154             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14155             *
14156             * <p>
14157             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14158             * </p>
14159             *
14160             * @param userId the user ID
14161             * @param classNameId the class name ID
14162             * @param classPK the class p k
14163             * @param start the lower bound of the range of message-boards messages
14164             * @param end the upper bound of the range of message-boards messages (not inclusive)
14165             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14166             * @return the ordered range of matching message-boards messages
14167             */
14168            @Override
14169            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14170                    long classPK, int start, int end,
14171                    OrderByComparator<MBMessage> orderByComparator) {
14172                    return findByU_C_C(userId, classNameId, classPK, start, end,
14173                            orderByComparator, true);
14174            }
14175    
14176            /**
14177             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14178             *
14179             * <p>
14180             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14181             * </p>
14182             *
14183             * @param userId the user ID
14184             * @param classNameId the class name ID
14185             * @param classPK the class p k
14186             * @param start the lower bound of the range of message-boards messages
14187             * @param end the upper bound of the range of message-boards messages (not inclusive)
14188             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14189             * @param retrieveFromCache whether to retrieve from the finder cache
14190             * @return the ordered range of matching message-boards messages
14191             */
14192            @Override
14193            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14194                    long classPK, int start, int end,
14195                    OrderByComparator<MBMessage> orderByComparator,
14196                    boolean retrieveFromCache) {
14197                    boolean pagination = true;
14198                    FinderPath finderPath = null;
14199                    Object[] finderArgs = null;
14200    
14201                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14202                                    (orderByComparator == null)) {
14203                            pagination = false;
14204                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
14205                            finderArgs = new Object[] { userId, classNameId, classPK };
14206                    }
14207                    else {
14208                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
14209                            finderArgs = new Object[] {
14210                                            userId, classNameId, classPK,
14211                                            
14212                                            start, end, orderByComparator
14213                                    };
14214                    }
14215    
14216                    List<MBMessage> list = null;
14217    
14218                    if (retrieveFromCache) {
14219                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14220                                            finderArgs, this);
14221    
14222                            if ((list != null) && !list.isEmpty()) {
14223                                    for (MBMessage mbMessage : list) {
14224                                            if ((userId != mbMessage.getUserId()) ||
14225                                                            (classNameId != mbMessage.getClassNameId()) ||
14226                                                            (classPK != mbMessage.getClassPK())) {
14227                                                    list = null;
14228    
14229                                                    break;
14230                                            }
14231                                    }
14232                            }
14233                    }
14234    
14235                    if (list == null) {
14236                            StringBundler query = null;
14237    
14238                            if (orderByComparator != null) {
14239                                    query = new StringBundler(5 +
14240                                                    (orderByComparator.getOrderByFields().length * 3));
14241                            }
14242                            else {
14243                                    query = new StringBundler(5);
14244                            }
14245    
14246                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14247    
14248                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14249    
14250                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14251    
14252                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14253    
14254                            if (orderByComparator != null) {
14255                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14256                                            orderByComparator);
14257                            }
14258                            else
14259                             if (pagination) {
14260                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14261                            }
14262    
14263                            String sql = query.toString();
14264    
14265                            Session session = null;
14266    
14267                            try {
14268                                    session = openSession();
14269    
14270                                    Query q = session.createQuery(sql);
14271    
14272                                    QueryPos qPos = QueryPos.getInstance(q);
14273    
14274                                    qPos.add(userId);
14275    
14276                                    qPos.add(classNameId);
14277    
14278                                    qPos.add(classPK);
14279    
14280                                    if (!pagination) {
14281                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14282                                                            start, end, false);
14283    
14284                                            Collections.sort(list);
14285    
14286                                            list = Collections.unmodifiableList(list);
14287                                    }
14288                                    else {
14289                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14290                                                            start, end);
14291                                    }
14292    
14293                                    cacheResult(list);
14294    
14295                                    finderCache.putResult(finderPath, finderArgs, list);
14296                            }
14297                            catch (Exception e) {
14298                                    finderCache.removeResult(finderPath, finderArgs);
14299    
14300                                    throw processException(e);
14301                            }
14302                            finally {
14303                                    closeSession(session);
14304                            }
14305                    }
14306    
14307                    return list;
14308            }
14309    
14310            /**
14311             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14312             *
14313             * @param userId the user ID
14314             * @param classNameId the class name ID
14315             * @param classPK the class p k
14316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14317             * @return the first matching message-boards message
14318             * @throws NoSuchMessageException if a matching message-boards message could not be found
14319             */
14320            @Override
14321            public MBMessage findByU_C_C_First(long userId, long classNameId,
14322                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14323                    throws NoSuchMessageException {
14324                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14325                                    orderByComparator);
14326    
14327                    if (mbMessage != null) {
14328                            return mbMessage;
14329                    }
14330    
14331                    StringBundler msg = new StringBundler(8);
14332    
14333                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14334    
14335                    msg.append("userId=");
14336                    msg.append(userId);
14337    
14338                    msg.append(", classNameId=");
14339                    msg.append(classNameId);
14340    
14341                    msg.append(", classPK=");
14342                    msg.append(classPK);
14343    
14344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14345    
14346                    throw new NoSuchMessageException(msg.toString());
14347            }
14348    
14349            /**
14350             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14351             *
14352             * @param userId the user ID
14353             * @param classNameId the class name ID
14354             * @param classPK the class p k
14355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14356             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14357             */
14358            @Override
14359            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14360                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14361                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14362                                    orderByComparator);
14363    
14364                    if (!list.isEmpty()) {
14365                            return list.get(0);
14366                    }
14367    
14368                    return null;
14369            }
14370    
14371            /**
14372             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14373             *
14374             * @param userId the user ID
14375             * @param classNameId the class name ID
14376             * @param classPK the class p k
14377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14378             * @return the last matching message-boards message
14379             * @throws NoSuchMessageException if a matching message-boards message could not be found
14380             */
14381            @Override
14382            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14383                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14384                    throws NoSuchMessageException {
14385                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14386                                    orderByComparator);
14387    
14388                    if (mbMessage != null) {
14389                            return mbMessage;
14390                    }
14391    
14392                    StringBundler msg = new StringBundler(8);
14393    
14394                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14395    
14396                    msg.append("userId=");
14397                    msg.append(userId);
14398    
14399                    msg.append(", classNameId=");
14400                    msg.append(classNameId);
14401    
14402                    msg.append(", classPK=");
14403                    msg.append(classPK);
14404    
14405                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14406    
14407                    throw new NoSuchMessageException(msg.toString());
14408            }
14409    
14410            /**
14411             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14412             *
14413             * @param userId the user ID
14414             * @param classNameId the class name ID
14415             * @param classPK the class p k
14416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14417             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14418             */
14419            @Override
14420            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14421                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14422                    int count = countByU_C_C(userId, classNameId, classPK);
14423    
14424                    if (count == 0) {
14425                            return null;
14426                    }
14427    
14428                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14429                                    count - 1, count, orderByComparator);
14430    
14431                    if (!list.isEmpty()) {
14432                            return list.get(0);
14433                    }
14434    
14435                    return null;
14436            }
14437    
14438            /**
14439             * 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;.
14440             *
14441             * @param messageId the primary key of the current message-boards message
14442             * @param userId the user ID
14443             * @param classNameId the class name ID
14444             * @param classPK the class p k
14445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14446             * @return the previous, current, and next message-boards message
14447             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14448             */
14449            @Override
14450            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14451                    long classNameId, long classPK,
14452                    OrderByComparator<MBMessage> orderByComparator)
14453                    throws NoSuchMessageException {
14454                    MBMessage mbMessage = findByPrimaryKey(messageId);
14455    
14456                    Session session = null;
14457    
14458                    try {
14459                            session = openSession();
14460    
14461                            MBMessage[] array = new MBMessageImpl[3];
14462    
14463                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14464                                            classNameId, classPK, orderByComparator, true);
14465    
14466                            array[1] = mbMessage;
14467    
14468                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14469                                            classNameId, classPK, orderByComparator, false);
14470    
14471                            return array;
14472                    }
14473                    catch (Exception e) {
14474                            throw processException(e);
14475                    }
14476                    finally {
14477                            closeSession(session);
14478                    }
14479            }
14480    
14481            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14482                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14483                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14484                    StringBundler query = null;
14485    
14486                    if (orderByComparator != null) {
14487                            query = new StringBundler(6 +
14488                                            (orderByComparator.getOrderByFields().length * 6));
14489                    }
14490                    else {
14491                            query = new StringBundler(3);
14492                    }
14493    
14494                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14495    
14496                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14497    
14498                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14499    
14500                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14501    
14502                    if (orderByComparator != null) {
14503                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14504    
14505                            if (orderByConditionFields.length > 0) {
14506                                    query.append(WHERE_AND);
14507                            }
14508    
14509                            for (int i = 0; i < orderByConditionFields.length; i++) {
14510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14511                                    query.append(orderByConditionFields[i]);
14512    
14513                                    if ((i + 1) < orderByConditionFields.length) {
14514                                            if (orderByComparator.isAscending() ^ previous) {
14515                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14516                                            }
14517                                            else {
14518                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14519                                            }
14520                                    }
14521                                    else {
14522                                            if (orderByComparator.isAscending() ^ previous) {
14523                                                    query.append(WHERE_GREATER_THAN);
14524                                            }
14525                                            else {
14526                                                    query.append(WHERE_LESSER_THAN);
14527                                            }
14528                                    }
14529                            }
14530    
14531                            query.append(ORDER_BY_CLAUSE);
14532    
14533                            String[] orderByFields = orderByComparator.getOrderByFields();
14534    
14535                            for (int i = 0; i < orderByFields.length; i++) {
14536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14537                                    query.append(orderByFields[i]);
14538    
14539                                    if ((i + 1) < orderByFields.length) {
14540                                            if (orderByComparator.isAscending() ^ previous) {
14541                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14542                                            }
14543                                            else {
14544                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14545                                            }
14546                                    }
14547                                    else {
14548                                            if (orderByComparator.isAscending() ^ previous) {
14549                                                    query.append(ORDER_BY_ASC);
14550                                            }
14551                                            else {
14552                                                    query.append(ORDER_BY_DESC);
14553                                            }
14554                                    }
14555                            }
14556                    }
14557                    else {
14558                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14559                    }
14560    
14561                    String sql = query.toString();
14562    
14563                    Query q = session.createQuery(sql);
14564    
14565                    q.setFirstResult(0);
14566                    q.setMaxResults(2);
14567    
14568                    QueryPos qPos = QueryPos.getInstance(q);
14569    
14570                    qPos.add(userId);
14571    
14572                    qPos.add(classNameId);
14573    
14574                    qPos.add(classPK);
14575    
14576                    if (orderByComparator != null) {
14577                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14578    
14579                            for (Object value : values) {
14580                                    qPos.add(value);
14581                            }
14582                    }
14583    
14584                    List<MBMessage> list = q.list();
14585    
14586                    if (list.size() == 2) {
14587                            return list.get(1);
14588                    }
14589                    else {
14590                            return null;
14591                    }
14592            }
14593    
14594            /**
14595             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14596             *
14597             * @param userId the user ID
14598             * @param classNameId the class name ID
14599             * @param classPK the class p k
14600             */
14601            @Override
14602            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14603                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14604                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14605                            remove(mbMessage);
14606                    }
14607            }
14608    
14609            /**
14610             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14611             *
14612             * @param userId the user ID
14613             * @param classNameId the class name ID
14614             * @param classPK the class p k
14615             * @return the number of matching message-boards messages
14616             */
14617            @Override
14618            public int countByU_C_C(long userId, long classNameId, long classPK) {
14619                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14620    
14621                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14622    
14623                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14624    
14625                    if (count == null) {
14626                            StringBundler query = new StringBundler(4);
14627    
14628                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14629    
14630                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14631    
14632                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14633    
14634                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14635    
14636                            String sql = query.toString();
14637    
14638                            Session session = null;
14639    
14640                            try {
14641                                    session = openSession();
14642    
14643                                    Query q = session.createQuery(sql);
14644    
14645                                    QueryPos qPos = QueryPos.getInstance(q);
14646    
14647                                    qPos.add(userId);
14648    
14649                                    qPos.add(classNameId);
14650    
14651                                    qPos.add(classPK);
14652    
14653                                    count = (Long)q.uniqueResult();
14654    
14655                                    finderCache.putResult(finderPath, finderArgs, count);
14656                            }
14657                            catch (Exception e) {
14658                                    finderCache.removeResult(finderPath, finderArgs);
14659    
14660                                    throw processException(e);
14661                            }
14662                            finally {
14663                                    closeSession(session);
14664                            }
14665                    }
14666    
14667                    return count.intValue();
14668            }
14669    
14670            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14671            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14672            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14673            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14674                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14675                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14676                            new String[] {
14677                                    Long.class.getName(), Long.class.getName(),
14678                                    Integer.class.getName(),
14679                                    
14680                            Integer.class.getName(), Integer.class.getName(),
14681                                    OrderByComparator.class.getName()
14682                            });
14683            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14684                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14685                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14686                            new String[] {
14687                                    Long.class.getName(), Long.class.getName(),
14688                                    Integer.class.getName()
14689                            },
14690                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14691                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14692                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14693                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14694            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14695                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14696                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14697                            new String[] {
14698                                    Long.class.getName(), Long.class.getName(),
14699                                    Integer.class.getName()
14700                            });
14701            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14702                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14703                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14704                            new String[] {
14705                                    Long.class.getName(), Long.class.getName(),
14706                                    Integer.class.getName()
14707                            });
14708    
14709            /**
14710             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14711             *
14712             * @param userId the user ID
14713             * @param classNameId the class name ID
14714             * @param status the status
14715             * @return the matching message-boards messages
14716             */
14717            @Override
14718            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14719                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14720                            QueryUtil.ALL_POS, null);
14721            }
14722    
14723            /**
14724             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14725             *
14726             * <p>
14727             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14728             * </p>
14729             *
14730             * @param userId the user ID
14731             * @param classNameId the class name ID
14732             * @param status the status
14733             * @param start the lower bound of the range of message-boards messages
14734             * @param end the upper bound of the range of message-boards messages (not inclusive)
14735             * @return the range of matching message-boards messages
14736             */
14737            @Override
14738            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14739                    int status, int start, int end) {
14740                    return findByU_C_S(userId, classNameId, status, start, end, null);
14741            }
14742    
14743            /**
14744             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14745             *
14746             * <p>
14747             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14748             * </p>
14749             *
14750             * @param userId the user ID
14751             * @param classNameId the class name ID
14752             * @param status the status
14753             * @param start the lower bound of the range of message-boards messages
14754             * @param end the upper bound of the range of message-boards messages (not inclusive)
14755             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14756             * @return the ordered range of matching message-boards messages
14757             */
14758            @Override
14759            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14760                    int status, int start, int end,
14761                    OrderByComparator<MBMessage> orderByComparator) {
14762                    return findByU_C_S(userId, classNameId, status, start, end,
14763                            orderByComparator, true);
14764            }
14765    
14766            /**
14767             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14768             *
14769             * <p>
14770             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14771             * </p>
14772             *
14773             * @param userId the user ID
14774             * @param classNameId the class name ID
14775             * @param status the status
14776             * @param start the lower bound of the range of message-boards messages
14777             * @param end the upper bound of the range of message-boards messages (not inclusive)
14778             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14779             * @param retrieveFromCache whether to retrieve from the finder cache
14780             * @return the ordered range of matching message-boards messages
14781             */
14782            @Override
14783            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14784                    int status, int start, int end,
14785                    OrderByComparator<MBMessage> orderByComparator,
14786                    boolean retrieveFromCache) {
14787                    boolean pagination = true;
14788                    FinderPath finderPath = null;
14789                    Object[] finderArgs = null;
14790    
14791                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14792                                    (orderByComparator == null)) {
14793                            pagination = false;
14794                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14795                            finderArgs = new Object[] { userId, classNameId, status };
14796                    }
14797                    else {
14798                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14799                            finderArgs = new Object[] {
14800                                            userId, classNameId, status,
14801                                            
14802                                            start, end, orderByComparator
14803                                    };
14804                    }
14805    
14806                    List<MBMessage> list = null;
14807    
14808                    if (retrieveFromCache) {
14809                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14810                                            finderArgs, this);
14811    
14812                            if ((list != null) && !list.isEmpty()) {
14813                                    for (MBMessage mbMessage : list) {
14814                                            if ((userId != mbMessage.getUserId()) ||
14815                                                            (classNameId != mbMessage.getClassNameId()) ||
14816                                                            (status != mbMessage.getStatus())) {
14817                                                    list = null;
14818    
14819                                                    break;
14820                                            }
14821                                    }
14822                            }
14823                    }
14824    
14825                    if (list == null) {
14826                            StringBundler query = null;
14827    
14828                            if (orderByComparator != null) {
14829                                    query = new StringBundler(5 +
14830                                                    (orderByComparator.getOrderByFields().length * 3));
14831                            }
14832                            else {
14833                                    query = new StringBundler(5);
14834                            }
14835    
14836                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14837    
14838                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14839    
14840                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14841    
14842                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14843    
14844                            if (orderByComparator != null) {
14845                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14846                                            orderByComparator);
14847                            }
14848                            else
14849                             if (pagination) {
14850                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14851                            }
14852    
14853                            String sql = query.toString();
14854    
14855                            Session session = null;
14856    
14857                            try {
14858                                    session = openSession();
14859    
14860                                    Query q = session.createQuery(sql);
14861    
14862                                    QueryPos qPos = QueryPos.getInstance(q);
14863    
14864                                    qPos.add(userId);
14865    
14866                                    qPos.add(classNameId);
14867    
14868                                    qPos.add(status);
14869    
14870                                    if (!pagination) {
14871                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14872                                                            start, end, false);
14873    
14874                                            Collections.sort(list);
14875    
14876                                            list = Collections.unmodifiableList(list);
14877                                    }
14878                                    else {
14879                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14880                                                            start, end);
14881                                    }
14882    
14883                                    cacheResult(list);
14884    
14885                                    finderCache.putResult(finderPath, finderArgs, list);
14886                            }
14887                            catch (Exception e) {
14888                                    finderCache.removeResult(finderPath, finderArgs);
14889    
14890                                    throw processException(e);
14891                            }
14892                            finally {
14893                                    closeSession(session);
14894                            }
14895                    }
14896    
14897                    return list;
14898            }
14899    
14900            /**
14901             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14902             *
14903             * @param userId the user ID
14904             * @param classNameId the class name ID
14905             * @param status the status
14906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14907             * @return the first matching message-boards message
14908             * @throws NoSuchMessageException if a matching message-boards message could not be found
14909             */
14910            @Override
14911            public MBMessage findByU_C_S_First(long userId, long classNameId,
14912                    int status, OrderByComparator<MBMessage> orderByComparator)
14913                    throws NoSuchMessageException {
14914                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14915                                    orderByComparator);
14916    
14917                    if (mbMessage != null) {
14918                            return mbMessage;
14919                    }
14920    
14921                    StringBundler msg = new StringBundler(8);
14922    
14923                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14924    
14925                    msg.append("userId=");
14926                    msg.append(userId);
14927    
14928                    msg.append(", classNameId=");
14929                    msg.append(classNameId);
14930    
14931                    msg.append(", status=");
14932                    msg.append(status);
14933    
14934                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14935    
14936                    throw new NoSuchMessageException(msg.toString());
14937            }
14938    
14939            /**
14940             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14941             *
14942             * @param userId the user ID
14943             * @param classNameId the class name ID
14944             * @param status the status
14945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14946             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14947             */
14948            @Override
14949            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14950                    int status, OrderByComparator<MBMessage> orderByComparator) {
14951                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14952                                    orderByComparator);
14953    
14954                    if (!list.isEmpty()) {
14955                            return list.get(0);
14956                    }
14957    
14958                    return null;
14959            }
14960    
14961            /**
14962             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14963             *
14964             * @param userId the user ID
14965             * @param classNameId the class name ID
14966             * @param status the status
14967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14968             * @return the last matching message-boards message
14969             * @throws NoSuchMessageException if a matching message-boards message could not be found
14970             */
14971            @Override
14972            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14973                    int status, OrderByComparator<MBMessage> orderByComparator)
14974                    throws NoSuchMessageException {
14975                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14976                                    orderByComparator);
14977    
14978                    if (mbMessage != null) {
14979                            return mbMessage;
14980                    }
14981    
14982                    StringBundler msg = new StringBundler(8);
14983    
14984                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14985    
14986                    msg.append("userId=");
14987                    msg.append(userId);
14988    
14989                    msg.append(", classNameId=");
14990                    msg.append(classNameId);
14991    
14992                    msg.append(", status=");
14993                    msg.append(status);
14994    
14995                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14996    
14997                    throw new NoSuchMessageException(msg.toString());
14998            }
14999    
15000            /**
15001             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
15002             *
15003             * @param userId the user ID
15004             * @param classNameId the class name ID
15005             * @param status the status
15006             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15007             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15008             */
15009            @Override
15010            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
15011                    int status, OrderByComparator<MBMessage> orderByComparator) {
15012                    int count = countByU_C_S(userId, classNameId, status);
15013    
15014                    if (count == 0) {
15015                            return null;
15016                    }
15017    
15018                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
15019                                    count - 1, count, orderByComparator);
15020    
15021                    if (!list.isEmpty()) {
15022                            return list.get(0);
15023                    }
15024    
15025                    return null;
15026            }
15027    
15028            /**
15029             * 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;.
15030             *
15031             * @param messageId the primary key of the current message-boards message
15032             * @param userId the user ID
15033             * @param classNameId the class name ID
15034             * @param status the status
15035             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15036             * @return the previous, current, and next message-boards message
15037             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15038             */
15039            @Override
15040            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
15041                    long classNameId, int status,
15042                    OrderByComparator<MBMessage> orderByComparator)
15043                    throws NoSuchMessageException {
15044                    MBMessage mbMessage = findByPrimaryKey(messageId);
15045    
15046                    Session session = null;
15047    
15048                    try {
15049                            session = openSession();
15050    
15051                            MBMessage[] array = new MBMessageImpl[3];
15052    
15053                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15054                                            classNameId, status, orderByComparator, true);
15055    
15056                            array[1] = mbMessage;
15057    
15058                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15059                                            classNameId, status, orderByComparator, false);
15060    
15061                            return array;
15062                    }
15063                    catch (Exception e) {
15064                            throw processException(e);
15065                    }
15066                    finally {
15067                            closeSession(session);
15068                    }
15069            }
15070    
15071            protected MBMessage getByU_C_S_PrevAndNext(Session session,
15072                    MBMessage mbMessage, long userId, long classNameId, int status,
15073                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15074                    StringBundler query = null;
15075    
15076                    if (orderByComparator != null) {
15077                            query = new StringBundler(6 +
15078                                            (orderByComparator.getOrderByFields().length * 6));
15079                    }
15080                    else {
15081                            query = new StringBundler(3);
15082                    }
15083    
15084                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15085    
15086                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15087    
15088                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15089    
15090                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15091    
15092                    if (orderByComparator != null) {
15093                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15094    
15095                            if (orderByConditionFields.length > 0) {
15096                                    query.append(WHERE_AND);
15097                            }
15098    
15099                            for (int i = 0; i < orderByConditionFields.length; i++) {
15100                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15101                                    query.append(orderByConditionFields[i]);
15102    
15103                                    if ((i + 1) < orderByConditionFields.length) {
15104                                            if (orderByComparator.isAscending() ^ previous) {
15105                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15106                                            }
15107                                            else {
15108                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15109                                            }
15110                                    }
15111                                    else {
15112                                            if (orderByComparator.isAscending() ^ previous) {
15113                                                    query.append(WHERE_GREATER_THAN);
15114                                            }
15115                                            else {
15116                                                    query.append(WHERE_LESSER_THAN);
15117                                            }
15118                                    }
15119                            }
15120    
15121                            query.append(ORDER_BY_CLAUSE);
15122    
15123                            String[] orderByFields = orderByComparator.getOrderByFields();
15124    
15125                            for (int i = 0; i < orderByFields.length; i++) {
15126                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15127                                    query.append(orderByFields[i]);
15128    
15129                                    if ((i + 1) < orderByFields.length) {
15130                                            if (orderByComparator.isAscending() ^ previous) {
15131                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15132                                            }
15133                                            else {
15134                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15135                                            }
15136                                    }
15137                                    else {
15138                                            if (orderByComparator.isAscending() ^ previous) {
15139                                                    query.append(ORDER_BY_ASC);
15140                                            }
15141                                            else {
15142                                                    query.append(ORDER_BY_DESC);
15143                                            }
15144                                    }
15145                            }
15146                    }
15147                    else {
15148                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15149                    }
15150    
15151                    String sql = query.toString();
15152    
15153                    Query q = session.createQuery(sql);
15154    
15155                    q.setFirstResult(0);
15156                    q.setMaxResults(2);
15157    
15158                    QueryPos qPos = QueryPos.getInstance(q);
15159    
15160                    qPos.add(userId);
15161    
15162                    qPos.add(classNameId);
15163    
15164                    qPos.add(status);
15165    
15166                    if (orderByComparator != null) {
15167                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15168    
15169                            for (Object value : values) {
15170                                    qPos.add(value);
15171                            }
15172                    }
15173    
15174                    List<MBMessage> list = q.list();
15175    
15176                    if (list.size() == 2) {
15177                            return list.get(1);
15178                    }
15179                    else {
15180                            return null;
15181                    }
15182            }
15183    
15184            /**
15185             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15186             *
15187             * <p>
15188             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15189             * </p>
15190             *
15191             * @param userId the user ID
15192             * @param classNameIds the class name IDs
15193             * @param status the status
15194             * @return the matching message-boards messages
15195             */
15196            @Override
15197            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15198                    int status) {
15199                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
15200                            QueryUtil.ALL_POS, null);
15201            }
15202    
15203            /**
15204             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15205             *
15206             * <p>
15207             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15208             * </p>
15209             *
15210             * @param userId the user ID
15211             * @param classNameIds the class name IDs
15212             * @param status the status
15213             * @param start the lower bound of the range of message-boards messages
15214             * @param end the upper bound of the range of message-boards messages (not inclusive)
15215             * @return the range of matching message-boards messages
15216             */
15217            @Override
15218            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15219                    int status, int start, int end) {
15220                    return findByU_C_S(userId, classNameIds, status, start, end, null);
15221            }
15222    
15223            /**
15224             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15225             *
15226             * <p>
15227             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15228             * </p>
15229             *
15230             * @param userId the user ID
15231             * @param classNameIds the class name IDs
15232             * @param status the status
15233             * @param start the lower bound of the range of message-boards messages
15234             * @param end the upper bound of the range of message-boards messages (not inclusive)
15235             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15236             * @return the ordered range of matching message-boards messages
15237             */
15238            @Override
15239            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15240                    int status, int start, int end,
15241                    OrderByComparator<MBMessage> orderByComparator) {
15242                    return findByU_C_S(userId, classNameIds, status, start, end,
15243                            orderByComparator, true);
15244            }
15245    
15246            /**
15247             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;, optionally using the finder cache.
15248             *
15249             * <p>
15250             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15251             * </p>
15252             *
15253             * @param userId the user ID
15254             * @param classNameId the class name ID
15255             * @param status the status
15256             * @param start the lower bound of the range of message-boards messages
15257             * @param end the upper bound of the range of message-boards messages (not inclusive)
15258             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15259             * @param retrieveFromCache whether to retrieve from the finder cache
15260             * @return the ordered range of matching message-boards messages
15261             */
15262            @Override
15263            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15264                    int status, int start, int end,
15265                    OrderByComparator<MBMessage> orderByComparator,
15266                    boolean retrieveFromCache) {
15267                    if (classNameIds == null) {
15268                            classNameIds = new long[0];
15269                    }
15270                    else if (classNameIds.length > 1) {
15271                            classNameIds = ArrayUtil.unique(classNameIds);
15272    
15273                            Arrays.sort(classNameIds);
15274                    }
15275    
15276                    if (classNameIds.length == 1) {
15277                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15278                                    orderByComparator);
15279                    }
15280    
15281                    boolean pagination = true;
15282                    Object[] finderArgs = null;
15283    
15284                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15285                                    (orderByComparator == null)) {
15286                            pagination = false;
15287                            finderArgs = new Object[] {
15288                                            userId, StringUtil.merge(classNameIds), status
15289                                    };
15290                    }
15291                    else {
15292                            finderArgs = new Object[] {
15293                                            userId, StringUtil.merge(classNameIds), status,
15294                                            
15295                                            start, end, orderByComparator
15296                                    };
15297                    }
15298    
15299                    List<MBMessage> list = null;
15300    
15301                    if (retrieveFromCache) {
15302                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15303                                            finderArgs, this);
15304    
15305                            if ((list != null) && !list.isEmpty()) {
15306                                    for (MBMessage mbMessage : list) {
15307                                            if ((userId != mbMessage.getUserId()) ||
15308                                                            !ArrayUtil.contains(classNameIds,
15309                                                                    mbMessage.getClassNameId()) ||
15310                                                            (status != mbMessage.getStatus())) {
15311                                                    list = null;
15312    
15313                                                    break;
15314                                            }
15315                                    }
15316                            }
15317                    }
15318    
15319                    if (list == null) {
15320                            StringBundler query = new StringBundler();
15321    
15322                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15323    
15324                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15325    
15326                            if (classNameIds.length > 0) {
15327                                    query.append(StringPool.OPEN_PARENTHESIS);
15328    
15329                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15330    
15331                                    query.append(StringUtil.merge(classNameIds));
15332    
15333                                    query.append(StringPool.CLOSE_PARENTHESIS);
15334    
15335                                    query.append(StringPool.CLOSE_PARENTHESIS);
15336    
15337                                    query.append(WHERE_AND);
15338                            }
15339    
15340                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15341    
15342                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15343                                                    1)), query.index() - 1);
15344    
15345                            if (orderByComparator != null) {
15346                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15347                                            orderByComparator);
15348                            }
15349                            else
15350                             if (pagination) {
15351                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15352                            }
15353    
15354                            String sql = query.toString();
15355    
15356                            Session session = null;
15357    
15358                            try {
15359                                    session = openSession();
15360    
15361                                    Query q = session.createQuery(sql);
15362    
15363                                    QueryPos qPos = QueryPos.getInstance(q);
15364    
15365                                    qPos.add(userId);
15366    
15367                                    qPos.add(status);
15368    
15369                                    if (!pagination) {
15370                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15371                                                            start, end, false);
15372    
15373                                            Collections.sort(list);
15374    
15375                                            list = Collections.unmodifiableList(list);
15376                                    }
15377                                    else {
15378                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15379                                                            start, end);
15380                                    }
15381    
15382                                    cacheResult(list);
15383    
15384                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15385                                            finderArgs, list);
15386                            }
15387                            catch (Exception e) {
15388                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15389                                            finderArgs);
15390    
15391                                    throw processException(e);
15392                            }
15393                            finally {
15394                                    closeSession(session);
15395                            }
15396                    }
15397    
15398                    return list;
15399            }
15400    
15401            /**
15402             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15403             *
15404             * @param userId the user ID
15405             * @param classNameId the class name ID
15406             * @param status the status
15407             */
15408            @Override
15409            public void removeByU_C_S(long userId, long classNameId, int status) {
15410                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15411                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15412                            remove(mbMessage);
15413                    }
15414            }
15415    
15416            /**
15417             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15418             *
15419             * @param userId the user ID
15420             * @param classNameId the class name ID
15421             * @param status the status
15422             * @return the number of matching message-boards messages
15423             */
15424            @Override
15425            public int countByU_C_S(long userId, long classNameId, int status) {
15426                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15427    
15428                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15429    
15430                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
15431    
15432                    if (count == null) {
15433                            StringBundler query = new StringBundler(4);
15434    
15435                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15436    
15437                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15438    
15439                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15440    
15441                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15442    
15443                            String sql = query.toString();
15444    
15445                            Session session = null;
15446    
15447                            try {
15448                                    session = openSession();
15449    
15450                                    Query q = session.createQuery(sql);
15451    
15452                                    QueryPos qPos = QueryPos.getInstance(q);
15453    
15454                                    qPos.add(userId);
15455    
15456                                    qPos.add(classNameId);
15457    
15458                                    qPos.add(status);
15459    
15460                                    count = (Long)q.uniqueResult();
15461    
15462                                    finderCache.putResult(finderPath, finderArgs, count);
15463                            }
15464                            catch (Exception e) {
15465                                    finderCache.removeResult(finderPath, finderArgs);
15466    
15467                                    throw processException(e);
15468                            }
15469                            finally {
15470                                    closeSession(session);
15471                            }
15472                    }
15473    
15474                    return count.intValue();
15475            }
15476    
15477            /**
15478             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15479             *
15480             * @param userId the user ID
15481             * @param classNameIds the class name IDs
15482             * @param status the status
15483             * @return the number of matching message-boards messages
15484             */
15485            @Override
15486            public int countByU_C_S(long userId, long[] classNameIds, int status) {
15487                    if (classNameIds == null) {
15488                            classNameIds = new long[0];
15489                    }
15490                    else if (classNameIds.length > 1) {
15491                            classNameIds = ArrayUtil.unique(classNameIds);
15492    
15493                            Arrays.sort(classNameIds);
15494                    }
15495    
15496                    Object[] finderArgs = new Object[] {
15497                                    userId, StringUtil.merge(classNameIds), status
15498                            };
15499    
15500                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15501                                    finderArgs, this);
15502    
15503                    if (count == null) {
15504                            StringBundler query = new StringBundler();
15505    
15506                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15507    
15508                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15509    
15510                            if (classNameIds.length > 0) {
15511                                    query.append(StringPool.OPEN_PARENTHESIS);
15512    
15513                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15514    
15515                                    query.append(StringUtil.merge(classNameIds));
15516    
15517                                    query.append(StringPool.CLOSE_PARENTHESIS);
15518    
15519                                    query.append(StringPool.CLOSE_PARENTHESIS);
15520    
15521                                    query.append(WHERE_AND);
15522                            }
15523    
15524                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15525    
15526                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15527                                                    1)), query.index() - 1);
15528    
15529                            String sql = query.toString();
15530    
15531                            Session session = null;
15532    
15533                            try {
15534                                    session = openSession();
15535    
15536                                    Query q = session.createQuery(sql);
15537    
15538                                    QueryPos qPos = QueryPos.getInstance(q);
15539    
15540                                    qPos.add(userId);
15541    
15542                                    qPos.add(status);
15543    
15544                                    count = (Long)q.uniqueResult();
15545    
15546                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15547                                            finderArgs, count);
15548                            }
15549                            catch (Exception e) {
15550                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15551                                            finderArgs);
15552    
15553                                    throw processException(e);
15554                            }
15555                            finally {
15556                                    closeSession(session);
15557                            }
15558                    }
15559    
15560                    return count.intValue();
15561            }
15562    
15563            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15564            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15565            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
15566            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15567            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15568                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15569                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15570                            new String[] {
15571                                    Long.class.getName(), Long.class.getName(),
15572                                    Integer.class.getName(),
15573                                    
15574                            Integer.class.getName(), Integer.class.getName(),
15575                                    OrderByComparator.class.getName()
15576                            });
15577            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15578                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15579                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15580                            new String[] {
15581                                    Long.class.getName(), Long.class.getName(),
15582                                    Integer.class.getName()
15583                            },
15584                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15585                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15586                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15587                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15588            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15589                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15590                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15591                            new String[] {
15592                                    Long.class.getName(), Long.class.getName(),
15593                                    Integer.class.getName()
15594                            });
15595    
15596            /**
15597             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15598             *
15599             * @param classNameId the class name ID
15600             * @param classPK the class p k
15601             * @param status the status
15602             * @return the matching message-boards messages
15603             */
15604            @Override
15605            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15606                    int status) {
15607                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15608                            QueryUtil.ALL_POS, null);
15609            }
15610    
15611            /**
15612             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15613             *
15614             * <p>
15615             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15616             * </p>
15617             *
15618             * @param classNameId the class name ID
15619             * @param classPK the class p k
15620             * @param status the status
15621             * @param start the lower bound of the range of message-boards messages
15622             * @param end the upper bound of the range of message-boards messages (not inclusive)
15623             * @return the range of matching message-boards messages
15624             */
15625            @Override
15626            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15627                    int status, int start, int end) {
15628                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15629            }
15630    
15631            /**
15632             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15633             *
15634             * <p>
15635             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15636             * </p>
15637             *
15638             * @param classNameId the class name ID
15639             * @param classPK the class p k
15640             * @param status the status
15641             * @param start the lower bound of the range of message-boards messages
15642             * @param end the upper bound of the range of message-boards messages (not inclusive)
15643             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15644             * @return the ordered range of matching message-boards messages
15645             */
15646            @Override
15647            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15648                    int status, int start, int end,
15649                    OrderByComparator<MBMessage> orderByComparator) {
15650                    return findByC_C_S(classNameId, classPK, status, start, end,
15651                            orderByComparator, true);
15652            }
15653    
15654            /**
15655             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15656             *
15657             * <p>
15658             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15659             * </p>
15660             *
15661             * @param classNameId the class name ID
15662             * @param classPK the class p k
15663             * @param status the status
15664             * @param start the lower bound of the range of message-boards messages
15665             * @param end the upper bound of the range of message-boards messages (not inclusive)
15666             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15667             * @param retrieveFromCache whether to retrieve from the finder cache
15668             * @return the ordered range of matching message-boards messages
15669             */
15670            @Override
15671            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15672                    int status, int start, int end,
15673                    OrderByComparator<MBMessage> orderByComparator,
15674                    boolean retrieveFromCache) {
15675                    boolean pagination = true;
15676                    FinderPath finderPath = null;
15677                    Object[] finderArgs = null;
15678    
15679                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15680                                    (orderByComparator == null)) {
15681                            pagination = false;
15682                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15683                            finderArgs = new Object[] { classNameId, classPK, status };
15684                    }
15685                    else {
15686                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15687                            finderArgs = new Object[] {
15688                                            classNameId, classPK, status,
15689                                            
15690                                            start, end, orderByComparator
15691                                    };
15692                    }
15693    
15694                    List<MBMessage> list = null;
15695    
15696                    if (retrieveFromCache) {
15697                            list = (List<MBMessage>)finderCache.getResult(finderPath,
15698                                            finderArgs, this);
15699    
15700                            if ((list != null) && !list.isEmpty()) {
15701                                    for (MBMessage mbMessage : list) {
15702                                            if ((classNameId != mbMessage.getClassNameId()) ||
15703                                                            (classPK != mbMessage.getClassPK()) ||
15704                                                            (status != mbMessage.getStatus())) {
15705                                                    list = null;
15706    
15707                                                    break;
15708                                            }
15709                                    }
15710                            }
15711                    }
15712    
15713                    if (list == null) {
15714                            StringBundler query = null;
15715    
15716                            if (orderByComparator != null) {
15717                                    query = new StringBundler(5 +
15718                                                    (orderByComparator.getOrderByFields().length * 3));
15719                            }
15720                            else {
15721                                    query = new StringBundler(5);
15722                            }
15723    
15724                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15725    
15726                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15727    
15728                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15729    
15730                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15731    
15732                            if (orderByComparator != null) {
15733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15734                                            orderByComparator);
15735                            }
15736                            else
15737                             if (pagination) {
15738                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15739                            }
15740    
15741                            String sql = query.toString();
15742    
15743                            Session session = null;
15744    
15745                            try {
15746                                    session = openSession();
15747    
15748                                    Query q = session.createQuery(sql);
15749    
15750                                    QueryPos qPos = QueryPos.getInstance(q);
15751    
15752                                    qPos.add(classNameId);
15753    
15754                                    qPos.add(classPK);
15755    
15756                                    qPos.add(status);
15757    
15758                                    if (!pagination) {
15759                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15760                                                            start, end, false);
15761    
15762                                            Collections.sort(list);
15763    
15764                                            list = Collections.unmodifiableList(list);
15765                                    }
15766                                    else {
15767                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15768                                                            start, end);
15769                                    }
15770    
15771                                    cacheResult(list);
15772    
15773                                    finderCache.putResult(finderPath, finderArgs, list);
15774                            }
15775                            catch (Exception e) {
15776                                    finderCache.removeResult(finderPath, finderArgs);
15777    
15778                                    throw processException(e);
15779                            }
15780                            finally {
15781                                    closeSession(session);
15782                            }
15783                    }
15784    
15785                    return list;
15786            }
15787    
15788            /**
15789             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15790             *
15791             * @param classNameId the class name ID
15792             * @param classPK the class p k
15793             * @param status the status
15794             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15795             * @return the first matching message-boards message
15796             * @throws NoSuchMessageException if a matching message-boards message could not be found
15797             */
15798            @Override
15799            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15800                    int status, OrderByComparator<MBMessage> orderByComparator)
15801                    throws NoSuchMessageException {
15802                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15803                                    orderByComparator);
15804    
15805                    if (mbMessage != null) {
15806                            return mbMessage;
15807                    }
15808    
15809                    StringBundler msg = new StringBundler(8);
15810    
15811                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15812    
15813                    msg.append("classNameId=");
15814                    msg.append(classNameId);
15815    
15816                    msg.append(", classPK=");
15817                    msg.append(classPK);
15818    
15819                    msg.append(", status=");
15820                    msg.append(status);
15821    
15822                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15823    
15824                    throw new NoSuchMessageException(msg.toString());
15825            }
15826    
15827            /**
15828             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15829             *
15830             * @param classNameId the class name ID
15831             * @param classPK the class p k
15832             * @param status the status
15833             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15834             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15835             */
15836            @Override
15837            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15838                    int status, OrderByComparator<MBMessage> orderByComparator) {
15839                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15840                                    orderByComparator);
15841    
15842                    if (!list.isEmpty()) {
15843                            return list.get(0);
15844                    }
15845    
15846                    return null;
15847            }
15848    
15849            /**
15850             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15851             *
15852             * @param classNameId the class name ID
15853             * @param classPK the class p k
15854             * @param status the status
15855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15856             * @return the last matching message-boards message
15857             * @throws NoSuchMessageException if a matching message-boards message could not be found
15858             */
15859            @Override
15860            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15861                    int status, OrderByComparator<MBMessage> orderByComparator)
15862                    throws NoSuchMessageException {
15863                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15864                                    orderByComparator);
15865    
15866                    if (mbMessage != null) {
15867                            return mbMessage;
15868                    }
15869    
15870                    StringBundler msg = new StringBundler(8);
15871    
15872                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15873    
15874                    msg.append("classNameId=");
15875                    msg.append(classNameId);
15876    
15877                    msg.append(", classPK=");
15878                    msg.append(classPK);
15879    
15880                    msg.append(", status=");
15881                    msg.append(status);
15882    
15883                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15884    
15885                    throw new NoSuchMessageException(msg.toString());
15886            }
15887    
15888            /**
15889             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15890             *
15891             * @param classNameId the class name ID
15892             * @param classPK the class p k
15893             * @param status the status
15894             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15895             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15896             */
15897            @Override
15898            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15899                    int status, OrderByComparator<MBMessage> orderByComparator) {
15900                    int count = countByC_C_S(classNameId, classPK, status);
15901    
15902                    if (count == 0) {
15903                            return null;
15904                    }
15905    
15906                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15907                                    count - 1, count, orderByComparator);
15908    
15909                    if (!list.isEmpty()) {
15910                            return list.get(0);
15911                    }
15912    
15913                    return null;
15914            }
15915    
15916            /**
15917             * 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;.
15918             *
15919             * @param messageId the primary key of the current message-boards message
15920             * @param classNameId the class name ID
15921             * @param classPK the class p k
15922             * @param status the status
15923             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15924             * @return the previous, current, and next message-boards message
15925             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15926             */
15927            @Override
15928            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15929                    long classNameId, long classPK, int status,
15930                    OrderByComparator<MBMessage> orderByComparator)
15931                    throws NoSuchMessageException {
15932                    MBMessage mbMessage = findByPrimaryKey(messageId);
15933    
15934                    Session session = null;
15935    
15936                    try {
15937                            session = openSession();
15938    
15939                            MBMessage[] array = new MBMessageImpl[3];
15940    
15941                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15942                                            classPK, status, orderByComparator, true);
15943    
15944                            array[1] = mbMessage;
15945    
15946                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15947                                            classPK, status, orderByComparator, false);
15948    
15949                            return array;
15950                    }
15951                    catch (Exception e) {
15952                            throw processException(e);
15953                    }
15954                    finally {
15955                            closeSession(session);
15956                    }
15957            }
15958    
15959            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15960                    MBMessage mbMessage, long classNameId, long classPK, int status,
15961                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15962                    StringBundler query = null;
15963    
15964                    if (orderByComparator != null) {
15965                            query = new StringBundler(6 +
15966                                            (orderByComparator.getOrderByFields().length * 6));
15967                    }
15968                    else {
15969                            query = new StringBundler(3);
15970                    }
15971    
15972                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15973    
15974                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15975    
15976                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15977    
15978                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15979    
15980                    if (orderByComparator != null) {
15981                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15982    
15983                            if (orderByConditionFields.length > 0) {
15984                                    query.append(WHERE_AND);
15985                            }
15986    
15987                            for (int i = 0; i < orderByConditionFields.length; i++) {
15988                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15989                                    query.append(orderByConditionFields[i]);
15990    
15991                                    if ((i + 1) < orderByConditionFields.length) {
15992                                            if (orderByComparator.isAscending() ^ previous) {
15993                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15994                                            }
15995                                            else {
15996                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15997                                            }
15998                                    }
15999                                    else {
16000                                            if (orderByComparator.isAscending() ^ previous) {
16001                                                    query.append(WHERE_GREATER_THAN);
16002                                            }
16003                                            else {
16004                                                    query.append(WHERE_LESSER_THAN);
16005                                            }
16006                                    }
16007                            }
16008    
16009                            query.append(ORDER_BY_CLAUSE);
16010    
16011                            String[] orderByFields = orderByComparator.getOrderByFields();
16012    
16013                            for (int i = 0; i < orderByFields.length; i++) {
16014                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16015                                    query.append(orderByFields[i]);
16016    
16017                                    if ((i + 1) < orderByFields.length) {
16018                                            if (orderByComparator.isAscending() ^ previous) {
16019                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16020                                            }
16021                                            else {
16022                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16023                                            }
16024                                    }
16025                                    else {
16026                                            if (orderByComparator.isAscending() ^ previous) {
16027                                                    query.append(ORDER_BY_ASC);
16028                                            }
16029                                            else {
16030                                                    query.append(ORDER_BY_DESC);
16031                                            }
16032                                    }
16033                            }
16034                    }
16035                    else {
16036                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16037                    }
16038    
16039                    String sql = query.toString();
16040    
16041                    Query q = session.createQuery(sql);
16042    
16043                    q.setFirstResult(0);
16044                    q.setMaxResults(2);
16045    
16046                    QueryPos qPos = QueryPos.getInstance(q);
16047    
16048                    qPos.add(classNameId);
16049    
16050                    qPos.add(classPK);
16051    
16052                    qPos.add(status);
16053    
16054                    if (orderByComparator != null) {
16055                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16056    
16057                            for (Object value : values) {
16058                                    qPos.add(value);
16059                            }
16060                    }
16061    
16062                    List<MBMessage> list = q.list();
16063    
16064                    if (list.size() == 2) {
16065                            return list.get(1);
16066                    }
16067                    else {
16068                            return null;
16069                    }
16070            }
16071    
16072            /**
16073             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16074             *
16075             * @param classNameId the class name ID
16076             * @param classPK the class p k
16077             * @param status the status
16078             */
16079            @Override
16080            public void removeByC_C_S(long classNameId, long classPK, int status) {
16081                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
16082                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16083                            remove(mbMessage);
16084                    }
16085            }
16086    
16087            /**
16088             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16089             *
16090             * @param classNameId the class name ID
16091             * @param classPK the class p k
16092             * @param status the status
16093             * @return the number of matching message-boards messages
16094             */
16095            @Override
16096            public int countByC_C_S(long classNameId, long classPK, int status) {
16097                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
16098    
16099                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16100    
16101                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
16102    
16103                    if (count == null) {
16104                            StringBundler query = new StringBundler(4);
16105    
16106                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16107    
16108                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16109    
16110                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16111    
16112                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16113    
16114                            String sql = query.toString();
16115    
16116                            Session session = null;
16117    
16118                            try {
16119                                    session = openSession();
16120    
16121                                    Query q = session.createQuery(sql);
16122    
16123                                    QueryPos qPos = QueryPos.getInstance(q);
16124    
16125                                    qPos.add(classNameId);
16126    
16127                                    qPos.add(classPK);
16128    
16129                                    qPos.add(status);
16130    
16131                                    count = (Long)q.uniqueResult();
16132    
16133                                    finderCache.putResult(finderPath, finderArgs, count);
16134                            }
16135                            catch (Exception e) {
16136                                    finderCache.removeResult(finderPath, finderArgs);
16137    
16138                                    throw processException(e);
16139                            }
16140                            finally {
16141                                    closeSession(session);
16142                            }
16143                    }
16144    
16145                    return count.intValue();
16146            }
16147    
16148            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
16149            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
16150            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
16151            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16152                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16153                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
16154                            new String[] {
16155                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16156                                    Boolean.class.getName(),
16157                                    
16158                            Integer.class.getName(), Integer.class.getName(),
16159                                    OrderByComparator.class.getName()
16160                            });
16161            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
16162                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16163                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16164                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
16165                            new String[] {
16166                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16167                                    Boolean.class.getName()
16168                            },
16169                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16170                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16171                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16172                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
16173                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16174            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16175                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
16177                            new String[] {
16178                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16179                                    Boolean.class.getName()
16180                            });
16181    
16182            /**
16183             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16184             *
16185             * @param groupId the group ID
16186             * @param categoryId the category ID
16187             * @param threadId the thread ID
16188             * @param answer the answer
16189             * @return the matching message-boards messages
16190             */
16191            @Override
16192            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16193                    long threadId, boolean answer) {
16194                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
16195                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16196            }
16197    
16198            /**
16199             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16200             *
16201             * <p>
16202             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16203             * </p>
16204             *
16205             * @param groupId the group ID
16206             * @param categoryId the category ID
16207             * @param threadId the thread ID
16208             * @param answer the answer
16209             * @param start the lower bound of the range of message-boards messages
16210             * @param end the upper bound of the range of message-boards messages (not inclusive)
16211             * @return the range of matching message-boards messages
16212             */
16213            @Override
16214            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16215                    long threadId, boolean answer, int start, int end) {
16216                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16217                            null);
16218            }
16219    
16220            /**
16221             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16222             *
16223             * <p>
16224             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16225             * </p>
16226             *
16227             * @param groupId the group ID
16228             * @param categoryId the category ID
16229             * @param threadId the thread ID
16230             * @param answer the answer
16231             * @param start the lower bound of the range of message-boards messages
16232             * @param end the upper bound of the range of message-boards messages (not inclusive)
16233             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16234             * @return the ordered range of matching message-boards messages
16235             */
16236            @Override
16237            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16238                    long threadId, boolean answer, int start, int end,
16239                    OrderByComparator<MBMessage> orderByComparator) {
16240                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16241                            orderByComparator, true);
16242            }
16243    
16244            /**
16245             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16246             *
16247             * <p>
16248             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16249             * </p>
16250             *
16251             * @param groupId the group ID
16252             * @param categoryId the category ID
16253             * @param threadId the thread ID
16254             * @param answer the answer
16255             * @param start the lower bound of the range of message-boards messages
16256             * @param end the upper bound of the range of message-boards messages (not inclusive)
16257             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16258             * @param retrieveFromCache whether to retrieve from the finder cache
16259             * @return the ordered range of matching message-boards messages
16260             */
16261            @Override
16262            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16263                    long threadId, boolean answer, int start, int end,
16264                    OrderByComparator<MBMessage> orderByComparator,
16265                    boolean retrieveFromCache) {
16266                    boolean pagination = true;
16267                    FinderPath finderPath = null;
16268                    Object[] finderArgs = null;
16269    
16270                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16271                                    (orderByComparator == null)) {
16272                            pagination = false;
16273                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16274                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16275                    }
16276                    else {
16277                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16278                            finderArgs = new Object[] {
16279                                            groupId, categoryId, threadId, answer,
16280                                            
16281                                            start, end, orderByComparator
16282                                    };
16283                    }
16284    
16285                    List<MBMessage> list = null;
16286    
16287                    if (retrieveFromCache) {
16288                            list = (List<MBMessage>)finderCache.getResult(finderPath,
16289                                            finderArgs, this);
16290    
16291                            if ((list != null) && !list.isEmpty()) {
16292                                    for (MBMessage mbMessage : list) {
16293                                            if ((groupId != mbMessage.getGroupId()) ||
16294                                                            (categoryId != mbMessage.getCategoryId()) ||
16295                                                            (threadId != mbMessage.getThreadId()) ||
16296                                                            (answer != mbMessage.getAnswer())) {
16297                                                    list = null;
16298    
16299                                                    break;
16300                                            }
16301                                    }
16302                            }
16303                    }
16304    
16305                    if (list == null) {
16306                            StringBundler query = null;
16307    
16308                            if (orderByComparator != null) {
16309                                    query = new StringBundler(6 +
16310                                                    (orderByComparator.getOrderByFields().length * 3));
16311                            }
16312                            else {
16313                                    query = new StringBundler(6);
16314                            }
16315    
16316                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16317    
16318                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16319    
16320                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16321    
16322                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16323    
16324                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16325    
16326                            if (orderByComparator != null) {
16327                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16328                                            orderByComparator);
16329                            }
16330                            else
16331                             if (pagination) {
16332                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16333                            }
16334    
16335                            String sql = query.toString();
16336    
16337                            Session session = null;
16338    
16339                            try {
16340                                    session = openSession();
16341    
16342                                    Query q = session.createQuery(sql);
16343    
16344                                    QueryPos qPos = QueryPos.getInstance(q);
16345    
16346                                    qPos.add(groupId);
16347    
16348                                    qPos.add(categoryId);
16349    
16350                                    qPos.add(threadId);
16351    
16352                                    qPos.add(answer);
16353    
16354                                    if (!pagination) {
16355                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16356                                                            start, end, false);
16357    
16358                                            Collections.sort(list);
16359    
16360                                            list = Collections.unmodifiableList(list);
16361                                    }
16362                                    else {
16363                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16364                                                            start, end);
16365                                    }
16366    
16367                                    cacheResult(list);
16368    
16369                                    finderCache.putResult(finderPath, finderArgs, list);
16370                            }
16371                            catch (Exception e) {
16372                                    finderCache.removeResult(finderPath, finderArgs);
16373    
16374                                    throw processException(e);
16375                            }
16376                            finally {
16377                                    closeSession(session);
16378                            }
16379                    }
16380    
16381                    return list;
16382            }
16383    
16384            /**
16385             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16386             *
16387             * @param groupId the group ID
16388             * @param categoryId the category ID
16389             * @param threadId the thread ID
16390             * @param answer the answer
16391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16392             * @return the first matching message-boards message
16393             * @throws NoSuchMessageException if a matching message-boards message could not be found
16394             */
16395            @Override
16396            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16397                    long threadId, boolean answer,
16398                    OrderByComparator<MBMessage> orderByComparator)
16399                    throws NoSuchMessageException {
16400                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16401                                    threadId, answer, orderByComparator);
16402    
16403                    if (mbMessage != null) {
16404                            return mbMessage;
16405                    }
16406    
16407                    StringBundler msg = new StringBundler(10);
16408    
16409                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16410    
16411                    msg.append("groupId=");
16412                    msg.append(groupId);
16413    
16414                    msg.append(", categoryId=");
16415                    msg.append(categoryId);
16416    
16417                    msg.append(", threadId=");
16418                    msg.append(threadId);
16419    
16420                    msg.append(", answer=");
16421                    msg.append(answer);
16422    
16423                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16424    
16425                    throw new NoSuchMessageException(msg.toString());
16426            }
16427    
16428            /**
16429             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16430             *
16431             * @param groupId the group ID
16432             * @param categoryId the category ID
16433             * @param threadId the thread ID
16434             * @param answer the answer
16435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16436             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16437             */
16438            @Override
16439            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16440                    long threadId, boolean answer,
16441                    OrderByComparator<MBMessage> orderByComparator) {
16442                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16443                                    answer, 0, 1, orderByComparator);
16444    
16445                    if (!list.isEmpty()) {
16446                            return list.get(0);
16447                    }
16448    
16449                    return null;
16450            }
16451    
16452            /**
16453             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16454             *
16455             * @param groupId the group ID
16456             * @param categoryId the category ID
16457             * @param threadId the thread ID
16458             * @param answer the answer
16459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16460             * @return the last matching message-boards message
16461             * @throws NoSuchMessageException if a matching message-boards message could not be found
16462             */
16463            @Override
16464            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16465                    long threadId, boolean answer,
16466                    OrderByComparator<MBMessage> orderByComparator)
16467                    throws NoSuchMessageException {
16468                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16469                                    threadId, answer, orderByComparator);
16470    
16471                    if (mbMessage != null) {
16472                            return mbMessage;
16473                    }
16474    
16475                    StringBundler msg = new StringBundler(10);
16476    
16477                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16478    
16479                    msg.append("groupId=");
16480                    msg.append(groupId);
16481    
16482                    msg.append(", categoryId=");
16483                    msg.append(categoryId);
16484    
16485                    msg.append(", threadId=");
16486                    msg.append(threadId);
16487    
16488                    msg.append(", answer=");
16489                    msg.append(answer);
16490    
16491                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16492    
16493                    throw new NoSuchMessageException(msg.toString());
16494            }
16495    
16496            /**
16497             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16498             *
16499             * @param groupId the group ID
16500             * @param categoryId the category ID
16501             * @param threadId the thread ID
16502             * @param answer the answer
16503             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16504             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16505             */
16506            @Override
16507            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16508                    long threadId, boolean answer,
16509                    OrderByComparator<MBMessage> orderByComparator) {
16510                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16511    
16512                    if (count == 0) {
16513                            return null;
16514                    }
16515    
16516                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16517                                    answer, count - 1, count, orderByComparator);
16518    
16519                    if (!list.isEmpty()) {
16520                            return list.get(0);
16521                    }
16522    
16523                    return null;
16524            }
16525    
16526            /**
16527             * 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;.
16528             *
16529             * @param messageId the primary key of the current message-boards message
16530             * @param groupId the group ID
16531             * @param categoryId the category ID
16532             * @param threadId the thread ID
16533             * @param answer the answer
16534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16535             * @return the previous, current, and next message-boards message
16536             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16537             */
16538            @Override
16539            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16540                    long categoryId, long threadId, boolean answer,
16541                    OrderByComparator<MBMessage> orderByComparator)
16542                    throws NoSuchMessageException {
16543                    MBMessage mbMessage = findByPrimaryKey(messageId);
16544    
16545                    Session session = null;
16546    
16547                    try {
16548                            session = openSession();
16549    
16550                            MBMessage[] array = new MBMessageImpl[3];
16551    
16552                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16553                                            categoryId, threadId, answer, orderByComparator, true);
16554    
16555                            array[1] = mbMessage;
16556    
16557                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16558                                            categoryId, threadId, answer, orderByComparator, false);
16559    
16560                            return array;
16561                    }
16562                    catch (Exception e) {
16563                            throw processException(e);
16564                    }
16565                    finally {
16566                            closeSession(session);
16567                    }
16568            }
16569    
16570            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16571                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16572                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16573                    boolean previous) {
16574                    StringBundler query = null;
16575    
16576                    if (orderByComparator != null) {
16577                            query = new StringBundler(6 +
16578                                            (orderByComparator.getOrderByFields().length * 6));
16579                    }
16580                    else {
16581                            query = new StringBundler(3);
16582                    }
16583    
16584                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16585    
16586                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16587    
16588                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16589    
16590                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16591    
16592                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16593    
16594                    if (orderByComparator != null) {
16595                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16596    
16597                            if (orderByConditionFields.length > 0) {
16598                                    query.append(WHERE_AND);
16599                            }
16600    
16601                            for (int i = 0; i < orderByConditionFields.length; i++) {
16602                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16603                                    query.append(orderByConditionFields[i]);
16604    
16605                                    if ((i + 1) < orderByConditionFields.length) {
16606                                            if (orderByComparator.isAscending() ^ previous) {
16607                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16608                                            }
16609                                            else {
16610                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16611                                            }
16612                                    }
16613                                    else {
16614                                            if (orderByComparator.isAscending() ^ previous) {
16615                                                    query.append(WHERE_GREATER_THAN);
16616                                            }
16617                                            else {
16618                                                    query.append(WHERE_LESSER_THAN);
16619                                            }
16620                                    }
16621                            }
16622    
16623                            query.append(ORDER_BY_CLAUSE);
16624    
16625                            String[] orderByFields = orderByComparator.getOrderByFields();
16626    
16627                            for (int i = 0; i < orderByFields.length; i++) {
16628                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16629                                    query.append(orderByFields[i]);
16630    
16631                                    if ((i + 1) < orderByFields.length) {
16632                                            if (orderByComparator.isAscending() ^ previous) {
16633                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16634                                            }
16635                                            else {
16636                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16637                                            }
16638                                    }
16639                                    else {
16640                                            if (orderByComparator.isAscending() ^ previous) {
16641                                                    query.append(ORDER_BY_ASC);
16642                                            }
16643                                            else {
16644                                                    query.append(ORDER_BY_DESC);
16645                                            }
16646                                    }
16647                            }
16648                    }
16649                    else {
16650                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16651                    }
16652    
16653                    String sql = query.toString();
16654    
16655                    Query q = session.createQuery(sql);
16656    
16657                    q.setFirstResult(0);
16658                    q.setMaxResults(2);
16659    
16660                    QueryPos qPos = QueryPos.getInstance(q);
16661    
16662                    qPos.add(groupId);
16663    
16664                    qPos.add(categoryId);
16665    
16666                    qPos.add(threadId);
16667    
16668                    qPos.add(answer);
16669    
16670                    if (orderByComparator != null) {
16671                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16672    
16673                            for (Object value : values) {
16674                                    qPos.add(value);
16675                            }
16676                    }
16677    
16678                    List<MBMessage> list = q.list();
16679    
16680                    if (list.size() == 2) {
16681                            return list.get(1);
16682                    }
16683                    else {
16684                            return null;
16685                    }
16686            }
16687    
16688            /**
16689             * 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;.
16690             *
16691             * @param groupId the group ID
16692             * @param categoryId the category ID
16693             * @param threadId the thread ID
16694             * @param answer the answer
16695             * @return the matching message-boards messages that the user has permission to view
16696             */
16697            @Override
16698            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16699                    long threadId, boolean answer) {
16700                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16701                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16702            }
16703    
16704            /**
16705             * 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;.
16706             *
16707             * <p>
16708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16709             * </p>
16710             *
16711             * @param groupId the group ID
16712             * @param categoryId the category ID
16713             * @param threadId the thread ID
16714             * @param answer the answer
16715             * @param start the lower bound of the range of message-boards messages
16716             * @param end the upper bound of the range of message-boards messages (not inclusive)
16717             * @return the range of matching message-boards messages that the user has permission to view
16718             */
16719            @Override
16720            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16721                    long threadId, boolean answer, int start, int end) {
16722                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16723                            start, end, null);
16724            }
16725    
16726            /**
16727             * 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;.
16728             *
16729             * <p>
16730             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16731             * </p>
16732             *
16733             * @param groupId the group ID
16734             * @param categoryId the category ID
16735             * @param threadId the thread ID
16736             * @param answer the answer
16737             * @param start the lower bound of the range of message-boards messages
16738             * @param end the upper bound of the range of message-boards messages (not inclusive)
16739             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16740             * @return the ordered range of matching message-boards messages that the user has permission to view
16741             */
16742            @Override
16743            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16744                    long threadId, boolean answer, int start, int end,
16745                    OrderByComparator<MBMessage> orderByComparator) {
16746                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16747                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16748                                    end, orderByComparator);
16749                    }
16750    
16751                    StringBundler query = null;
16752    
16753                    if (orderByComparator != null) {
16754                            query = new StringBundler(6 +
16755                                            (orderByComparator.getOrderByFields().length * 3));
16756                    }
16757                    else {
16758                            query = new StringBundler(6);
16759                    }
16760    
16761                    if (getDB().isSupportsInlineDistinct()) {
16762                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16763                    }
16764                    else {
16765                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16766                    }
16767    
16768                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16769    
16770                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16771    
16772                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16773    
16774                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16775    
16776                    if (!getDB().isSupportsInlineDistinct()) {
16777                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16778                    }
16779    
16780                    if (orderByComparator != null) {
16781                            if (getDB().isSupportsInlineDistinct()) {
16782                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16783                                            orderByComparator, true);
16784                            }
16785                            else {
16786                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16787                                            orderByComparator, true);
16788                            }
16789                    }
16790                    else {
16791                            if (getDB().isSupportsInlineDistinct()) {
16792                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16793                            }
16794                            else {
16795                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16796                            }
16797                    }
16798    
16799                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16800                                    MBMessage.class.getName(),
16801                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16802    
16803                    Session session = null;
16804    
16805                    try {
16806                            session = openSession();
16807    
16808                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16809    
16810                            if (getDB().isSupportsInlineDistinct()) {
16811                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16812                            }
16813                            else {
16814                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16815                            }
16816    
16817                            QueryPos qPos = QueryPos.getInstance(q);
16818    
16819                            qPos.add(groupId);
16820    
16821                            qPos.add(categoryId);
16822    
16823                            qPos.add(threadId);
16824    
16825                            qPos.add(answer);
16826    
16827                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16828                    }
16829                    catch (Exception e) {
16830                            throw processException(e);
16831                    }
16832                    finally {
16833                            closeSession(session);
16834                    }
16835            }
16836    
16837            /**
16838             * 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;.
16839             *
16840             * @param messageId the primary key of the current message-boards message
16841             * @param groupId the group ID
16842             * @param categoryId the category ID
16843             * @param threadId the thread ID
16844             * @param answer the answer
16845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16846             * @return the previous, current, and next message-boards message
16847             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16848             */
16849            @Override
16850            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16851                    long groupId, long categoryId, long threadId, boolean answer,
16852                    OrderByComparator<MBMessage> orderByComparator)
16853                    throws NoSuchMessageException {
16854                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16855                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16856                                    threadId, answer, orderByComparator);
16857                    }
16858    
16859                    MBMessage mbMessage = findByPrimaryKey(messageId);
16860    
16861                    Session session = null;
16862    
16863                    try {
16864                            session = openSession();
16865    
16866                            MBMessage[] array = new MBMessageImpl[3];
16867    
16868                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16869                                            groupId, categoryId, threadId, answer, orderByComparator,
16870                                            true);
16871    
16872                            array[1] = mbMessage;
16873    
16874                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16875                                            groupId, categoryId, threadId, answer, orderByComparator,
16876                                            false);
16877    
16878                            return array;
16879                    }
16880                    catch (Exception e) {
16881                            throw processException(e);
16882                    }
16883                    finally {
16884                            closeSession(session);
16885                    }
16886            }
16887    
16888            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16889                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16890                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16891                    boolean previous) {
16892                    StringBundler query = null;
16893    
16894                    if (orderByComparator != null) {
16895                            query = new StringBundler(6 +
16896                                            (orderByComparator.getOrderByFields().length * 6));
16897                    }
16898                    else {
16899                            query = new StringBundler(3);
16900                    }
16901    
16902                    if (getDB().isSupportsInlineDistinct()) {
16903                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16904                    }
16905                    else {
16906                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16907                    }
16908    
16909                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16910    
16911                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16912    
16913                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16914    
16915                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16916    
16917                    if (!getDB().isSupportsInlineDistinct()) {
16918                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16919                    }
16920    
16921                    if (orderByComparator != null) {
16922                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16923    
16924                            if (orderByConditionFields.length > 0) {
16925                                    query.append(WHERE_AND);
16926                            }
16927    
16928                            for (int i = 0; i < orderByConditionFields.length; i++) {
16929                                    if (getDB().isSupportsInlineDistinct()) {
16930                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16931                                    }
16932                                    else {
16933                                            query.append(_ORDER_BY_ENTITY_TABLE);
16934                                    }
16935    
16936                                    query.append(orderByConditionFields[i]);
16937    
16938                                    if ((i + 1) < orderByConditionFields.length) {
16939                                            if (orderByComparator.isAscending() ^ previous) {
16940                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16941                                            }
16942                                            else {
16943                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16944                                            }
16945                                    }
16946                                    else {
16947                                            if (orderByComparator.isAscending() ^ previous) {
16948                                                    query.append(WHERE_GREATER_THAN);
16949                                            }
16950                                            else {
16951                                                    query.append(WHERE_LESSER_THAN);
16952                                            }
16953                                    }
16954                            }
16955    
16956                            query.append(ORDER_BY_CLAUSE);
16957    
16958                            String[] orderByFields = orderByComparator.getOrderByFields();
16959    
16960                            for (int i = 0; i < orderByFields.length; i++) {
16961                                    if (getDB().isSupportsInlineDistinct()) {
16962                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16963                                    }
16964                                    else {
16965                                            query.append(_ORDER_BY_ENTITY_TABLE);
16966                                    }
16967    
16968                                    query.append(orderByFields[i]);
16969    
16970                                    if ((i + 1) < orderByFields.length) {
16971                                            if (orderByComparator.isAscending() ^ previous) {
16972                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16973                                            }
16974                                            else {
16975                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16976                                            }
16977                                    }
16978                                    else {
16979                                            if (orderByComparator.isAscending() ^ previous) {
16980                                                    query.append(ORDER_BY_ASC);
16981                                            }
16982                                            else {
16983                                                    query.append(ORDER_BY_DESC);
16984                                            }
16985                                    }
16986                            }
16987                    }
16988                    else {
16989                            if (getDB().isSupportsInlineDistinct()) {
16990                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16991                            }
16992                            else {
16993                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16994                            }
16995                    }
16996    
16997                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16998                                    MBMessage.class.getName(),
16999                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17000    
17001                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17002    
17003                    q.setFirstResult(0);
17004                    q.setMaxResults(2);
17005    
17006                    if (getDB().isSupportsInlineDistinct()) {
17007                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17008                    }
17009                    else {
17010                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17011                    }
17012    
17013                    QueryPos qPos = QueryPos.getInstance(q);
17014    
17015                    qPos.add(groupId);
17016    
17017                    qPos.add(categoryId);
17018    
17019                    qPos.add(threadId);
17020    
17021                    qPos.add(answer);
17022    
17023                    if (orderByComparator != null) {
17024                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17025    
17026                            for (Object value : values) {
17027                                    qPos.add(value);
17028                            }
17029                    }
17030    
17031                    List<MBMessage> list = q.list();
17032    
17033                    if (list.size() == 2) {
17034                            return list.get(1);
17035                    }
17036                    else {
17037                            return null;
17038                    }
17039            }
17040    
17041            /**
17042             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
17043             *
17044             * @param groupId the group ID
17045             * @param categoryId the category ID
17046             * @param threadId the thread ID
17047             * @param answer the answer
17048             */
17049            @Override
17050            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
17051                    boolean answer) {
17052                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
17053                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17054                            remove(mbMessage);
17055                    }
17056            }
17057    
17058            /**
17059             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17060             *
17061             * @param groupId the group ID
17062             * @param categoryId the category ID
17063             * @param threadId the thread ID
17064             * @param answer the answer
17065             * @return the number of matching message-boards messages
17066             */
17067            @Override
17068            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17069                    boolean answer) {
17070                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
17071    
17072                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17073    
17074                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
17075    
17076                    if (count == null) {
17077                            StringBundler query = new StringBundler(5);
17078    
17079                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17080    
17081                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17082    
17083                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17084    
17085                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17086    
17087                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17088    
17089                            String sql = query.toString();
17090    
17091                            Session session = null;
17092    
17093                            try {
17094                                    session = openSession();
17095    
17096                                    Query q = session.createQuery(sql);
17097    
17098                                    QueryPos qPos = QueryPos.getInstance(q);
17099    
17100                                    qPos.add(groupId);
17101    
17102                                    qPos.add(categoryId);
17103    
17104                                    qPos.add(threadId);
17105    
17106                                    qPos.add(answer);
17107    
17108                                    count = (Long)q.uniqueResult();
17109    
17110                                    finderCache.putResult(finderPath, finderArgs, count);
17111                            }
17112                            catch (Exception e) {
17113                                    finderCache.removeResult(finderPath, finderArgs);
17114    
17115                                    throw processException(e);
17116                            }
17117                            finally {
17118                                    closeSession(session);
17119                            }
17120                    }
17121    
17122                    return count.intValue();
17123            }
17124    
17125            /**
17126             * 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;.
17127             *
17128             * @param groupId the group ID
17129             * @param categoryId the category ID
17130             * @param threadId the thread ID
17131             * @param answer the answer
17132             * @return the number of matching message-boards messages that the user has permission to view
17133             */
17134            @Override
17135            public int filterCountByG_C_T_A(long groupId, long categoryId,
17136                    long threadId, boolean answer) {
17137                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17138                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17139                    }
17140    
17141                    StringBundler query = new StringBundler(5);
17142    
17143                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17144    
17145                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17146    
17147                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17148    
17149                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17150    
17151                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17152    
17153                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17154                                    MBMessage.class.getName(),
17155                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17156    
17157                    Session session = null;
17158    
17159                    try {
17160                            session = openSession();
17161    
17162                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17163    
17164                            q.addScalar(COUNT_COLUMN_NAME,
17165                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17166    
17167                            QueryPos qPos = QueryPos.getInstance(q);
17168    
17169                            qPos.add(groupId);
17170    
17171                            qPos.add(categoryId);
17172    
17173                            qPos.add(threadId);
17174    
17175                            qPos.add(answer);
17176    
17177                            Long count = (Long)q.uniqueResult();
17178    
17179                            return count.intValue();
17180                    }
17181                    catch (Exception e) {
17182                            throw processException(e);
17183                    }
17184                    finally {
17185                            closeSession(session);
17186                    }
17187            }
17188    
17189            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17190            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17191            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17192            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17193            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17194                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17195                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
17196                            new String[] {
17197                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17198                                    Integer.class.getName(),
17199                                    
17200                            Integer.class.getName(), Integer.class.getName(),
17201                                    OrderByComparator.class.getName()
17202                            });
17203            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
17204                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17205                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17206                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
17207                            new String[] {
17208                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17209                                    Integer.class.getName()
17210                            },
17211                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17212                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17213                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17214                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17215                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17216            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17217                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17218                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
17219                            new String[] {
17220                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17221                                    Integer.class.getName()
17222                            });
17223    
17224            /**
17225             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17226             *
17227             * @param groupId the group ID
17228             * @param categoryId the category ID
17229             * @param threadId the thread ID
17230             * @param status the status
17231             * @return the matching message-boards messages
17232             */
17233            @Override
17234            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17235                    long threadId, int status) {
17236                    return findByG_C_T_S(groupId, categoryId, threadId, status,
17237                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17238            }
17239    
17240            /**
17241             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17242             *
17243             * <p>
17244             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17245             * </p>
17246             *
17247             * @param groupId the group ID
17248             * @param categoryId the category ID
17249             * @param threadId the thread ID
17250             * @param status the status
17251             * @param start the lower bound of the range of message-boards messages
17252             * @param end the upper bound of the range of message-boards messages (not inclusive)
17253             * @return the range of matching message-boards messages
17254             */
17255            @Override
17256            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17257                    long threadId, int status, int start, int end) {
17258                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17259                            null);
17260            }
17261    
17262            /**
17263             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17264             *
17265             * <p>
17266             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17267             * </p>
17268             *
17269             * @param groupId the group ID
17270             * @param categoryId the category ID
17271             * @param threadId the thread ID
17272             * @param status the status
17273             * @param start the lower bound of the range of message-boards messages
17274             * @param end the upper bound of the range of message-boards messages (not inclusive)
17275             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17276             * @return the ordered range of matching message-boards messages
17277             */
17278            @Override
17279            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17280                    long threadId, int status, int start, int end,
17281                    OrderByComparator<MBMessage> orderByComparator) {
17282                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17283                            orderByComparator, true);
17284            }
17285    
17286            /**
17287             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17288             *
17289             * <p>
17290             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17291             * </p>
17292             *
17293             * @param groupId the group ID
17294             * @param categoryId the category ID
17295             * @param threadId the thread ID
17296             * @param status the status
17297             * @param start the lower bound of the range of message-boards messages
17298             * @param end the upper bound of the range of message-boards messages (not inclusive)
17299             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17300             * @param retrieveFromCache whether to retrieve from the finder cache
17301             * @return the ordered range of matching message-boards messages
17302             */
17303            @Override
17304            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17305                    long threadId, int status, int start, int end,
17306                    OrderByComparator<MBMessage> orderByComparator,
17307                    boolean retrieveFromCache) {
17308                    boolean pagination = true;
17309                    FinderPath finderPath = null;
17310                    Object[] finderArgs = null;
17311    
17312                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17313                                    (orderByComparator == null)) {
17314                            pagination = false;
17315                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17316                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17317                    }
17318                    else {
17319                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17320                            finderArgs = new Object[] {
17321                                            groupId, categoryId, threadId, status,
17322                                            
17323                                            start, end, orderByComparator
17324                                    };
17325                    }
17326    
17327                    List<MBMessage> list = null;
17328    
17329                    if (retrieveFromCache) {
17330                            list = (List<MBMessage>)finderCache.getResult(finderPath,
17331                                            finderArgs, this);
17332    
17333                            if ((list != null) && !list.isEmpty()) {
17334                                    for (MBMessage mbMessage : list) {
17335                                            if ((groupId != mbMessage.getGroupId()) ||
17336                                                            (categoryId != mbMessage.getCategoryId()) ||
17337                                                            (threadId != mbMessage.getThreadId()) ||
17338                                                            (status != mbMessage.getStatus())) {
17339                                                    list = null;
17340    
17341                                                    break;
17342                                            }
17343                                    }
17344                            }
17345                    }
17346    
17347                    if (list == null) {
17348                            StringBundler query = null;
17349    
17350                            if (orderByComparator != null) {
17351                                    query = new StringBundler(6 +
17352                                                    (orderByComparator.getOrderByFields().length * 3));
17353                            }
17354                            else {
17355                                    query = new StringBundler(6);
17356                            }
17357    
17358                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17359    
17360                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17361    
17362                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17363    
17364                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17365    
17366                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17367    
17368                            if (orderByComparator != null) {
17369                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17370                                            orderByComparator);
17371                            }
17372                            else
17373                             if (pagination) {
17374                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17375                            }
17376    
17377                            String sql = query.toString();
17378    
17379                            Session session = null;
17380    
17381                            try {
17382                                    session = openSession();
17383    
17384                                    Query q = session.createQuery(sql);
17385    
17386                                    QueryPos qPos = QueryPos.getInstance(q);
17387    
17388                                    qPos.add(groupId);
17389    
17390                                    qPos.add(categoryId);
17391    
17392                                    qPos.add(threadId);
17393    
17394                                    qPos.add(status);
17395    
17396                                    if (!pagination) {
17397                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17398                                                            start, end, false);
17399    
17400                                            Collections.sort(list);
17401    
17402                                            list = Collections.unmodifiableList(list);
17403                                    }
17404                                    else {
17405                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17406                                                            start, end);
17407                                    }
17408    
17409                                    cacheResult(list);
17410    
17411                                    finderCache.putResult(finderPath, finderArgs, list);
17412                            }
17413                            catch (Exception e) {
17414                                    finderCache.removeResult(finderPath, finderArgs);
17415    
17416                                    throw processException(e);
17417                            }
17418                            finally {
17419                                    closeSession(session);
17420                            }
17421                    }
17422    
17423                    return list;
17424            }
17425    
17426            /**
17427             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17428             *
17429             * @param groupId the group ID
17430             * @param categoryId the category ID
17431             * @param threadId the thread ID
17432             * @param status the status
17433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17434             * @return the first matching message-boards message
17435             * @throws NoSuchMessageException if a matching message-boards message could not be found
17436             */
17437            @Override
17438            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17439                    long threadId, int status,
17440                    OrderByComparator<MBMessage> orderByComparator)
17441                    throws NoSuchMessageException {
17442                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17443                                    threadId, status, orderByComparator);
17444    
17445                    if (mbMessage != null) {
17446                            return mbMessage;
17447                    }
17448    
17449                    StringBundler msg = new StringBundler(10);
17450    
17451                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17452    
17453                    msg.append("groupId=");
17454                    msg.append(groupId);
17455    
17456                    msg.append(", categoryId=");
17457                    msg.append(categoryId);
17458    
17459                    msg.append(", threadId=");
17460                    msg.append(threadId);
17461    
17462                    msg.append(", status=");
17463                    msg.append(status);
17464    
17465                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17466    
17467                    throw new NoSuchMessageException(msg.toString());
17468            }
17469    
17470            /**
17471             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17472             *
17473             * @param groupId the group ID
17474             * @param categoryId the category ID
17475             * @param threadId the thread ID
17476             * @param status the status
17477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17478             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17479             */
17480            @Override
17481            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17482                    long threadId, int status,
17483                    OrderByComparator<MBMessage> orderByComparator) {
17484                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17485                                    status, 0, 1, orderByComparator);
17486    
17487                    if (!list.isEmpty()) {
17488                            return list.get(0);
17489                    }
17490    
17491                    return null;
17492            }
17493    
17494            /**
17495             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17496             *
17497             * @param groupId the group ID
17498             * @param categoryId the category ID
17499             * @param threadId the thread ID
17500             * @param status the status
17501             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17502             * @return the last matching message-boards message
17503             * @throws NoSuchMessageException if a matching message-boards message could not be found
17504             */
17505            @Override
17506            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17507                    long threadId, int status,
17508                    OrderByComparator<MBMessage> orderByComparator)
17509                    throws NoSuchMessageException {
17510                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17511                                    threadId, status, orderByComparator);
17512    
17513                    if (mbMessage != null) {
17514                            return mbMessage;
17515                    }
17516    
17517                    StringBundler msg = new StringBundler(10);
17518    
17519                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17520    
17521                    msg.append("groupId=");
17522                    msg.append(groupId);
17523    
17524                    msg.append(", categoryId=");
17525                    msg.append(categoryId);
17526    
17527                    msg.append(", threadId=");
17528                    msg.append(threadId);
17529    
17530                    msg.append(", status=");
17531                    msg.append(status);
17532    
17533                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17534    
17535                    throw new NoSuchMessageException(msg.toString());
17536            }
17537    
17538            /**
17539             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17540             *
17541             * @param groupId the group ID
17542             * @param categoryId the category ID
17543             * @param threadId the thread ID
17544             * @param status the status
17545             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17546             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17547             */
17548            @Override
17549            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17550                    long threadId, int status,
17551                    OrderByComparator<MBMessage> orderByComparator) {
17552                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17553    
17554                    if (count == 0) {
17555                            return null;
17556                    }
17557    
17558                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17559                                    status, count - 1, count, orderByComparator);
17560    
17561                    if (!list.isEmpty()) {
17562                            return list.get(0);
17563                    }
17564    
17565                    return null;
17566            }
17567    
17568            /**
17569             * 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;.
17570             *
17571             * @param messageId the primary key of the current message-boards message
17572             * @param groupId the group ID
17573             * @param categoryId the category ID
17574             * @param threadId the thread ID
17575             * @param status the status
17576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17577             * @return the previous, current, and next message-boards message
17578             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17579             */
17580            @Override
17581            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17582                    long categoryId, long threadId, int status,
17583                    OrderByComparator<MBMessage> orderByComparator)
17584                    throws NoSuchMessageException {
17585                    MBMessage mbMessage = findByPrimaryKey(messageId);
17586    
17587                    Session session = null;
17588    
17589                    try {
17590                            session = openSession();
17591    
17592                            MBMessage[] array = new MBMessageImpl[3];
17593    
17594                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17595                                            categoryId, threadId, status, orderByComparator, true);
17596    
17597                            array[1] = mbMessage;
17598    
17599                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17600                                            categoryId, threadId, status, orderByComparator, false);
17601    
17602                            return array;
17603                    }
17604                    catch (Exception e) {
17605                            throw processException(e);
17606                    }
17607                    finally {
17608                            closeSession(session);
17609                    }
17610            }
17611    
17612            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17613                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17614                    int status, OrderByComparator<MBMessage> orderByComparator,
17615                    boolean previous) {
17616                    StringBundler query = null;
17617    
17618                    if (orderByComparator != null) {
17619                            query = new StringBundler(6 +
17620                                            (orderByComparator.getOrderByFields().length * 6));
17621                    }
17622                    else {
17623                            query = new StringBundler(3);
17624                    }
17625    
17626                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17627    
17628                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17629    
17630                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17631    
17632                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17633    
17634                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17635    
17636                    if (orderByComparator != null) {
17637                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17638    
17639                            if (orderByConditionFields.length > 0) {
17640                                    query.append(WHERE_AND);
17641                            }
17642    
17643                            for (int i = 0; i < orderByConditionFields.length; i++) {
17644                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17645                                    query.append(orderByConditionFields[i]);
17646    
17647                                    if ((i + 1) < orderByConditionFields.length) {
17648                                            if (orderByComparator.isAscending() ^ previous) {
17649                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17650                                            }
17651                                            else {
17652                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17653                                            }
17654                                    }
17655                                    else {
17656                                            if (orderByComparator.isAscending() ^ previous) {
17657                                                    query.append(WHERE_GREATER_THAN);
17658                                            }
17659                                            else {
17660                                                    query.append(WHERE_LESSER_THAN);
17661                                            }
17662                                    }
17663                            }
17664    
17665                            query.append(ORDER_BY_CLAUSE);
17666    
17667                            String[] orderByFields = orderByComparator.getOrderByFields();
17668    
17669                            for (int i = 0; i < orderByFields.length; i++) {
17670                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17671                                    query.append(orderByFields[i]);
17672    
17673                                    if ((i + 1) < orderByFields.length) {
17674                                            if (orderByComparator.isAscending() ^ previous) {
17675                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17676                                            }
17677                                            else {
17678                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17679                                            }
17680                                    }
17681                                    else {
17682                                            if (orderByComparator.isAscending() ^ previous) {
17683                                                    query.append(ORDER_BY_ASC);
17684                                            }
17685                                            else {
17686                                                    query.append(ORDER_BY_DESC);
17687                                            }
17688                                    }
17689                            }
17690                    }
17691                    else {
17692                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17693                    }
17694    
17695                    String sql = query.toString();
17696    
17697                    Query q = session.createQuery(sql);
17698    
17699                    q.setFirstResult(0);
17700                    q.setMaxResults(2);
17701    
17702                    QueryPos qPos = QueryPos.getInstance(q);
17703    
17704                    qPos.add(groupId);
17705    
17706                    qPos.add(categoryId);
17707    
17708                    qPos.add(threadId);
17709    
17710                    qPos.add(status);
17711    
17712                    if (orderByComparator != null) {
17713                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17714    
17715                            for (Object value : values) {
17716                                    qPos.add(value);
17717                            }
17718                    }
17719    
17720                    List<MBMessage> list = q.list();
17721    
17722                    if (list.size() == 2) {
17723                            return list.get(1);
17724                    }
17725                    else {
17726                            return null;
17727                    }
17728            }
17729    
17730            /**
17731             * 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;.
17732             *
17733             * @param groupId the group ID
17734             * @param categoryId the category ID
17735             * @param threadId the thread ID
17736             * @param status the status
17737             * @return the matching message-boards messages that the user has permission to view
17738             */
17739            @Override
17740            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17741                    long threadId, int status) {
17742                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17743                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17744            }
17745    
17746            /**
17747             * 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;.
17748             *
17749             * <p>
17750             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17751             * </p>
17752             *
17753             * @param groupId the group ID
17754             * @param categoryId the category ID
17755             * @param threadId the thread ID
17756             * @param status the status
17757             * @param start the lower bound of the range of message-boards messages
17758             * @param end the upper bound of the range of message-boards messages (not inclusive)
17759             * @return the range of matching message-boards messages that the user has permission to view
17760             */
17761            @Override
17762            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17763                    long threadId, int status, int start, int end) {
17764                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17765                            start, end, null);
17766            }
17767    
17768            /**
17769             * 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;.
17770             *
17771             * <p>
17772             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17773             * </p>
17774             *
17775             * @param groupId the group ID
17776             * @param categoryId the category ID
17777             * @param threadId the thread ID
17778             * @param status the status
17779             * @param start the lower bound of the range of message-boards messages
17780             * @param end the upper bound of the range of message-boards messages (not inclusive)
17781             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17782             * @return the ordered range of matching message-boards messages that the user has permission to view
17783             */
17784            @Override
17785            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17786                    long threadId, int status, int start, int end,
17787                    OrderByComparator<MBMessage> orderByComparator) {
17788                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17789                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17790                                    end, orderByComparator);
17791                    }
17792    
17793                    StringBundler query = null;
17794    
17795                    if (orderByComparator != null) {
17796                            query = new StringBundler(6 +
17797                                            (orderByComparator.getOrderByFields().length * 3));
17798                    }
17799                    else {
17800                            query = new StringBundler(6);
17801                    }
17802    
17803                    if (getDB().isSupportsInlineDistinct()) {
17804                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17805                    }
17806                    else {
17807                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17808                    }
17809    
17810                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17811    
17812                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17813    
17814                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17815    
17816                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17817    
17818                    if (!getDB().isSupportsInlineDistinct()) {
17819                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17820                    }
17821    
17822                    if (orderByComparator != null) {
17823                            if (getDB().isSupportsInlineDistinct()) {
17824                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17825                                            orderByComparator, true);
17826                            }
17827                            else {
17828                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17829                                            orderByComparator, true);
17830                            }
17831                    }
17832                    else {
17833                            if (getDB().isSupportsInlineDistinct()) {
17834                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17835                            }
17836                            else {
17837                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17838                            }
17839                    }
17840    
17841                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17842                                    MBMessage.class.getName(),
17843                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17844    
17845                    Session session = null;
17846    
17847                    try {
17848                            session = openSession();
17849    
17850                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17851    
17852                            if (getDB().isSupportsInlineDistinct()) {
17853                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17854                            }
17855                            else {
17856                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17857                            }
17858    
17859                            QueryPos qPos = QueryPos.getInstance(q);
17860    
17861                            qPos.add(groupId);
17862    
17863                            qPos.add(categoryId);
17864    
17865                            qPos.add(threadId);
17866    
17867                            qPos.add(status);
17868    
17869                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17870                    }
17871                    catch (Exception e) {
17872                            throw processException(e);
17873                    }
17874                    finally {
17875                            closeSession(session);
17876                    }
17877            }
17878    
17879            /**
17880             * 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;.
17881             *
17882             * @param messageId the primary key of the current message-boards message
17883             * @param groupId the group ID
17884             * @param categoryId the category ID
17885             * @param threadId the thread ID
17886             * @param status the status
17887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17888             * @return the previous, current, and next message-boards message
17889             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17890             */
17891            @Override
17892            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17893                    long groupId, long categoryId, long threadId, int status,
17894                    OrderByComparator<MBMessage> orderByComparator)
17895                    throws NoSuchMessageException {
17896                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17897                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17898                                    threadId, status, orderByComparator);
17899                    }
17900    
17901                    MBMessage mbMessage = findByPrimaryKey(messageId);
17902    
17903                    Session session = null;
17904    
17905                    try {
17906                            session = openSession();
17907    
17908                            MBMessage[] array = new MBMessageImpl[3];
17909    
17910                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17911                                            groupId, categoryId, threadId, status, orderByComparator,
17912                                            true);
17913    
17914                            array[1] = mbMessage;
17915    
17916                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17917                                            groupId, categoryId, threadId, status, orderByComparator,
17918                                            false);
17919    
17920                            return array;
17921                    }
17922                    catch (Exception e) {
17923                            throw processException(e);
17924                    }
17925                    finally {
17926                            closeSession(session);
17927                    }
17928            }
17929    
17930            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17931                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17932                    int status, OrderByComparator<MBMessage> orderByComparator,
17933                    boolean previous) {
17934                    StringBundler query = null;
17935    
17936                    if (orderByComparator != null) {
17937                            query = new StringBundler(6 +
17938                                            (orderByComparator.getOrderByFields().length * 6));
17939                    }
17940                    else {
17941                            query = new StringBundler(3);
17942                    }
17943    
17944                    if (getDB().isSupportsInlineDistinct()) {
17945                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17946                    }
17947                    else {
17948                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17949                    }
17950    
17951                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17952    
17953                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17954    
17955                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17956    
17957                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17958    
17959                    if (!getDB().isSupportsInlineDistinct()) {
17960                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17961                    }
17962    
17963                    if (orderByComparator != null) {
17964                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17965    
17966                            if (orderByConditionFields.length > 0) {
17967                                    query.append(WHERE_AND);
17968                            }
17969    
17970                            for (int i = 0; i < orderByConditionFields.length; i++) {
17971                                    if (getDB().isSupportsInlineDistinct()) {
17972                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17973                                    }
17974                                    else {
17975                                            query.append(_ORDER_BY_ENTITY_TABLE);
17976                                    }
17977    
17978                                    query.append(orderByConditionFields[i]);
17979    
17980                                    if ((i + 1) < orderByConditionFields.length) {
17981                                            if (orderByComparator.isAscending() ^ previous) {
17982                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17983                                            }
17984                                            else {
17985                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17986                                            }
17987                                    }
17988                                    else {
17989                                            if (orderByComparator.isAscending() ^ previous) {
17990                                                    query.append(WHERE_GREATER_THAN);
17991                                            }
17992                                            else {
17993                                                    query.append(WHERE_LESSER_THAN);
17994                                            }
17995                                    }
17996                            }
17997    
17998                            query.append(ORDER_BY_CLAUSE);
17999    
18000                            String[] orderByFields = orderByComparator.getOrderByFields();
18001    
18002                            for (int i = 0; i < orderByFields.length; i++) {
18003                                    if (getDB().isSupportsInlineDistinct()) {
18004                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18005                                    }
18006                                    else {
18007                                            query.append(_ORDER_BY_ENTITY_TABLE);
18008                                    }
18009    
18010                                    query.append(orderByFields[i]);
18011    
18012                                    if ((i + 1) < orderByFields.length) {
18013                                            if (orderByComparator.isAscending() ^ previous) {
18014                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18015                                            }
18016                                            else {
18017                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18018                                            }
18019                                    }
18020                                    else {
18021                                            if (orderByComparator.isAscending() ^ previous) {
18022                                                    query.append(ORDER_BY_ASC);
18023                                            }
18024                                            else {
18025                                                    query.append(ORDER_BY_DESC);
18026                                            }
18027                                    }
18028                            }
18029                    }
18030                    else {
18031                            if (getDB().isSupportsInlineDistinct()) {
18032                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18033                            }
18034                            else {
18035                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18036                            }
18037                    }
18038    
18039                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18040                                    MBMessage.class.getName(),
18041                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18042    
18043                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
18044    
18045                    q.setFirstResult(0);
18046                    q.setMaxResults(2);
18047    
18048                    if (getDB().isSupportsInlineDistinct()) {
18049                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18050                    }
18051                    else {
18052                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18053                    }
18054    
18055                    QueryPos qPos = QueryPos.getInstance(q);
18056    
18057                    qPos.add(groupId);
18058    
18059                    qPos.add(categoryId);
18060    
18061                    qPos.add(threadId);
18062    
18063                    qPos.add(status);
18064    
18065                    if (orderByComparator != null) {
18066                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18067    
18068                            for (Object value : values) {
18069                                    qPos.add(value);
18070                            }
18071                    }
18072    
18073                    List<MBMessage> list = q.list();
18074    
18075                    if (list.size() == 2) {
18076                            return list.get(1);
18077                    }
18078                    else {
18079                            return null;
18080                    }
18081            }
18082    
18083            /**
18084             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
18085             *
18086             * @param groupId the group ID
18087             * @param categoryId the category ID
18088             * @param threadId the thread ID
18089             * @param status the status
18090             */
18091            @Override
18092            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
18093                    int status) {
18094                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
18095                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18096                            remove(mbMessage);
18097                    }
18098            }
18099    
18100            /**
18101             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18102             *
18103             * @param groupId the group ID
18104             * @param categoryId the category ID
18105             * @param threadId the thread ID
18106             * @param status the status
18107             * @return the number of matching message-boards messages
18108             */
18109            @Override
18110            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18111                    int status) {
18112                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
18113    
18114                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18115    
18116                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18117    
18118                    if (count == null) {
18119                            StringBundler query = new StringBundler(5);
18120    
18121                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18122    
18123                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18124    
18125                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18126    
18127                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18128    
18129                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18130    
18131                            String sql = query.toString();
18132    
18133                            Session session = null;
18134    
18135                            try {
18136                                    session = openSession();
18137    
18138                                    Query q = session.createQuery(sql);
18139    
18140                                    QueryPos qPos = QueryPos.getInstance(q);
18141    
18142                                    qPos.add(groupId);
18143    
18144                                    qPos.add(categoryId);
18145    
18146                                    qPos.add(threadId);
18147    
18148                                    qPos.add(status);
18149    
18150                                    count = (Long)q.uniqueResult();
18151    
18152                                    finderCache.putResult(finderPath, finderArgs, count);
18153                            }
18154                            catch (Exception e) {
18155                                    finderCache.removeResult(finderPath, finderArgs);
18156    
18157                                    throw processException(e);
18158                            }
18159                            finally {
18160                                    closeSession(session);
18161                            }
18162                    }
18163    
18164                    return count.intValue();
18165            }
18166    
18167            /**
18168             * 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;.
18169             *
18170             * @param groupId the group ID
18171             * @param categoryId the category ID
18172             * @param threadId the thread ID
18173             * @param status the status
18174             * @return the number of matching message-boards messages that the user has permission to view
18175             */
18176            @Override
18177            public int filterCountByG_C_T_S(long groupId, long categoryId,
18178                    long threadId, int status) {
18179                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18180                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18181                    }
18182    
18183                    StringBundler query = new StringBundler(5);
18184    
18185                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18186    
18187                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18188    
18189                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18190    
18191                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18192    
18193                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18194    
18195                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18196                                    MBMessage.class.getName(),
18197                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18198    
18199                    Session session = null;
18200    
18201                    try {
18202                            session = openSession();
18203    
18204                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
18205    
18206                            q.addScalar(COUNT_COLUMN_NAME,
18207                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18208    
18209                            QueryPos qPos = QueryPos.getInstance(q);
18210    
18211                            qPos.add(groupId);
18212    
18213                            qPos.add(categoryId);
18214    
18215                            qPos.add(threadId);
18216    
18217                            qPos.add(status);
18218    
18219                            Long count = (Long)q.uniqueResult();
18220    
18221                            return count.intValue();
18222                    }
18223                    catch (Exception e) {
18224                            throw processException(e);
18225                    }
18226                    finally {
18227                            closeSession(session);
18228                    }
18229            }
18230    
18231            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18232            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18233            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18234            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18235            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18236                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18237                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
18238                            new String[] {
18239                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18240                                    Integer.class.getName(),
18241                                    
18242                            Integer.class.getName(), Integer.class.getName(),
18243                                    OrderByComparator.class.getName()
18244                            });
18245            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
18246                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18247                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18248                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
18249                            new String[] {
18250                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18251                                    Integer.class.getName()
18252                            },
18253                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
18254                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
18255                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
18256                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18257                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18258            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18259                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18260                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
18261                            new String[] {
18262                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18263                                    Integer.class.getName()
18264                            });
18265    
18266            /**
18267             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18268             *
18269             * @param userId the user ID
18270             * @param classNameId the class name ID
18271             * @param classPK the class p k
18272             * @param status the status
18273             * @return the matching message-boards messages
18274             */
18275            @Override
18276            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18277                    long classPK, int status) {
18278                    return findByU_C_C_S(userId, classNameId, classPK, status,
18279                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18280            }
18281    
18282            /**
18283             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18284             *
18285             * <p>
18286             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
18287             * </p>
18288             *
18289             * @param userId the user ID
18290             * @param classNameId the class name ID
18291             * @param classPK the class p k
18292             * @param status the status
18293             * @param start the lower bound of the range of message-boards messages
18294             * @param end the upper bound of the range of message-boards messages (not inclusive)
18295             * @return the range of matching message-boards messages
18296             */
18297            @Override
18298            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18299                    long classPK, int status, int start, int end) {
18300                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18301                            null);
18302            }
18303    
18304            /**
18305             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18306             *
18307             * <p>
18308             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
18309             * </p>
18310             *
18311             * @param userId the user ID
18312             * @param classNameId the class name ID
18313             * @param classPK the class p k
18314             * @param status the status
18315             * @param start the lower bound of the range of message-boards messages
18316             * @param end the upper bound of the range of message-boards messages (not inclusive)
18317             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18318             * @return the ordered range of matching message-boards messages
18319             */
18320            @Override
18321            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18322                    long classPK, int status, int start, int end,
18323                    OrderByComparator<MBMessage> orderByComparator) {
18324                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18325                            orderByComparator, true);
18326            }
18327    
18328            /**
18329             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18330             *
18331             * <p>
18332             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
18333             * </p>
18334             *
18335             * @param userId the user ID
18336             * @param classNameId the class name ID
18337             * @param classPK the class p k
18338             * @param status the status
18339             * @param start the lower bound of the range of message-boards messages
18340             * @param end the upper bound of the range of message-boards messages (not inclusive)
18341             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18342             * @param retrieveFromCache whether to retrieve from the finder cache
18343             * @return the ordered range of matching message-boards messages
18344             */
18345            @Override
18346            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18347                    long classPK, int status, int start, int end,
18348                    OrderByComparator<MBMessage> orderByComparator,
18349                    boolean retrieveFromCache) {
18350                    boolean pagination = true;
18351                    FinderPath finderPath = null;
18352                    Object[] finderArgs = null;
18353    
18354                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18355                                    (orderByComparator == null)) {
18356                            pagination = false;
18357                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18358                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18359                    }
18360                    else {
18361                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18362                            finderArgs = new Object[] {
18363                                            userId, classNameId, classPK, status,
18364                                            
18365                                            start, end, orderByComparator
18366                                    };
18367                    }
18368    
18369                    List<MBMessage> list = null;
18370    
18371                    if (retrieveFromCache) {
18372                            list = (List<MBMessage>)finderCache.getResult(finderPath,
18373                                            finderArgs, this);
18374    
18375                            if ((list != null) && !list.isEmpty()) {
18376                                    for (MBMessage mbMessage : list) {
18377                                            if ((userId != mbMessage.getUserId()) ||
18378                                                            (classNameId != mbMessage.getClassNameId()) ||
18379                                                            (classPK != mbMessage.getClassPK()) ||
18380                                                            (status != mbMessage.getStatus())) {
18381                                                    list = null;
18382    
18383                                                    break;
18384                                            }
18385                                    }
18386                            }
18387                    }
18388    
18389                    if (list == null) {
18390                            StringBundler query = null;
18391    
18392                            if (orderByComparator != null) {
18393                                    query = new StringBundler(6 +
18394                                                    (orderByComparator.getOrderByFields().length * 3));
18395                            }
18396                            else {
18397                                    query = new StringBundler(6);
18398                            }
18399    
18400                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18401    
18402                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18403    
18404                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18405    
18406                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18407    
18408                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18409    
18410                            if (orderByComparator != null) {
18411                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18412                                            orderByComparator);
18413                            }
18414                            else
18415                             if (pagination) {
18416                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18417                            }
18418    
18419                            String sql = query.toString();
18420    
18421                            Session session = null;
18422    
18423                            try {
18424                                    session = openSession();
18425    
18426                                    Query q = session.createQuery(sql);
18427    
18428                                    QueryPos qPos = QueryPos.getInstance(q);
18429    
18430                                    qPos.add(userId);
18431    
18432                                    qPos.add(classNameId);
18433    
18434                                    qPos.add(classPK);
18435    
18436                                    qPos.add(status);
18437    
18438                                    if (!pagination) {
18439                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18440                                                            start, end, false);
18441    
18442                                            Collections.sort(list);
18443    
18444                                            list = Collections.unmodifiableList(list);
18445                                    }
18446                                    else {
18447                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18448                                                            start, end);
18449                                    }
18450    
18451                                    cacheResult(list);
18452    
18453                                    finderCache.putResult(finderPath, finderArgs, list);
18454                            }
18455                            catch (Exception e) {
18456                                    finderCache.removeResult(finderPath, finderArgs);
18457    
18458                                    throw processException(e);
18459                            }
18460                            finally {
18461                                    closeSession(session);
18462                            }
18463                    }
18464    
18465                    return list;
18466            }
18467    
18468            /**
18469             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18470             *
18471             * @param userId the user ID
18472             * @param classNameId the class name ID
18473             * @param classPK the class p k
18474             * @param status the status
18475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18476             * @return the first matching message-boards message
18477             * @throws NoSuchMessageException if a matching message-boards message could not be found
18478             */
18479            @Override
18480            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18481                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18482                    throws NoSuchMessageException {
18483                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18484                                    classPK, status, orderByComparator);
18485    
18486                    if (mbMessage != null) {
18487                            return mbMessage;
18488                    }
18489    
18490                    StringBundler msg = new StringBundler(10);
18491    
18492                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18493    
18494                    msg.append("userId=");
18495                    msg.append(userId);
18496    
18497                    msg.append(", classNameId=");
18498                    msg.append(classNameId);
18499    
18500                    msg.append(", classPK=");
18501                    msg.append(classPK);
18502    
18503                    msg.append(", status=");
18504                    msg.append(status);
18505    
18506                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18507    
18508                    throw new NoSuchMessageException(msg.toString());
18509            }
18510    
18511            /**
18512             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18513             *
18514             * @param userId the user ID
18515             * @param classNameId the class name ID
18516             * @param classPK the class p k
18517             * @param status the status
18518             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18519             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18520             */
18521            @Override
18522            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18523                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18524                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18525                                    status, 0, 1, orderByComparator);
18526    
18527                    if (!list.isEmpty()) {
18528                            return list.get(0);
18529                    }
18530    
18531                    return null;
18532            }
18533    
18534            /**
18535             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18536             *
18537             * @param userId the user ID
18538             * @param classNameId the class name ID
18539             * @param classPK the class p k
18540             * @param status the status
18541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18542             * @return the last matching message-boards message
18543             * @throws NoSuchMessageException if a matching message-boards message could not be found
18544             */
18545            @Override
18546            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18547                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18548                    throws NoSuchMessageException {
18549                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18550                                    status, orderByComparator);
18551    
18552                    if (mbMessage != null) {
18553                            return mbMessage;
18554                    }
18555    
18556                    StringBundler msg = new StringBundler(10);
18557    
18558                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18559    
18560                    msg.append("userId=");
18561                    msg.append(userId);
18562    
18563                    msg.append(", classNameId=");
18564                    msg.append(classNameId);
18565    
18566                    msg.append(", classPK=");
18567                    msg.append(classPK);
18568    
18569                    msg.append(", status=");
18570                    msg.append(status);
18571    
18572                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18573    
18574                    throw new NoSuchMessageException(msg.toString());
18575            }
18576    
18577            /**
18578             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18579             *
18580             * @param userId the user ID
18581             * @param classNameId the class name ID
18582             * @param classPK the class p k
18583             * @param status the status
18584             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18585             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18586             */
18587            @Override
18588            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18589                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18590                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18591    
18592                    if (count == 0) {
18593                            return null;
18594                    }
18595    
18596                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18597                                    status, count - 1, count, orderByComparator);
18598    
18599                    if (!list.isEmpty()) {
18600                            return list.get(0);
18601                    }
18602    
18603                    return null;
18604            }
18605    
18606            /**
18607             * 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;.
18608             *
18609             * @param messageId the primary key of the current message-boards message
18610             * @param userId the user ID
18611             * @param classNameId the class name ID
18612             * @param classPK the class p k
18613             * @param status the status
18614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18615             * @return the previous, current, and next message-boards message
18616             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18617             */
18618            @Override
18619            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18620                    long classNameId, long classPK, int status,
18621                    OrderByComparator<MBMessage> orderByComparator)
18622                    throws NoSuchMessageException {
18623                    MBMessage mbMessage = findByPrimaryKey(messageId);
18624    
18625                    Session session = null;
18626    
18627                    try {
18628                            session = openSession();
18629    
18630                            MBMessage[] array = new MBMessageImpl[3];
18631    
18632                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18633                                            classNameId, classPK, status, orderByComparator, true);
18634    
18635                            array[1] = mbMessage;
18636    
18637                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18638                                            classNameId, classPK, status, orderByComparator, false);
18639    
18640                            return array;
18641                    }
18642                    catch (Exception e) {
18643                            throw processException(e);
18644                    }
18645                    finally {
18646                            closeSession(session);
18647                    }
18648            }
18649    
18650            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18651                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18652                    int status, OrderByComparator<MBMessage> orderByComparator,
18653                    boolean previous) {
18654                    StringBundler query = null;
18655    
18656                    if (orderByComparator != null) {
18657                            query = new StringBundler(6 +
18658                                            (orderByComparator.getOrderByFields().length * 6));
18659                    }
18660                    else {
18661                            query = new StringBundler(3);
18662                    }
18663    
18664                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18665    
18666                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18667    
18668                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18669    
18670                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18671    
18672                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18673    
18674                    if (orderByComparator != null) {
18675                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18676    
18677                            if (orderByConditionFields.length > 0) {
18678                                    query.append(WHERE_AND);
18679                            }
18680    
18681                            for (int i = 0; i < orderByConditionFields.length; i++) {
18682                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18683                                    query.append(orderByConditionFields[i]);
18684    
18685                                    if ((i + 1) < orderByConditionFields.length) {
18686                                            if (orderByComparator.isAscending() ^ previous) {
18687                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18688                                            }
18689                                            else {
18690                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18691                                            }
18692                                    }
18693                                    else {
18694                                            if (orderByComparator.isAscending() ^ previous) {
18695                                                    query.append(WHERE_GREATER_THAN);
18696                                            }
18697                                            else {
18698                                                    query.append(WHERE_LESSER_THAN);
18699                                            }
18700                                    }
18701                            }
18702    
18703                            query.append(ORDER_BY_CLAUSE);
18704    
18705                            String[] orderByFields = orderByComparator.getOrderByFields();
18706    
18707                            for (int i = 0; i < orderByFields.length; i++) {
18708                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18709                                    query.append(orderByFields[i]);
18710    
18711                                    if ((i + 1) < orderByFields.length) {
18712                                            if (orderByComparator.isAscending() ^ previous) {
18713                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18714                                            }
18715                                            else {
18716                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18717                                            }
18718                                    }
18719                                    else {
18720                                            if (orderByComparator.isAscending() ^ previous) {
18721                                                    query.append(ORDER_BY_ASC);
18722                                            }
18723                                            else {
18724                                                    query.append(ORDER_BY_DESC);
18725                                            }
18726                                    }
18727                            }
18728                    }
18729                    else {
18730                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18731                    }
18732    
18733                    String sql = query.toString();
18734    
18735                    Query q = session.createQuery(sql);
18736    
18737                    q.setFirstResult(0);
18738                    q.setMaxResults(2);
18739    
18740                    QueryPos qPos = QueryPos.getInstance(q);
18741    
18742                    qPos.add(userId);
18743    
18744                    qPos.add(classNameId);
18745    
18746                    qPos.add(classPK);
18747    
18748                    qPos.add(status);
18749    
18750                    if (orderByComparator != null) {
18751                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18752    
18753                            for (Object value : values) {
18754                                    qPos.add(value);
18755                            }
18756                    }
18757    
18758                    List<MBMessage> list = q.list();
18759    
18760                    if (list.size() == 2) {
18761                            return list.get(1);
18762                    }
18763                    else {
18764                            return null;
18765                    }
18766            }
18767    
18768            /**
18769             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18770             *
18771             * @param userId the user ID
18772             * @param classNameId the class name ID
18773             * @param classPK the class p k
18774             * @param status the status
18775             */
18776            @Override
18777            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18778                    int status) {
18779                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18780                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18781                            remove(mbMessage);
18782                    }
18783            }
18784    
18785            /**
18786             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18787             *
18788             * @param userId the user ID
18789             * @param classNameId the class name ID
18790             * @param classPK the class p k
18791             * @param status the status
18792             * @return the number of matching message-boards messages
18793             */
18794            @Override
18795            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18796                    int status) {
18797                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18798    
18799                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18800    
18801                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18802    
18803                    if (count == null) {
18804                            StringBundler query = new StringBundler(5);
18805    
18806                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18807    
18808                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18809    
18810                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18811    
18812                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18813    
18814                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18815    
18816                            String sql = query.toString();
18817    
18818                            Session session = null;
18819    
18820                            try {
18821                                    session = openSession();
18822    
18823                                    Query q = session.createQuery(sql);
18824    
18825                                    QueryPos qPos = QueryPos.getInstance(q);
18826    
18827                                    qPos.add(userId);
18828    
18829                                    qPos.add(classNameId);
18830    
18831                                    qPos.add(classPK);
18832    
18833                                    qPos.add(status);
18834    
18835                                    count = (Long)q.uniqueResult();
18836    
18837                                    finderCache.putResult(finderPath, finderArgs, count);
18838                            }
18839                            catch (Exception e) {
18840                                    finderCache.removeResult(finderPath, finderArgs);
18841    
18842                                    throw processException(e);
18843                            }
18844                            finally {
18845                                    closeSession(session);
18846                            }
18847                    }
18848    
18849                    return count.intValue();
18850            }
18851    
18852            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18853            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18854            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18855            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18856    
18857            public MBMessagePersistenceImpl() {
18858                    setModelClass(MBMessage.class);
18859            }
18860    
18861            /**
18862             * Caches the message-boards message in the entity cache if it is enabled.
18863             *
18864             * @param mbMessage the message-boards message
18865             */
18866            @Override
18867            public void cacheResult(MBMessage mbMessage) {
18868                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18869                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18870    
18871                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18872                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18873                            mbMessage);
18874    
18875                    mbMessage.resetOriginalValues();
18876            }
18877    
18878            /**
18879             * Caches the message-boards messages in the entity cache if it is enabled.
18880             *
18881             * @param mbMessages the message-boards messages
18882             */
18883            @Override
18884            public void cacheResult(List<MBMessage> mbMessages) {
18885                    for (MBMessage mbMessage : mbMessages) {
18886                            if (entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18887                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18888                                    cacheResult(mbMessage);
18889                            }
18890                            else {
18891                                    mbMessage.resetOriginalValues();
18892                            }
18893                    }
18894            }
18895    
18896            /**
18897             * Clears the cache for all message-boards messages.
18898             *
18899             * <p>
18900             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18901             * </p>
18902             */
18903            @Override
18904            public void clearCache() {
18905                    entityCache.clearCache(MBMessageImpl.class);
18906    
18907                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
18908                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18909                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18910            }
18911    
18912            /**
18913             * Clears the cache for the message-boards message.
18914             *
18915             * <p>
18916             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18917             * </p>
18918             */
18919            @Override
18920            public void clearCache(MBMessage mbMessage) {
18921                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18922                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18923    
18924                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18925                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18926    
18927                    clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18928            }
18929    
18930            @Override
18931            public void clearCache(List<MBMessage> mbMessages) {
18932                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18933                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18934    
18935                    for (MBMessage mbMessage : mbMessages) {
18936                            entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18937                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18938    
18939                            clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18940                    }
18941            }
18942    
18943            protected void cacheUniqueFindersCache(
18944                    MBMessageModelImpl mbMessageModelImpl, boolean isNew) {
18945                    if (isNew) {
18946                            Object[] args = new Object[] {
18947                                            mbMessageModelImpl.getUuid(),
18948                                            mbMessageModelImpl.getGroupId()
18949                                    };
18950    
18951                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18952                                    Long.valueOf(1));
18953                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18954                                    mbMessageModelImpl);
18955                    }
18956                    else {
18957                            if ((mbMessageModelImpl.getColumnBitmask() &
18958                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18959                                    Object[] args = new Object[] {
18960                                                    mbMessageModelImpl.getUuid(),
18961                                                    mbMessageModelImpl.getGroupId()
18962                                            };
18963    
18964                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18965                                            Long.valueOf(1));
18966                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18967                                            mbMessageModelImpl);
18968                            }
18969                    }
18970            }
18971    
18972            protected void clearUniqueFindersCache(
18973                    MBMessageModelImpl mbMessageModelImpl) {
18974                    Object[] args = new Object[] {
18975                                    mbMessageModelImpl.getUuid(), mbMessageModelImpl.getGroupId()
18976                            };
18977    
18978                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18979                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18980    
18981                    if ((mbMessageModelImpl.getColumnBitmask() &
18982                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18983                            args = new Object[] {
18984                                            mbMessageModelImpl.getOriginalUuid(),
18985                                            mbMessageModelImpl.getOriginalGroupId()
18986                                    };
18987    
18988                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18989                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18990                    }
18991            }
18992    
18993            /**
18994             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18995             *
18996             * @param messageId the primary key for the new message-boards message
18997             * @return the new message-boards message
18998             */
18999            @Override
19000            public MBMessage create(long messageId) {
19001                    MBMessage mbMessage = new MBMessageImpl();
19002    
19003                    mbMessage.setNew(true);
19004                    mbMessage.setPrimaryKey(messageId);
19005    
19006                    String uuid = PortalUUIDUtil.generate();
19007    
19008                    mbMessage.setUuid(uuid);
19009    
19010                    return mbMessage;
19011            }
19012    
19013            /**
19014             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19015             *
19016             * @param messageId the primary key of the message-boards message
19017             * @return the message-boards message that was removed
19018             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19019             */
19020            @Override
19021            public MBMessage remove(long messageId) throws NoSuchMessageException {
19022                    return remove((Serializable)messageId);
19023            }
19024    
19025            /**
19026             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19027             *
19028             * @param primaryKey the primary key of the message-boards message
19029             * @return the message-boards message that was removed
19030             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19031             */
19032            @Override
19033            public MBMessage remove(Serializable primaryKey)
19034                    throws NoSuchMessageException {
19035                    Session session = null;
19036    
19037                    try {
19038                            session = openSession();
19039    
19040                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19041                                            primaryKey);
19042    
19043                            if (mbMessage == null) {
19044                                    if (_log.isWarnEnabled()) {
19045                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19046                                    }
19047    
19048                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19049                                            primaryKey);
19050                            }
19051    
19052                            return remove(mbMessage);
19053                    }
19054                    catch (NoSuchMessageException nsee) {
19055                            throw nsee;
19056                    }
19057                    catch (Exception e) {
19058                            throw processException(e);
19059                    }
19060                    finally {
19061                            closeSession(session);
19062                    }
19063            }
19064    
19065            @Override
19066            protected MBMessage removeImpl(MBMessage mbMessage) {
19067                    mbMessage = toUnwrappedModel(mbMessage);
19068    
19069                    Session session = null;
19070    
19071                    try {
19072                            session = openSession();
19073    
19074                            if (!session.contains(mbMessage)) {
19075                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19076                                                    mbMessage.getPrimaryKeyObj());
19077                            }
19078    
19079                            if (mbMessage != null) {
19080                                    session.delete(mbMessage);
19081                            }
19082                    }
19083                    catch (Exception e) {
19084                            throw processException(e);
19085                    }
19086                    finally {
19087                            closeSession(session);
19088                    }
19089    
19090                    if (mbMessage != null) {
19091                            clearCache(mbMessage);
19092                    }
19093    
19094                    return mbMessage;
19095            }
19096    
19097            @Override
19098            public MBMessage updateImpl(MBMessage mbMessage) {
19099                    mbMessage = toUnwrappedModel(mbMessage);
19100    
19101                    boolean isNew = mbMessage.isNew();
19102    
19103                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19104    
19105                    if (Validator.isNull(mbMessage.getUuid())) {
19106                            String uuid = PortalUUIDUtil.generate();
19107    
19108                            mbMessage.setUuid(uuid);
19109                    }
19110    
19111                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
19112    
19113                    Date now = new Date();
19114    
19115                    if (isNew && (mbMessage.getCreateDate() == null)) {
19116                            if (serviceContext == null) {
19117                                    mbMessage.setCreateDate(now);
19118                            }
19119                            else {
19120                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
19121                            }
19122                    }
19123    
19124                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
19125                            if (serviceContext == null) {
19126                                    mbMessage.setModifiedDate(now);
19127                            }
19128                            else {
19129                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
19130                            }
19131                    }
19132    
19133                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
19134    
19135                    if (userId > 0) {
19136                            long companyId = mbMessage.getCompanyId();
19137    
19138                            long groupId = mbMessage.getGroupId();
19139    
19140                            long messageId = 0;
19141    
19142                            if (!isNew) {
19143                                    messageId = mbMessage.getPrimaryKey();
19144                            }
19145    
19146                            try {
19147                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
19148                                                    userId,
19149                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
19150                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
19151                                                    mbMessage.getSubject(), null));
19152                            }
19153                            catch (SanitizerException se) {
19154                                    throw new SystemException(se);
19155                            }
19156                    }
19157    
19158                    Session session = null;
19159    
19160                    try {
19161                            session = openSession();
19162    
19163                            if (mbMessage.isNew()) {
19164                                    session.save(mbMessage);
19165    
19166                                    mbMessage.setNew(false);
19167                            }
19168                            else {
19169                                    mbMessage = (MBMessage)session.merge(mbMessage);
19170                            }
19171                    }
19172                    catch (Exception e) {
19173                            throw processException(e);
19174                    }
19175                    finally {
19176                            closeSession(session);
19177                    }
19178    
19179                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19180    
19181                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
19182                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19183                    }
19184    
19185                    else {
19186                            if ((mbMessageModelImpl.getColumnBitmask() &
19187                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
19188                                    Object[] args = new Object[] {
19189                                                    mbMessageModelImpl.getOriginalUuid()
19190                                            };
19191    
19192                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19193                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19194                                            args);
19195    
19196                                    args = new Object[] { mbMessageModelImpl.getUuid() };
19197    
19198                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19199                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19200                                            args);
19201                            }
19202    
19203                            if ((mbMessageModelImpl.getColumnBitmask() &
19204                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
19205                                    Object[] args = new Object[] {
19206                                                    mbMessageModelImpl.getOriginalUuid(),
19207                                                    mbMessageModelImpl.getOriginalCompanyId()
19208                                            };
19209    
19210                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19211                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19212                                            args);
19213    
19214                                    args = new Object[] {
19215                                                    mbMessageModelImpl.getUuid(),
19216                                                    mbMessageModelImpl.getCompanyId()
19217                                            };
19218    
19219                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19220                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19221                                            args);
19222                            }
19223    
19224                            if ((mbMessageModelImpl.getColumnBitmask() &
19225                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
19226                                    Object[] args = new Object[] {
19227                                                    mbMessageModelImpl.getOriginalGroupId()
19228                                            };
19229    
19230                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19231                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19232                                            args);
19233    
19234                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
19235    
19236                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19237                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19238                                            args);
19239                            }
19240    
19241                            if ((mbMessageModelImpl.getColumnBitmask() &
19242                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
19243                                    Object[] args = new Object[] {
19244                                                    mbMessageModelImpl.getOriginalCompanyId()
19245                                            };
19246    
19247                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19248                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19249                                            args);
19250    
19251                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
19252    
19253                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19254                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19255                                            args);
19256                            }
19257    
19258                            if ((mbMessageModelImpl.getColumnBitmask() &
19259                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
19260                                    Object[] args = new Object[] {
19261                                                    mbMessageModelImpl.getOriginalUserId()
19262                                            };
19263    
19264                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19265                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19266                                            args);
19267    
19268                                    args = new Object[] { mbMessageModelImpl.getUserId() };
19269    
19270                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19271                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19272                                            args);
19273                            }
19274    
19275                            if ((mbMessageModelImpl.getColumnBitmask() &
19276                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
19277                                    Object[] args = new Object[] {
19278                                                    mbMessageModelImpl.getOriginalThreadId()
19279                                            };
19280    
19281                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19282                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19283                                            args);
19284    
19285                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19286    
19287                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19288                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19289                                            args);
19290                            }
19291    
19292                            if ((mbMessageModelImpl.getColumnBitmask() &
19293                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
19294                                    Object[] args = new Object[] {
19295                                                    mbMessageModelImpl.getOriginalThreadId()
19296                                            };
19297    
19298                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19299                                            args);
19300                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19301                                            args);
19302    
19303                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19304    
19305                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19306                                            args);
19307                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19308                                            args);
19309                            }
19310    
19311                            if ((mbMessageModelImpl.getColumnBitmask() &
19312                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19313                                    Object[] args = new Object[] {
19314                                                    mbMessageModelImpl.getOriginalGroupId(),
19315                                                    mbMessageModelImpl.getOriginalUserId()
19316                                            };
19317    
19318                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19319                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19320                                            args);
19321    
19322                                    args = new Object[] {
19323                                                    mbMessageModelImpl.getGroupId(),
19324                                                    mbMessageModelImpl.getUserId()
19325                                            };
19326    
19327                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19328                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19329                                            args);
19330                            }
19331    
19332                            if ((mbMessageModelImpl.getColumnBitmask() &
19333                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19334                                    Object[] args = new Object[] {
19335                                                    mbMessageModelImpl.getOriginalGroupId(),
19336                                                    mbMessageModelImpl.getOriginalCategoryId()
19337                                            };
19338    
19339                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19340                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19341                                            args);
19342    
19343                                    args = new Object[] {
19344                                                    mbMessageModelImpl.getGroupId(),
19345                                                    mbMessageModelImpl.getCategoryId()
19346                                            };
19347    
19348                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19349                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19350                                            args);
19351                            }
19352    
19353                            if ((mbMessageModelImpl.getColumnBitmask() &
19354                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19355                                    Object[] args = new Object[] {
19356                                                    mbMessageModelImpl.getOriginalGroupId(),
19357                                                    mbMessageModelImpl.getOriginalStatus()
19358                                            };
19359    
19360                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19361                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19362                                            args);
19363    
19364                                    args = new Object[] {
19365                                                    mbMessageModelImpl.getGroupId(),
19366                                                    mbMessageModelImpl.getStatus()
19367                                            };
19368    
19369                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19370                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19371                                            args);
19372                            }
19373    
19374                            if ((mbMessageModelImpl.getColumnBitmask() &
19375                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19376                                    Object[] args = new Object[] {
19377                                                    mbMessageModelImpl.getOriginalCompanyId(),
19378                                                    mbMessageModelImpl.getOriginalStatus()
19379                                            };
19380    
19381                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19382                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19383                                            args);
19384    
19385                                    args = new Object[] {
19386                                                    mbMessageModelImpl.getCompanyId(),
19387                                                    mbMessageModelImpl.getStatus()
19388                                            };
19389    
19390                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19391                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19392                                            args);
19393                            }
19394    
19395                            if ((mbMessageModelImpl.getColumnBitmask() &
19396                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19397                                    Object[] args = new Object[] {
19398                                                    mbMessageModelImpl.getOriginalUserId(),
19399                                                    mbMessageModelImpl.getOriginalClassNameId()
19400                                            };
19401    
19402                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19403                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19404                                            args);
19405    
19406                                    args = new Object[] {
19407                                                    mbMessageModelImpl.getUserId(),
19408                                                    mbMessageModelImpl.getClassNameId()
19409                                            };
19410    
19411                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19412                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19413                                            args);
19414                            }
19415    
19416                            if ((mbMessageModelImpl.getColumnBitmask() &
19417                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19418                                    Object[] args = new Object[] {
19419                                                    mbMessageModelImpl.getOriginalClassNameId(),
19420                                                    mbMessageModelImpl.getOriginalClassPK()
19421                                            };
19422    
19423                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19424                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19425                                            args);
19426    
19427                                    args = new Object[] {
19428                                                    mbMessageModelImpl.getClassNameId(),
19429                                                    mbMessageModelImpl.getClassPK()
19430                                            };
19431    
19432                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19433                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19434                                            args);
19435                            }
19436    
19437                            if ((mbMessageModelImpl.getColumnBitmask() &
19438                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19439                                    Object[] args = new Object[] {
19440                                                    mbMessageModelImpl.getOriginalThreadId(),
19441                                                    mbMessageModelImpl.getOriginalParentMessageId()
19442                                            };
19443    
19444                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19445                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19446                                            args);
19447    
19448                                    args = new Object[] {
19449                                                    mbMessageModelImpl.getThreadId(),
19450                                                    mbMessageModelImpl.getParentMessageId()
19451                                            };
19452    
19453                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19454                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19455                                            args);
19456                            }
19457    
19458                            if ((mbMessageModelImpl.getColumnBitmask() &
19459                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19460                                    Object[] args = new Object[] {
19461                                                    mbMessageModelImpl.getOriginalThreadId(),
19462                                                    mbMessageModelImpl.getOriginalAnswer()
19463                                            };
19464    
19465                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19466                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19467                                            args);
19468    
19469                                    args = new Object[] {
19470                                                    mbMessageModelImpl.getThreadId(),
19471                                                    mbMessageModelImpl.getAnswer()
19472                                            };
19473    
19474                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19475                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19476                                            args);
19477                            }
19478    
19479                            if ((mbMessageModelImpl.getColumnBitmask() &
19480                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19481                                    Object[] args = new Object[] {
19482                                                    mbMessageModelImpl.getOriginalThreadId(),
19483                                                    mbMessageModelImpl.getOriginalStatus()
19484                                            };
19485    
19486                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19487                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19488                                            args);
19489    
19490                                    args = new Object[] {
19491                                                    mbMessageModelImpl.getThreadId(),
19492                                                    mbMessageModelImpl.getStatus()
19493                                            };
19494    
19495                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19496                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19497                                            args);
19498                            }
19499    
19500                            if ((mbMessageModelImpl.getColumnBitmask() &
19501                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19502                                    Object[] args = new Object[] {
19503                                                    mbMessageModelImpl.getOriginalThreadId(),
19504                                                    mbMessageModelImpl.getOriginalStatus()
19505                                            };
19506    
19507                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19508                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19509                                            args);
19510    
19511                                    args = new Object[] {
19512                                                    mbMessageModelImpl.getThreadId(),
19513                                                    mbMessageModelImpl.getStatus()
19514                                            };
19515    
19516                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19517                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19518                                            args);
19519                            }
19520    
19521                            if ((mbMessageModelImpl.getColumnBitmask() &
19522                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19523                                    Object[] args = new Object[] {
19524                                                    mbMessageModelImpl.getOriginalGroupId(),
19525                                                    mbMessageModelImpl.getOriginalUserId(),
19526                                                    mbMessageModelImpl.getOriginalStatus()
19527                                            };
19528    
19529                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19530                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19531                                            args);
19532    
19533                                    args = new Object[] {
19534                                                    mbMessageModelImpl.getGroupId(),
19535                                                    mbMessageModelImpl.getUserId(),
19536                                                    mbMessageModelImpl.getStatus()
19537                                            };
19538    
19539                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19540                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19541                                            args);
19542                            }
19543    
19544                            if ((mbMessageModelImpl.getColumnBitmask() &
19545                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19546                                    Object[] args = new Object[] {
19547                                                    mbMessageModelImpl.getOriginalGroupId(),
19548                                                    mbMessageModelImpl.getOriginalCategoryId(),
19549                                                    mbMessageModelImpl.getOriginalThreadId()
19550                                            };
19551    
19552                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19553                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19554                                            args);
19555    
19556                                    args = new Object[] {
19557                                                    mbMessageModelImpl.getGroupId(),
19558                                                    mbMessageModelImpl.getCategoryId(),
19559                                                    mbMessageModelImpl.getThreadId()
19560                                            };
19561    
19562                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19563                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19564                                            args);
19565                            }
19566    
19567                            if ((mbMessageModelImpl.getColumnBitmask() &
19568                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19569                                    Object[] args = new Object[] {
19570                                                    mbMessageModelImpl.getOriginalGroupId(),
19571                                                    mbMessageModelImpl.getOriginalCategoryId(),
19572                                                    mbMessageModelImpl.getOriginalStatus()
19573                                            };
19574    
19575                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19576                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19577                                            args);
19578    
19579                                    args = new Object[] {
19580                                                    mbMessageModelImpl.getGroupId(),
19581                                                    mbMessageModelImpl.getCategoryId(),
19582                                                    mbMessageModelImpl.getStatus()
19583                                            };
19584    
19585                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19586                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19587                                            args);
19588                            }
19589    
19590                            if ((mbMessageModelImpl.getColumnBitmask() &
19591                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19592                                    Object[] args = new Object[] {
19593                                                    mbMessageModelImpl.getOriginalUserId(),
19594                                                    mbMessageModelImpl.getOriginalClassNameId(),
19595                                                    mbMessageModelImpl.getOriginalClassPK()
19596                                            };
19597    
19598                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19599                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19600                                            args);
19601    
19602                                    args = new Object[] {
19603                                                    mbMessageModelImpl.getUserId(),
19604                                                    mbMessageModelImpl.getClassNameId(),
19605                                                    mbMessageModelImpl.getClassPK()
19606                                            };
19607    
19608                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19609                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19610                                            args);
19611                            }
19612    
19613                            if ((mbMessageModelImpl.getColumnBitmask() &
19614                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19615                                    Object[] args = new Object[] {
19616                                                    mbMessageModelImpl.getOriginalUserId(),
19617                                                    mbMessageModelImpl.getOriginalClassNameId(),
19618                                                    mbMessageModelImpl.getOriginalStatus()
19619                                            };
19620    
19621                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19622                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19623                                            args);
19624    
19625                                    args = new Object[] {
19626                                                    mbMessageModelImpl.getUserId(),
19627                                                    mbMessageModelImpl.getClassNameId(),
19628                                                    mbMessageModelImpl.getStatus()
19629                                            };
19630    
19631                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19632                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19633                                            args);
19634                            }
19635    
19636                            if ((mbMessageModelImpl.getColumnBitmask() &
19637                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19638                                    Object[] args = new Object[] {
19639                                                    mbMessageModelImpl.getOriginalClassNameId(),
19640                                                    mbMessageModelImpl.getOriginalClassPK(),
19641                                                    mbMessageModelImpl.getOriginalStatus()
19642                                            };
19643    
19644                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19645                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19646                                            args);
19647    
19648                                    args = new Object[] {
19649                                                    mbMessageModelImpl.getClassNameId(),
19650                                                    mbMessageModelImpl.getClassPK(),
19651                                                    mbMessageModelImpl.getStatus()
19652                                            };
19653    
19654                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19655                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19656                                            args);
19657                            }
19658    
19659                            if ((mbMessageModelImpl.getColumnBitmask() &
19660                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19661                                    Object[] args = new Object[] {
19662                                                    mbMessageModelImpl.getOriginalGroupId(),
19663                                                    mbMessageModelImpl.getOriginalCategoryId(),
19664                                                    mbMessageModelImpl.getOriginalThreadId(),
19665                                                    mbMessageModelImpl.getOriginalAnswer()
19666                                            };
19667    
19668                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19669                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19670                                            args);
19671    
19672                                    args = new Object[] {
19673                                                    mbMessageModelImpl.getGroupId(),
19674                                                    mbMessageModelImpl.getCategoryId(),
19675                                                    mbMessageModelImpl.getThreadId(),
19676                                                    mbMessageModelImpl.getAnswer()
19677                                            };
19678    
19679                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19680                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19681                                            args);
19682                            }
19683    
19684                            if ((mbMessageModelImpl.getColumnBitmask() &
19685                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19686                                    Object[] args = new Object[] {
19687                                                    mbMessageModelImpl.getOriginalGroupId(),
19688                                                    mbMessageModelImpl.getOriginalCategoryId(),
19689                                                    mbMessageModelImpl.getOriginalThreadId(),
19690                                                    mbMessageModelImpl.getOriginalStatus()
19691                                            };
19692    
19693                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19694                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19695                                            args);
19696    
19697                                    args = new Object[] {
19698                                                    mbMessageModelImpl.getGroupId(),
19699                                                    mbMessageModelImpl.getCategoryId(),
19700                                                    mbMessageModelImpl.getThreadId(),
19701                                                    mbMessageModelImpl.getStatus()
19702                                            };
19703    
19704                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19705                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19706                                            args);
19707                            }
19708    
19709                            if ((mbMessageModelImpl.getColumnBitmask() &
19710                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19711                                    Object[] args = new Object[] {
19712                                                    mbMessageModelImpl.getOriginalUserId(),
19713                                                    mbMessageModelImpl.getOriginalClassNameId(),
19714                                                    mbMessageModelImpl.getOriginalClassPK(),
19715                                                    mbMessageModelImpl.getOriginalStatus()
19716                                            };
19717    
19718                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19719                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19720                                            args);
19721    
19722                                    args = new Object[] {
19723                                                    mbMessageModelImpl.getUserId(),
19724                                                    mbMessageModelImpl.getClassNameId(),
19725                                                    mbMessageModelImpl.getClassPK(),
19726                                                    mbMessageModelImpl.getStatus()
19727                                            };
19728    
19729                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19730                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19731                                            args);
19732                            }
19733                    }
19734    
19735                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19736                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
19737    
19738                    clearUniqueFindersCache(mbMessageModelImpl);
19739                    cacheUniqueFindersCache(mbMessageModelImpl, isNew);
19740    
19741                    mbMessage.resetOriginalValues();
19742    
19743                    return mbMessage;
19744            }
19745    
19746            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19747                    if (mbMessage instanceof MBMessageImpl) {
19748                            return mbMessage;
19749                    }
19750    
19751                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19752    
19753                    mbMessageImpl.setNew(mbMessage.isNew());
19754                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19755    
19756                    mbMessageImpl.setUuid(mbMessage.getUuid());
19757                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19758                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19759                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19760                    mbMessageImpl.setUserId(mbMessage.getUserId());
19761                    mbMessageImpl.setUserName(mbMessage.getUserName());
19762                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19763                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19764                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19765                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19766                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19767                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19768                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19769                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19770                    mbMessageImpl.setSubject(mbMessage.getSubject());
19771                    mbMessageImpl.setBody(mbMessage.getBody());
19772                    mbMessageImpl.setFormat(mbMessage.getFormat());
19773                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19774                    mbMessageImpl.setPriority(mbMessage.getPriority());
19775                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19776                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19777                    mbMessageImpl.setLastPublishDate(mbMessage.getLastPublishDate());
19778                    mbMessageImpl.setStatus(mbMessage.getStatus());
19779                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19780                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19781                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19782    
19783                    return mbMessageImpl;
19784            }
19785    
19786            /**
19787             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19788             *
19789             * @param primaryKey the primary key of the message-boards message
19790             * @return the message-boards message
19791             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19792             */
19793            @Override
19794            public MBMessage findByPrimaryKey(Serializable primaryKey)
19795                    throws NoSuchMessageException {
19796                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19797    
19798                    if (mbMessage == null) {
19799                            if (_log.isWarnEnabled()) {
19800                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19801                            }
19802    
19803                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19804                                    primaryKey);
19805                    }
19806    
19807                    return mbMessage;
19808            }
19809    
19810            /**
19811             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19812             *
19813             * @param messageId the primary key of the message-boards message
19814             * @return the message-boards message
19815             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19816             */
19817            @Override
19818            public MBMessage findByPrimaryKey(long messageId)
19819                    throws NoSuchMessageException {
19820                    return findByPrimaryKey((Serializable)messageId);
19821            }
19822    
19823            /**
19824             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19825             *
19826             * @param primaryKey the primary key of the message-boards message
19827             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19828             */
19829            @Override
19830            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19831                    MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19832                                    MBMessageImpl.class, primaryKey);
19833    
19834                    if (mbMessage == _nullMBMessage) {
19835                            return null;
19836                    }
19837    
19838                    if (mbMessage == null) {
19839                            Session session = null;
19840    
19841                            try {
19842                                    session = openSession();
19843    
19844                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19845                                                    primaryKey);
19846    
19847                                    if (mbMessage != null) {
19848                                            cacheResult(mbMessage);
19849                                    }
19850                                    else {
19851                                            entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19852                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19853                                    }
19854                            }
19855                            catch (Exception e) {
19856                                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19857                                            MBMessageImpl.class, primaryKey);
19858    
19859                                    throw processException(e);
19860                            }
19861                            finally {
19862                                    closeSession(session);
19863                            }
19864                    }
19865    
19866                    return mbMessage;
19867            }
19868    
19869            /**
19870             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19871             *
19872             * @param messageId the primary key of the message-boards message
19873             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19874             */
19875            @Override
19876            public MBMessage fetchByPrimaryKey(long messageId) {
19877                    return fetchByPrimaryKey((Serializable)messageId);
19878            }
19879    
19880            @Override
19881            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19882                    Set<Serializable> primaryKeys) {
19883                    if (primaryKeys.isEmpty()) {
19884                            return Collections.emptyMap();
19885                    }
19886    
19887                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19888    
19889                    if (primaryKeys.size() == 1) {
19890                            Iterator<Serializable> iterator = primaryKeys.iterator();
19891    
19892                            Serializable primaryKey = iterator.next();
19893    
19894                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19895    
19896                            if (mbMessage != null) {
19897                                    map.put(primaryKey, mbMessage);
19898                            }
19899    
19900                            return map;
19901                    }
19902    
19903                    Set<Serializable> uncachedPrimaryKeys = null;
19904    
19905                    for (Serializable primaryKey : primaryKeys) {
19906                            MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19907                                            MBMessageImpl.class, primaryKey);
19908    
19909                            if (mbMessage == null) {
19910                                    if (uncachedPrimaryKeys == null) {
19911                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19912                                    }
19913    
19914                                    uncachedPrimaryKeys.add(primaryKey);
19915                            }
19916                            else {
19917                                    map.put(primaryKey, mbMessage);
19918                            }
19919                    }
19920    
19921                    if (uncachedPrimaryKeys == null) {
19922                            return map;
19923                    }
19924    
19925                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19926                                    1);
19927    
19928                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19929    
19930                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19931                            query.append(String.valueOf(primaryKey));
19932    
19933                            query.append(StringPool.COMMA);
19934                    }
19935    
19936                    query.setIndex(query.index() - 1);
19937    
19938                    query.append(StringPool.CLOSE_PARENTHESIS);
19939    
19940                    String sql = query.toString();
19941    
19942                    Session session = null;
19943    
19944                    try {
19945                            session = openSession();
19946    
19947                            Query q = session.createQuery(sql);
19948    
19949                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19950                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19951    
19952                                    cacheResult(mbMessage);
19953    
19954                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19955                            }
19956    
19957                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19958                                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19959                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
19960                            }
19961                    }
19962                    catch (Exception e) {
19963                            throw processException(e);
19964                    }
19965                    finally {
19966                            closeSession(session);
19967                    }
19968    
19969                    return map;
19970            }
19971    
19972            /**
19973             * Returns all the message-boards messages.
19974             *
19975             * @return the message-boards messages
19976             */
19977            @Override
19978            public List<MBMessage> findAll() {
19979                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19980            }
19981    
19982            /**
19983             * Returns a range of all the message-boards messages.
19984             *
19985             * <p>
19986             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
19987             * </p>
19988             *
19989             * @param start the lower bound of the range of message-boards messages
19990             * @param end the upper bound of the range of message-boards messages (not inclusive)
19991             * @return the range of message-boards messages
19992             */
19993            @Override
19994            public List<MBMessage> findAll(int start, int end) {
19995                    return findAll(start, end, null);
19996            }
19997    
19998            /**
19999             * Returns an ordered range of all the message-boards messages.
20000             *
20001             * <p>
20002             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
20003             * </p>
20004             *
20005             * @param start the lower bound of the range of message-boards messages
20006             * @param end the upper bound of the range of message-boards messages (not inclusive)
20007             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20008             * @return the ordered range of message-boards messages
20009             */
20010            @Override
20011            public List<MBMessage> findAll(int start, int end,
20012                    OrderByComparator<MBMessage> orderByComparator) {
20013                    return findAll(start, end, orderByComparator, true);
20014            }
20015    
20016            /**
20017             * Returns an ordered range of all the message-boards messages.
20018             *
20019             * <p>
20020             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
20021             * </p>
20022             *
20023             * @param start the lower bound of the range of message-boards messages
20024             * @param end the upper bound of the range of message-boards messages (not inclusive)
20025             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20026             * @param retrieveFromCache whether to retrieve from the finder cache
20027             * @return the ordered range of message-boards messages
20028             */
20029            @Override
20030            public List<MBMessage> findAll(int start, int end,
20031                    OrderByComparator<MBMessage> orderByComparator,
20032                    boolean retrieveFromCache) {
20033                    boolean pagination = true;
20034                    FinderPath finderPath = null;
20035                    Object[] finderArgs = null;
20036    
20037                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20038                                    (orderByComparator == null)) {
20039                            pagination = false;
20040                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20041                            finderArgs = FINDER_ARGS_EMPTY;
20042                    }
20043                    else {
20044                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20045                            finderArgs = new Object[] { start, end, orderByComparator };
20046                    }
20047    
20048                    List<MBMessage> list = null;
20049    
20050                    if (retrieveFromCache) {
20051                            list = (List<MBMessage>)finderCache.getResult(finderPath,
20052                                            finderArgs, this);
20053                    }
20054    
20055                    if (list == null) {
20056                            StringBundler query = null;
20057                            String sql = null;
20058    
20059                            if (orderByComparator != null) {
20060                                    query = new StringBundler(2 +
20061                                                    (orderByComparator.getOrderByFields().length * 3));
20062    
20063                                    query.append(_SQL_SELECT_MBMESSAGE);
20064    
20065                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20066                                            orderByComparator);
20067    
20068                                    sql = query.toString();
20069                            }
20070                            else {
20071                                    sql = _SQL_SELECT_MBMESSAGE;
20072    
20073                                    if (pagination) {
20074                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20075                                    }
20076                            }
20077    
20078                            Session session = null;
20079    
20080                            try {
20081                                    session = openSession();
20082    
20083                                    Query q = session.createQuery(sql);
20084    
20085                                    if (!pagination) {
20086                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20087                                                            start, end, false);
20088    
20089                                            Collections.sort(list);
20090    
20091                                            list = Collections.unmodifiableList(list);
20092                                    }
20093                                    else {
20094                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20095                                                            start, end);
20096                                    }
20097    
20098                                    cacheResult(list);
20099    
20100                                    finderCache.putResult(finderPath, finderArgs, list);
20101                            }
20102                            catch (Exception e) {
20103                                    finderCache.removeResult(finderPath, finderArgs);
20104    
20105                                    throw processException(e);
20106                            }
20107                            finally {
20108                                    closeSession(session);
20109                            }
20110                    }
20111    
20112                    return list;
20113            }
20114    
20115            /**
20116             * Removes all the message-boards messages from the database.
20117             *
20118             */
20119            @Override
20120            public void removeAll() {
20121                    for (MBMessage mbMessage : findAll()) {
20122                            remove(mbMessage);
20123                    }
20124            }
20125    
20126            /**
20127             * Returns the number of message-boards messages.
20128             *
20129             * @return the number of message-boards messages
20130             */
20131            @Override
20132            public int countAll() {
20133                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
20134                                    FINDER_ARGS_EMPTY, this);
20135    
20136                    if (count == null) {
20137                            Session session = null;
20138    
20139                            try {
20140                                    session = openSession();
20141    
20142                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20143    
20144                                    count = (Long)q.uniqueResult();
20145    
20146                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
20147                                            count);
20148                            }
20149                            catch (Exception e) {
20150                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
20151                                            FINDER_ARGS_EMPTY);
20152    
20153                                    throw processException(e);
20154                            }
20155                            finally {
20156                                    closeSession(session);
20157                            }
20158                    }
20159    
20160                    return count.intValue();
20161            }
20162    
20163            @Override
20164            public Set<String> getBadColumnNames() {
20165                    return _badColumnNames;
20166            }
20167    
20168            @Override
20169            protected Map<String, Integer> getTableColumnsMap() {
20170                    return MBMessageModelImpl.TABLE_COLUMNS_MAP;
20171            }
20172    
20173            /**
20174             * Initializes the message-boards message persistence.
20175             */
20176            public void afterPropertiesSet() {
20177            }
20178    
20179            public void destroy() {
20180                    entityCache.removeCache(MBMessageImpl.class.getName());
20181                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
20182                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20183                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20184            }
20185    
20186            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
20187            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
20188            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
20189            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
20190            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
20191            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
20192            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
20193            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
20194            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
20195            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
20196                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
20197            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
20198                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
20199            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
20200            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
20201            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
20202            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
20203            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
20204            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
20205            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
20206            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
20207            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
20208                                    "uuid"
20209                            });
20210            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
20211                            @Override
20212                            public Object clone() {
20213                                    return this;
20214                            }
20215    
20216                            @Override
20217                            public CacheModel<MBMessage> toCacheModel() {
20218                                    return _nullMBMessageCacheModel;
20219                            }
20220                    };
20221    
20222            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
20223                            @Override
20224                            public MBMessage toEntityModel() {
20225                                    return _nullMBMessage;
20226                            }
20227                    };
20228    }