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.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.exception.SystemException;
031    import com.liferay.portal.kernel.log.Log;
032    import com.liferay.portal.kernel.log.LogFactoryUtil;
033    import com.liferay.portal.kernel.sanitizer.Sanitizer;
034    import com.liferay.portal.kernel.sanitizer.SanitizerException;
035    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
036    import com.liferay.portal.kernel.util.ArrayUtil;
037    import com.liferay.portal.kernel.util.ContentTypes;
038    import com.liferay.portal.kernel.util.GetterUtil;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
046    import com.liferay.portal.model.CacheModel;
047    import com.liferay.portal.security.auth.PrincipalThreadLocal;
048    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
049    import com.liferay.portal.service.ServiceContext;
050    import com.liferay.portal.service.ServiceContextThreadLocal;
051    import com.liferay.portal.service.persistence.CompanyProvider;
052    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
053    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
054    
055    import com.liferay.portlet.messageboards.exception.NoSuchMessageException;
056    import com.liferay.portlet.messageboards.model.MBMessage;
057    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
058    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
059    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
060    
061    import java.io.Serializable;
062    
063    import java.util.Arrays;
064    import java.util.Collections;
065    import java.util.Date;
066    import java.util.HashMap;
067    import java.util.HashSet;
068    import java.util.Iterator;
069    import java.util.List;
070    import java.util.Map;
071    import java.util.Set;
072    
073    /**
074     * The persistence implementation for the message-boards message service.
075     *
076     * <p>
077     * Caching information and settings can be found in <code>portal.properties</code>
078     * </p>
079     *
080     * @author Brian Wing Shun Chan
081     * @see MBMessagePersistence
082     * @see com.liferay.portlet.messageboards.service.persistence.MBMessageUtil
083     * @generated
084     */
085    @ProviderType
086    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
087            implements MBMessagePersistence {
088            /*
089             * NOTE FOR DEVELOPERS:
090             *
091             * 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.
092             */
093            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
094            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
095                    ".List1";
096            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
097                    ".List2";
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
099                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
104            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
105                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
108                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
109                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
110                            new String[] {
111                                    String.class.getName(),
112                                    
113                            Integer.class.getName(), Integer.class.getName(),
114                                    OrderByComparator.class.getName()
115                            });
116            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
119                            new String[] { String.class.getName() },
120                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
121                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
122            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
123                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
125                            new String[] { String.class.getName() });
126    
127            /**
128             * Returns all the message-boards messages where uuid = &#63;.
129             *
130             * @param uuid the uuid
131             * @return the matching message-boards messages
132             */
133            @Override
134            public List<MBMessage> findByUuid(String uuid) {
135                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
136            }
137    
138            /**
139             * Returns a range of all the message-boards messages where uuid = &#63;.
140             *
141             * <p>
142             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
143             * </p>
144             *
145             * @param uuid the uuid
146             * @param start the lower bound of the range of message-boards messages
147             * @param end the upper bound of the range of message-boards messages (not inclusive)
148             * @return the range of matching message-boards messages
149             */
150            @Override
151            public List<MBMessage> findByUuid(String uuid, int start, int end) {
152                    return findByUuid(uuid, start, end, null);
153            }
154    
155            /**
156             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
157             *
158             * <p>
159             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
160             * </p>
161             *
162             * @param uuid the uuid
163             * @param start the lower bound of the range of message-boards messages
164             * @param end the upper bound of the range of message-boards messages (not inclusive)
165             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
166             * @return the ordered range of matching message-boards messages
167             */
168            @Override
169            public List<MBMessage> findByUuid(String uuid, int start, int end,
170                    OrderByComparator<MBMessage> orderByComparator) {
171                    return findByUuid(uuid, start, end, orderByComparator, true);
172            }
173    
174            /**
175             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
176             *
177             * <p>
178             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
179             * </p>
180             *
181             * @param uuid the uuid
182             * @param start the lower bound of the range of message-boards messages
183             * @param end the upper bound of the range of message-boards messages (not inclusive)
184             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
185             * @param retrieveFromCache whether to retrieve from the finder cache
186             * @return the ordered range of matching message-boards messages
187             */
188            @Override
189            public List<MBMessage> findByUuid(String uuid, int start, int end,
190                    OrderByComparator<MBMessage> orderByComparator,
191                    boolean retrieveFromCache) {
192                    boolean pagination = true;
193                    FinderPath finderPath = null;
194                    Object[] finderArgs = null;
195    
196                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
197                                    (orderByComparator == null)) {
198                            pagination = false;
199                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
200                            finderArgs = new Object[] { uuid };
201                    }
202                    else {
203                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
204                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
205                    }
206    
207                    List<MBMessage> list = null;
208    
209                    if (retrieveFromCache) {
210                            list = (List<MBMessage>)finderCache.getResult(finderPath,
211                                            finderArgs, this);
212    
213                            if ((list != null) && !list.isEmpty()) {
214                                    for (MBMessage mbMessage : list) {
215                                            if (!Validator.equals(uuid, mbMessage.getUuid())) {
216                                                    list = null;
217    
218                                                    break;
219                                            }
220                                    }
221                            }
222                    }
223    
224                    if (list == null) {
225                            StringBundler query = null;
226    
227                            if (orderByComparator != null) {
228                                    query = new StringBundler(3 +
229                                                    (orderByComparator.getOrderByFields().length * 3));
230                            }
231                            else {
232                                    query = new StringBundler(3);
233                            }
234    
235                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
236    
237                            boolean bindUuid = false;
238    
239                            if (uuid == null) {
240                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
241                            }
242                            else if (uuid.equals(StringPool.BLANK)) {
243                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
244                            }
245                            else {
246                                    bindUuid = true;
247    
248                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
249                            }
250    
251                            if (orderByComparator != null) {
252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
253                                            orderByComparator);
254                            }
255                            else
256                             if (pagination) {
257                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
258                            }
259    
260                            String sql = query.toString();
261    
262                            Session session = null;
263    
264                            try {
265                                    session = openSession();
266    
267                                    Query q = session.createQuery(sql);
268    
269                                    QueryPos qPos = QueryPos.getInstance(q);
270    
271                                    if (bindUuid) {
272                                            qPos.add(uuid);
273                                    }
274    
275                                    if (!pagination) {
276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
277                                                            start, end, false);
278    
279                                            Collections.sort(list);
280    
281                                            list = Collections.unmodifiableList(list);
282                                    }
283                                    else {
284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
285                                                            start, end);
286                                    }
287    
288                                    cacheResult(list);
289    
290                                    finderCache.putResult(finderPath, finderArgs, list);
291                            }
292                            catch (Exception e) {
293                                    finderCache.removeResult(finderPath, finderArgs);
294    
295                                    throw processException(e);
296                            }
297                            finally {
298                                    closeSession(session);
299                            }
300                    }
301    
302                    return list;
303            }
304    
305            /**
306             * Returns the first message-boards message in the ordered set where uuid = &#63;.
307             *
308             * @param uuid the uuid
309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
310             * @return the first matching message-boards message
311             * @throws NoSuchMessageException if a matching message-boards message could not be found
312             */
313            @Override
314            public MBMessage findByUuid_First(String uuid,
315                    OrderByComparator<MBMessage> orderByComparator)
316                    throws NoSuchMessageException {
317                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
318    
319                    if (mbMessage != null) {
320                            return mbMessage;
321                    }
322    
323                    StringBundler msg = new StringBundler(4);
324    
325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
326    
327                    msg.append("uuid=");
328                    msg.append(uuid);
329    
330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
331    
332                    throw new NoSuchMessageException(msg.toString());
333            }
334    
335            /**
336             * Returns the first message-boards message in the ordered set where uuid = &#63;.
337             *
338             * @param uuid the uuid
339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
340             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
341             */
342            @Override
343            public MBMessage fetchByUuid_First(String uuid,
344                    OrderByComparator<MBMessage> orderByComparator) {
345                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
346    
347                    if (!list.isEmpty()) {
348                            return list.get(0);
349                    }
350    
351                    return null;
352            }
353    
354            /**
355             * Returns the last message-boards message in the ordered set where uuid = &#63;.
356             *
357             * @param uuid the uuid
358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
359             * @return the last matching message-boards message
360             * @throws NoSuchMessageException if a matching message-boards message could not be found
361             */
362            @Override
363            public MBMessage findByUuid_Last(String uuid,
364                    OrderByComparator<MBMessage> orderByComparator)
365                    throws NoSuchMessageException {
366                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
367    
368                    if (mbMessage != null) {
369                            return mbMessage;
370                    }
371    
372                    StringBundler msg = new StringBundler(4);
373    
374                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
375    
376                    msg.append("uuid=");
377                    msg.append(uuid);
378    
379                    msg.append(StringPool.CLOSE_CURLY_BRACE);
380    
381                    throw new NoSuchMessageException(msg.toString());
382            }
383    
384            /**
385             * Returns the last message-boards message in the ordered set where uuid = &#63;.
386             *
387             * @param uuid the uuid
388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
389             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
390             */
391            @Override
392            public MBMessage fetchByUuid_Last(String uuid,
393                    OrderByComparator<MBMessage> orderByComparator) {
394                    int count = countByUuid(uuid);
395    
396                    if (count == 0) {
397                            return null;
398                    }
399    
400                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
401                                    orderByComparator);
402    
403                    if (!list.isEmpty()) {
404                            return list.get(0);
405                    }
406    
407                    return null;
408            }
409    
410            /**
411             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
412             *
413             * @param messageId the primary key of the current message-boards message
414             * @param uuid the uuid
415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
416             * @return the previous, current, and next message-boards message
417             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
418             */
419            @Override
420            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
421                    OrderByComparator<MBMessage> orderByComparator)
422                    throws NoSuchMessageException {
423                    MBMessage mbMessage = findByPrimaryKey(messageId);
424    
425                    Session session = null;
426    
427                    try {
428                            session = openSession();
429    
430                            MBMessage[] array = new MBMessageImpl[3];
431    
432                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
433                                            orderByComparator, true);
434    
435                            array[1] = mbMessage;
436    
437                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
438                                            orderByComparator, false);
439    
440                            return array;
441                    }
442                    catch (Exception e) {
443                            throw processException(e);
444                    }
445                    finally {
446                            closeSession(session);
447                    }
448            }
449    
450            protected MBMessage getByUuid_PrevAndNext(Session session,
451                    MBMessage mbMessage, String uuid,
452                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
453                    StringBundler query = null;
454    
455                    if (orderByComparator != null) {
456                            query = new StringBundler(6 +
457                                            (orderByComparator.getOrderByFields().length * 6));
458                    }
459                    else {
460                            query = new StringBundler(3);
461                    }
462    
463                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
464    
465                    boolean bindUuid = false;
466    
467                    if (uuid == null) {
468                            query.append(_FINDER_COLUMN_UUID_UUID_1);
469                    }
470                    else if (uuid.equals(StringPool.BLANK)) {
471                            query.append(_FINDER_COLUMN_UUID_UUID_3);
472                    }
473                    else {
474                            bindUuid = true;
475    
476                            query.append(_FINDER_COLUMN_UUID_UUID_2);
477                    }
478    
479                    if (orderByComparator != null) {
480                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
481    
482                            if (orderByConditionFields.length > 0) {
483                                    query.append(WHERE_AND);
484                            }
485    
486                            for (int i = 0; i < orderByConditionFields.length; i++) {
487                                    query.append(_ORDER_BY_ENTITY_ALIAS);
488                                    query.append(orderByConditionFields[i]);
489    
490                                    if ((i + 1) < orderByConditionFields.length) {
491                                            if (orderByComparator.isAscending() ^ previous) {
492                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
493                                            }
494                                            else {
495                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
496                                            }
497                                    }
498                                    else {
499                                            if (orderByComparator.isAscending() ^ previous) {
500                                                    query.append(WHERE_GREATER_THAN);
501                                            }
502                                            else {
503                                                    query.append(WHERE_LESSER_THAN);
504                                            }
505                                    }
506                            }
507    
508                            query.append(ORDER_BY_CLAUSE);
509    
510                            String[] orderByFields = orderByComparator.getOrderByFields();
511    
512                            for (int i = 0; i < orderByFields.length; i++) {
513                                    query.append(_ORDER_BY_ENTITY_ALIAS);
514                                    query.append(orderByFields[i]);
515    
516                                    if ((i + 1) < orderByFields.length) {
517                                            if (orderByComparator.isAscending() ^ previous) {
518                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
519                                            }
520                                            else {
521                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
522                                            }
523                                    }
524                                    else {
525                                            if (orderByComparator.isAscending() ^ previous) {
526                                                    query.append(ORDER_BY_ASC);
527                                            }
528                                            else {
529                                                    query.append(ORDER_BY_DESC);
530                                            }
531                                    }
532                            }
533                    }
534                    else {
535                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
536                    }
537    
538                    String sql = query.toString();
539    
540                    Query q = session.createQuery(sql);
541    
542                    q.setFirstResult(0);
543                    q.setMaxResults(2);
544    
545                    QueryPos qPos = QueryPos.getInstance(q);
546    
547                    if (bindUuid) {
548                            qPos.add(uuid);
549                    }
550    
551                    if (orderByComparator != null) {
552                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
553    
554                            for (Object value : values) {
555                                    qPos.add(value);
556                            }
557                    }
558    
559                    List<MBMessage> list = q.list();
560    
561                    if (list.size() == 2) {
562                            return list.get(1);
563                    }
564                    else {
565                            return null;
566                    }
567            }
568    
569            /**
570             * Removes all the message-boards messages where uuid = &#63; from the database.
571             *
572             * @param uuid the uuid
573             */
574            @Override
575            public void removeByUuid(String uuid) {
576                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
577                                    QueryUtil.ALL_POS, null)) {
578                            remove(mbMessage);
579                    }
580            }
581    
582            /**
583             * Returns the number of message-boards messages where uuid = &#63;.
584             *
585             * @param uuid the uuid
586             * @return the number of matching message-boards messages
587             */
588            @Override
589            public int countByUuid(String uuid) {
590                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
591    
592                    Object[] finderArgs = new Object[] { uuid };
593    
594                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
595    
596                    if (count == null) {
597                            StringBundler query = new StringBundler(2);
598    
599                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
600    
601                            boolean bindUuid = false;
602    
603                            if (uuid == null) {
604                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
605                            }
606                            else if (uuid.equals(StringPool.BLANK)) {
607                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
608                            }
609                            else {
610                                    bindUuid = true;
611    
612                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
613                            }
614    
615                            String sql = query.toString();
616    
617                            Session session = null;
618    
619                            try {
620                                    session = openSession();
621    
622                                    Query q = session.createQuery(sql);
623    
624                                    QueryPos qPos = QueryPos.getInstance(q);
625    
626                                    if (bindUuid) {
627                                            qPos.add(uuid);
628                                    }
629    
630                                    count = (Long)q.uniqueResult();
631    
632                                    finderCache.putResult(finderPath, finderArgs, count);
633                            }
634                            catch (Exception e) {
635                                    finderCache.removeResult(finderPath, finderArgs);
636    
637                                    throw processException(e);
638                            }
639                            finally {
640                                    closeSession(session);
641                            }
642                    }
643    
644                    return count.intValue();
645            }
646    
647            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
648            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
649            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
650            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
651                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
652                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
653                            new String[] { String.class.getName(), Long.class.getName() },
654                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
655                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
656            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
657                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
658                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
659                            new String[] { String.class.getName(), Long.class.getName() });
660    
661            /**
662             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
663             *
664             * @param uuid the uuid
665             * @param groupId the group ID
666             * @return the matching message-boards message
667             * @throws NoSuchMessageException if a matching message-boards message could not be found
668             */
669            @Override
670            public MBMessage findByUUID_G(String uuid, long groupId)
671                    throws NoSuchMessageException {
672                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
673    
674                    if (mbMessage == null) {
675                            StringBundler msg = new StringBundler(6);
676    
677                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
678    
679                            msg.append("uuid=");
680                            msg.append(uuid);
681    
682                            msg.append(", groupId=");
683                            msg.append(groupId);
684    
685                            msg.append(StringPool.CLOSE_CURLY_BRACE);
686    
687                            if (_log.isWarnEnabled()) {
688                                    _log.warn(msg.toString());
689                            }
690    
691                            throw new NoSuchMessageException(msg.toString());
692                    }
693    
694                    return mbMessage;
695            }
696    
697            /**
698             * 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.
699             *
700             * @param uuid the uuid
701             * @param groupId the group ID
702             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
703             */
704            @Override
705            public MBMessage fetchByUUID_G(String uuid, long groupId) {
706                    return fetchByUUID_G(uuid, groupId, true);
707            }
708    
709            /**
710             * 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.
711             *
712             * @param uuid the uuid
713             * @param groupId the group ID
714             * @param retrieveFromCache whether to retrieve from the finder cache
715             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
716             */
717            @Override
718            public MBMessage fetchByUUID_G(String uuid, long groupId,
719                    boolean retrieveFromCache) {
720                    Object[] finderArgs = new Object[] { uuid, groupId };
721    
722                    Object result = null;
723    
724                    if (retrieveFromCache) {
725                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
726                                            finderArgs, this);
727                    }
728    
729                    if (result instanceof MBMessage) {
730                            MBMessage mbMessage = (MBMessage)result;
731    
732                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
733                                            (groupId != mbMessage.getGroupId())) {
734                                    result = null;
735                            }
736                    }
737    
738                    if (result == null) {
739                            StringBundler query = new StringBundler(4);
740    
741                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
742    
743                            boolean bindUuid = false;
744    
745                            if (uuid == null) {
746                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
747                            }
748                            else if (uuid.equals(StringPool.BLANK)) {
749                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
750                            }
751                            else {
752                                    bindUuid = true;
753    
754                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
755                            }
756    
757                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
758    
759                            String sql = query.toString();
760    
761                            Session session = null;
762    
763                            try {
764                                    session = openSession();
765    
766                                    Query q = session.createQuery(sql);
767    
768                                    QueryPos qPos = QueryPos.getInstance(q);
769    
770                                    if (bindUuid) {
771                                            qPos.add(uuid);
772                                    }
773    
774                                    qPos.add(groupId);
775    
776                                    List<MBMessage> list = q.list();
777    
778                                    if (list.isEmpty()) {
779                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
780                                                    finderArgs, list);
781                                    }
782                                    else {
783                                            MBMessage mbMessage = list.get(0);
784    
785                                            result = mbMessage;
786    
787                                            cacheResult(mbMessage);
788    
789                                            if ((mbMessage.getUuid() == null) ||
790                                                            !mbMessage.getUuid().equals(uuid) ||
791                                                            (mbMessage.getGroupId() != groupId)) {
792                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
793                                                            finderArgs, mbMessage);
794                                            }
795                                    }
796                            }
797                            catch (Exception e) {
798                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
799    
800                                    throw processException(e);
801                            }
802                            finally {
803                                    closeSession(session);
804                            }
805                    }
806    
807                    if (result instanceof List<?>) {
808                            return null;
809                    }
810                    else {
811                            return (MBMessage)result;
812                    }
813            }
814    
815            /**
816             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
817             *
818             * @param uuid the uuid
819             * @param groupId the group ID
820             * @return the message-boards message that was removed
821             */
822            @Override
823            public MBMessage removeByUUID_G(String uuid, long groupId)
824                    throws NoSuchMessageException {
825                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
826    
827                    return remove(mbMessage);
828            }
829    
830            /**
831             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
832             *
833             * @param uuid the uuid
834             * @param groupId the group ID
835             * @return the number of matching message-boards messages
836             */
837            @Override
838            public int countByUUID_G(String uuid, long groupId) {
839                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
840    
841                    Object[] finderArgs = new Object[] { uuid, groupId };
842    
843                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
844    
845                    if (count == null) {
846                            StringBundler query = new StringBundler(3);
847    
848                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
849    
850                            boolean bindUuid = false;
851    
852                            if (uuid == null) {
853                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
854                            }
855                            else if (uuid.equals(StringPool.BLANK)) {
856                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
857                            }
858                            else {
859                                    bindUuid = true;
860    
861                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
862                            }
863    
864                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
865    
866                            String sql = query.toString();
867    
868                            Session session = null;
869    
870                            try {
871                                    session = openSession();
872    
873                                    Query q = session.createQuery(sql);
874    
875                                    QueryPos qPos = QueryPos.getInstance(q);
876    
877                                    if (bindUuid) {
878                                            qPos.add(uuid);
879                                    }
880    
881                                    qPos.add(groupId);
882    
883                                    count = (Long)q.uniqueResult();
884    
885                                    finderCache.putResult(finderPath, finderArgs, count);
886                            }
887                            catch (Exception e) {
888                                    finderCache.removeResult(finderPath, finderArgs);
889    
890                                    throw processException(e);
891                            }
892                            finally {
893                                    closeSession(session);
894                            }
895                    }
896    
897                    return count.intValue();
898            }
899    
900            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
901            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
902            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
903            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
904            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
905                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
906                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
907                            new String[] {
908                                    String.class.getName(), Long.class.getName(),
909                                    
910                            Integer.class.getName(), Integer.class.getName(),
911                                    OrderByComparator.class.getName()
912                            });
913            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
914                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
915                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
916                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
917                            new String[] { String.class.getName(), Long.class.getName() },
918                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
919                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
920                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
921            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
922                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
923                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
924                            new String[] { String.class.getName(), Long.class.getName() });
925    
926            /**
927             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
928             *
929             * @param uuid the uuid
930             * @param companyId the company ID
931             * @return the matching message-boards messages
932             */
933            @Override
934            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
935                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
936                            QueryUtil.ALL_POS, null);
937            }
938    
939            /**
940             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
941             *
942             * <p>
943             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
944             * </p>
945             *
946             * @param uuid the uuid
947             * @param companyId the company ID
948             * @param start the lower bound of the range of message-boards messages
949             * @param end the upper bound of the range of message-boards messages (not inclusive)
950             * @return the range of matching message-boards messages
951             */
952            @Override
953            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
954                    int end) {
955                    return findByUuid_C(uuid, companyId, start, end, null);
956            }
957    
958            /**
959             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
960             *
961             * <p>
962             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
963             * </p>
964             *
965             * @param uuid the uuid
966             * @param companyId the company ID
967             * @param start the lower bound of the range of message-boards messages
968             * @param end the upper bound of the range of message-boards messages (not inclusive)
969             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
970             * @return the ordered range of matching message-boards messages
971             */
972            @Override
973            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
974                    int end, OrderByComparator<MBMessage> orderByComparator) {
975                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
976            }
977    
978            /**
979             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
980             *
981             * <p>
982             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
983             * </p>
984             *
985             * @param uuid the uuid
986             * @param companyId the company ID
987             * @param start the lower bound of the range of message-boards messages
988             * @param end the upper bound of the range of message-boards messages (not inclusive)
989             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
990             * @param retrieveFromCache whether to retrieve from the finder cache
991             * @return the ordered range of matching message-boards messages
992             */
993            @Override
994            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
995                    int end, OrderByComparator<MBMessage> orderByComparator,
996                    boolean retrieveFromCache) {
997                    boolean pagination = true;
998                    FinderPath finderPath = null;
999                    Object[] finderArgs = null;
1000    
1001                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1002                                    (orderByComparator == null)) {
1003                            pagination = false;
1004                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1005                            finderArgs = new Object[] { uuid, companyId };
1006                    }
1007                    else {
1008                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1009                            finderArgs = new Object[] {
1010                                            uuid, companyId,
1011                                            
1012                                            start, end, orderByComparator
1013                                    };
1014                    }
1015    
1016                    List<MBMessage> list = null;
1017    
1018                    if (retrieveFromCache) {
1019                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1020                                            finderArgs, this);
1021    
1022                            if ((list != null) && !list.isEmpty()) {
1023                                    for (MBMessage mbMessage : list) {
1024                                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
1025                                                            (companyId != mbMessage.getCompanyId())) {
1026                                                    list = null;
1027    
1028                                                    break;
1029                                            }
1030                                    }
1031                            }
1032                    }
1033    
1034                    if (list == null) {
1035                            StringBundler query = null;
1036    
1037                            if (orderByComparator != null) {
1038                                    query = new StringBundler(4 +
1039                                                    (orderByComparator.getOrderByFields().length * 3));
1040                            }
1041                            else {
1042                                    query = new StringBundler(4);
1043                            }
1044    
1045                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1046    
1047                            boolean bindUuid = false;
1048    
1049                            if (uuid == null) {
1050                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1051                            }
1052                            else if (uuid.equals(StringPool.BLANK)) {
1053                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1054                            }
1055                            else {
1056                                    bindUuid = true;
1057    
1058                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1059                            }
1060    
1061                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1062    
1063                            if (orderByComparator != null) {
1064                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1065                                            orderByComparator);
1066                            }
1067                            else
1068                             if (pagination) {
1069                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1070                            }
1071    
1072                            String sql = query.toString();
1073    
1074                            Session session = null;
1075    
1076                            try {
1077                                    session = openSession();
1078    
1079                                    Query q = session.createQuery(sql);
1080    
1081                                    QueryPos qPos = QueryPos.getInstance(q);
1082    
1083                                    if (bindUuid) {
1084                                            qPos.add(uuid);
1085                                    }
1086    
1087                                    qPos.add(companyId);
1088    
1089                                    if (!pagination) {
1090                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1091                                                            start, end, false);
1092    
1093                                            Collections.sort(list);
1094    
1095                                            list = Collections.unmodifiableList(list);
1096                                    }
1097                                    else {
1098                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1099                                                            start, end);
1100                                    }
1101    
1102                                    cacheResult(list);
1103    
1104                                    finderCache.putResult(finderPath, finderArgs, list);
1105                            }
1106                            catch (Exception e) {
1107                                    finderCache.removeResult(finderPath, finderArgs);
1108    
1109                                    throw processException(e);
1110                            }
1111                            finally {
1112                                    closeSession(session);
1113                            }
1114                    }
1115    
1116                    return list;
1117            }
1118    
1119            /**
1120             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1121             *
1122             * @param uuid the uuid
1123             * @param companyId the company ID
1124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1125             * @return the first matching message-boards message
1126             * @throws NoSuchMessageException if a matching message-boards message could not be found
1127             */
1128            @Override
1129            public MBMessage findByUuid_C_First(String uuid, long companyId,
1130                    OrderByComparator<MBMessage> orderByComparator)
1131                    throws NoSuchMessageException {
1132                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1133                                    orderByComparator);
1134    
1135                    if (mbMessage != null) {
1136                            return mbMessage;
1137                    }
1138    
1139                    StringBundler msg = new StringBundler(6);
1140    
1141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1142    
1143                    msg.append("uuid=");
1144                    msg.append(uuid);
1145    
1146                    msg.append(", companyId=");
1147                    msg.append(companyId);
1148    
1149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1150    
1151                    throw new NoSuchMessageException(msg.toString());
1152            }
1153    
1154            /**
1155             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1156             *
1157             * @param uuid the uuid
1158             * @param companyId the company ID
1159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1160             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1161             */
1162            @Override
1163            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1164                    OrderByComparator<MBMessage> orderByComparator) {
1165                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1166                                    orderByComparator);
1167    
1168                    if (!list.isEmpty()) {
1169                            return list.get(0);
1170                    }
1171    
1172                    return null;
1173            }
1174    
1175            /**
1176             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1177             *
1178             * @param uuid the uuid
1179             * @param companyId the company ID
1180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1181             * @return the last matching message-boards message
1182             * @throws NoSuchMessageException if a matching message-boards message could not be found
1183             */
1184            @Override
1185            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1186                    OrderByComparator<MBMessage> orderByComparator)
1187                    throws NoSuchMessageException {
1188                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1189                                    orderByComparator);
1190    
1191                    if (mbMessage != null) {
1192                            return mbMessage;
1193                    }
1194    
1195                    StringBundler msg = new StringBundler(6);
1196    
1197                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1198    
1199                    msg.append("uuid=");
1200                    msg.append(uuid);
1201    
1202                    msg.append(", companyId=");
1203                    msg.append(companyId);
1204    
1205                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1206    
1207                    throw new NoSuchMessageException(msg.toString());
1208            }
1209    
1210            /**
1211             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1212             *
1213             * @param uuid the uuid
1214             * @param companyId the company ID
1215             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1216             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1217             */
1218            @Override
1219            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1220                    OrderByComparator<MBMessage> orderByComparator) {
1221                    int count = countByUuid_C(uuid, companyId);
1222    
1223                    if (count == 0) {
1224                            return null;
1225                    }
1226    
1227                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1228                                    orderByComparator);
1229    
1230                    if (!list.isEmpty()) {
1231                            return list.get(0);
1232                    }
1233    
1234                    return null;
1235            }
1236    
1237            /**
1238             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1239             *
1240             * @param messageId the primary key of the current message-boards message
1241             * @param uuid the uuid
1242             * @param companyId the company ID
1243             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1244             * @return the previous, current, and next message-boards message
1245             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1246             */
1247            @Override
1248            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1249                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1250                    throws NoSuchMessageException {
1251                    MBMessage mbMessage = findByPrimaryKey(messageId);
1252    
1253                    Session session = null;
1254    
1255                    try {
1256                            session = openSession();
1257    
1258                            MBMessage[] array = new MBMessageImpl[3];
1259    
1260                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1261                                            companyId, orderByComparator, true);
1262    
1263                            array[1] = mbMessage;
1264    
1265                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1266                                            companyId, orderByComparator, false);
1267    
1268                            return array;
1269                    }
1270                    catch (Exception e) {
1271                            throw processException(e);
1272                    }
1273                    finally {
1274                            closeSession(session);
1275                    }
1276            }
1277    
1278            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1279                    MBMessage mbMessage, String uuid, long companyId,
1280                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1281                    StringBundler query = null;
1282    
1283                    if (orderByComparator != null) {
1284                            query = new StringBundler(6 +
1285                                            (orderByComparator.getOrderByFields().length * 6));
1286                    }
1287                    else {
1288                            query = new StringBundler(3);
1289                    }
1290    
1291                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1292    
1293                    boolean bindUuid = false;
1294    
1295                    if (uuid == null) {
1296                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1297                    }
1298                    else if (uuid.equals(StringPool.BLANK)) {
1299                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1300                    }
1301                    else {
1302                            bindUuid = true;
1303    
1304                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1305                    }
1306    
1307                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1308    
1309                    if (orderByComparator != null) {
1310                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1311    
1312                            if (orderByConditionFields.length > 0) {
1313                                    query.append(WHERE_AND);
1314                            }
1315    
1316                            for (int i = 0; i < orderByConditionFields.length; i++) {
1317                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1318                                    query.append(orderByConditionFields[i]);
1319    
1320                                    if ((i + 1) < orderByConditionFields.length) {
1321                                            if (orderByComparator.isAscending() ^ previous) {
1322                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1323                                            }
1324                                            else {
1325                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1326                                            }
1327                                    }
1328                                    else {
1329                                            if (orderByComparator.isAscending() ^ previous) {
1330                                                    query.append(WHERE_GREATER_THAN);
1331                                            }
1332                                            else {
1333                                                    query.append(WHERE_LESSER_THAN);
1334                                            }
1335                                    }
1336                            }
1337    
1338                            query.append(ORDER_BY_CLAUSE);
1339    
1340                            String[] orderByFields = orderByComparator.getOrderByFields();
1341    
1342                            for (int i = 0; i < orderByFields.length; i++) {
1343                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1344                                    query.append(orderByFields[i]);
1345    
1346                                    if ((i + 1) < orderByFields.length) {
1347                                            if (orderByComparator.isAscending() ^ previous) {
1348                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1349                                            }
1350                                            else {
1351                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1352                                            }
1353                                    }
1354                                    else {
1355                                            if (orderByComparator.isAscending() ^ previous) {
1356                                                    query.append(ORDER_BY_ASC);
1357                                            }
1358                                            else {
1359                                                    query.append(ORDER_BY_DESC);
1360                                            }
1361                                    }
1362                            }
1363                    }
1364                    else {
1365                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1366                    }
1367    
1368                    String sql = query.toString();
1369    
1370                    Query q = session.createQuery(sql);
1371    
1372                    q.setFirstResult(0);
1373                    q.setMaxResults(2);
1374    
1375                    QueryPos qPos = QueryPos.getInstance(q);
1376    
1377                    if (bindUuid) {
1378                            qPos.add(uuid);
1379                    }
1380    
1381                    qPos.add(companyId);
1382    
1383                    if (orderByComparator != null) {
1384                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1385    
1386                            for (Object value : values) {
1387                                    qPos.add(value);
1388                            }
1389                    }
1390    
1391                    List<MBMessage> list = q.list();
1392    
1393                    if (list.size() == 2) {
1394                            return list.get(1);
1395                    }
1396                    else {
1397                            return null;
1398                    }
1399            }
1400    
1401            /**
1402             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1403             *
1404             * @param uuid the uuid
1405             * @param companyId the company ID
1406             */
1407            @Override
1408            public void removeByUuid_C(String uuid, long companyId) {
1409                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1410                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1411                            remove(mbMessage);
1412                    }
1413            }
1414    
1415            /**
1416             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1417             *
1418             * @param uuid the uuid
1419             * @param companyId the company ID
1420             * @return the number of matching message-boards messages
1421             */
1422            @Override
1423            public int countByUuid_C(String uuid, long companyId) {
1424                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1425    
1426                    Object[] finderArgs = new Object[] { uuid, companyId };
1427    
1428                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1429    
1430                    if (count == null) {
1431                            StringBundler query = new StringBundler(3);
1432    
1433                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1434    
1435                            boolean bindUuid = false;
1436    
1437                            if (uuid == null) {
1438                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1439                            }
1440                            else if (uuid.equals(StringPool.BLANK)) {
1441                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1442                            }
1443                            else {
1444                                    bindUuid = true;
1445    
1446                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1447                            }
1448    
1449                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1450    
1451                            String sql = query.toString();
1452    
1453                            Session session = null;
1454    
1455                            try {
1456                                    session = openSession();
1457    
1458                                    Query q = session.createQuery(sql);
1459    
1460                                    QueryPos qPos = QueryPos.getInstance(q);
1461    
1462                                    if (bindUuid) {
1463                                            qPos.add(uuid);
1464                                    }
1465    
1466                                    qPos.add(companyId);
1467    
1468                                    count = (Long)q.uniqueResult();
1469    
1470                                    finderCache.putResult(finderPath, finderArgs, count);
1471                            }
1472                            catch (Exception e) {
1473                                    finderCache.removeResult(finderPath, finderArgs);
1474    
1475                                    throw processException(e);
1476                            }
1477                            finally {
1478                                    closeSession(session);
1479                            }
1480                    }
1481    
1482                    return count.intValue();
1483            }
1484    
1485            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1486            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1487            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1488            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1489            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1490                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1491                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1492                            new String[] {
1493                                    Long.class.getName(),
1494                                    
1495                            Integer.class.getName(), Integer.class.getName(),
1496                                    OrderByComparator.class.getName()
1497                            });
1498            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1499                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1500                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1501                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1502                            new String[] { Long.class.getName() },
1503                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1504                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1505            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1506                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1507                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1508                            new String[] { Long.class.getName() });
1509    
1510            /**
1511             * Returns all the message-boards messages where groupId = &#63;.
1512             *
1513             * @param groupId the group ID
1514             * @return the matching message-boards messages
1515             */
1516            @Override
1517            public List<MBMessage> findByGroupId(long groupId) {
1518                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1519            }
1520    
1521            /**
1522             * Returns a range of all the message-boards messages where groupId = &#63;.
1523             *
1524             * <p>
1525             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1526             * </p>
1527             *
1528             * @param groupId the group ID
1529             * @param start the lower bound of the range of message-boards messages
1530             * @param end the upper bound of the range of message-boards messages (not inclusive)
1531             * @return the range of matching message-boards messages
1532             */
1533            @Override
1534            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1535                    return findByGroupId(groupId, start, end, null);
1536            }
1537    
1538            /**
1539             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1540             *
1541             * <p>
1542             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1543             * </p>
1544             *
1545             * @param groupId the group ID
1546             * @param start the lower bound of the range of message-boards messages
1547             * @param end the upper bound of the range of message-boards messages (not inclusive)
1548             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1549             * @return the ordered range of matching message-boards messages
1550             */
1551            @Override
1552            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1553                    OrderByComparator<MBMessage> orderByComparator) {
1554                    return findByGroupId(groupId, start, end, orderByComparator, true);
1555            }
1556    
1557            /**
1558             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1559             *
1560             * <p>
1561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1562             * </p>
1563             *
1564             * @param groupId the group ID
1565             * @param start the lower bound of the range of message-boards messages
1566             * @param end the upper bound of the range of message-boards messages (not inclusive)
1567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1568             * @param retrieveFromCache whether to retrieve from the finder cache
1569             * @return the ordered range of matching message-boards messages
1570             */
1571            @Override
1572            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1573                    OrderByComparator<MBMessage> orderByComparator,
1574                    boolean retrieveFromCache) {
1575                    boolean pagination = true;
1576                    FinderPath finderPath = null;
1577                    Object[] finderArgs = null;
1578    
1579                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1580                                    (orderByComparator == null)) {
1581                            pagination = false;
1582                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1583                            finderArgs = new Object[] { groupId };
1584                    }
1585                    else {
1586                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1587                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1588                    }
1589    
1590                    List<MBMessage> list = null;
1591    
1592                    if (retrieveFromCache) {
1593                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1594                                            finderArgs, this);
1595    
1596                            if ((list != null) && !list.isEmpty()) {
1597                                    for (MBMessage mbMessage : list) {
1598                                            if ((groupId != mbMessage.getGroupId())) {
1599                                                    list = null;
1600    
1601                                                    break;
1602                                            }
1603                                    }
1604                            }
1605                    }
1606    
1607                    if (list == null) {
1608                            StringBundler query = null;
1609    
1610                            if (orderByComparator != null) {
1611                                    query = new StringBundler(3 +
1612                                                    (orderByComparator.getOrderByFields().length * 3));
1613                            }
1614                            else {
1615                                    query = new StringBundler(3);
1616                            }
1617    
1618                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1619    
1620                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1621    
1622                            if (orderByComparator != null) {
1623                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1624                                            orderByComparator);
1625                            }
1626                            else
1627                             if (pagination) {
1628                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1629                            }
1630    
1631                            String sql = query.toString();
1632    
1633                            Session session = null;
1634    
1635                            try {
1636                                    session = openSession();
1637    
1638                                    Query q = session.createQuery(sql);
1639    
1640                                    QueryPos qPos = QueryPos.getInstance(q);
1641    
1642                                    qPos.add(groupId);
1643    
1644                                    if (!pagination) {
1645                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1646                                                            start, end, false);
1647    
1648                                            Collections.sort(list);
1649    
1650                                            list = Collections.unmodifiableList(list);
1651                                    }
1652                                    else {
1653                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1654                                                            start, end);
1655                                    }
1656    
1657                                    cacheResult(list);
1658    
1659                                    finderCache.putResult(finderPath, finderArgs, list);
1660                            }
1661                            catch (Exception e) {
1662                                    finderCache.removeResult(finderPath, finderArgs);
1663    
1664                                    throw processException(e);
1665                            }
1666                            finally {
1667                                    closeSession(session);
1668                            }
1669                    }
1670    
1671                    return list;
1672            }
1673    
1674            /**
1675             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1676             *
1677             * @param groupId the group ID
1678             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1679             * @return the first matching message-boards message
1680             * @throws NoSuchMessageException if a matching message-boards message could not be found
1681             */
1682            @Override
1683            public MBMessage findByGroupId_First(long groupId,
1684                    OrderByComparator<MBMessage> orderByComparator)
1685                    throws NoSuchMessageException {
1686                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1687    
1688                    if (mbMessage != null) {
1689                            return mbMessage;
1690                    }
1691    
1692                    StringBundler msg = new StringBundler(4);
1693    
1694                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1695    
1696                    msg.append("groupId=");
1697                    msg.append(groupId);
1698    
1699                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1700    
1701                    throw new NoSuchMessageException(msg.toString());
1702            }
1703    
1704            /**
1705             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1706             *
1707             * @param groupId the group ID
1708             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1709             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1710             */
1711            @Override
1712            public MBMessage fetchByGroupId_First(long groupId,
1713                    OrderByComparator<MBMessage> orderByComparator) {
1714                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1715    
1716                    if (!list.isEmpty()) {
1717                            return list.get(0);
1718                    }
1719    
1720                    return null;
1721            }
1722    
1723            /**
1724             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1725             *
1726             * @param groupId the group ID
1727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1728             * @return the last matching message-boards message
1729             * @throws NoSuchMessageException if a matching message-boards message could not be found
1730             */
1731            @Override
1732            public MBMessage findByGroupId_Last(long groupId,
1733                    OrderByComparator<MBMessage> orderByComparator)
1734                    throws NoSuchMessageException {
1735                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1736    
1737                    if (mbMessage != null) {
1738                            return mbMessage;
1739                    }
1740    
1741                    StringBundler msg = new StringBundler(4);
1742    
1743                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1744    
1745                    msg.append("groupId=");
1746                    msg.append(groupId);
1747    
1748                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1749    
1750                    throw new NoSuchMessageException(msg.toString());
1751            }
1752    
1753            /**
1754             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1755             *
1756             * @param groupId the group ID
1757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1758             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1759             */
1760            @Override
1761            public MBMessage fetchByGroupId_Last(long groupId,
1762                    OrderByComparator<MBMessage> orderByComparator) {
1763                    int count = countByGroupId(groupId);
1764    
1765                    if (count == 0) {
1766                            return null;
1767                    }
1768    
1769                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1770                                    orderByComparator);
1771    
1772                    if (!list.isEmpty()) {
1773                            return list.get(0);
1774                    }
1775    
1776                    return null;
1777            }
1778    
1779            /**
1780             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1781             *
1782             * @param messageId the primary key of the current message-boards message
1783             * @param groupId the group ID
1784             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1785             * @return the previous, current, and next message-boards message
1786             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1787             */
1788            @Override
1789            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1790                    OrderByComparator<MBMessage> orderByComparator)
1791                    throws NoSuchMessageException {
1792                    MBMessage mbMessage = findByPrimaryKey(messageId);
1793    
1794                    Session session = null;
1795    
1796                    try {
1797                            session = openSession();
1798    
1799                            MBMessage[] array = new MBMessageImpl[3];
1800    
1801                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1802                                            orderByComparator, true);
1803    
1804                            array[1] = mbMessage;
1805    
1806                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1807                                            orderByComparator, false);
1808    
1809                            return array;
1810                    }
1811                    catch (Exception e) {
1812                            throw processException(e);
1813                    }
1814                    finally {
1815                            closeSession(session);
1816                    }
1817            }
1818    
1819            protected MBMessage getByGroupId_PrevAndNext(Session session,
1820                    MBMessage mbMessage, long groupId,
1821                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1822                    StringBundler query = null;
1823    
1824                    if (orderByComparator != null) {
1825                            query = new StringBundler(6 +
1826                                            (orderByComparator.getOrderByFields().length * 6));
1827                    }
1828                    else {
1829                            query = new StringBundler(3);
1830                    }
1831    
1832                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1833    
1834                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1835    
1836                    if (orderByComparator != null) {
1837                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1838    
1839                            if (orderByConditionFields.length > 0) {
1840                                    query.append(WHERE_AND);
1841                            }
1842    
1843                            for (int i = 0; i < orderByConditionFields.length; i++) {
1844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1845                                    query.append(orderByConditionFields[i]);
1846    
1847                                    if ((i + 1) < orderByConditionFields.length) {
1848                                            if (orderByComparator.isAscending() ^ previous) {
1849                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1850                                            }
1851                                            else {
1852                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1853                                            }
1854                                    }
1855                                    else {
1856                                            if (orderByComparator.isAscending() ^ previous) {
1857                                                    query.append(WHERE_GREATER_THAN);
1858                                            }
1859                                            else {
1860                                                    query.append(WHERE_LESSER_THAN);
1861                                            }
1862                                    }
1863                            }
1864    
1865                            query.append(ORDER_BY_CLAUSE);
1866    
1867                            String[] orderByFields = orderByComparator.getOrderByFields();
1868    
1869                            for (int i = 0; i < orderByFields.length; i++) {
1870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1871                                    query.append(orderByFields[i]);
1872    
1873                                    if ((i + 1) < orderByFields.length) {
1874                                            if (orderByComparator.isAscending() ^ previous) {
1875                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1876                                            }
1877                                            else {
1878                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1879                                            }
1880                                    }
1881                                    else {
1882                                            if (orderByComparator.isAscending() ^ previous) {
1883                                                    query.append(ORDER_BY_ASC);
1884                                            }
1885                                            else {
1886                                                    query.append(ORDER_BY_DESC);
1887                                            }
1888                                    }
1889                            }
1890                    }
1891                    else {
1892                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1893                    }
1894    
1895                    String sql = query.toString();
1896    
1897                    Query q = session.createQuery(sql);
1898    
1899                    q.setFirstResult(0);
1900                    q.setMaxResults(2);
1901    
1902                    QueryPos qPos = QueryPos.getInstance(q);
1903    
1904                    qPos.add(groupId);
1905    
1906                    if (orderByComparator != null) {
1907                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1908    
1909                            for (Object value : values) {
1910                                    qPos.add(value);
1911                            }
1912                    }
1913    
1914                    List<MBMessage> list = q.list();
1915    
1916                    if (list.size() == 2) {
1917                            return list.get(1);
1918                    }
1919                    else {
1920                            return null;
1921                    }
1922            }
1923    
1924            /**
1925             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1926             *
1927             * @param groupId the group ID
1928             * @return the matching message-boards messages that the user has permission to view
1929             */
1930            @Override
1931            public List<MBMessage> filterFindByGroupId(long groupId) {
1932                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1933                            QueryUtil.ALL_POS, null);
1934            }
1935    
1936            /**
1937             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1938             *
1939             * <p>
1940             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1941             * </p>
1942             *
1943             * @param groupId the group ID
1944             * @param start the lower bound of the range of message-boards messages
1945             * @param end the upper bound of the range of message-boards messages (not inclusive)
1946             * @return the range of matching message-boards messages that the user has permission to view
1947             */
1948            @Override
1949            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1950                    return filterFindByGroupId(groupId, start, end, null);
1951            }
1952    
1953            /**
1954             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1955             *
1956             * <p>
1957             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1958             * </p>
1959             *
1960             * @param groupId the group ID
1961             * @param start the lower bound of the range of message-boards messages
1962             * @param end the upper bound of the range of message-boards messages (not inclusive)
1963             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1964             * @return the ordered range of matching message-boards messages that the user has permission to view
1965             */
1966            @Override
1967            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1968                    int end, OrderByComparator<MBMessage> orderByComparator) {
1969                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1970                            return findByGroupId(groupId, start, end, orderByComparator);
1971                    }
1972    
1973                    StringBundler query = null;
1974    
1975                    if (orderByComparator != null) {
1976                            query = new StringBundler(3 +
1977                                            (orderByComparator.getOrderByFields().length * 3));
1978                    }
1979                    else {
1980                            query = new StringBundler(3);
1981                    }
1982    
1983                    if (getDB().isSupportsInlineDistinct()) {
1984                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1985                    }
1986                    else {
1987                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1988                    }
1989    
1990                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1991    
1992                    if (!getDB().isSupportsInlineDistinct()) {
1993                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1994                    }
1995    
1996                    if (orderByComparator != null) {
1997                            if (getDB().isSupportsInlineDistinct()) {
1998                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1999                                            orderByComparator, true);
2000                            }
2001                            else {
2002                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2003                                            orderByComparator, true);
2004                            }
2005                    }
2006                    else {
2007                            if (getDB().isSupportsInlineDistinct()) {
2008                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2009                            }
2010                            else {
2011                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2012                            }
2013                    }
2014    
2015                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2016                                    MBMessage.class.getName(),
2017                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2018    
2019                    Session session = null;
2020    
2021                    try {
2022                            session = openSession();
2023    
2024                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2025    
2026                            if (getDB().isSupportsInlineDistinct()) {
2027                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2028                            }
2029                            else {
2030                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2031                            }
2032    
2033                            QueryPos qPos = QueryPos.getInstance(q);
2034    
2035                            qPos.add(groupId);
2036    
2037                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2038                    }
2039                    catch (Exception e) {
2040                            throw processException(e);
2041                    }
2042                    finally {
2043                            closeSession(session);
2044                    }
2045            }
2046    
2047            /**
2048             * 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;.
2049             *
2050             * @param messageId the primary key of the current message-boards message
2051             * @param groupId the group ID
2052             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2053             * @return the previous, current, and next message-boards message
2054             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2055             */
2056            @Override
2057            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2058                    long groupId, OrderByComparator<MBMessage> orderByComparator)
2059                    throws NoSuchMessageException {
2060                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2061                            return findByGroupId_PrevAndNext(messageId, groupId,
2062                                    orderByComparator);
2063                    }
2064    
2065                    MBMessage mbMessage = findByPrimaryKey(messageId);
2066    
2067                    Session session = null;
2068    
2069                    try {
2070                            session = openSession();
2071    
2072                            MBMessage[] array = new MBMessageImpl[3];
2073    
2074                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2075                                            groupId, orderByComparator, true);
2076    
2077                            array[1] = mbMessage;
2078    
2079                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2080                                            groupId, orderByComparator, false);
2081    
2082                            return array;
2083                    }
2084                    catch (Exception e) {
2085                            throw processException(e);
2086                    }
2087                    finally {
2088                            closeSession(session);
2089                    }
2090            }
2091    
2092            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2093                    MBMessage mbMessage, long groupId,
2094                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2095                    StringBundler query = null;
2096    
2097                    if (orderByComparator != null) {
2098                            query = new StringBundler(6 +
2099                                            (orderByComparator.getOrderByFields().length * 6));
2100                    }
2101                    else {
2102                            query = new StringBundler(3);
2103                    }
2104    
2105                    if (getDB().isSupportsInlineDistinct()) {
2106                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2107                    }
2108                    else {
2109                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2110                    }
2111    
2112                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2113    
2114                    if (!getDB().isSupportsInlineDistinct()) {
2115                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2116                    }
2117    
2118                    if (orderByComparator != null) {
2119                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2120    
2121                            if (orderByConditionFields.length > 0) {
2122                                    query.append(WHERE_AND);
2123                            }
2124    
2125                            for (int i = 0; i < orderByConditionFields.length; i++) {
2126                                    if (getDB().isSupportsInlineDistinct()) {
2127                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2128                                    }
2129                                    else {
2130                                            query.append(_ORDER_BY_ENTITY_TABLE);
2131                                    }
2132    
2133                                    query.append(orderByConditionFields[i]);
2134    
2135                                    if ((i + 1) < orderByConditionFields.length) {
2136                                            if (orderByComparator.isAscending() ^ previous) {
2137                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2138                                            }
2139                                            else {
2140                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2141                                            }
2142                                    }
2143                                    else {
2144                                            if (orderByComparator.isAscending() ^ previous) {
2145                                                    query.append(WHERE_GREATER_THAN);
2146                                            }
2147                                            else {
2148                                                    query.append(WHERE_LESSER_THAN);
2149                                            }
2150                                    }
2151                            }
2152    
2153                            query.append(ORDER_BY_CLAUSE);
2154    
2155                            String[] orderByFields = orderByComparator.getOrderByFields();
2156    
2157                            for (int i = 0; i < orderByFields.length; i++) {
2158                                    if (getDB().isSupportsInlineDistinct()) {
2159                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2160                                    }
2161                                    else {
2162                                            query.append(_ORDER_BY_ENTITY_TABLE);
2163                                    }
2164    
2165                                    query.append(orderByFields[i]);
2166    
2167                                    if ((i + 1) < orderByFields.length) {
2168                                            if (orderByComparator.isAscending() ^ previous) {
2169                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2170                                            }
2171                                            else {
2172                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2173                                            }
2174                                    }
2175                                    else {
2176                                            if (orderByComparator.isAscending() ^ previous) {
2177                                                    query.append(ORDER_BY_ASC);
2178                                            }
2179                                            else {
2180                                                    query.append(ORDER_BY_DESC);
2181                                            }
2182                                    }
2183                            }
2184                    }
2185                    else {
2186                            if (getDB().isSupportsInlineDistinct()) {
2187                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2188                            }
2189                            else {
2190                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2191                            }
2192                    }
2193    
2194                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2195                                    MBMessage.class.getName(),
2196                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2197    
2198                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2199    
2200                    q.setFirstResult(0);
2201                    q.setMaxResults(2);
2202    
2203                    if (getDB().isSupportsInlineDistinct()) {
2204                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2205                    }
2206                    else {
2207                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2208                    }
2209    
2210                    QueryPos qPos = QueryPos.getInstance(q);
2211    
2212                    qPos.add(groupId);
2213    
2214                    if (orderByComparator != null) {
2215                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2216    
2217                            for (Object value : values) {
2218                                    qPos.add(value);
2219                            }
2220                    }
2221    
2222                    List<MBMessage> list = q.list();
2223    
2224                    if (list.size() == 2) {
2225                            return list.get(1);
2226                    }
2227                    else {
2228                            return null;
2229                    }
2230            }
2231    
2232            /**
2233             * Removes all the message-boards messages where groupId = &#63; from the database.
2234             *
2235             * @param groupId the group ID
2236             */
2237            @Override
2238            public void removeByGroupId(long groupId) {
2239                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2240                                    QueryUtil.ALL_POS, null)) {
2241                            remove(mbMessage);
2242                    }
2243            }
2244    
2245            /**
2246             * Returns the number of message-boards messages where groupId = &#63;.
2247             *
2248             * @param groupId the group ID
2249             * @return the number of matching message-boards messages
2250             */
2251            @Override
2252            public int countByGroupId(long groupId) {
2253                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2254    
2255                    Object[] finderArgs = new Object[] { groupId };
2256    
2257                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2258    
2259                    if (count == null) {
2260                            StringBundler query = new StringBundler(2);
2261    
2262                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2263    
2264                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2265    
2266                            String sql = query.toString();
2267    
2268                            Session session = null;
2269    
2270                            try {
2271                                    session = openSession();
2272    
2273                                    Query q = session.createQuery(sql);
2274    
2275                                    QueryPos qPos = QueryPos.getInstance(q);
2276    
2277                                    qPos.add(groupId);
2278    
2279                                    count = (Long)q.uniqueResult();
2280    
2281                                    finderCache.putResult(finderPath, finderArgs, count);
2282                            }
2283                            catch (Exception e) {
2284                                    finderCache.removeResult(finderPath, finderArgs);
2285    
2286                                    throw processException(e);
2287                            }
2288                            finally {
2289                                    closeSession(session);
2290                            }
2291                    }
2292    
2293                    return count.intValue();
2294            }
2295    
2296            /**
2297             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2298             *
2299             * @param groupId the group ID
2300             * @return the number of matching message-boards messages that the user has permission to view
2301             */
2302            @Override
2303            public int filterCountByGroupId(long groupId) {
2304                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2305                            return countByGroupId(groupId);
2306                    }
2307    
2308                    StringBundler query = new StringBundler(2);
2309    
2310                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2311    
2312                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2313    
2314                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2315                                    MBMessage.class.getName(),
2316                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2317    
2318                    Session session = null;
2319    
2320                    try {
2321                            session = openSession();
2322    
2323                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2324    
2325                            q.addScalar(COUNT_COLUMN_NAME,
2326                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2327    
2328                            QueryPos qPos = QueryPos.getInstance(q);
2329    
2330                            qPos.add(groupId);
2331    
2332                            Long count = (Long)q.uniqueResult();
2333    
2334                            return count.intValue();
2335                    }
2336                    catch (Exception e) {
2337                            throw processException(e);
2338                    }
2339                    finally {
2340                            closeSession(session);
2341                    }
2342            }
2343    
2344            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2345            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2346                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2347                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2348                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2349                            new String[] {
2350                                    Long.class.getName(),
2351                                    
2352                            Integer.class.getName(), Integer.class.getName(),
2353                                    OrderByComparator.class.getName()
2354                            });
2355            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2356                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2357                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2358                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2359                            new String[] { Long.class.getName() },
2360                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2361                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2362            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2363                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2364                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2365                            new String[] { Long.class.getName() });
2366    
2367            /**
2368             * Returns all the message-boards messages where companyId = &#63;.
2369             *
2370             * @param companyId the company ID
2371             * @return the matching message-boards messages
2372             */
2373            @Override
2374            public List<MBMessage> findByCompanyId(long companyId) {
2375                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2376                            null);
2377            }
2378    
2379            /**
2380             * Returns a range of all the message-boards messages where companyId = &#63;.
2381             *
2382             * <p>
2383             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2384             * </p>
2385             *
2386             * @param companyId the company ID
2387             * @param start the lower bound of the range of message-boards messages
2388             * @param end the upper bound of the range of message-boards messages (not inclusive)
2389             * @return the range of matching message-boards messages
2390             */
2391            @Override
2392            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2393                    return findByCompanyId(companyId, start, end, null);
2394            }
2395    
2396            /**
2397             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2398             *
2399             * <p>
2400             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2401             * </p>
2402             *
2403             * @param companyId the company ID
2404             * @param start the lower bound of the range of message-boards messages
2405             * @param end the upper bound of the range of message-boards messages (not inclusive)
2406             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2407             * @return the ordered range of matching message-boards messages
2408             */
2409            @Override
2410            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2411                    OrderByComparator<MBMessage> orderByComparator) {
2412                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2413            }
2414    
2415            /**
2416             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2417             *
2418             * <p>
2419             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2420             * </p>
2421             *
2422             * @param companyId the company ID
2423             * @param start the lower bound of the range of message-boards messages
2424             * @param end the upper bound of the range of message-boards messages (not inclusive)
2425             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2426             * @param retrieveFromCache whether to retrieve from the finder cache
2427             * @return the ordered range of matching message-boards messages
2428             */
2429            @Override
2430            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2431                    OrderByComparator<MBMessage> orderByComparator,
2432                    boolean retrieveFromCache) {
2433                    boolean pagination = true;
2434                    FinderPath finderPath = null;
2435                    Object[] finderArgs = null;
2436    
2437                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2438                                    (orderByComparator == null)) {
2439                            pagination = false;
2440                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2441                            finderArgs = new Object[] { companyId };
2442                    }
2443                    else {
2444                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2445                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2446                    }
2447    
2448                    List<MBMessage> list = null;
2449    
2450                    if (retrieveFromCache) {
2451                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2452                                            finderArgs, this);
2453    
2454                            if ((list != null) && !list.isEmpty()) {
2455                                    for (MBMessage mbMessage : list) {
2456                                            if ((companyId != mbMessage.getCompanyId())) {
2457                                                    list = null;
2458    
2459                                                    break;
2460                                            }
2461                                    }
2462                            }
2463                    }
2464    
2465                    if (list == null) {
2466                            StringBundler query = null;
2467    
2468                            if (orderByComparator != null) {
2469                                    query = new StringBundler(3 +
2470                                                    (orderByComparator.getOrderByFields().length * 3));
2471                            }
2472                            else {
2473                                    query = new StringBundler(3);
2474                            }
2475    
2476                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2477    
2478                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2479    
2480                            if (orderByComparator != null) {
2481                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2482                                            orderByComparator);
2483                            }
2484                            else
2485                             if (pagination) {
2486                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2487                            }
2488    
2489                            String sql = query.toString();
2490    
2491                            Session session = null;
2492    
2493                            try {
2494                                    session = openSession();
2495    
2496                                    Query q = session.createQuery(sql);
2497    
2498                                    QueryPos qPos = QueryPos.getInstance(q);
2499    
2500                                    qPos.add(companyId);
2501    
2502                                    if (!pagination) {
2503                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2504                                                            start, end, false);
2505    
2506                                            Collections.sort(list);
2507    
2508                                            list = Collections.unmodifiableList(list);
2509                                    }
2510                                    else {
2511                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2512                                                            start, end);
2513                                    }
2514    
2515                                    cacheResult(list);
2516    
2517                                    finderCache.putResult(finderPath, finderArgs, list);
2518                            }
2519                            catch (Exception e) {
2520                                    finderCache.removeResult(finderPath, finderArgs);
2521    
2522                                    throw processException(e);
2523                            }
2524                            finally {
2525                                    closeSession(session);
2526                            }
2527                    }
2528    
2529                    return list;
2530            }
2531    
2532            /**
2533             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2534             *
2535             * @param companyId the company ID
2536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2537             * @return the first matching message-boards message
2538             * @throws NoSuchMessageException if a matching message-boards message could not be found
2539             */
2540            @Override
2541            public MBMessage findByCompanyId_First(long companyId,
2542                    OrderByComparator<MBMessage> orderByComparator)
2543                    throws NoSuchMessageException {
2544                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2545                                    orderByComparator);
2546    
2547                    if (mbMessage != null) {
2548                            return mbMessage;
2549                    }
2550    
2551                    StringBundler msg = new StringBundler(4);
2552    
2553                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2554    
2555                    msg.append("companyId=");
2556                    msg.append(companyId);
2557    
2558                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2559    
2560                    throw new NoSuchMessageException(msg.toString());
2561            }
2562    
2563            /**
2564             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2565             *
2566             * @param companyId the company ID
2567             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2568             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2569             */
2570            @Override
2571            public MBMessage fetchByCompanyId_First(long companyId,
2572                    OrderByComparator<MBMessage> orderByComparator) {
2573                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2574                                    orderByComparator);
2575    
2576                    if (!list.isEmpty()) {
2577                            return list.get(0);
2578                    }
2579    
2580                    return null;
2581            }
2582    
2583            /**
2584             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2585             *
2586             * @param companyId the company ID
2587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2588             * @return the last matching message-boards message
2589             * @throws NoSuchMessageException if a matching message-boards message could not be found
2590             */
2591            @Override
2592            public MBMessage findByCompanyId_Last(long companyId,
2593                    OrderByComparator<MBMessage> orderByComparator)
2594                    throws NoSuchMessageException {
2595                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2596    
2597                    if (mbMessage != null) {
2598                            return mbMessage;
2599                    }
2600    
2601                    StringBundler msg = new StringBundler(4);
2602    
2603                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2604    
2605                    msg.append("companyId=");
2606                    msg.append(companyId);
2607    
2608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2609    
2610                    throw new NoSuchMessageException(msg.toString());
2611            }
2612    
2613            /**
2614             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2615             *
2616             * @param companyId the company ID
2617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2618             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2619             */
2620            @Override
2621            public MBMessage fetchByCompanyId_Last(long companyId,
2622                    OrderByComparator<MBMessage> orderByComparator) {
2623                    int count = countByCompanyId(companyId);
2624    
2625                    if (count == 0) {
2626                            return null;
2627                    }
2628    
2629                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2630                                    orderByComparator);
2631    
2632                    if (!list.isEmpty()) {
2633                            return list.get(0);
2634                    }
2635    
2636                    return null;
2637            }
2638    
2639            /**
2640             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2641             *
2642             * @param messageId the primary key of the current message-boards message
2643             * @param companyId the company ID
2644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2645             * @return the previous, current, and next message-boards message
2646             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2647             */
2648            @Override
2649            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2650                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2651                    throws NoSuchMessageException {
2652                    MBMessage mbMessage = findByPrimaryKey(messageId);
2653    
2654                    Session session = null;
2655    
2656                    try {
2657                            session = openSession();
2658    
2659                            MBMessage[] array = new MBMessageImpl[3];
2660    
2661                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2662                                            companyId, orderByComparator, true);
2663    
2664                            array[1] = mbMessage;
2665    
2666                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2667                                            companyId, orderByComparator, false);
2668    
2669                            return array;
2670                    }
2671                    catch (Exception e) {
2672                            throw processException(e);
2673                    }
2674                    finally {
2675                            closeSession(session);
2676                    }
2677            }
2678    
2679            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2680                    MBMessage mbMessage, long companyId,
2681                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2682                    StringBundler query = null;
2683    
2684                    if (orderByComparator != null) {
2685                            query = new StringBundler(6 +
2686                                            (orderByComparator.getOrderByFields().length * 6));
2687                    }
2688                    else {
2689                            query = new StringBundler(3);
2690                    }
2691    
2692                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2693    
2694                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2695    
2696                    if (orderByComparator != null) {
2697                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2698    
2699                            if (orderByConditionFields.length > 0) {
2700                                    query.append(WHERE_AND);
2701                            }
2702    
2703                            for (int i = 0; i < orderByConditionFields.length; i++) {
2704                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2705                                    query.append(orderByConditionFields[i]);
2706    
2707                                    if ((i + 1) < orderByConditionFields.length) {
2708                                            if (orderByComparator.isAscending() ^ previous) {
2709                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2710                                            }
2711                                            else {
2712                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2713                                            }
2714                                    }
2715                                    else {
2716                                            if (orderByComparator.isAscending() ^ previous) {
2717                                                    query.append(WHERE_GREATER_THAN);
2718                                            }
2719                                            else {
2720                                                    query.append(WHERE_LESSER_THAN);
2721                                            }
2722                                    }
2723                            }
2724    
2725                            query.append(ORDER_BY_CLAUSE);
2726    
2727                            String[] orderByFields = orderByComparator.getOrderByFields();
2728    
2729                            for (int i = 0; i < orderByFields.length; i++) {
2730                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2731                                    query.append(orderByFields[i]);
2732    
2733                                    if ((i + 1) < orderByFields.length) {
2734                                            if (orderByComparator.isAscending() ^ previous) {
2735                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2736                                            }
2737                                            else {
2738                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2739                                            }
2740                                    }
2741                                    else {
2742                                            if (orderByComparator.isAscending() ^ previous) {
2743                                                    query.append(ORDER_BY_ASC);
2744                                            }
2745                                            else {
2746                                                    query.append(ORDER_BY_DESC);
2747                                            }
2748                                    }
2749                            }
2750                    }
2751                    else {
2752                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2753                    }
2754    
2755                    String sql = query.toString();
2756    
2757                    Query q = session.createQuery(sql);
2758    
2759                    q.setFirstResult(0);
2760                    q.setMaxResults(2);
2761    
2762                    QueryPos qPos = QueryPos.getInstance(q);
2763    
2764                    qPos.add(companyId);
2765    
2766                    if (orderByComparator != null) {
2767                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2768    
2769                            for (Object value : values) {
2770                                    qPos.add(value);
2771                            }
2772                    }
2773    
2774                    List<MBMessage> list = q.list();
2775    
2776                    if (list.size() == 2) {
2777                            return list.get(1);
2778                    }
2779                    else {
2780                            return null;
2781                    }
2782            }
2783    
2784            /**
2785             * Removes all the message-boards messages where companyId = &#63; from the database.
2786             *
2787             * @param companyId the company ID
2788             */
2789            @Override
2790            public void removeByCompanyId(long companyId) {
2791                    for (MBMessage mbMessage : findByCompanyId(companyId,
2792                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2793                            remove(mbMessage);
2794                    }
2795            }
2796    
2797            /**
2798             * Returns the number of message-boards messages where companyId = &#63;.
2799             *
2800             * @param companyId the company ID
2801             * @return the number of matching message-boards messages
2802             */
2803            @Override
2804            public int countByCompanyId(long companyId) {
2805                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2806    
2807                    Object[] finderArgs = new Object[] { companyId };
2808    
2809                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2810    
2811                    if (count == null) {
2812                            StringBundler query = new StringBundler(2);
2813    
2814                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2815    
2816                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2817    
2818                            String sql = query.toString();
2819    
2820                            Session session = null;
2821    
2822                            try {
2823                                    session = openSession();
2824    
2825                                    Query q = session.createQuery(sql);
2826    
2827                                    QueryPos qPos = QueryPos.getInstance(q);
2828    
2829                                    qPos.add(companyId);
2830    
2831                                    count = (Long)q.uniqueResult();
2832    
2833                                    finderCache.putResult(finderPath, finderArgs, count);
2834                            }
2835                            catch (Exception e) {
2836                                    finderCache.removeResult(finderPath, finderArgs);
2837    
2838                                    throw processException(e);
2839                            }
2840                            finally {
2841                                    closeSession(session);
2842                            }
2843                    }
2844    
2845                    return count.intValue();
2846            }
2847    
2848            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2849            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2850                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2851                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2852                            new String[] {
2853                                    Long.class.getName(),
2854                                    
2855                            Integer.class.getName(), Integer.class.getName(),
2856                                    OrderByComparator.class.getName()
2857                            });
2858            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2859                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2860                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2861                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2862                            new String[] { Long.class.getName() },
2863                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2864                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2865            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2866                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2867                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2868                            new String[] { Long.class.getName() });
2869    
2870            /**
2871             * Returns all the message-boards messages where userId = &#63;.
2872             *
2873             * @param userId the user ID
2874             * @return the matching message-boards messages
2875             */
2876            @Override
2877            public List<MBMessage> findByUserId(long userId) {
2878                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2879            }
2880    
2881            /**
2882             * Returns a range of all the message-boards messages where userId = &#63;.
2883             *
2884             * <p>
2885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2886             * </p>
2887             *
2888             * @param userId the user ID
2889             * @param start the lower bound of the range of message-boards messages
2890             * @param end the upper bound of the range of message-boards messages (not inclusive)
2891             * @return the range of matching message-boards messages
2892             */
2893            @Override
2894            public List<MBMessage> findByUserId(long userId, int start, int end) {
2895                    return findByUserId(userId, start, end, null);
2896            }
2897    
2898            /**
2899             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2900             *
2901             * <p>
2902             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2903             * </p>
2904             *
2905             * @param userId the user ID
2906             * @param start the lower bound of the range of message-boards messages
2907             * @param end the upper bound of the range of message-boards messages (not inclusive)
2908             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2909             * @return the ordered range of matching message-boards messages
2910             */
2911            @Override
2912            public List<MBMessage> findByUserId(long userId, int start, int end,
2913                    OrderByComparator<MBMessage> orderByComparator) {
2914                    return findByUserId(userId, start, end, orderByComparator, true);
2915            }
2916    
2917            /**
2918             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2919             *
2920             * <p>
2921             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2922             * </p>
2923             *
2924             * @param userId the user ID
2925             * @param start the lower bound of the range of message-boards messages
2926             * @param end the upper bound of the range of message-boards messages (not inclusive)
2927             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2928             * @param retrieveFromCache whether to retrieve from the finder cache
2929             * @return the ordered range of matching message-boards messages
2930             */
2931            @Override
2932            public List<MBMessage> findByUserId(long userId, int start, int end,
2933                    OrderByComparator<MBMessage> orderByComparator,
2934                    boolean retrieveFromCache) {
2935                    boolean pagination = true;
2936                    FinderPath finderPath = null;
2937                    Object[] finderArgs = null;
2938    
2939                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2940                                    (orderByComparator == null)) {
2941                            pagination = false;
2942                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2943                            finderArgs = new Object[] { userId };
2944                    }
2945                    else {
2946                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2947                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2948                    }
2949    
2950                    List<MBMessage> list = null;
2951    
2952                    if (retrieveFromCache) {
2953                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2954                                            finderArgs, this);
2955    
2956                            if ((list != null) && !list.isEmpty()) {
2957                                    for (MBMessage mbMessage : list) {
2958                                            if ((userId != mbMessage.getUserId())) {
2959                                                    list = null;
2960    
2961                                                    break;
2962                                            }
2963                                    }
2964                            }
2965                    }
2966    
2967                    if (list == null) {
2968                            StringBundler query = null;
2969    
2970                            if (orderByComparator != null) {
2971                                    query = new StringBundler(3 +
2972                                                    (orderByComparator.getOrderByFields().length * 3));
2973                            }
2974                            else {
2975                                    query = new StringBundler(3);
2976                            }
2977    
2978                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2979    
2980                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2981    
2982                            if (orderByComparator != null) {
2983                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2984                                            orderByComparator);
2985                            }
2986                            else
2987                             if (pagination) {
2988                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2989                            }
2990    
2991                            String sql = query.toString();
2992    
2993                            Session session = null;
2994    
2995                            try {
2996                                    session = openSession();
2997    
2998                                    Query q = session.createQuery(sql);
2999    
3000                                    QueryPos qPos = QueryPos.getInstance(q);
3001    
3002                                    qPos.add(userId);
3003    
3004                                    if (!pagination) {
3005                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3006                                                            start, end, false);
3007    
3008                                            Collections.sort(list);
3009    
3010                                            list = Collections.unmodifiableList(list);
3011                                    }
3012                                    else {
3013                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3014                                                            start, end);
3015                                    }
3016    
3017                                    cacheResult(list);
3018    
3019                                    finderCache.putResult(finderPath, finderArgs, list);
3020                            }
3021                            catch (Exception e) {
3022                                    finderCache.removeResult(finderPath, finderArgs);
3023    
3024                                    throw processException(e);
3025                            }
3026                            finally {
3027                                    closeSession(session);
3028                            }
3029                    }
3030    
3031                    return list;
3032            }
3033    
3034            /**
3035             * Returns the first message-boards message in the ordered set where userId = &#63;.
3036             *
3037             * @param userId the user ID
3038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3039             * @return the first matching message-boards message
3040             * @throws NoSuchMessageException if a matching message-boards message could not be found
3041             */
3042            @Override
3043            public MBMessage findByUserId_First(long userId,
3044                    OrderByComparator<MBMessage> orderByComparator)
3045                    throws NoSuchMessageException {
3046                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3047    
3048                    if (mbMessage != null) {
3049                            return mbMessage;
3050                    }
3051    
3052                    StringBundler msg = new StringBundler(4);
3053    
3054                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3055    
3056                    msg.append("userId=");
3057                    msg.append(userId);
3058    
3059                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3060    
3061                    throw new NoSuchMessageException(msg.toString());
3062            }
3063    
3064            /**
3065             * Returns the first message-boards message in the ordered set where userId = &#63;.
3066             *
3067             * @param userId the user ID
3068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3069             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3070             */
3071            @Override
3072            public MBMessage fetchByUserId_First(long userId,
3073                    OrderByComparator<MBMessage> orderByComparator) {
3074                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3075    
3076                    if (!list.isEmpty()) {
3077                            return list.get(0);
3078                    }
3079    
3080                    return null;
3081            }
3082    
3083            /**
3084             * Returns the last message-boards message in the ordered set where userId = &#63;.
3085             *
3086             * @param userId the user ID
3087             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3088             * @return the last matching message-boards message
3089             * @throws NoSuchMessageException if a matching message-boards message could not be found
3090             */
3091            @Override
3092            public MBMessage findByUserId_Last(long userId,
3093                    OrderByComparator<MBMessage> orderByComparator)
3094                    throws NoSuchMessageException {
3095                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3096    
3097                    if (mbMessage != null) {
3098                            return mbMessage;
3099                    }
3100    
3101                    StringBundler msg = new StringBundler(4);
3102    
3103                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3104    
3105                    msg.append("userId=");
3106                    msg.append(userId);
3107    
3108                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3109    
3110                    throw new NoSuchMessageException(msg.toString());
3111            }
3112    
3113            /**
3114             * Returns the last message-boards message in the ordered set where userId = &#63;.
3115             *
3116             * @param userId the user ID
3117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3118             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3119             */
3120            @Override
3121            public MBMessage fetchByUserId_Last(long userId,
3122                    OrderByComparator<MBMessage> orderByComparator) {
3123                    int count = countByUserId(userId);
3124    
3125                    if (count == 0) {
3126                            return null;
3127                    }
3128    
3129                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3130                                    orderByComparator);
3131    
3132                    if (!list.isEmpty()) {
3133                            return list.get(0);
3134                    }
3135    
3136                    return null;
3137            }
3138    
3139            /**
3140             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3141             *
3142             * @param messageId the primary key of the current message-boards message
3143             * @param userId the user ID
3144             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3145             * @return the previous, current, and next message-boards message
3146             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3147             */
3148            @Override
3149            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3150                    OrderByComparator<MBMessage> orderByComparator)
3151                    throws NoSuchMessageException {
3152                    MBMessage mbMessage = findByPrimaryKey(messageId);
3153    
3154                    Session session = null;
3155    
3156                    try {
3157                            session = openSession();
3158    
3159                            MBMessage[] array = new MBMessageImpl[3];
3160    
3161                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3162                                            orderByComparator, true);
3163    
3164                            array[1] = mbMessage;
3165    
3166                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3167                                            orderByComparator, false);
3168    
3169                            return array;
3170                    }
3171                    catch (Exception e) {
3172                            throw processException(e);
3173                    }
3174                    finally {
3175                            closeSession(session);
3176                    }
3177            }
3178    
3179            protected MBMessage getByUserId_PrevAndNext(Session session,
3180                    MBMessage mbMessage, long userId,
3181                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3182                    StringBundler query = null;
3183    
3184                    if (orderByComparator != null) {
3185                            query = new StringBundler(6 +
3186                                            (orderByComparator.getOrderByFields().length * 6));
3187                    }
3188                    else {
3189                            query = new StringBundler(3);
3190                    }
3191    
3192                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3193    
3194                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3195    
3196                    if (orderByComparator != null) {
3197                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3198    
3199                            if (orderByConditionFields.length > 0) {
3200                                    query.append(WHERE_AND);
3201                            }
3202    
3203                            for (int i = 0; i < orderByConditionFields.length; i++) {
3204                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3205                                    query.append(orderByConditionFields[i]);
3206    
3207                                    if ((i + 1) < orderByConditionFields.length) {
3208                                            if (orderByComparator.isAscending() ^ previous) {
3209                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3210                                            }
3211                                            else {
3212                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3213                                            }
3214                                    }
3215                                    else {
3216                                            if (orderByComparator.isAscending() ^ previous) {
3217                                                    query.append(WHERE_GREATER_THAN);
3218                                            }
3219                                            else {
3220                                                    query.append(WHERE_LESSER_THAN);
3221                                            }
3222                                    }
3223                            }
3224    
3225                            query.append(ORDER_BY_CLAUSE);
3226    
3227                            String[] orderByFields = orderByComparator.getOrderByFields();
3228    
3229                            for (int i = 0; i < orderByFields.length; i++) {
3230                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3231                                    query.append(orderByFields[i]);
3232    
3233                                    if ((i + 1) < orderByFields.length) {
3234                                            if (orderByComparator.isAscending() ^ previous) {
3235                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3236                                            }
3237                                            else {
3238                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3239                                            }
3240                                    }
3241                                    else {
3242                                            if (orderByComparator.isAscending() ^ previous) {
3243                                                    query.append(ORDER_BY_ASC);
3244                                            }
3245                                            else {
3246                                                    query.append(ORDER_BY_DESC);
3247                                            }
3248                                    }
3249                            }
3250                    }
3251                    else {
3252                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3253                    }
3254    
3255                    String sql = query.toString();
3256    
3257                    Query q = session.createQuery(sql);
3258    
3259                    q.setFirstResult(0);
3260                    q.setMaxResults(2);
3261    
3262                    QueryPos qPos = QueryPos.getInstance(q);
3263    
3264                    qPos.add(userId);
3265    
3266                    if (orderByComparator != null) {
3267                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3268    
3269                            for (Object value : values) {
3270                                    qPos.add(value);
3271                            }
3272                    }
3273    
3274                    List<MBMessage> list = q.list();
3275    
3276                    if (list.size() == 2) {
3277                            return list.get(1);
3278                    }
3279                    else {
3280                            return null;
3281                    }
3282            }
3283    
3284            /**
3285             * Removes all the message-boards messages where userId = &#63; from the database.
3286             *
3287             * @param userId the user ID
3288             */
3289            @Override
3290            public void removeByUserId(long userId) {
3291                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3292                                    QueryUtil.ALL_POS, null)) {
3293                            remove(mbMessage);
3294                    }
3295            }
3296    
3297            /**
3298             * Returns the number of message-boards messages where userId = &#63;.
3299             *
3300             * @param userId the user ID
3301             * @return the number of matching message-boards messages
3302             */
3303            @Override
3304            public int countByUserId(long userId) {
3305                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3306    
3307                    Object[] finderArgs = new Object[] { userId };
3308    
3309                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3310    
3311                    if (count == null) {
3312                            StringBundler query = new StringBundler(2);
3313    
3314                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3315    
3316                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3317    
3318                            String sql = query.toString();
3319    
3320                            Session session = null;
3321    
3322                            try {
3323                                    session = openSession();
3324    
3325                                    Query q = session.createQuery(sql);
3326    
3327                                    QueryPos qPos = QueryPos.getInstance(q);
3328    
3329                                    qPos.add(userId);
3330    
3331                                    count = (Long)q.uniqueResult();
3332    
3333                                    finderCache.putResult(finderPath, finderArgs, count);
3334                            }
3335                            catch (Exception e) {
3336                                    finderCache.removeResult(finderPath, finderArgs);
3337    
3338                                    throw processException(e);
3339                            }
3340                            finally {
3341                                    closeSession(session);
3342                            }
3343                    }
3344    
3345                    return count.intValue();
3346            }
3347    
3348            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3349            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3350                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3351                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3352                            new String[] {
3353                                    Long.class.getName(),
3354                                    
3355                            Integer.class.getName(), Integer.class.getName(),
3356                                    OrderByComparator.class.getName()
3357                            });
3358            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3359                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3360                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3361                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3362                            new String[] { Long.class.getName() },
3363                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3364                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3365            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3366                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3367                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3368                            new String[] { Long.class.getName() });
3369    
3370            /**
3371             * Returns all the message-boards messages where threadId = &#63;.
3372             *
3373             * @param threadId the thread ID
3374             * @return the matching message-boards messages
3375             */
3376            @Override
3377            public List<MBMessage> findByThreadId(long threadId) {
3378                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3379                            null);
3380            }
3381    
3382            /**
3383             * Returns a range of all the message-boards messages where threadId = &#63;.
3384             *
3385             * <p>
3386             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3387             * </p>
3388             *
3389             * @param threadId the thread ID
3390             * @param start the lower bound of the range of message-boards messages
3391             * @param end the upper bound of the range of message-boards messages (not inclusive)
3392             * @return the range of matching message-boards messages
3393             */
3394            @Override
3395            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3396                    return findByThreadId(threadId, start, end, null);
3397            }
3398    
3399            /**
3400             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3401             *
3402             * <p>
3403             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3404             * </p>
3405             *
3406             * @param threadId the thread ID
3407             * @param start the lower bound of the range of message-boards messages
3408             * @param end the upper bound of the range of message-boards messages (not inclusive)
3409             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3410             * @return the ordered range of matching message-boards messages
3411             */
3412            @Override
3413            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3414                    OrderByComparator<MBMessage> orderByComparator) {
3415                    return findByThreadId(threadId, start, end, orderByComparator, true);
3416            }
3417    
3418            /**
3419             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3420             *
3421             * <p>
3422             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3423             * </p>
3424             *
3425             * @param threadId the thread ID
3426             * @param start the lower bound of the range of message-boards messages
3427             * @param end the upper bound of the range of message-boards messages (not inclusive)
3428             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3429             * @param retrieveFromCache whether to retrieve from the finder cache
3430             * @return the ordered range of matching message-boards messages
3431             */
3432            @Override
3433            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3434                    OrderByComparator<MBMessage> orderByComparator,
3435                    boolean retrieveFromCache) {
3436                    boolean pagination = true;
3437                    FinderPath finderPath = null;
3438                    Object[] finderArgs = null;
3439    
3440                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3441                                    (orderByComparator == null)) {
3442                            pagination = false;
3443                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3444                            finderArgs = new Object[] { threadId };
3445                    }
3446                    else {
3447                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3448                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3449                    }
3450    
3451                    List<MBMessage> list = null;
3452    
3453                    if (retrieveFromCache) {
3454                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3455                                            finderArgs, this);
3456    
3457                            if ((list != null) && !list.isEmpty()) {
3458                                    for (MBMessage mbMessage : list) {
3459                                            if ((threadId != mbMessage.getThreadId())) {
3460                                                    list = null;
3461    
3462                                                    break;
3463                                            }
3464                                    }
3465                            }
3466                    }
3467    
3468                    if (list == null) {
3469                            StringBundler query = null;
3470    
3471                            if (orderByComparator != null) {
3472                                    query = new StringBundler(3 +
3473                                                    (orderByComparator.getOrderByFields().length * 3));
3474                            }
3475                            else {
3476                                    query = new StringBundler(3);
3477                            }
3478    
3479                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3480    
3481                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3482    
3483                            if (orderByComparator != null) {
3484                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3485                                            orderByComparator);
3486                            }
3487                            else
3488                             if (pagination) {
3489                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3490                            }
3491    
3492                            String sql = query.toString();
3493    
3494                            Session session = null;
3495    
3496                            try {
3497                                    session = openSession();
3498    
3499                                    Query q = session.createQuery(sql);
3500    
3501                                    QueryPos qPos = QueryPos.getInstance(q);
3502    
3503                                    qPos.add(threadId);
3504    
3505                                    if (!pagination) {
3506                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3507                                                            start, end, false);
3508    
3509                                            Collections.sort(list);
3510    
3511                                            list = Collections.unmodifiableList(list);
3512                                    }
3513                                    else {
3514                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3515                                                            start, end);
3516                                    }
3517    
3518                                    cacheResult(list);
3519    
3520                                    finderCache.putResult(finderPath, finderArgs, list);
3521                            }
3522                            catch (Exception e) {
3523                                    finderCache.removeResult(finderPath, finderArgs);
3524    
3525                                    throw processException(e);
3526                            }
3527                            finally {
3528                                    closeSession(session);
3529                            }
3530                    }
3531    
3532                    return list;
3533            }
3534    
3535            /**
3536             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3537             *
3538             * @param threadId the thread ID
3539             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3540             * @return the first matching message-boards message
3541             * @throws NoSuchMessageException if a matching message-boards message could not be found
3542             */
3543            @Override
3544            public MBMessage findByThreadId_First(long threadId,
3545                    OrderByComparator<MBMessage> orderByComparator)
3546                    throws NoSuchMessageException {
3547                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3548    
3549                    if (mbMessage != null) {
3550                            return mbMessage;
3551                    }
3552    
3553                    StringBundler msg = new StringBundler(4);
3554    
3555                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3556    
3557                    msg.append("threadId=");
3558                    msg.append(threadId);
3559    
3560                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3561    
3562                    throw new NoSuchMessageException(msg.toString());
3563            }
3564    
3565            /**
3566             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3567             *
3568             * @param threadId the thread ID
3569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3570             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3571             */
3572            @Override
3573            public MBMessage fetchByThreadId_First(long threadId,
3574                    OrderByComparator<MBMessage> orderByComparator) {
3575                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3576    
3577                    if (!list.isEmpty()) {
3578                            return list.get(0);
3579                    }
3580    
3581                    return null;
3582            }
3583    
3584            /**
3585             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3586             *
3587             * @param threadId the thread ID
3588             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3589             * @return the last matching message-boards message
3590             * @throws NoSuchMessageException if a matching message-boards message could not be found
3591             */
3592            @Override
3593            public MBMessage findByThreadId_Last(long threadId,
3594                    OrderByComparator<MBMessage> orderByComparator)
3595                    throws NoSuchMessageException {
3596                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3597    
3598                    if (mbMessage != null) {
3599                            return mbMessage;
3600                    }
3601    
3602                    StringBundler msg = new StringBundler(4);
3603    
3604                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3605    
3606                    msg.append("threadId=");
3607                    msg.append(threadId);
3608    
3609                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3610    
3611                    throw new NoSuchMessageException(msg.toString());
3612            }
3613    
3614            /**
3615             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3616             *
3617             * @param threadId the thread ID
3618             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3619             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3620             */
3621            @Override
3622            public MBMessage fetchByThreadId_Last(long threadId,
3623                    OrderByComparator<MBMessage> orderByComparator) {
3624                    int count = countByThreadId(threadId);
3625    
3626                    if (count == 0) {
3627                            return null;
3628                    }
3629    
3630                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3631                                    orderByComparator);
3632    
3633                    if (!list.isEmpty()) {
3634                            return list.get(0);
3635                    }
3636    
3637                    return null;
3638            }
3639    
3640            /**
3641             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3642             *
3643             * @param messageId the primary key of the current message-boards message
3644             * @param threadId the thread ID
3645             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3646             * @return the previous, current, and next message-boards message
3647             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3648             */
3649            @Override
3650            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3651                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3652                    throws NoSuchMessageException {
3653                    MBMessage mbMessage = findByPrimaryKey(messageId);
3654    
3655                    Session session = null;
3656    
3657                    try {
3658                            session = openSession();
3659    
3660                            MBMessage[] array = new MBMessageImpl[3];
3661    
3662                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3663                                            orderByComparator, true);
3664    
3665                            array[1] = mbMessage;
3666    
3667                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3668                                            orderByComparator, false);
3669    
3670                            return array;
3671                    }
3672                    catch (Exception e) {
3673                            throw processException(e);
3674                    }
3675                    finally {
3676                            closeSession(session);
3677                    }
3678            }
3679    
3680            protected MBMessage getByThreadId_PrevAndNext(Session session,
3681                    MBMessage mbMessage, long threadId,
3682                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3683                    StringBundler query = null;
3684    
3685                    if (orderByComparator != null) {
3686                            query = new StringBundler(6 +
3687                                            (orderByComparator.getOrderByFields().length * 6));
3688                    }
3689                    else {
3690                            query = new StringBundler(3);
3691                    }
3692    
3693                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3694    
3695                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3696    
3697                    if (orderByComparator != null) {
3698                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3699    
3700                            if (orderByConditionFields.length > 0) {
3701                                    query.append(WHERE_AND);
3702                            }
3703    
3704                            for (int i = 0; i < orderByConditionFields.length; i++) {
3705                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3706                                    query.append(orderByConditionFields[i]);
3707    
3708                                    if ((i + 1) < orderByConditionFields.length) {
3709                                            if (orderByComparator.isAscending() ^ previous) {
3710                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3711                                            }
3712                                            else {
3713                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3714                                            }
3715                                    }
3716                                    else {
3717                                            if (orderByComparator.isAscending() ^ previous) {
3718                                                    query.append(WHERE_GREATER_THAN);
3719                                            }
3720                                            else {
3721                                                    query.append(WHERE_LESSER_THAN);
3722                                            }
3723                                    }
3724                            }
3725    
3726                            query.append(ORDER_BY_CLAUSE);
3727    
3728                            String[] orderByFields = orderByComparator.getOrderByFields();
3729    
3730                            for (int i = 0; i < orderByFields.length; i++) {
3731                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3732                                    query.append(orderByFields[i]);
3733    
3734                                    if ((i + 1) < orderByFields.length) {
3735                                            if (orderByComparator.isAscending() ^ previous) {
3736                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3737                                            }
3738                                            else {
3739                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3740                                            }
3741                                    }
3742                                    else {
3743                                            if (orderByComparator.isAscending() ^ previous) {
3744                                                    query.append(ORDER_BY_ASC);
3745                                            }
3746                                            else {
3747                                                    query.append(ORDER_BY_DESC);
3748                                            }
3749                                    }
3750                            }
3751                    }
3752                    else {
3753                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3754                    }
3755    
3756                    String sql = query.toString();
3757    
3758                    Query q = session.createQuery(sql);
3759    
3760                    q.setFirstResult(0);
3761                    q.setMaxResults(2);
3762    
3763                    QueryPos qPos = QueryPos.getInstance(q);
3764    
3765                    qPos.add(threadId);
3766    
3767                    if (orderByComparator != null) {
3768                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3769    
3770                            for (Object value : values) {
3771                                    qPos.add(value);
3772                            }
3773                    }
3774    
3775                    List<MBMessage> list = q.list();
3776    
3777                    if (list.size() == 2) {
3778                            return list.get(1);
3779                    }
3780                    else {
3781                            return null;
3782                    }
3783            }
3784    
3785            /**
3786             * Removes all the message-boards messages where threadId = &#63; from the database.
3787             *
3788             * @param threadId the thread ID
3789             */
3790            @Override
3791            public void removeByThreadId(long threadId) {
3792                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3793                                    QueryUtil.ALL_POS, null)) {
3794                            remove(mbMessage);
3795                    }
3796            }
3797    
3798            /**
3799             * Returns the number of message-boards messages where threadId = &#63;.
3800             *
3801             * @param threadId the thread ID
3802             * @return the number of matching message-boards messages
3803             */
3804            @Override
3805            public int countByThreadId(long threadId) {
3806                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3807    
3808                    Object[] finderArgs = new Object[] { threadId };
3809    
3810                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3811    
3812                    if (count == null) {
3813                            StringBundler query = new StringBundler(2);
3814    
3815                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3816    
3817                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3818    
3819                            String sql = query.toString();
3820    
3821                            Session session = null;
3822    
3823                            try {
3824                                    session = openSession();
3825    
3826                                    Query q = session.createQuery(sql);
3827    
3828                                    QueryPos qPos = QueryPos.getInstance(q);
3829    
3830                                    qPos.add(threadId);
3831    
3832                                    count = (Long)q.uniqueResult();
3833    
3834                                    finderCache.putResult(finderPath, finderArgs, count);
3835                            }
3836                            catch (Exception e) {
3837                                    finderCache.removeResult(finderPath, finderArgs);
3838    
3839                                    throw processException(e);
3840                            }
3841                            finally {
3842                                    closeSession(session);
3843                            }
3844                    }
3845    
3846                    return count.intValue();
3847            }
3848    
3849            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3850            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3851                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3852                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3853                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3854                            new String[] {
3855                                    Long.class.getName(),
3856                                    
3857                            Integer.class.getName(), Integer.class.getName(),
3858                                    OrderByComparator.class.getName()
3859                            });
3860            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3861                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3862                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3863                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3864                            new String[] { Long.class.getName() },
3865                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3866                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3867            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3868                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3869                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3870                            new String[] { Long.class.getName() });
3871    
3872            /**
3873             * Returns all the message-boards messages where threadId = &#63;.
3874             *
3875             * @param threadId the thread ID
3876             * @return the matching message-boards messages
3877             */
3878            @Override
3879            public List<MBMessage> findByThreadReplies(long threadId) {
3880                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3881                            QueryUtil.ALL_POS, null);
3882            }
3883    
3884            /**
3885             * Returns a range of all the message-boards messages where threadId = &#63;.
3886             *
3887             * <p>
3888             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3889             * </p>
3890             *
3891             * @param threadId the thread ID
3892             * @param start the lower bound of the range of message-boards messages
3893             * @param end the upper bound of the range of message-boards messages (not inclusive)
3894             * @return the range of matching message-boards messages
3895             */
3896            @Override
3897            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3898                    return findByThreadReplies(threadId, start, end, null);
3899            }
3900    
3901            /**
3902             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3903             *
3904             * <p>
3905             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3906             * </p>
3907             *
3908             * @param threadId the thread ID
3909             * @param start the lower bound of the range of message-boards messages
3910             * @param end the upper bound of the range of message-boards messages (not inclusive)
3911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3912             * @return the ordered range of matching message-boards messages
3913             */
3914            @Override
3915            public List<MBMessage> findByThreadReplies(long threadId, int start,
3916                    int end, OrderByComparator<MBMessage> orderByComparator) {
3917                    return findByThreadReplies(threadId, start, end, orderByComparator, true);
3918            }
3919    
3920            /**
3921             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3922             *
3923             * <p>
3924             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3925             * </p>
3926             *
3927             * @param threadId the thread ID
3928             * @param start the lower bound of the range of message-boards messages
3929             * @param end the upper bound of the range of message-boards messages (not inclusive)
3930             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3931             * @param retrieveFromCache whether to retrieve from the finder cache
3932             * @return the ordered range of matching message-boards messages
3933             */
3934            @Override
3935            public List<MBMessage> findByThreadReplies(long threadId, int start,
3936                    int end, OrderByComparator<MBMessage> orderByComparator,
3937                    boolean retrieveFromCache) {
3938                    boolean pagination = true;
3939                    FinderPath finderPath = null;
3940                    Object[] finderArgs = null;
3941    
3942                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3943                                    (orderByComparator == null)) {
3944                            pagination = false;
3945                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3946                            finderArgs = new Object[] { threadId };
3947                    }
3948                    else {
3949                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3950                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3951                    }
3952    
3953                    List<MBMessage> list = null;
3954    
3955                    if (retrieveFromCache) {
3956                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3957                                            finderArgs, this);
3958    
3959                            if ((list != null) && !list.isEmpty()) {
3960                                    for (MBMessage mbMessage : list) {
3961                                            if ((threadId != mbMessage.getThreadId())) {
3962                                                    list = null;
3963    
3964                                                    break;
3965                                            }
3966                                    }
3967                            }
3968                    }
3969    
3970                    if (list == null) {
3971                            StringBundler query = null;
3972    
3973                            if (orderByComparator != null) {
3974                                    query = new StringBundler(3 +
3975                                                    (orderByComparator.getOrderByFields().length * 3));
3976                            }
3977                            else {
3978                                    query = new StringBundler(3);
3979                            }
3980    
3981                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3982    
3983                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3984    
3985                            if (orderByComparator != null) {
3986                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3987                                            orderByComparator);
3988                            }
3989                            else
3990                             if (pagination) {
3991                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3992                            }
3993    
3994                            String sql = query.toString();
3995    
3996                            Session session = null;
3997    
3998                            try {
3999                                    session = openSession();
4000    
4001                                    Query q = session.createQuery(sql);
4002    
4003                                    QueryPos qPos = QueryPos.getInstance(q);
4004    
4005                                    qPos.add(threadId);
4006    
4007                                    if (!pagination) {
4008                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4009                                                            start, end, false);
4010    
4011                                            Collections.sort(list);
4012    
4013                                            list = Collections.unmodifiableList(list);
4014                                    }
4015                                    else {
4016                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4017                                                            start, end);
4018                                    }
4019    
4020                                    cacheResult(list);
4021    
4022                                    finderCache.putResult(finderPath, finderArgs, list);
4023                            }
4024                            catch (Exception e) {
4025                                    finderCache.removeResult(finderPath, finderArgs);
4026    
4027                                    throw processException(e);
4028                            }
4029                            finally {
4030                                    closeSession(session);
4031                            }
4032                    }
4033    
4034                    return list;
4035            }
4036    
4037            /**
4038             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4039             *
4040             * @param threadId the thread ID
4041             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4042             * @return the first matching message-boards message
4043             * @throws NoSuchMessageException if a matching message-boards message could not be found
4044             */
4045            @Override
4046            public MBMessage findByThreadReplies_First(long threadId,
4047                    OrderByComparator<MBMessage> orderByComparator)
4048                    throws NoSuchMessageException {
4049                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4050                                    orderByComparator);
4051    
4052                    if (mbMessage != null) {
4053                            return mbMessage;
4054                    }
4055    
4056                    StringBundler msg = new StringBundler(4);
4057    
4058                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4059    
4060                    msg.append("threadId=");
4061                    msg.append(threadId);
4062    
4063                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4064    
4065                    throw new NoSuchMessageException(msg.toString());
4066            }
4067    
4068            /**
4069             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4070             *
4071             * @param threadId the thread ID
4072             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4073             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4074             */
4075            @Override
4076            public MBMessage fetchByThreadReplies_First(long threadId,
4077                    OrderByComparator<MBMessage> orderByComparator) {
4078                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4079                                    orderByComparator);
4080    
4081                    if (!list.isEmpty()) {
4082                            return list.get(0);
4083                    }
4084    
4085                    return null;
4086            }
4087    
4088            /**
4089             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4090             *
4091             * @param threadId the thread ID
4092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4093             * @return the last matching message-boards message
4094             * @throws NoSuchMessageException if a matching message-boards message could not be found
4095             */
4096            @Override
4097            public MBMessage findByThreadReplies_Last(long threadId,
4098                    OrderByComparator<MBMessage> orderByComparator)
4099                    throws NoSuchMessageException {
4100                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4101                                    orderByComparator);
4102    
4103                    if (mbMessage != null) {
4104                            return mbMessage;
4105                    }
4106    
4107                    StringBundler msg = new StringBundler(4);
4108    
4109                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4110    
4111                    msg.append("threadId=");
4112                    msg.append(threadId);
4113    
4114                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4115    
4116                    throw new NoSuchMessageException(msg.toString());
4117            }
4118    
4119            /**
4120             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4121             *
4122             * @param threadId the thread ID
4123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4124             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4125             */
4126            @Override
4127            public MBMessage fetchByThreadReplies_Last(long threadId,
4128                    OrderByComparator<MBMessage> orderByComparator) {
4129                    int count = countByThreadReplies(threadId);
4130    
4131                    if (count == 0) {
4132                            return null;
4133                    }
4134    
4135                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4136                                    orderByComparator);
4137    
4138                    if (!list.isEmpty()) {
4139                            return list.get(0);
4140                    }
4141    
4142                    return null;
4143            }
4144    
4145            /**
4146             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4147             *
4148             * @param messageId the primary key of the current message-boards message
4149             * @param threadId the thread ID
4150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4151             * @return the previous, current, and next message-boards message
4152             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4153             */
4154            @Override
4155            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4156                    long threadId, OrderByComparator<MBMessage> orderByComparator)
4157                    throws NoSuchMessageException {
4158                    MBMessage mbMessage = findByPrimaryKey(messageId);
4159    
4160                    Session session = null;
4161    
4162                    try {
4163                            session = openSession();
4164    
4165                            MBMessage[] array = new MBMessageImpl[3];
4166    
4167                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4168                                            threadId, orderByComparator, true);
4169    
4170                            array[1] = mbMessage;
4171    
4172                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4173                                            threadId, orderByComparator, false);
4174    
4175                            return array;
4176                    }
4177                    catch (Exception e) {
4178                            throw processException(e);
4179                    }
4180                    finally {
4181                            closeSession(session);
4182                    }
4183            }
4184    
4185            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4186                    MBMessage mbMessage, long threadId,
4187                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4188                    StringBundler query = null;
4189    
4190                    if (orderByComparator != null) {
4191                            query = new StringBundler(6 +
4192                                            (orderByComparator.getOrderByFields().length * 6));
4193                    }
4194                    else {
4195                            query = new StringBundler(3);
4196                    }
4197    
4198                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4199    
4200                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4201    
4202                    if (orderByComparator != null) {
4203                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4204    
4205                            if (orderByConditionFields.length > 0) {
4206                                    query.append(WHERE_AND);
4207                            }
4208    
4209                            for (int i = 0; i < orderByConditionFields.length; i++) {
4210                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4211                                    query.append(orderByConditionFields[i]);
4212    
4213                                    if ((i + 1) < orderByConditionFields.length) {
4214                                            if (orderByComparator.isAscending() ^ previous) {
4215                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4216                                            }
4217                                            else {
4218                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4219                                            }
4220                                    }
4221                                    else {
4222                                            if (orderByComparator.isAscending() ^ previous) {
4223                                                    query.append(WHERE_GREATER_THAN);
4224                                            }
4225                                            else {
4226                                                    query.append(WHERE_LESSER_THAN);
4227                                            }
4228                                    }
4229                            }
4230    
4231                            query.append(ORDER_BY_CLAUSE);
4232    
4233                            String[] orderByFields = orderByComparator.getOrderByFields();
4234    
4235                            for (int i = 0; i < orderByFields.length; i++) {
4236                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4237                                    query.append(orderByFields[i]);
4238    
4239                                    if ((i + 1) < orderByFields.length) {
4240                                            if (orderByComparator.isAscending() ^ previous) {
4241                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4242                                            }
4243                                            else {
4244                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4245                                            }
4246                                    }
4247                                    else {
4248                                            if (orderByComparator.isAscending() ^ previous) {
4249                                                    query.append(ORDER_BY_ASC);
4250                                            }
4251                                            else {
4252                                                    query.append(ORDER_BY_DESC);
4253                                            }
4254                                    }
4255                            }
4256                    }
4257                    else {
4258                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4259                    }
4260    
4261                    String sql = query.toString();
4262    
4263                    Query q = session.createQuery(sql);
4264    
4265                    q.setFirstResult(0);
4266                    q.setMaxResults(2);
4267    
4268                    QueryPos qPos = QueryPos.getInstance(q);
4269    
4270                    qPos.add(threadId);
4271    
4272                    if (orderByComparator != null) {
4273                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4274    
4275                            for (Object value : values) {
4276                                    qPos.add(value);
4277                            }
4278                    }
4279    
4280                    List<MBMessage> list = q.list();
4281    
4282                    if (list.size() == 2) {
4283                            return list.get(1);
4284                    }
4285                    else {
4286                            return null;
4287                    }
4288            }
4289    
4290            /**
4291             * Removes all the message-boards messages where threadId = &#63; from the database.
4292             *
4293             * @param threadId the thread ID
4294             */
4295            @Override
4296            public void removeByThreadReplies(long threadId) {
4297                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4298                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4299                            remove(mbMessage);
4300                    }
4301            }
4302    
4303            /**
4304             * Returns the number of message-boards messages where threadId = &#63;.
4305             *
4306             * @param threadId the thread ID
4307             * @return the number of matching message-boards messages
4308             */
4309            @Override
4310            public int countByThreadReplies(long threadId) {
4311                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4312    
4313                    Object[] finderArgs = new Object[] { threadId };
4314    
4315                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4316    
4317                    if (count == null) {
4318                            StringBundler query = new StringBundler(2);
4319    
4320                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4321    
4322                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4323    
4324                            String sql = query.toString();
4325    
4326                            Session session = null;
4327    
4328                            try {
4329                                    session = openSession();
4330    
4331                                    Query q = session.createQuery(sql);
4332    
4333                                    QueryPos qPos = QueryPos.getInstance(q);
4334    
4335                                    qPos.add(threadId);
4336    
4337                                    count = (Long)q.uniqueResult();
4338    
4339                                    finderCache.putResult(finderPath, finderArgs, count);
4340                            }
4341                            catch (Exception e) {
4342                                    finderCache.removeResult(finderPath, finderArgs);
4343    
4344                                    throw processException(e);
4345                            }
4346                            finally {
4347                                    closeSession(session);
4348                            }
4349                    }
4350    
4351                    return count.intValue();
4352            }
4353    
4354            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4355            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4356                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4357                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4358                            new String[] {
4359                                    Long.class.getName(), Long.class.getName(),
4360                                    
4361                            Integer.class.getName(), Integer.class.getName(),
4362                                    OrderByComparator.class.getName()
4363                            });
4364            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4365                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4366                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4367                            new String[] { Long.class.getName(), Long.class.getName() },
4368                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4369                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4370                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4371            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4372                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4373                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4374                            new String[] { Long.class.getName(), Long.class.getName() });
4375    
4376            /**
4377             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4378             *
4379             * @param groupId the group ID
4380             * @param userId the user ID
4381             * @return the matching message-boards messages
4382             */
4383            @Override
4384            public List<MBMessage> findByG_U(long groupId, long userId) {
4385                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4386                            null);
4387            }
4388    
4389            /**
4390             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4391             *
4392             * <p>
4393             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4394             * </p>
4395             *
4396             * @param groupId the group ID
4397             * @param userId the user ID
4398             * @param start the lower bound of the range of message-boards messages
4399             * @param end the upper bound of the range of message-boards messages (not inclusive)
4400             * @return the range of matching message-boards messages
4401             */
4402            @Override
4403            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4404                    int end) {
4405                    return findByG_U(groupId, userId, start, end, null);
4406            }
4407    
4408            /**
4409             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4410             *
4411             * <p>
4412             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4413             * </p>
4414             *
4415             * @param groupId the group ID
4416             * @param userId the user ID
4417             * @param start the lower bound of the range of message-boards messages
4418             * @param end the upper bound of the range of message-boards messages (not inclusive)
4419             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4420             * @return the ordered range of matching message-boards messages
4421             */
4422            @Override
4423            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4424                    int end, OrderByComparator<MBMessage> orderByComparator) {
4425                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
4426            }
4427    
4428            /**
4429             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4430             *
4431             * <p>
4432             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4433             * </p>
4434             *
4435             * @param groupId the group ID
4436             * @param userId the user ID
4437             * @param start the lower bound of the range of message-boards messages
4438             * @param end the upper bound of the range of message-boards messages (not inclusive)
4439             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4440             * @param retrieveFromCache whether to retrieve from the finder cache
4441             * @return the ordered range of matching message-boards messages
4442             */
4443            @Override
4444            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4445                    int end, OrderByComparator<MBMessage> orderByComparator,
4446                    boolean retrieveFromCache) {
4447                    boolean pagination = true;
4448                    FinderPath finderPath = null;
4449                    Object[] finderArgs = null;
4450    
4451                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4452                                    (orderByComparator == null)) {
4453                            pagination = false;
4454                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4455                            finderArgs = new Object[] { groupId, userId };
4456                    }
4457                    else {
4458                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4459                            finderArgs = new Object[] {
4460                                            groupId, userId,
4461                                            
4462                                            start, end, orderByComparator
4463                                    };
4464                    }
4465    
4466                    List<MBMessage> list = null;
4467    
4468                    if (retrieveFromCache) {
4469                            list = (List<MBMessage>)finderCache.getResult(finderPath,
4470                                            finderArgs, this);
4471    
4472                            if ((list != null) && !list.isEmpty()) {
4473                                    for (MBMessage mbMessage : list) {
4474                                            if ((groupId != mbMessage.getGroupId()) ||
4475                                                            (userId != mbMessage.getUserId())) {
4476                                                    list = null;
4477    
4478                                                    break;
4479                                            }
4480                                    }
4481                            }
4482                    }
4483    
4484                    if (list == null) {
4485                            StringBundler query = null;
4486    
4487                            if (orderByComparator != null) {
4488                                    query = new StringBundler(4 +
4489                                                    (orderByComparator.getOrderByFields().length * 3));
4490                            }
4491                            else {
4492                                    query = new StringBundler(4);
4493                            }
4494    
4495                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4496    
4497                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4498    
4499                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4500    
4501                            if (orderByComparator != null) {
4502                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4503                                            orderByComparator);
4504                            }
4505                            else
4506                             if (pagination) {
4507                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4508                            }
4509    
4510                            String sql = query.toString();
4511    
4512                            Session session = null;
4513    
4514                            try {
4515                                    session = openSession();
4516    
4517                                    Query q = session.createQuery(sql);
4518    
4519                                    QueryPos qPos = QueryPos.getInstance(q);
4520    
4521                                    qPos.add(groupId);
4522    
4523                                    qPos.add(userId);
4524    
4525                                    if (!pagination) {
4526                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4527                                                            start, end, false);
4528    
4529                                            Collections.sort(list);
4530    
4531                                            list = Collections.unmodifiableList(list);
4532                                    }
4533                                    else {
4534                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4535                                                            start, end);
4536                                    }
4537    
4538                                    cacheResult(list);
4539    
4540                                    finderCache.putResult(finderPath, finderArgs, list);
4541                            }
4542                            catch (Exception e) {
4543                                    finderCache.removeResult(finderPath, finderArgs);
4544    
4545                                    throw processException(e);
4546                            }
4547                            finally {
4548                                    closeSession(session);
4549                            }
4550                    }
4551    
4552                    return list;
4553            }
4554    
4555            /**
4556             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4557             *
4558             * @param groupId the group ID
4559             * @param userId the user ID
4560             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4561             * @return the first matching message-boards message
4562             * @throws NoSuchMessageException if a matching message-boards message could not be found
4563             */
4564            @Override
4565            public MBMessage findByG_U_First(long groupId, long userId,
4566                    OrderByComparator<MBMessage> orderByComparator)
4567                    throws NoSuchMessageException {
4568                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4569                                    orderByComparator);
4570    
4571                    if (mbMessage != null) {
4572                            return mbMessage;
4573                    }
4574    
4575                    StringBundler msg = new StringBundler(6);
4576    
4577                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4578    
4579                    msg.append("groupId=");
4580                    msg.append(groupId);
4581    
4582                    msg.append(", userId=");
4583                    msg.append(userId);
4584    
4585                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4586    
4587                    throw new NoSuchMessageException(msg.toString());
4588            }
4589    
4590            /**
4591             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4592             *
4593             * @param groupId the group ID
4594             * @param userId the user ID
4595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4596             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4597             */
4598            @Override
4599            public MBMessage fetchByG_U_First(long groupId, long userId,
4600                    OrderByComparator<MBMessage> orderByComparator) {
4601                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4602                                    orderByComparator);
4603    
4604                    if (!list.isEmpty()) {
4605                            return list.get(0);
4606                    }
4607    
4608                    return null;
4609            }
4610    
4611            /**
4612             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4613             *
4614             * @param groupId the group ID
4615             * @param userId the user ID
4616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4617             * @return the last matching message-boards message
4618             * @throws NoSuchMessageException if a matching message-boards message could not be found
4619             */
4620            @Override
4621            public MBMessage findByG_U_Last(long groupId, long userId,
4622                    OrderByComparator<MBMessage> orderByComparator)
4623                    throws NoSuchMessageException {
4624                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4625    
4626                    if (mbMessage != null) {
4627                            return mbMessage;
4628                    }
4629    
4630                    StringBundler msg = new StringBundler(6);
4631    
4632                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4633    
4634                    msg.append("groupId=");
4635                    msg.append(groupId);
4636    
4637                    msg.append(", userId=");
4638                    msg.append(userId);
4639    
4640                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4641    
4642                    throw new NoSuchMessageException(msg.toString());
4643            }
4644    
4645            /**
4646             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4647             *
4648             * @param groupId the group ID
4649             * @param userId the user ID
4650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4651             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4652             */
4653            @Override
4654            public MBMessage fetchByG_U_Last(long groupId, long userId,
4655                    OrderByComparator<MBMessage> orderByComparator) {
4656                    int count = countByG_U(groupId, userId);
4657    
4658                    if (count == 0) {
4659                            return null;
4660                    }
4661    
4662                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4663                                    orderByComparator);
4664    
4665                    if (!list.isEmpty()) {
4666                            return list.get(0);
4667                    }
4668    
4669                    return null;
4670            }
4671    
4672            /**
4673             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4674             *
4675             * @param messageId the primary key of the current message-boards message
4676             * @param groupId the group ID
4677             * @param userId the user ID
4678             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4679             * @return the previous, current, and next message-boards message
4680             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4681             */
4682            @Override
4683            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4684                    long userId, OrderByComparator<MBMessage> orderByComparator)
4685                    throws NoSuchMessageException {
4686                    MBMessage mbMessage = findByPrimaryKey(messageId);
4687    
4688                    Session session = null;
4689    
4690                    try {
4691                            session = openSession();
4692    
4693                            MBMessage[] array = new MBMessageImpl[3];
4694    
4695                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4696                                            userId, orderByComparator, true);
4697    
4698                            array[1] = mbMessage;
4699    
4700                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4701                                            userId, orderByComparator, false);
4702    
4703                            return array;
4704                    }
4705                    catch (Exception e) {
4706                            throw processException(e);
4707                    }
4708                    finally {
4709                            closeSession(session);
4710                    }
4711            }
4712    
4713            protected MBMessage getByG_U_PrevAndNext(Session session,
4714                    MBMessage mbMessage, long groupId, long userId,
4715                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4716                    StringBundler query = null;
4717    
4718                    if (orderByComparator != null) {
4719                            query = new StringBundler(6 +
4720                                            (orderByComparator.getOrderByFields().length * 6));
4721                    }
4722                    else {
4723                            query = new StringBundler(3);
4724                    }
4725    
4726                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4727    
4728                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4729    
4730                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4731    
4732                    if (orderByComparator != null) {
4733                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4734    
4735                            if (orderByConditionFields.length > 0) {
4736                                    query.append(WHERE_AND);
4737                            }
4738    
4739                            for (int i = 0; i < orderByConditionFields.length; i++) {
4740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4741                                    query.append(orderByConditionFields[i]);
4742    
4743                                    if ((i + 1) < orderByConditionFields.length) {
4744                                            if (orderByComparator.isAscending() ^ previous) {
4745                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4746                                            }
4747                                            else {
4748                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4749                                            }
4750                                    }
4751                                    else {
4752                                            if (orderByComparator.isAscending() ^ previous) {
4753                                                    query.append(WHERE_GREATER_THAN);
4754                                            }
4755                                            else {
4756                                                    query.append(WHERE_LESSER_THAN);
4757                                            }
4758                                    }
4759                            }
4760    
4761                            query.append(ORDER_BY_CLAUSE);
4762    
4763                            String[] orderByFields = orderByComparator.getOrderByFields();
4764    
4765                            for (int i = 0; i < orderByFields.length; i++) {
4766                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4767                                    query.append(orderByFields[i]);
4768    
4769                                    if ((i + 1) < orderByFields.length) {
4770                                            if (orderByComparator.isAscending() ^ previous) {
4771                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4772                                            }
4773                                            else {
4774                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4775                                            }
4776                                    }
4777                                    else {
4778                                            if (orderByComparator.isAscending() ^ previous) {
4779                                                    query.append(ORDER_BY_ASC);
4780                                            }
4781                                            else {
4782                                                    query.append(ORDER_BY_DESC);
4783                                            }
4784                                    }
4785                            }
4786                    }
4787                    else {
4788                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4789                    }
4790    
4791                    String sql = query.toString();
4792    
4793                    Query q = session.createQuery(sql);
4794    
4795                    q.setFirstResult(0);
4796                    q.setMaxResults(2);
4797    
4798                    QueryPos qPos = QueryPos.getInstance(q);
4799    
4800                    qPos.add(groupId);
4801    
4802                    qPos.add(userId);
4803    
4804                    if (orderByComparator != null) {
4805                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4806    
4807                            for (Object value : values) {
4808                                    qPos.add(value);
4809                            }
4810                    }
4811    
4812                    List<MBMessage> list = q.list();
4813    
4814                    if (list.size() == 2) {
4815                            return list.get(1);
4816                    }
4817                    else {
4818                            return null;
4819                    }
4820            }
4821    
4822            /**
4823             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4824             *
4825             * @param groupId the group ID
4826             * @param userId the user ID
4827             * @return the matching message-boards messages that the user has permission to view
4828             */
4829            @Override
4830            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4831                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4832                            QueryUtil.ALL_POS, null);
4833            }
4834    
4835            /**
4836             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4837             *
4838             * <p>
4839             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4840             * </p>
4841             *
4842             * @param groupId the group ID
4843             * @param userId the user ID
4844             * @param start the lower bound of the range of message-boards messages
4845             * @param end the upper bound of the range of message-boards messages (not inclusive)
4846             * @return the range of matching message-boards messages that the user has permission to view
4847             */
4848            @Override
4849            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4850                    int start, int end) {
4851                    return filterFindByG_U(groupId, userId, start, end, null);
4852            }
4853    
4854            /**
4855             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4856             *
4857             * <p>
4858             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4859             * </p>
4860             *
4861             * @param groupId the group ID
4862             * @param userId the user ID
4863             * @param start the lower bound of the range of message-boards messages
4864             * @param end the upper bound of the range of message-boards messages (not inclusive)
4865             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4866             * @return the ordered range of matching message-boards messages that the user has permission to view
4867             */
4868            @Override
4869            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4870                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4871                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4872                            return findByG_U(groupId, userId, start, end, orderByComparator);
4873                    }
4874    
4875                    StringBundler query = null;
4876    
4877                    if (orderByComparator != null) {
4878                            query = new StringBundler(4 +
4879                                            (orderByComparator.getOrderByFields().length * 3));
4880                    }
4881                    else {
4882                            query = new StringBundler(4);
4883                    }
4884    
4885                    if (getDB().isSupportsInlineDistinct()) {
4886                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4887                    }
4888                    else {
4889                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4890                    }
4891    
4892                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4893    
4894                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4895    
4896                    if (!getDB().isSupportsInlineDistinct()) {
4897                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4898                    }
4899    
4900                    if (orderByComparator != null) {
4901                            if (getDB().isSupportsInlineDistinct()) {
4902                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4903                                            orderByComparator, true);
4904                            }
4905                            else {
4906                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4907                                            orderByComparator, true);
4908                            }
4909                    }
4910                    else {
4911                            if (getDB().isSupportsInlineDistinct()) {
4912                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4913                            }
4914                            else {
4915                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4916                            }
4917                    }
4918    
4919                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4920                                    MBMessage.class.getName(),
4921                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4922    
4923                    Session session = null;
4924    
4925                    try {
4926                            session = openSession();
4927    
4928                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4929    
4930                            if (getDB().isSupportsInlineDistinct()) {
4931                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4932                            }
4933                            else {
4934                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4935                            }
4936    
4937                            QueryPos qPos = QueryPos.getInstance(q);
4938    
4939                            qPos.add(groupId);
4940    
4941                            qPos.add(userId);
4942    
4943                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4944                    }
4945                    catch (Exception e) {
4946                            throw processException(e);
4947                    }
4948                    finally {
4949                            closeSession(session);
4950                    }
4951            }
4952    
4953            /**
4954             * 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;.
4955             *
4956             * @param messageId the primary key of the current message-boards message
4957             * @param groupId the group ID
4958             * @param userId the user ID
4959             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4960             * @return the previous, current, and next message-boards message
4961             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4962             */
4963            @Override
4964            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4965                    long groupId, long userId,
4966                    OrderByComparator<MBMessage> orderByComparator)
4967                    throws NoSuchMessageException {
4968                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4969                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4970                                    orderByComparator);
4971                    }
4972    
4973                    MBMessage mbMessage = findByPrimaryKey(messageId);
4974    
4975                    Session session = null;
4976    
4977                    try {
4978                            session = openSession();
4979    
4980                            MBMessage[] array = new MBMessageImpl[3];
4981    
4982                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4983                                            userId, orderByComparator, true);
4984    
4985                            array[1] = mbMessage;
4986    
4987                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4988                                            userId, orderByComparator, false);
4989    
4990                            return array;
4991                    }
4992                    catch (Exception e) {
4993                            throw processException(e);
4994                    }
4995                    finally {
4996                            closeSession(session);
4997                    }
4998            }
4999    
5000            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5001                    MBMessage mbMessage, long groupId, long userId,
5002                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5003                    StringBundler query = null;
5004    
5005                    if (orderByComparator != null) {
5006                            query = new StringBundler(6 +
5007                                            (orderByComparator.getOrderByFields().length * 6));
5008                    }
5009                    else {
5010                            query = new StringBundler(3);
5011                    }
5012    
5013                    if (getDB().isSupportsInlineDistinct()) {
5014                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5015                    }
5016                    else {
5017                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5018                    }
5019    
5020                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5021    
5022                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5023    
5024                    if (!getDB().isSupportsInlineDistinct()) {
5025                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5026                    }
5027    
5028                    if (orderByComparator != null) {
5029                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5030    
5031                            if (orderByConditionFields.length > 0) {
5032                                    query.append(WHERE_AND);
5033                            }
5034    
5035                            for (int i = 0; i < orderByConditionFields.length; i++) {
5036                                    if (getDB().isSupportsInlineDistinct()) {
5037                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5038                                    }
5039                                    else {
5040                                            query.append(_ORDER_BY_ENTITY_TABLE);
5041                                    }
5042    
5043                                    query.append(orderByConditionFields[i]);
5044    
5045                                    if ((i + 1) < orderByConditionFields.length) {
5046                                            if (orderByComparator.isAscending() ^ previous) {
5047                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5048                                            }
5049                                            else {
5050                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5051                                            }
5052                                    }
5053                                    else {
5054                                            if (orderByComparator.isAscending() ^ previous) {
5055                                                    query.append(WHERE_GREATER_THAN);
5056                                            }
5057                                            else {
5058                                                    query.append(WHERE_LESSER_THAN);
5059                                            }
5060                                    }
5061                            }
5062    
5063                            query.append(ORDER_BY_CLAUSE);
5064    
5065                            String[] orderByFields = orderByComparator.getOrderByFields();
5066    
5067                            for (int i = 0; i < orderByFields.length; i++) {
5068                                    if (getDB().isSupportsInlineDistinct()) {
5069                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5070                                    }
5071                                    else {
5072                                            query.append(_ORDER_BY_ENTITY_TABLE);
5073                                    }
5074    
5075                                    query.append(orderByFields[i]);
5076    
5077                                    if ((i + 1) < orderByFields.length) {
5078                                            if (orderByComparator.isAscending() ^ previous) {
5079                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5080                                            }
5081                                            else {
5082                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5083                                            }
5084                                    }
5085                                    else {
5086                                            if (orderByComparator.isAscending() ^ previous) {
5087                                                    query.append(ORDER_BY_ASC);
5088                                            }
5089                                            else {
5090                                                    query.append(ORDER_BY_DESC);
5091                                            }
5092                                    }
5093                            }
5094                    }
5095                    else {
5096                            if (getDB().isSupportsInlineDistinct()) {
5097                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5098                            }
5099                            else {
5100                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5101                            }
5102                    }
5103    
5104                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5105                                    MBMessage.class.getName(),
5106                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5107    
5108                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5109    
5110                    q.setFirstResult(0);
5111                    q.setMaxResults(2);
5112    
5113                    if (getDB().isSupportsInlineDistinct()) {
5114                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5115                    }
5116                    else {
5117                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5118                    }
5119    
5120                    QueryPos qPos = QueryPos.getInstance(q);
5121    
5122                    qPos.add(groupId);
5123    
5124                    qPos.add(userId);
5125    
5126                    if (orderByComparator != null) {
5127                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5128    
5129                            for (Object value : values) {
5130                                    qPos.add(value);
5131                            }
5132                    }
5133    
5134                    List<MBMessage> list = q.list();
5135    
5136                    if (list.size() == 2) {
5137                            return list.get(1);
5138                    }
5139                    else {
5140                            return null;
5141                    }
5142            }
5143    
5144            /**
5145             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5146             *
5147             * @param groupId the group ID
5148             * @param userId the user ID
5149             */
5150            @Override
5151            public void removeByG_U(long groupId, long userId) {
5152                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5153                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5154                            remove(mbMessage);
5155                    }
5156            }
5157    
5158            /**
5159             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5160             *
5161             * @param groupId the group ID
5162             * @param userId the user ID
5163             * @return the number of matching message-boards messages
5164             */
5165            @Override
5166            public int countByG_U(long groupId, long userId) {
5167                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5168    
5169                    Object[] finderArgs = new Object[] { groupId, userId };
5170    
5171                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5172    
5173                    if (count == null) {
5174                            StringBundler query = new StringBundler(3);
5175    
5176                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5177    
5178                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5179    
5180                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5181    
5182                            String sql = query.toString();
5183    
5184                            Session session = null;
5185    
5186                            try {
5187                                    session = openSession();
5188    
5189                                    Query q = session.createQuery(sql);
5190    
5191                                    QueryPos qPos = QueryPos.getInstance(q);
5192    
5193                                    qPos.add(groupId);
5194    
5195                                    qPos.add(userId);
5196    
5197                                    count = (Long)q.uniqueResult();
5198    
5199                                    finderCache.putResult(finderPath, finderArgs, count);
5200                            }
5201                            catch (Exception e) {
5202                                    finderCache.removeResult(finderPath, finderArgs);
5203    
5204                                    throw processException(e);
5205                            }
5206                            finally {
5207                                    closeSession(session);
5208                            }
5209                    }
5210    
5211                    return count.intValue();
5212            }
5213    
5214            /**
5215             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5216             *
5217             * @param groupId the group ID
5218             * @param userId the user ID
5219             * @return the number of matching message-boards messages that the user has permission to view
5220             */
5221            @Override
5222            public int filterCountByG_U(long groupId, long userId) {
5223                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5224                            return countByG_U(groupId, userId);
5225                    }
5226    
5227                    StringBundler query = new StringBundler(3);
5228    
5229                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5230    
5231                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5232    
5233                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5234    
5235                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5236                                    MBMessage.class.getName(),
5237                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5238    
5239                    Session session = null;
5240    
5241                    try {
5242                            session = openSession();
5243    
5244                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5245    
5246                            q.addScalar(COUNT_COLUMN_NAME,
5247                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5248    
5249                            QueryPos qPos = QueryPos.getInstance(q);
5250    
5251                            qPos.add(groupId);
5252    
5253                            qPos.add(userId);
5254    
5255                            Long count = (Long)q.uniqueResult();
5256    
5257                            return count.intValue();
5258                    }
5259                    catch (Exception e) {
5260                            throw processException(e);
5261                    }
5262                    finally {
5263                            closeSession(session);
5264                    }
5265            }
5266    
5267            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5268            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5269            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5270                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5271                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5272                            new String[] {
5273                                    Long.class.getName(), Long.class.getName(),
5274                                    
5275                            Integer.class.getName(), Integer.class.getName(),
5276                                    OrderByComparator.class.getName()
5277                            });
5278            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5279                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5280                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5281                            new String[] { Long.class.getName(), Long.class.getName() },
5282                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5283                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5284                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5285            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5286                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5287                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5288                            new String[] { Long.class.getName(), Long.class.getName() });
5289    
5290            /**
5291             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5292             *
5293             * @param groupId the group ID
5294             * @param categoryId the category ID
5295             * @return the matching message-boards messages
5296             */
5297            @Override
5298            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5299                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5300                            QueryUtil.ALL_POS, null);
5301            }
5302    
5303            /**
5304             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5305             *
5306             * <p>
5307             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5308             * </p>
5309             *
5310             * @param groupId the group ID
5311             * @param categoryId the category ID
5312             * @param start the lower bound of the range of message-boards messages
5313             * @param end the upper bound of the range of message-boards messages (not inclusive)
5314             * @return the range of matching message-boards messages
5315             */
5316            @Override
5317            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5318                    int end) {
5319                    return findByG_C(groupId, categoryId, start, end, null);
5320            }
5321    
5322            /**
5323             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5324             *
5325             * <p>
5326             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5327             * </p>
5328             *
5329             * @param groupId the group ID
5330             * @param categoryId the category ID
5331             * @param start the lower bound of the range of message-boards messages
5332             * @param end the upper bound of the range of message-boards messages (not inclusive)
5333             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5334             * @return the ordered range of matching message-boards messages
5335             */
5336            @Override
5337            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5338                    int end, OrderByComparator<MBMessage> orderByComparator) {
5339                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
5340                            true);
5341            }
5342    
5343            /**
5344             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5345             *
5346             * <p>
5347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5348             * </p>
5349             *
5350             * @param groupId the group ID
5351             * @param categoryId the category ID
5352             * @param start the lower bound of the range of message-boards messages
5353             * @param end the upper bound of the range of message-boards messages (not inclusive)
5354             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5355             * @param retrieveFromCache whether to retrieve from the finder cache
5356             * @return the ordered range of matching message-boards messages
5357             */
5358            @Override
5359            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5360                    int end, OrderByComparator<MBMessage> orderByComparator,
5361                    boolean retrieveFromCache) {
5362                    boolean pagination = true;
5363                    FinderPath finderPath = null;
5364                    Object[] finderArgs = null;
5365    
5366                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5367                                    (orderByComparator == null)) {
5368                            pagination = false;
5369                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5370                            finderArgs = new Object[] { groupId, categoryId };
5371                    }
5372                    else {
5373                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5374                            finderArgs = new Object[] {
5375                                            groupId, categoryId,
5376                                            
5377                                            start, end, orderByComparator
5378                                    };
5379                    }
5380    
5381                    List<MBMessage> list = null;
5382    
5383                    if (retrieveFromCache) {
5384                            list = (List<MBMessage>)finderCache.getResult(finderPath,
5385                                            finderArgs, this);
5386    
5387                            if ((list != null) && !list.isEmpty()) {
5388                                    for (MBMessage mbMessage : list) {
5389                                            if ((groupId != mbMessage.getGroupId()) ||
5390                                                            (categoryId != mbMessage.getCategoryId())) {
5391                                                    list = null;
5392    
5393                                                    break;
5394                                            }
5395                                    }
5396                            }
5397                    }
5398    
5399                    if (list == null) {
5400                            StringBundler query = null;
5401    
5402                            if (orderByComparator != null) {
5403                                    query = new StringBundler(4 +
5404                                                    (orderByComparator.getOrderByFields().length * 3));
5405                            }
5406                            else {
5407                                    query = new StringBundler(4);
5408                            }
5409    
5410                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5411    
5412                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5413    
5414                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5415    
5416                            if (orderByComparator != null) {
5417                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5418                                            orderByComparator);
5419                            }
5420                            else
5421                             if (pagination) {
5422                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5423                            }
5424    
5425                            String sql = query.toString();
5426    
5427                            Session session = null;
5428    
5429                            try {
5430                                    session = openSession();
5431    
5432                                    Query q = session.createQuery(sql);
5433    
5434                                    QueryPos qPos = QueryPos.getInstance(q);
5435    
5436                                    qPos.add(groupId);
5437    
5438                                    qPos.add(categoryId);
5439    
5440                                    if (!pagination) {
5441                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5442                                                            start, end, false);
5443    
5444                                            Collections.sort(list);
5445    
5446                                            list = Collections.unmodifiableList(list);
5447                                    }
5448                                    else {
5449                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5450                                                            start, end);
5451                                    }
5452    
5453                                    cacheResult(list);
5454    
5455                                    finderCache.putResult(finderPath, finderArgs, list);
5456                            }
5457                            catch (Exception e) {
5458                                    finderCache.removeResult(finderPath, finderArgs);
5459    
5460                                    throw processException(e);
5461                            }
5462                            finally {
5463                                    closeSession(session);
5464                            }
5465                    }
5466    
5467                    return list;
5468            }
5469    
5470            /**
5471             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5472             *
5473             * @param groupId the group ID
5474             * @param categoryId the category ID
5475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5476             * @return the first matching message-boards message
5477             * @throws NoSuchMessageException if a matching message-boards message could not be found
5478             */
5479            @Override
5480            public MBMessage findByG_C_First(long groupId, long categoryId,
5481                    OrderByComparator<MBMessage> orderByComparator)
5482                    throws NoSuchMessageException {
5483                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5484                                    orderByComparator);
5485    
5486                    if (mbMessage != null) {
5487                            return mbMessage;
5488                    }
5489    
5490                    StringBundler msg = new StringBundler(6);
5491    
5492                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5493    
5494                    msg.append("groupId=");
5495                    msg.append(groupId);
5496    
5497                    msg.append(", categoryId=");
5498                    msg.append(categoryId);
5499    
5500                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5501    
5502                    throw new NoSuchMessageException(msg.toString());
5503            }
5504    
5505            /**
5506             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5507             *
5508             * @param groupId the group ID
5509             * @param categoryId the category ID
5510             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5511             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5512             */
5513            @Override
5514            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5515                    OrderByComparator<MBMessage> orderByComparator) {
5516                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5517                                    orderByComparator);
5518    
5519                    if (!list.isEmpty()) {
5520                            return list.get(0);
5521                    }
5522    
5523                    return null;
5524            }
5525    
5526            /**
5527             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5528             *
5529             * @param groupId the group ID
5530             * @param categoryId the category ID
5531             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5532             * @return the last matching message-boards message
5533             * @throws NoSuchMessageException if a matching message-boards message could not be found
5534             */
5535            @Override
5536            public MBMessage findByG_C_Last(long groupId, long categoryId,
5537                    OrderByComparator<MBMessage> orderByComparator)
5538                    throws NoSuchMessageException {
5539                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5540                                    orderByComparator);
5541    
5542                    if (mbMessage != null) {
5543                            return mbMessage;
5544                    }
5545    
5546                    StringBundler msg = new StringBundler(6);
5547    
5548                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5549    
5550                    msg.append("groupId=");
5551                    msg.append(groupId);
5552    
5553                    msg.append(", categoryId=");
5554                    msg.append(categoryId);
5555    
5556                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5557    
5558                    throw new NoSuchMessageException(msg.toString());
5559            }
5560    
5561            /**
5562             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5563             *
5564             * @param groupId the group ID
5565             * @param categoryId the category ID
5566             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5567             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5568             */
5569            @Override
5570            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5571                    OrderByComparator<MBMessage> orderByComparator) {
5572                    int count = countByG_C(groupId, categoryId);
5573    
5574                    if (count == 0) {
5575                            return null;
5576                    }
5577    
5578                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5579                                    orderByComparator);
5580    
5581                    if (!list.isEmpty()) {
5582                            return list.get(0);
5583                    }
5584    
5585                    return null;
5586            }
5587    
5588            /**
5589             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5590             *
5591             * @param messageId the primary key of the current message-boards message
5592             * @param groupId the group ID
5593             * @param categoryId the category ID
5594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5595             * @return the previous, current, and next message-boards message
5596             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5597             */
5598            @Override
5599            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5600                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5601                    throws NoSuchMessageException {
5602                    MBMessage mbMessage = findByPrimaryKey(messageId);
5603    
5604                    Session session = null;
5605    
5606                    try {
5607                            session = openSession();
5608    
5609                            MBMessage[] array = new MBMessageImpl[3];
5610    
5611                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5612                                            categoryId, orderByComparator, true);
5613    
5614                            array[1] = mbMessage;
5615    
5616                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5617                                            categoryId, orderByComparator, false);
5618    
5619                            return array;
5620                    }
5621                    catch (Exception e) {
5622                            throw processException(e);
5623                    }
5624                    finally {
5625                            closeSession(session);
5626                    }
5627            }
5628    
5629            protected MBMessage getByG_C_PrevAndNext(Session session,
5630                    MBMessage mbMessage, long groupId, long categoryId,
5631                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5632                    StringBundler query = null;
5633    
5634                    if (orderByComparator != null) {
5635                            query = new StringBundler(6 +
5636                                            (orderByComparator.getOrderByFields().length * 6));
5637                    }
5638                    else {
5639                            query = new StringBundler(3);
5640                    }
5641    
5642                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5643    
5644                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5645    
5646                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5647    
5648                    if (orderByComparator != null) {
5649                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5650    
5651                            if (orderByConditionFields.length > 0) {
5652                                    query.append(WHERE_AND);
5653                            }
5654    
5655                            for (int i = 0; i < orderByConditionFields.length; i++) {
5656                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5657                                    query.append(orderByConditionFields[i]);
5658    
5659                                    if ((i + 1) < orderByConditionFields.length) {
5660                                            if (orderByComparator.isAscending() ^ previous) {
5661                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5662                                            }
5663                                            else {
5664                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5665                                            }
5666                                    }
5667                                    else {
5668                                            if (orderByComparator.isAscending() ^ previous) {
5669                                                    query.append(WHERE_GREATER_THAN);
5670                                            }
5671                                            else {
5672                                                    query.append(WHERE_LESSER_THAN);
5673                                            }
5674                                    }
5675                            }
5676    
5677                            query.append(ORDER_BY_CLAUSE);
5678    
5679                            String[] orderByFields = orderByComparator.getOrderByFields();
5680    
5681                            for (int i = 0; i < orderByFields.length; i++) {
5682                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5683                                    query.append(orderByFields[i]);
5684    
5685                                    if ((i + 1) < orderByFields.length) {
5686                                            if (orderByComparator.isAscending() ^ previous) {
5687                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5688                                            }
5689                                            else {
5690                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5691                                            }
5692                                    }
5693                                    else {
5694                                            if (orderByComparator.isAscending() ^ previous) {
5695                                                    query.append(ORDER_BY_ASC);
5696                                            }
5697                                            else {
5698                                                    query.append(ORDER_BY_DESC);
5699                                            }
5700                                    }
5701                            }
5702                    }
5703                    else {
5704                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5705                    }
5706    
5707                    String sql = query.toString();
5708    
5709                    Query q = session.createQuery(sql);
5710    
5711                    q.setFirstResult(0);
5712                    q.setMaxResults(2);
5713    
5714                    QueryPos qPos = QueryPos.getInstance(q);
5715    
5716                    qPos.add(groupId);
5717    
5718                    qPos.add(categoryId);
5719    
5720                    if (orderByComparator != null) {
5721                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5722    
5723                            for (Object value : values) {
5724                                    qPos.add(value);
5725                            }
5726                    }
5727    
5728                    List<MBMessage> list = q.list();
5729    
5730                    if (list.size() == 2) {
5731                            return list.get(1);
5732                    }
5733                    else {
5734                            return null;
5735                    }
5736            }
5737    
5738            /**
5739             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5740             *
5741             * @param groupId the group ID
5742             * @param categoryId the category ID
5743             * @return the matching message-boards messages that the user has permission to view
5744             */
5745            @Override
5746            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5747                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5748                            QueryUtil.ALL_POS, null);
5749            }
5750    
5751            /**
5752             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5753             *
5754             * <p>
5755             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5756             * </p>
5757             *
5758             * @param groupId the group ID
5759             * @param categoryId the category ID
5760             * @param start the lower bound of the range of message-boards messages
5761             * @param end the upper bound of the range of message-boards messages (not inclusive)
5762             * @return the range of matching message-boards messages that the user has permission to view
5763             */
5764            @Override
5765            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5766                    int start, int end) {
5767                    return filterFindByG_C(groupId, categoryId, start, end, null);
5768            }
5769    
5770            /**
5771             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5772             *
5773             * <p>
5774             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5775             * </p>
5776             *
5777             * @param groupId the group ID
5778             * @param categoryId the category ID
5779             * @param start the lower bound of the range of message-boards messages
5780             * @param end the upper bound of the range of message-boards messages (not inclusive)
5781             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5782             * @return the ordered range of matching message-boards messages that the user has permission to view
5783             */
5784            @Override
5785            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5786                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5787                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5788                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5789                    }
5790    
5791                    StringBundler query = null;
5792    
5793                    if (orderByComparator != null) {
5794                            query = new StringBundler(4 +
5795                                            (orderByComparator.getOrderByFields().length * 3));
5796                    }
5797                    else {
5798                            query = new StringBundler(4);
5799                    }
5800    
5801                    if (getDB().isSupportsInlineDistinct()) {
5802                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5803                    }
5804                    else {
5805                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5806                    }
5807    
5808                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5809    
5810                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5811    
5812                    if (!getDB().isSupportsInlineDistinct()) {
5813                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5814                    }
5815    
5816                    if (orderByComparator != null) {
5817                            if (getDB().isSupportsInlineDistinct()) {
5818                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5819                                            orderByComparator, true);
5820                            }
5821                            else {
5822                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5823                                            orderByComparator, true);
5824                            }
5825                    }
5826                    else {
5827                            if (getDB().isSupportsInlineDistinct()) {
5828                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5829                            }
5830                            else {
5831                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5832                            }
5833                    }
5834    
5835                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5836                                    MBMessage.class.getName(),
5837                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5838    
5839                    Session session = null;
5840    
5841                    try {
5842                            session = openSession();
5843    
5844                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5845    
5846                            if (getDB().isSupportsInlineDistinct()) {
5847                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5848                            }
5849                            else {
5850                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5851                            }
5852    
5853                            QueryPos qPos = QueryPos.getInstance(q);
5854    
5855                            qPos.add(groupId);
5856    
5857                            qPos.add(categoryId);
5858    
5859                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5860                    }
5861                    catch (Exception e) {
5862                            throw processException(e);
5863                    }
5864                    finally {
5865                            closeSession(session);
5866                    }
5867            }
5868    
5869            /**
5870             * 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;.
5871             *
5872             * @param messageId the primary key of the current message-boards message
5873             * @param groupId the group ID
5874             * @param categoryId the category ID
5875             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5876             * @return the previous, current, and next message-boards message
5877             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5878             */
5879            @Override
5880            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5881                    long groupId, long categoryId,
5882                    OrderByComparator<MBMessage> orderByComparator)
5883                    throws NoSuchMessageException {
5884                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5885                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5886                                    orderByComparator);
5887                    }
5888    
5889                    MBMessage mbMessage = findByPrimaryKey(messageId);
5890    
5891                    Session session = null;
5892    
5893                    try {
5894                            session = openSession();
5895    
5896                            MBMessage[] array = new MBMessageImpl[3];
5897    
5898                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5899                                            categoryId, orderByComparator, true);
5900    
5901                            array[1] = mbMessage;
5902    
5903                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5904                                            categoryId, orderByComparator, false);
5905    
5906                            return array;
5907                    }
5908                    catch (Exception e) {
5909                            throw processException(e);
5910                    }
5911                    finally {
5912                            closeSession(session);
5913                    }
5914            }
5915    
5916            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5917                    MBMessage mbMessage, long groupId, long categoryId,
5918                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5919                    StringBundler query = null;
5920    
5921                    if (orderByComparator != null) {
5922                            query = new StringBundler(6 +
5923                                            (orderByComparator.getOrderByFields().length * 6));
5924                    }
5925                    else {
5926                            query = new StringBundler(3);
5927                    }
5928    
5929                    if (getDB().isSupportsInlineDistinct()) {
5930                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5931                    }
5932                    else {
5933                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5934                    }
5935    
5936                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5937    
5938                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5939    
5940                    if (!getDB().isSupportsInlineDistinct()) {
5941                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5942                    }
5943    
5944                    if (orderByComparator != null) {
5945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5946    
5947                            if (orderByConditionFields.length > 0) {
5948                                    query.append(WHERE_AND);
5949                            }
5950    
5951                            for (int i = 0; i < orderByConditionFields.length; i++) {
5952                                    if (getDB().isSupportsInlineDistinct()) {
5953                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5954                                    }
5955                                    else {
5956                                            query.append(_ORDER_BY_ENTITY_TABLE);
5957                                    }
5958    
5959                                    query.append(orderByConditionFields[i]);
5960    
5961                                    if ((i + 1) < orderByConditionFields.length) {
5962                                            if (orderByComparator.isAscending() ^ previous) {
5963                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5964                                            }
5965                                            else {
5966                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5967                                            }
5968                                    }
5969                                    else {
5970                                            if (orderByComparator.isAscending() ^ previous) {
5971                                                    query.append(WHERE_GREATER_THAN);
5972                                            }
5973                                            else {
5974                                                    query.append(WHERE_LESSER_THAN);
5975                                            }
5976                                    }
5977                            }
5978    
5979                            query.append(ORDER_BY_CLAUSE);
5980    
5981                            String[] orderByFields = orderByComparator.getOrderByFields();
5982    
5983                            for (int i = 0; i < orderByFields.length; i++) {
5984                                    if (getDB().isSupportsInlineDistinct()) {
5985                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5986                                    }
5987                                    else {
5988                                            query.append(_ORDER_BY_ENTITY_TABLE);
5989                                    }
5990    
5991                                    query.append(orderByFields[i]);
5992    
5993                                    if ((i + 1) < orderByFields.length) {
5994                                            if (orderByComparator.isAscending() ^ previous) {
5995                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5996                                            }
5997                                            else {
5998                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5999                                            }
6000                                    }
6001                                    else {
6002                                            if (orderByComparator.isAscending() ^ previous) {
6003                                                    query.append(ORDER_BY_ASC);
6004                                            }
6005                                            else {
6006                                                    query.append(ORDER_BY_DESC);
6007                                            }
6008                                    }
6009                            }
6010                    }
6011                    else {
6012                            if (getDB().isSupportsInlineDistinct()) {
6013                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6014                            }
6015                            else {
6016                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6017                            }
6018                    }
6019    
6020                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6021                                    MBMessage.class.getName(),
6022                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6023    
6024                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6025    
6026                    q.setFirstResult(0);
6027                    q.setMaxResults(2);
6028    
6029                    if (getDB().isSupportsInlineDistinct()) {
6030                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6031                    }
6032                    else {
6033                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6034                    }
6035    
6036                    QueryPos qPos = QueryPos.getInstance(q);
6037    
6038                    qPos.add(groupId);
6039    
6040                    qPos.add(categoryId);
6041    
6042                    if (orderByComparator != null) {
6043                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6044    
6045                            for (Object value : values) {
6046                                    qPos.add(value);
6047                            }
6048                    }
6049    
6050                    List<MBMessage> list = q.list();
6051    
6052                    if (list.size() == 2) {
6053                            return list.get(1);
6054                    }
6055                    else {
6056                            return null;
6057                    }
6058            }
6059    
6060            /**
6061             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
6062             *
6063             * @param groupId the group ID
6064             * @param categoryId the category ID
6065             */
6066            @Override
6067            public void removeByG_C(long groupId, long categoryId) {
6068                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
6069                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6070                            remove(mbMessage);
6071                    }
6072            }
6073    
6074            /**
6075             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
6076             *
6077             * @param groupId the group ID
6078             * @param categoryId the category ID
6079             * @return the number of matching message-boards messages
6080             */
6081            @Override
6082            public int countByG_C(long groupId, long categoryId) {
6083                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6084    
6085                    Object[] finderArgs = new Object[] { groupId, categoryId };
6086    
6087                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6088    
6089                    if (count == null) {
6090                            StringBundler query = new StringBundler(3);
6091    
6092                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6093    
6094                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6095    
6096                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6097    
6098                            String sql = query.toString();
6099    
6100                            Session session = null;
6101    
6102                            try {
6103                                    session = openSession();
6104    
6105                                    Query q = session.createQuery(sql);
6106    
6107                                    QueryPos qPos = QueryPos.getInstance(q);
6108    
6109                                    qPos.add(groupId);
6110    
6111                                    qPos.add(categoryId);
6112    
6113                                    count = (Long)q.uniqueResult();
6114    
6115                                    finderCache.putResult(finderPath, finderArgs, count);
6116                            }
6117                            catch (Exception e) {
6118                                    finderCache.removeResult(finderPath, finderArgs);
6119    
6120                                    throw processException(e);
6121                            }
6122                            finally {
6123                                    closeSession(session);
6124                            }
6125                    }
6126    
6127                    return count.intValue();
6128            }
6129    
6130            /**
6131             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6132             *
6133             * @param groupId the group ID
6134             * @param categoryId the category ID
6135             * @return the number of matching message-boards messages that the user has permission to view
6136             */
6137            @Override
6138            public int filterCountByG_C(long groupId, long categoryId) {
6139                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6140                            return countByG_C(groupId, categoryId);
6141                    }
6142    
6143                    StringBundler query = new StringBundler(3);
6144    
6145                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6146    
6147                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6148    
6149                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6150    
6151                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6152                                    MBMessage.class.getName(),
6153                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6154    
6155                    Session session = null;
6156    
6157                    try {
6158                            session = openSession();
6159    
6160                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6161    
6162                            q.addScalar(COUNT_COLUMN_NAME,
6163                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6164    
6165                            QueryPos qPos = QueryPos.getInstance(q);
6166    
6167                            qPos.add(groupId);
6168    
6169                            qPos.add(categoryId);
6170    
6171                            Long count = (Long)q.uniqueResult();
6172    
6173                            return count.intValue();
6174                    }
6175                    catch (Exception e) {
6176                            throw processException(e);
6177                    }
6178                    finally {
6179                            closeSession(session);
6180                    }
6181            }
6182    
6183            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6184            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6185            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6186                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6187                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6188                            new String[] {
6189                                    Long.class.getName(), Integer.class.getName(),
6190                                    
6191                            Integer.class.getName(), Integer.class.getName(),
6192                                    OrderByComparator.class.getName()
6193                            });
6194            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6195                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6197                            new String[] { Long.class.getName(), Integer.class.getName() },
6198                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6199                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6200                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6201            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6202                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6204                            new String[] { Long.class.getName(), Integer.class.getName() });
6205    
6206            /**
6207             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6208             *
6209             * @param groupId the group ID
6210             * @param status the status
6211             * @return the matching message-boards messages
6212             */
6213            @Override
6214            public List<MBMessage> findByG_S(long groupId, int status) {
6215                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6216                            null);
6217            }
6218    
6219            /**
6220             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6221             *
6222             * <p>
6223             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6224             * </p>
6225             *
6226             * @param groupId the group ID
6227             * @param status the status
6228             * @param start the lower bound of the range of message-boards messages
6229             * @param end the upper bound of the range of message-boards messages (not inclusive)
6230             * @return the range of matching message-boards messages
6231             */
6232            @Override
6233            public List<MBMessage> findByG_S(long groupId, int status, int start,
6234                    int end) {
6235                    return findByG_S(groupId, status, start, end, null);
6236            }
6237    
6238            /**
6239             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6240             *
6241             * <p>
6242             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6243             * </p>
6244             *
6245             * @param groupId the group ID
6246             * @param status the status
6247             * @param start the lower bound of the range of message-boards messages
6248             * @param end the upper bound of the range of message-boards messages (not inclusive)
6249             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6250             * @return the ordered range of matching message-boards messages
6251             */
6252            @Override
6253            public List<MBMessage> findByG_S(long groupId, int status, int start,
6254                    int end, OrderByComparator<MBMessage> orderByComparator) {
6255                    return findByG_S(groupId, status, start, end, orderByComparator, true);
6256            }
6257    
6258            /**
6259             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6260             *
6261             * <p>
6262             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6263             * </p>
6264             *
6265             * @param groupId the group ID
6266             * @param status the status
6267             * @param start the lower bound of the range of message-boards messages
6268             * @param end the upper bound of the range of message-boards messages (not inclusive)
6269             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6270             * @param retrieveFromCache whether to retrieve from the finder cache
6271             * @return the ordered range of matching message-boards messages
6272             */
6273            @Override
6274            public List<MBMessage> findByG_S(long groupId, int status, int start,
6275                    int end, OrderByComparator<MBMessage> orderByComparator,
6276                    boolean retrieveFromCache) {
6277                    boolean pagination = true;
6278                    FinderPath finderPath = null;
6279                    Object[] finderArgs = null;
6280    
6281                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6282                                    (orderByComparator == null)) {
6283                            pagination = false;
6284                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6285                            finderArgs = new Object[] { groupId, status };
6286                    }
6287                    else {
6288                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6289                            finderArgs = new Object[] {
6290                                            groupId, status,
6291                                            
6292                                            start, end, orderByComparator
6293                                    };
6294                    }
6295    
6296                    List<MBMessage> list = null;
6297    
6298                    if (retrieveFromCache) {
6299                            list = (List<MBMessage>)finderCache.getResult(finderPath,
6300                                            finderArgs, this);
6301    
6302                            if ((list != null) && !list.isEmpty()) {
6303                                    for (MBMessage mbMessage : list) {
6304                                            if ((groupId != mbMessage.getGroupId()) ||
6305                                                            (status != mbMessage.getStatus())) {
6306                                                    list = null;
6307    
6308                                                    break;
6309                                            }
6310                                    }
6311                            }
6312                    }
6313    
6314                    if (list == null) {
6315                            StringBundler query = null;
6316    
6317                            if (orderByComparator != null) {
6318                                    query = new StringBundler(4 +
6319                                                    (orderByComparator.getOrderByFields().length * 3));
6320                            }
6321                            else {
6322                                    query = new StringBundler(4);
6323                            }
6324    
6325                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6326    
6327                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6328    
6329                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6330    
6331                            if (orderByComparator != null) {
6332                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6333                                            orderByComparator);
6334                            }
6335                            else
6336                             if (pagination) {
6337                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6338                            }
6339    
6340                            String sql = query.toString();
6341    
6342                            Session session = null;
6343    
6344                            try {
6345                                    session = openSession();
6346    
6347                                    Query q = session.createQuery(sql);
6348    
6349                                    QueryPos qPos = QueryPos.getInstance(q);
6350    
6351                                    qPos.add(groupId);
6352    
6353                                    qPos.add(status);
6354    
6355                                    if (!pagination) {
6356                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6357                                                            start, end, false);
6358    
6359                                            Collections.sort(list);
6360    
6361                                            list = Collections.unmodifiableList(list);
6362                                    }
6363                                    else {
6364                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6365                                                            start, end);
6366                                    }
6367    
6368                                    cacheResult(list);
6369    
6370                                    finderCache.putResult(finderPath, finderArgs, list);
6371                            }
6372                            catch (Exception e) {
6373                                    finderCache.removeResult(finderPath, finderArgs);
6374    
6375                                    throw processException(e);
6376                            }
6377                            finally {
6378                                    closeSession(session);
6379                            }
6380                    }
6381    
6382                    return list;
6383            }
6384    
6385            /**
6386             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6387             *
6388             * @param groupId the group ID
6389             * @param status the status
6390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6391             * @return the first matching message-boards message
6392             * @throws NoSuchMessageException if a matching message-boards message could not be found
6393             */
6394            @Override
6395            public MBMessage findByG_S_First(long groupId, int status,
6396                    OrderByComparator<MBMessage> orderByComparator)
6397                    throws NoSuchMessageException {
6398                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6399                                    orderByComparator);
6400    
6401                    if (mbMessage != null) {
6402                            return mbMessage;
6403                    }
6404    
6405                    StringBundler msg = new StringBundler(6);
6406    
6407                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6408    
6409                    msg.append("groupId=");
6410                    msg.append(groupId);
6411    
6412                    msg.append(", status=");
6413                    msg.append(status);
6414    
6415                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6416    
6417                    throw new NoSuchMessageException(msg.toString());
6418            }
6419    
6420            /**
6421             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6422             *
6423             * @param groupId the group ID
6424             * @param status the status
6425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6426             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6427             */
6428            @Override
6429            public MBMessage fetchByG_S_First(long groupId, int status,
6430                    OrderByComparator<MBMessage> orderByComparator) {
6431                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6432                                    orderByComparator);
6433    
6434                    if (!list.isEmpty()) {
6435                            return list.get(0);
6436                    }
6437    
6438                    return null;
6439            }
6440    
6441            /**
6442             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6443             *
6444             * @param groupId the group ID
6445             * @param status the status
6446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6447             * @return the last matching message-boards message
6448             * @throws NoSuchMessageException if a matching message-boards message could not be found
6449             */
6450            @Override
6451            public MBMessage findByG_S_Last(long groupId, int status,
6452                    OrderByComparator<MBMessage> orderByComparator)
6453                    throws NoSuchMessageException {
6454                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6455    
6456                    if (mbMessage != null) {
6457                            return mbMessage;
6458                    }
6459    
6460                    StringBundler msg = new StringBundler(6);
6461    
6462                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6463    
6464                    msg.append("groupId=");
6465                    msg.append(groupId);
6466    
6467                    msg.append(", status=");
6468                    msg.append(status);
6469    
6470                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6471    
6472                    throw new NoSuchMessageException(msg.toString());
6473            }
6474    
6475            /**
6476             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6477             *
6478             * @param groupId the group ID
6479             * @param status the status
6480             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6481             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6482             */
6483            @Override
6484            public MBMessage fetchByG_S_Last(long groupId, int status,
6485                    OrderByComparator<MBMessage> orderByComparator) {
6486                    int count = countByG_S(groupId, status);
6487    
6488                    if (count == 0) {
6489                            return null;
6490                    }
6491    
6492                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6493                                    orderByComparator);
6494    
6495                    if (!list.isEmpty()) {
6496                            return list.get(0);
6497                    }
6498    
6499                    return null;
6500            }
6501    
6502            /**
6503             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6504             *
6505             * @param messageId the primary key of the current message-boards message
6506             * @param groupId the group ID
6507             * @param status the status
6508             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6509             * @return the previous, current, and next message-boards message
6510             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6511             */
6512            @Override
6513            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6514                    int status, OrderByComparator<MBMessage> orderByComparator)
6515                    throws NoSuchMessageException {
6516                    MBMessage mbMessage = findByPrimaryKey(messageId);
6517    
6518                    Session session = null;
6519    
6520                    try {
6521                            session = openSession();
6522    
6523                            MBMessage[] array = new MBMessageImpl[3];
6524    
6525                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6526                                            status, orderByComparator, true);
6527    
6528                            array[1] = mbMessage;
6529    
6530                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6531                                            status, orderByComparator, false);
6532    
6533                            return array;
6534                    }
6535                    catch (Exception e) {
6536                            throw processException(e);
6537                    }
6538                    finally {
6539                            closeSession(session);
6540                    }
6541            }
6542    
6543            protected MBMessage getByG_S_PrevAndNext(Session session,
6544                    MBMessage mbMessage, long groupId, int status,
6545                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6546                    StringBundler query = null;
6547    
6548                    if (orderByComparator != null) {
6549                            query = new StringBundler(6 +
6550                                            (orderByComparator.getOrderByFields().length * 6));
6551                    }
6552                    else {
6553                            query = new StringBundler(3);
6554                    }
6555    
6556                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6557    
6558                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6559    
6560                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6561    
6562                    if (orderByComparator != null) {
6563                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6564    
6565                            if (orderByConditionFields.length > 0) {
6566                                    query.append(WHERE_AND);
6567                            }
6568    
6569                            for (int i = 0; i < orderByConditionFields.length; i++) {
6570                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6571                                    query.append(orderByConditionFields[i]);
6572    
6573                                    if ((i + 1) < orderByConditionFields.length) {
6574                                            if (orderByComparator.isAscending() ^ previous) {
6575                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6576                                            }
6577                                            else {
6578                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6579                                            }
6580                                    }
6581                                    else {
6582                                            if (orderByComparator.isAscending() ^ previous) {
6583                                                    query.append(WHERE_GREATER_THAN);
6584                                            }
6585                                            else {
6586                                                    query.append(WHERE_LESSER_THAN);
6587                                            }
6588                                    }
6589                            }
6590    
6591                            query.append(ORDER_BY_CLAUSE);
6592    
6593                            String[] orderByFields = orderByComparator.getOrderByFields();
6594    
6595                            for (int i = 0; i < orderByFields.length; i++) {
6596                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6597                                    query.append(orderByFields[i]);
6598    
6599                                    if ((i + 1) < orderByFields.length) {
6600                                            if (orderByComparator.isAscending() ^ previous) {
6601                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6602                                            }
6603                                            else {
6604                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6605                                            }
6606                                    }
6607                                    else {
6608                                            if (orderByComparator.isAscending() ^ previous) {
6609                                                    query.append(ORDER_BY_ASC);
6610                                            }
6611                                            else {
6612                                                    query.append(ORDER_BY_DESC);
6613                                            }
6614                                    }
6615                            }
6616                    }
6617                    else {
6618                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6619                    }
6620    
6621                    String sql = query.toString();
6622    
6623                    Query q = session.createQuery(sql);
6624    
6625                    q.setFirstResult(0);
6626                    q.setMaxResults(2);
6627    
6628                    QueryPos qPos = QueryPos.getInstance(q);
6629    
6630                    qPos.add(groupId);
6631    
6632                    qPos.add(status);
6633    
6634                    if (orderByComparator != null) {
6635                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6636    
6637                            for (Object value : values) {
6638                                    qPos.add(value);
6639                            }
6640                    }
6641    
6642                    List<MBMessage> list = q.list();
6643    
6644                    if (list.size() == 2) {
6645                            return list.get(1);
6646                    }
6647                    else {
6648                            return null;
6649                    }
6650            }
6651    
6652            /**
6653             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6654             *
6655             * @param groupId the group ID
6656             * @param status the status
6657             * @return the matching message-boards messages that the user has permission to view
6658             */
6659            @Override
6660            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6661                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6662                            QueryUtil.ALL_POS, null);
6663            }
6664    
6665            /**
6666             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6667             *
6668             * <p>
6669             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6670             * </p>
6671             *
6672             * @param groupId the group ID
6673             * @param status the status
6674             * @param start the lower bound of the range of message-boards messages
6675             * @param end the upper bound of the range of message-boards messages (not inclusive)
6676             * @return the range of matching message-boards messages that the user has permission to view
6677             */
6678            @Override
6679            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6680                    int end) {
6681                    return filterFindByG_S(groupId, status, start, end, null);
6682            }
6683    
6684            /**
6685             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6686             *
6687             * <p>
6688             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6689             * </p>
6690             *
6691             * @param groupId the group ID
6692             * @param status the status
6693             * @param start the lower bound of the range of message-boards messages
6694             * @param end the upper bound of the range of message-boards messages (not inclusive)
6695             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6696             * @return the ordered range of matching message-boards messages that the user has permission to view
6697             */
6698            @Override
6699            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6700                    int end, OrderByComparator<MBMessage> orderByComparator) {
6701                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6702                            return findByG_S(groupId, status, start, end, orderByComparator);
6703                    }
6704    
6705                    StringBundler query = null;
6706    
6707                    if (orderByComparator != null) {
6708                            query = new StringBundler(4 +
6709                                            (orderByComparator.getOrderByFields().length * 3));
6710                    }
6711                    else {
6712                            query = new StringBundler(4);
6713                    }
6714    
6715                    if (getDB().isSupportsInlineDistinct()) {
6716                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6717                    }
6718                    else {
6719                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6720                    }
6721    
6722                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6723    
6724                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6725    
6726                    if (!getDB().isSupportsInlineDistinct()) {
6727                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6728                    }
6729    
6730                    if (orderByComparator != null) {
6731                            if (getDB().isSupportsInlineDistinct()) {
6732                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6733                                            orderByComparator, true);
6734                            }
6735                            else {
6736                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6737                                            orderByComparator, true);
6738                            }
6739                    }
6740                    else {
6741                            if (getDB().isSupportsInlineDistinct()) {
6742                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6743                            }
6744                            else {
6745                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6746                            }
6747                    }
6748    
6749                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6750                                    MBMessage.class.getName(),
6751                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6752    
6753                    Session session = null;
6754    
6755                    try {
6756                            session = openSession();
6757    
6758                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6759    
6760                            if (getDB().isSupportsInlineDistinct()) {
6761                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6762                            }
6763                            else {
6764                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6765                            }
6766    
6767                            QueryPos qPos = QueryPos.getInstance(q);
6768    
6769                            qPos.add(groupId);
6770    
6771                            qPos.add(status);
6772    
6773                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6774                    }
6775                    catch (Exception e) {
6776                            throw processException(e);
6777                    }
6778                    finally {
6779                            closeSession(session);
6780                    }
6781            }
6782    
6783            /**
6784             * 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;.
6785             *
6786             * @param messageId the primary key of the current message-boards message
6787             * @param groupId the group ID
6788             * @param status the status
6789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6790             * @return the previous, current, and next message-boards message
6791             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6792             */
6793            @Override
6794            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6795                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6796                    throws NoSuchMessageException {
6797                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6798                            return findByG_S_PrevAndNext(messageId, groupId, status,
6799                                    orderByComparator);
6800                    }
6801    
6802                    MBMessage mbMessage = findByPrimaryKey(messageId);
6803    
6804                    Session session = null;
6805    
6806                    try {
6807                            session = openSession();
6808    
6809                            MBMessage[] array = new MBMessageImpl[3];
6810    
6811                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6812                                            status, orderByComparator, true);
6813    
6814                            array[1] = mbMessage;
6815    
6816                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6817                                            status, orderByComparator, false);
6818    
6819                            return array;
6820                    }
6821                    catch (Exception e) {
6822                            throw processException(e);
6823                    }
6824                    finally {
6825                            closeSession(session);
6826                    }
6827            }
6828    
6829            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6830                    MBMessage mbMessage, long groupId, int status,
6831                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6832                    StringBundler query = null;
6833    
6834                    if (orderByComparator != null) {
6835                            query = new StringBundler(6 +
6836                                            (orderByComparator.getOrderByFields().length * 6));
6837                    }
6838                    else {
6839                            query = new StringBundler(3);
6840                    }
6841    
6842                    if (getDB().isSupportsInlineDistinct()) {
6843                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6844                    }
6845                    else {
6846                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6847                    }
6848    
6849                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6850    
6851                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6852    
6853                    if (!getDB().isSupportsInlineDistinct()) {
6854                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6855                    }
6856    
6857                    if (orderByComparator != null) {
6858                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6859    
6860                            if (orderByConditionFields.length > 0) {
6861                                    query.append(WHERE_AND);
6862                            }
6863    
6864                            for (int i = 0; i < orderByConditionFields.length; i++) {
6865                                    if (getDB().isSupportsInlineDistinct()) {
6866                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6867                                    }
6868                                    else {
6869                                            query.append(_ORDER_BY_ENTITY_TABLE);
6870                                    }
6871    
6872                                    query.append(orderByConditionFields[i]);
6873    
6874                                    if ((i + 1) < orderByConditionFields.length) {
6875                                            if (orderByComparator.isAscending() ^ previous) {
6876                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6877                                            }
6878                                            else {
6879                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6880                                            }
6881                                    }
6882                                    else {
6883                                            if (orderByComparator.isAscending() ^ previous) {
6884                                                    query.append(WHERE_GREATER_THAN);
6885                                            }
6886                                            else {
6887                                                    query.append(WHERE_LESSER_THAN);
6888                                            }
6889                                    }
6890                            }
6891    
6892                            query.append(ORDER_BY_CLAUSE);
6893    
6894                            String[] orderByFields = orderByComparator.getOrderByFields();
6895    
6896                            for (int i = 0; i < orderByFields.length; i++) {
6897                                    if (getDB().isSupportsInlineDistinct()) {
6898                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6899                                    }
6900                                    else {
6901                                            query.append(_ORDER_BY_ENTITY_TABLE);
6902                                    }
6903    
6904                                    query.append(orderByFields[i]);
6905    
6906                                    if ((i + 1) < orderByFields.length) {
6907                                            if (orderByComparator.isAscending() ^ previous) {
6908                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6909                                            }
6910                                            else {
6911                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6912                                            }
6913                                    }
6914                                    else {
6915                                            if (orderByComparator.isAscending() ^ previous) {
6916                                                    query.append(ORDER_BY_ASC);
6917                                            }
6918                                            else {
6919                                                    query.append(ORDER_BY_DESC);
6920                                            }
6921                                    }
6922                            }
6923                    }
6924                    else {
6925                            if (getDB().isSupportsInlineDistinct()) {
6926                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6927                            }
6928                            else {
6929                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6930                            }
6931                    }
6932    
6933                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6934                                    MBMessage.class.getName(),
6935                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6936    
6937                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6938    
6939                    q.setFirstResult(0);
6940                    q.setMaxResults(2);
6941    
6942                    if (getDB().isSupportsInlineDistinct()) {
6943                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6944                    }
6945                    else {
6946                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6947                    }
6948    
6949                    QueryPos qPos = QueryPos.getInstance(q);
6950    
6951                    qPos.add(groupId);
6952    
6953                    qPos.add(status);
6954    
6955                    if (orderByComparator != null) {
6956                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6957    
6958                            for (Object value : values) {
6959                                    qPos.add(value);
6960                            }
6961                    }
6962    
6963                    List<MBMessage> list = q.list();
6964    
6965                    if (list.size() == 2) {
6966                            return list.get(1);
6967                    }
6968                    else {
6969                            return null;
6970                    }
6971            }
6972    
6973            /**
6974             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6975             *
6976             * @param groupId the group ID
6977             * @param status the status
6978             */
6979            @Override
6980            public void removeByG_S(long groupId, int status) {
6981                    for (MBMessage mbMessage : findByG_S(groupId, status,
6982                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6983                            remove(mbMessage);
6984                    }
6985            }
6986    
6987            /**
6988             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6989             *
6990             * @param groupId the group ID
6991             * @param status the status
6992             * @return the number of matching message-boards messages
6993             */
6994            @Override
6995            public int countByG_S(long groupId, int status) {
6996                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6997    
6998                    Object[] finderArgs = new Object[] { groupId, status };
6999    
7000                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7001    
7002                    if (count == null) {
7003                            StringBundler query = new StringBundler(3);
7004    
7005                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7006    
7007                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7008    
7009                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
7010    
7011                            String sql = query.toString();
7012    
7013                            Session session = null;
7014    
7015                            try {
7016                                    session = openSession();
7017    
7018                                    Query q = session.createQuery(sql);
7019    
7020                                    QueryPos qPos = QueryPos.getInstance(q);
7021    
7022                                    qPos.add(groupId);
7023    
7024                                    qPos.add(status);
7025    
7026                                    count = (Long)q.uniqueResult();
7027    
7028                                    finderCache.putResult(finderPath, finderArgs, count);
7029                            }
7030                            catch (Exception e) {
7031                                    finderCache.removeResult(finderPath, finderArgs);
7032    
7033                                    throw processException(e);
7034                            }
7035                            finally {
7036                                    closeSession(session);
7037                            }
7038                    }
7039    
7040                    return count.intValue();
7041            }
7042    
7043            /**
7044             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
7045             *
7046             * @param groupId the group ID
7047             * @param status the status
7048             * @return the number of matching message-boards messages that the user has permission to view
7049             */
7050            @Override
7051            public int filterCountByG_S(long groupId, int status) {
7052                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7053                            return countByG_S(groupId, status);
7054                    }
7055    
7056                    StringBundler query = new StringBundler(3);
7057    
7058                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
7059    
7060                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7061    
7062                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
7063    
7064                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7065                                    MBMessage.class.getName(),
7066                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7067    
7068                    Session session = null;
7069    
7070                    try {
7071                            session = openSession();
7072    
7073                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7074    
7075                            q.addScalar(COUNT_COLUMN_NAME,
7076                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7077    
7078                            QueryPos qPos = QueryPos.getInstance(q);
7079    
7080                            qPos.add(groupId);
7081    
7082                            qPos.add(status);
7083    
7084                            Long count = (Long)q.uniqueResult();
7085    
7086                            return count.intValue();
7087                    }
7088                    catch (Exception e) {
7089                            throw processException(e);
7090                    }
7091                    finally {
7092                            closeSession(session);
7093                    }
7094            }
7095    
7096            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
7097            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7099                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7100                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7101                            new String[] {
7102                                    Long.class.getName(), Integer.class.getName(),
7103                                    
7104                            Integer.class.getName(), Integer.class.getName(),
7105                                    OrderByComparator.class.getName()
7106                            });
7107            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7108                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7110                            new String[] { Long.class.getName(), Integer.class.getName() },
7111                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7112                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7113                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7114            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7117                            new String[] { Long.class.getName(), Integer.class.getName() });
7118    
7119            /**
7120             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7121             *
7122             * @param companyId the company ID
7123             * @param status the status
7124             * @return the matching message-boards messages
7125             */
7126            @Override
7127            public List<MBMessage> findByC_S(long companyId, int status) {
7128                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7129                            QueryUtil.ALL_POS, null);
7130            }
7131    
7132            /**
7133             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7134             *
7135             * <p>
7136             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7137             * </p>
7138             *
7139             * @param companyId the company ID
7140             * @param status the status
7141             * @param start the lower bound of the range of message-boards messages
7142             * @param end the upper bound of the range of message-boards messages (not inclusive)
7143             * @return the range of matching message-boards messages
7144             */
7145            @Override
7146            public List<MBMessage> findByC_S(long companyId, int status, int start,
7147                    int end) {
7148                    return findByC_S(companyId, status, start, end, null);
7149            }
7150    
7151            /**
7152             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7153             *
7154             * <p>
7155             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7156             * </p>
7157             *
7158             * @param companyId the company ID
7159             * @param status the status
7160             * @param start the lower bound of the range of message-boards messages
7161             * @param end the upper bound of the range of message-boards messages (not inclusive)
7162             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7163             * @return the ordered range of matching message-boards messages
7164             */
7165            @Override
7166            public List<MBMessage> findByC_S(long companyId, int status, int start,
7167                    int end, OrderByComparator<MBMessage> orderByComparator) {
7168                    return findByC_S(companyId, status, start, end, orderByComparator, true);
7169            }
7170    
7171            /**
7172             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7173             *
7174             * <p>
7175             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7176             * </p>
7177             *
7178             * @param companyId the company ID
7179             * @param status the status
7180             * @param start the lower bound of the range of message-boards messages
7181             * @param end the upper bound of the range of message-boards messages (not inclusive)
7182             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7183             * @param retrieveFromCache whether to retrieve from the finder cache
7184             * @return the ordered range of matching message-boards messages
7185             */
7186            @Override
7187            public List<MBMessage> findByC_S(long companyId, int status, int start,
7188                    int end, OrderByComparator<MBMessage> orderByComparator,
7189                    boolean retrieveFromCache) {
7190                    boolean pagination = true;
7191                    FinderPath finderPath = null;
7192                    Object[] finderArgs = null;
7193    
7194                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7195                                    (orderByComparator == null)) {
7196                            pagination = false;
7197                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7198                            finderArgs = new Object[] { companyId, status };
7199                    }
7200                    else {
7201                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7202                            finderArgs = new Object[] {
7203                                            companyId, status,
7204                                            
7205                                            start, end, orderByComparator
7206                                    };
7207                    }
7208    
7209                    List<MBMessage> list = null;
7210    
7211                    if (retrieveFromCache) {
7212                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7213                                            finderArgs, this);
7214    
7215                            if ((list != null) && !list.isEmpty()) {
7216                                    for (MBMessage mbMessage : list) {
7217                                            if ((companyId != mbMessage.getCompanyId()) ||
7218                                                            (status != mbMessage.getStatus())) {
7219                                                    list = null;
7220    
7221                                                    break;
7222                                            }
7223                                    }
7224                            }
7225                    }
7226    
7227                    if (list == null) {
7228                            StringBundler query = null;
7229    
7230                            if (orderByComparator != null) {
7231                                    query = new StringBundler(4 +
7232                                                    (orderByComparator.getOrderByFields().length * 3));
7233                            }
7234                            else {
7235                                    query = new StringBundler(4);
7236                            }
7237    
7238                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7239    
7240                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7241    
7242                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7243    
7244                            if (orderByComparator != null) {
7245                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7246                                            orderByComparator);
7247                            }
7248                            else
7249                             if (pagination) {
7250                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7251                            }
7252    
7253                            String sql = query.toString();
7254    
7255                            Session session = null;
7256    
7257                            try {
7258                                    session = openSession();
7259    
7260                                    Query q = session.createQuery(sql);
7261    
7262                                    QueryPos qPos = QueryPos.getInstance(q);
7263    
7264                                    qPos.add(companyId);
7265    
7266                                    qPos.add(status);
7267    
7268                                    if (!pagination) {
7269                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7270                                                            start, end, false);
7271    
7272                                            Collections.sort(list);
7273    
7274                                            list = Collections.unmodifiableList(list);
7275                                    }
7276                                    else {
7277                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7278                                                            start, end);
7279                                    }
7280    
7281                                    cacheResult(list);
7282    
7283                                    finderCache.putResult(finderPath, finderArgs, list);
7284                            }
7285                            catch (Exception e) {
7286                                    finderCache.removeResult(finderPath, finderArgs);
7287    
7288                                    throw processException(e);
7289                            }
7290                            finally {
7291                                    closeSession(session);
7292                            }
7293                    }
7294    
7295                    return list;
7296            }
7297    
7298            /**
7299             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7300             *
7301             * @param companyId the company ID
7302             * @param status the status
7303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7304             * @return the first matching message-boards message
7305             * @throws NoSuchMessageException if a matching message-boards message could not be found
7306             */
7307            @Override
7308            public MBMessage findByC_S_First(long companyId, int status,
7309                    OrderByComparator<MBMessage> orderByComparator)
7310                    throws NoSuchMessageException {
7311                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7312                                    orderByComparator);
7313    
7314                    if (mbMessage != null) {
7315                            return mbMessage;
7316                    }
7317    
7318                    StringBundler msg = new StringBundler(6);
7319    
7320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7321    
7322                    msg.append("companyId=");
7323                    msg.append(companyId);
7324    
7325                    msg.append(", status=");
7326                    msg.append(status);
7327    
7328                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7329    
7330                    throw new NoSuchMessageException(msg.toString());
7331            }
7332    
7333            /**
7334             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7335             *
7336             * @param companyId the company ID
7337             * @param status the status
7338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7339             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7340             */
7341            @Override
7342            public MBMessage fetchByC_S_First(long companyId, int status,
7343                    OrderByComparator<MBMessage> orderByComparator) {
7344                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7345                                    orderByComparator);
7346    
7347                    if (!list.isEmpty()) {
7348                            return list.get(0);
7349                    }
7350    
7351                    return null;
7352            }
7353    
7354            /**
7355             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7356             *
7357             * @param companyId the company ID
7358             * @param status the status
7359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7360             * @return the last matching message-boards message
7361             * @throws NoSuchMessageException if a matching message-boards message could not be found
7362             */
7363            @Override
7364            public MBMessage findByC_S_Last(long companyId, int status,
7365                    OrderByComparator<MBMessage> orderByComparator)
7366                    throws NoSuchMessageException {
7367                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7368                                    orderByComparator);
7369    
7370                    if (mbMessage != null) {
7371                            return mbMessage;
7372                    }
7373    
7374                    StringBundler msg = new StringBundler(6);
7375    
7376                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7377    
7378                    msg.append("companyId=");
7379                    msg.append(companyId);
7380    
7381                    msg.append(", status=");
7382                    msg.append(status);
7383    
7384                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7385    
7386                    throw new NoSuchMessageException(msg.toString());
7387            }
7388    
7389            /**
7390             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7391             *
7392             * @param companyId the company ID
7393             * @param status the status
7394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7395             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7396             */
7397            @Override
7398            public MBMessage fetchByC_S_Last(long companyId, int status,
7399                    OrderByComparator<MBMessage> orderByComparator) {
7400                    int count = countByC_S(companyId, status);
7401    
7402                    if (count == 0) {
7403                            return null;
7404                    }
7405    
7406                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7407                                    orderByComparator);
7408    
7409                    if (!list.isEmpty()) {
7410                            return list.get(0);
7411                    }
7412    
7413                    return null;
7414            }
7415    
7416            /**
7417             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7418             *
7419             * @param messageId the primary key of the current message-boards message
7420             * @param companyId the company ID
7421             * @param status the status
7422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7423             * @return the previous, current, and next message-boards message
7424             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7425             */
7426            @Override
7427            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7428                    int status, OrderByComparator<MBMessage> orderByComparator)
7429                    throws NoSuchMessageException {
7430                    MBMessage mbMessage = findByPrimaryKey(messageId);
7431    
7432                    Session session = null;
7433    
7434                    try {
7435                            session = openSession();
7436    
7437                            MBMessage[] array = new MBMessageImpl[3];
7438    
7439                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7440                                            status, orderByComparator, true);
7441    
7442                            array[1] = mbMessage;
7443    
7444                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7445                                            status, orderByComparator, false);
7446    
7447                            return array;
7448                    }
7449                    catch (Exception e) {
7450                            throw processException(e);
7451                    }
7452                    finally {
7453                            closeSession(session);
7454                    }
7455            }
7456    
7457            protected MBMessage getByC_S_PrevAndNext(Session session,
7458                    MBMessage mbMessage, long companyId, int status,
7459                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7460                    StringBundler query = null;
7461    
7462                    if (orderByComparator != null) {
7463                            query = new StringBundler(6 +
7464                                            (orderByComparator.getOrderByFields().length * 6));
7465                    }
7466                    else {
7467                            query = new StringBundler(3);
7468                    }
7469    
7470                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7471    
7472                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7473    
7474                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7475    
7476                    if (orderByComparator != null) {
7477                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7478    
7479                            if (orderByConditionFields.length > 0) {
7480                                    query.append(WHERE_AND);
7481                            }
7482    
7483                            for (int i = 0; i < orderByConditionFields.length; i++) {
7484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7485                                    query.append(orderByConditionFields[i]);
7486    
7487                                    if ((i + 1) < orderByConditionFields.length) {
7488                                            if (orderByComparator.isAscending() ^ previous) {
7489                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7490                                            }
7491                                            else {
7492                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7493                                            }
7494                                    }
7495                                    else {
7496                                            if (orderByComparator.isAscending() ^ previous) {
7497                                                    query.append(WHERE_GREATER_THAN);
7498                                            }
7499                                            else {
7500                                                    query.append(WHERE_LESSER_THAN);
7501                                            }
7502                                    }
7503                            }
7504    
7505                            query.append(ORDER_BY_CLAUSE);
7506    
7507                            String[] orderByFields = orderByComparator.getOrderByFields();
7508    
7509                            for (int i = 0; i < orderByFields.length; i++) {
7510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7511                                    query.append(orderByFields[i]);
7512    
7513                                    if ((i + 1) < orderByFields.length) {
7514                                            if (orderByComparator.isAscending() ^ previous) {
7515                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7516                                            }
7517                                            else {
7518                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7519                                            }
7520                                    }
7521                                    else {
7522                                            if (orderByComparator.isAscending() ^ previous) {
7523                                                    query.append(ORDER_BY_ASC);
7524                                            }
7525                                            else {
7526                                                    query.append(ORDER_BY_DESC);
7527                                            }
7528                                    }
7529                            }
7530                    }
7531                    else {
7532                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7533                    }
7534    
7535                    String sql = query.toString();
7536    
7537                    Query q = session.createQuery(sql);
7538    
7539                    q.setFirstResult(0);
7540                    q.setMaxResults(2);
7541    
7542                    QueryPos qPos = QueryPos.getInstance(q);
7543    
7544                    qPos.add(companyId);
7545    
7546                    qPos.add(status);
7547    
7548                    if (orderByComparator != null) {
7549                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7550    
7551                            for (Object value : values) {
7552                                    qPos.add(value);
7553                            }
7554                    }
7555    
7556                    List<MBMessage> list = q.list();
7557    
7558                    if (list.size() == 2) {
7559                            return list.get(1);
7560                    }
7561                    else {
7562                            return null;
7563                    }
7564            }
7565    
7566            /**
7567             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7568             *
7569             * @param companyId the company ID
7570             * @param status the status
7571             */
7572            @Override
7573            public void removeByC_S(long companyId, int status) {
7574                    for (MBMessage mbMessage : findByC_S(companyId, status,
7575                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7576                            remove(mbMessage);
7577                    }
7578            }
7579    
7580            /**
7581             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7582             *
7583             * @param companyId the company ID
7584             * @param status the status
7585             * @return the number of matching message-boards messages
7586             */
7587            @Override
7588            public int countByC_S(long companyId, int status) {
7589                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7590    
7591                    Object[] finderArgs = new Object[] { companyId, status };
7592    
7593                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7594    
7595                    if (count == null) {
7596                            StringBundler query = new StringBundler(3);
7597    
7598                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7599    
7600                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7601    
7602                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7603    
7604                            String sql = query.toString();
7605    
7606                            Session session = null;
7607    
7608                            try {
7609                                    session = openSession();
7610    
7611                                    Query q = session.createQuery(sql);
7612    
7613                                    QueryPos qPos = QueryPos.getInstance(q);
7614    
7615                                    qPos.add(companyId);
7616    
7617                                    qPos.add(status);
7618    
7619                                    count = (Long)q.uniqueResult();
7620    
7621                                    finderCache.putResult(finderPath, finderArgs, count);
7622                            }
7623                            catch (Exception e) {
7624                                    finderCache.removeResult(finderPath, finderArgs);
7625    
7626                                    throw processException(e);
7627                            }
7628                            finally {
7629                                    closeSession(session);
7630                            }
7631                    }
7632    
7633                    return count.intValue();
7634            }
7635    
7636            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7637            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7638            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7639                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7640                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7641                            new String[] {
7642                                    Long.class.getName(), Long.class.getName(),
7643                                    
7644                            Integer.class.getName(), Integer.class.getName(),
7645                                    OrderByComparator.class.getName()
7646                            });
7647            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7648                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7649                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7650                            new String[] { Long.class.getName(), Long.class.getName() },
7651                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7652                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7653                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7654            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7655                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7656                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7657                            new String[] { Long.class.getName(), Long.class.getName() });
7658            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7659                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7660                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7661                            new String[] { Long.class.getName(), Long.class.getName() });
7662    
7663            /**
7664             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7665             *
7666             * @param userId the user ID
7667             * @param classNameId the class name ID
7668             * @return the matching message-boards messages
7669             */
7670            @Override
7671            public List<MBMessage> findByU_C(long userId, long classNameId) {
7672                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7673                            QueryUtil.ALL_POS, null);
7674            }
7675    
7676            /**
7677             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7678             *
7679             * <p>
7680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7681             * </p>
7682             *
7683             * @param userId the user ID
7684             * @param classNameId the class name ID
7685             * @param start the lower bound of the range of message-boards messages
7686             * @param end the upper bound of the range of message-boards messages (not inclusive)
7687             * @return the range of matching message-boards messages
7688             */
7689            @Override
7690            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7691                    int end) {
7692                    return findByU_C(userId, classNameId, start, end, null);
7693            }
7694    
7695            /**
7696             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7697             *
7698             * <p>
7699             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7700             * </p>
7701             *
7702             * @param userId the user ID
7703             * @param classNameId the class name ID
7704             * @param start the lower bound of the range of message-boards messages
7705             * @param end the upper bound of the range of message-boards messages (not inclusive)
7706             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7707             * @return the ordered range of matching message-boards messages
7708             */
7709            @Override
7710            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7711                    int end, OrderByComparator<MBMessage> orderByComparator) {
7712                    return findByU_C(userId, classNameId, start, end, orderByComparator,
7713                            true);
7714            }
7715    
7716            /**
7717             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7718             *
7719             * <p>
7720             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
7721             * </p>
7722             *
7723             * @param userId the user ID
7724             * @param classNameId the class name ID
7725             * @param start the lower bound of the range of message-boards messages
7726             * @param end the upper bound of the range of message-boards messages (not inclusive)
7727             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7728             * @param retrieveFromCache whether to retrieve from the finder cache
7729             * @return the ordered range of matching message-boards messages
7730             */
7731            @Override
7732            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7733                    int end, OrderByComparator<MBMessage> orderByComparator,
7734                    boolean retrieveFromCache) {
7735                    boolean pagination = true;
7736                    FinderPath finderPath = null;
7737                    Object[] finderArgs = null;
7738    
7739                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7740                                    (orderByComparator == null)) {
7741                            pagination = false;
7742                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7743                            finderArgs = new Object[] { userId, classNameId };
7744                    }
7745                    else {
7746                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7747                            finderArgs = new Object[] {
7748                                            userId, classNameId,
7749                                            
7750                                            start, end, orderByComparator
7751                                    };
7752                    }
7753    
7754                    List<MBMessage> list = null;
7755    
7756                    if (retrieveFromCache) {
7757                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7758                                            finderArgs, this);
7759    
7760                            if ((list != null) && !list.isEmpty()) {
7761                                    for (MBMessage mbMessage : list) {
7762                                            if ((userId != mbMessage.getUserId()) ||
7763                                                            (classNameId != mbMessage.getClassNameId())) {
7764                                                    list = null;
7765    
7766                                                    break;
7767                                            }
7768                                    }
7769                            }
7770                    }
7771    
7772                    if (list == null) {
7773                            StringBundler query = null;
7774    
7775                            if (orderByComparator != null) {
7776                                    query = new StringBundler(4 +
7777                                                    (orderByComparator.getOrderByFields().length * 3));
7778                            }
7779                            else {
7780                                    query = new StringBundler(4);
7781                            }
7782    
7783                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7784    
7785                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7786    
7787                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7788    
7789                            if (orderByComparator != null) {
7790                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7791                                            orderByComparator);
7792                            }
7793                            else
7794                             if (pagination) {
7795                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7796                            }
7797    
7798                            String sql = query.toString();
7799    
7800                            Session session = null;
7801    
7802                            try {
7803                                    session = openSession();
7804    
7805                                    Query q = session.createQuery(sql);
7806    
7807                                    QueryPos qPos = QueryPos.getInstance(q);
7808    
7809                                    qPos.add(userId);
7810    
7811                                    qPos.add(classNameId);
7812    
7813                                    if (!pagination) {
7814                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7815                                                            start, end, false);
7816    
7817                                            Collections.sort(list);
7818    
7819                                            list = Collections.unmodifiableList(list);
7820                                    }
7821                                    else {
7822                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7823                                                            start, end);
7824                                    }
7825    
7826                                    cacheResult(list);
7827    
7828                                    finderCache.putResult(finderPath, finderArgs, list);
7829                            }
7830                            catch (Exception e) {
7831                                    finderCache.removeResult(finderPath, finderArgs);
7832    
7833                                    throw processException(e);
7834                            }
7835                            finally {
7836                                    closeSession(session);
7837                            }
7838                    }
7839    
7840                    return list;
7841            }
7842    
7843            /**
7844             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7845             *
7846             * @param userId the user ID
7847             * @param classNameId the class name ID
7848             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7849             * @return the first matching message-boards message
7850             * @throws NoSuchMessageException if a matching message-boards message could not be found
7851             */
7852            @Override
7853            public MBMessage findByU_C_First(long userId, long classNameId,
7854                    OrderByComparator<MBMessage> orderByComparator)
7855                    throws NoSuchMessageException {
7856                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7857                                    orderByComparator);
7858    
7859                    if (mbMessage != null) {
7860                            return mbMessage;
7861                    }
7862    
7863                    StringBundler msg = new StringBundler(6);
7864    
7865                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7866    
7867                    msg.append("userId=");
7868                    msg.append(userId);
7869    
7870                    msg.append(", classNameId=");
7871                    msg.append(classNameId);
7872    
7873                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7874    
7875                    throw new NoSuchMessageException(msg.toString());
7876            }
7877    
7878            /**
7879             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7880             *
7881             * @param userId the user ID
7882             * @param classNameId the class name ID
7883             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7884             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7885             */
7886            @Override
7887            public MBMessage fetchByU_C_First(long userId, long classNameId,
7888                    OrderByComparator<MBMessage> orderByComparator) {
7889                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7890                                    orderByComparator);
7891    
7892                    if (!list.isEmpty()) {
7893                            return list.get(0);
7894                    }
7895    
7896                    return null;
7897            }
7898    
7899            /**
7900             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7901             *
7902             * @param userId the user ID
7903             * @param classNameId the class name ID
7904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7905             * @return the last matching message-boards message
7906             * @throws NoSuchMessageException if a matching message-boards message could not be found
7907             */
7908            @Override
7909            public MBMessage findByU_C_Last(long userId, long classNameId,
7910                    OrderByComparator<MBMessage> orderByComparator)
7911                    throws NoSuchMessageException {
7912                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7913                                    orderByComparator);
7914    
7915                    if (mbMessage != null) {
7916                            return mbMessage;
7917                    }
7918    
7919                    StringBundler msg = new StringBundler(6);
7920    
7921                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7922    
7923                    msg.append("userId=");
7924                    msg.append(userId);
7925    
7926                    msg.append(", classNameId=");
7927                    msg.append(classNameId);
7928    
7929                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7930    
7931                    throw new NoSuchMessageException(msg.toString());
7932            }
7933    
7934            /**
7935             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7936             *
7937             * @param userId the user ID
7938             * @param classNameId the class name ID
7939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7940             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7941             */
7942            @Override
7943            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7944                    OrderByComparator<MBMessage> orderByComparator) {
7945                    int count = countByU_C(userId, classNameId);
7946    
7947                    if (count == 0) {
7948                            return null;
7949                    }
7950    
7951                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7952                                    orderByComparator);
7953    
7954                    if (!list.isEmpty()) {
7955                            return list.get(0);
7956                    }
7957    
7958                    return null;
7959            }
7960    
7961            /**
7962             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7963             *
7964             * @param messageId the primary key of the current message-boards message
7965             * @param userId the user ID
7966             * @param classNameId the class name ID
7967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7968             * @return the previous, current, and next message-boards message
7969             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7970             */
7971            @Override
7972            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7973                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7974                    throws NoSuchMessageException {
7975                    MBMessage mbMessage = findByPrimaryKey(messageId);
7976    
7977                    Session session = null;
7978    
7979                    try {
7980                            session = openSession();
7981    
7982                            MBMessage[] array = new MBMessageImpl[3];
7983    
7984                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7985                                            classNameId, orderByComparator, true);
7986    
7987                            array[1] = mbMessage;
7988    
7989                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7990                                            classNameId, orderByComparator, false);
7991    
7992                            return array;
7993                    }
7994                    catch (Exception e) {
7995                            throw processException(e);
7996                    }
7997                    finally {
7998                            closeSession(session);
7999                    }
8000            }
8001    
8002            protected MBMessage getByU_C_PrevAndNext(Session session,
8003                    MBMessage mbMessage, long userId, long classNameId,
8004                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8005                    StringBundler query = null;
8006    
8007                    if (orderByComparator != null) {
8008                            query = new StringBundler(6 +
8009                                            (orderByComparator.getOrderByFields().length * 6));
8010                    }
8011                    else {
8012                            query = new StringBundler(3);
8013                    }
8014    
8015                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8016    
8017                    query.append(_FINDER_COLUMN_U_C_USERID_2);
8018    
8019                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8020    
8021                    if (orderByComparator != null) {
8022                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8023    
8024                            if (orderByConditionFields.length > 0) {
8025                                    query.append(WHERE_AND);
8026                            }
8027    
8028                            for (int i = 0; i < orderByConditionFields.length; i++) {
8029                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8030                                    query.append(orderByConditionFields[i]);
8031    
8032                                    if ((i + 1) < orderByConditionFields.length) {
8033                                            if (orderByComparator.isAscending() ^ previous) {
8034                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8035                                            }
8036                                            else {
8037                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8038                                            }
8039                                    }
8040                                    else {
8041                                            if (orderByComparator.isAscending() ^ previous) {
8042                                                    query.append(WHERE_GREATER_THAN);
8043                                            }
8044                                            else {
8045                                                    query.append(WHERE_LESSER_THAN);
8046                                            }
8047                                    }
8048                            }
8049    
8050                            query.append(ORDER_BY_CLAUSE);
8051    
8052                            String[] orderByFields = orderByComparator.getOrderByFields();
8053    
8054                            for (int i = 0; i < orderByFields.length; i++) {
8055                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8056                                    query.append(orderByFields[i]);
8057    
8058                                    if ((i + 1) < orderByFields.length) {
8059                                            if (orderByComparator.isAscending() ^ previous) {
8060                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8061                                            }
8062                                            else {
8063                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8064                                            }
8065                                    }
8066                                    else {
8067                                            if (orderByComparator.isAscending() ^ previous) {
8068                                                    query.append(ORDER_BY_ASC);
8069                                            }
8070                                            else {
8071                                                    query.append(ORDER_BY_DESC);
8072                                            }
8073                                    }
8074                            }
8075                    }
8076                    else {
8077                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8078                    }
8079    
8080                    String sql = query.toString();
8081    
8082                    Query q = session.createQuery(sql);
8083    
8084                    q.setFirstResult(0);
8085                    q.setMaxResults(2);
8086    
8087                    QueryPos qPos = QueryPos.getInstance(q);
8088    
8089                    qPos.add(userId);
8090    
8091                    qPos.add(classNameId);
8092    
8093                    if (orderByComparator != null) {
8094                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8095    
8096                            for (Object value : values) {
8097                                    qPos.add(value);
8098                            }
8099                    }
8100    
8101                    List<MBMessage> list = q.list();
8102    
8103                    if (list.size() == 2) {
8104                            return list.get(1);
8105                    }
8106                    else {
8107                            return null;
8108                    }
8109            }
8110    
8111            /**
8112             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8113             *
8114             * <p>
8115             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8116             * </p>
8117             *
8118             * @param userId the user ID
8119             * @param classNameIds the class name IDs
8120             * @return the matching message-boards messages
8121             */
8122            @Override
8123            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
8124                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
8125                            QueryUtil.ALL_POS, null);
8126            }
8127    
8128            /**
8129             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8130             *
8131             * <p>
8132             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8133             * </p>
8134             *
8135             * @param userId the user ID
8136             * @param classNameIds the class name IDs
8137             * @param start the lower bound of the range of message-boards messages
8138             * @param end the upper bound of the range of message-boards messages (not inclusive)
8139             * @return the range of matching message-boards messages
8140             */
8141            @Override
8142            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8143                    int start, int end) {
8144                    return findByU_C(userId, classNameIds, start, end, null);
8145            }
8146    
8147            /**
8148             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8149             *
8150             * <p>
8151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8152             * </p>
8153             *
8154             * @param userId the user ID
8155             * @param classNameIds the class name IDs
8156             * @param start the lower bound of the range of message-boards messages
8157             * @param end the upper bound of the range of message-boards messages (not inclusive)
8158             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8159             * @return the ordered range of matching message-boards messages
8160             */
8161            @Override
8162            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8163                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8164                    return findByU_C(userId, classNameIds, start, end, orderByComparator,
8165                            true);
8166            }
8167    
8168            /**
8169             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;, optionally using the finder cache.
8170             *
8171             * <p>
8172             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8173             * </p>
8174             *
8175             * @param userId the user ID
8176             * @param classNameId the class name ID
8177             * @param start the lower bound of the range of message-boards messages
8178             * @param end the upper bound of the range of message-boards messages (not inclusive)
8179             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8180             * @param retrieveFromCache whether to retrieve from the finder cache
8181             * @return the ordered range of matching message-boards messages
8182             */
8183            @Override
8184            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8185                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
8186                    boolean retrieveFromCache) {
8187                    if (classNameIds == null) {
8188                            classNameIds = new long[0];
8189                    }
8190                    else if (classNameIds.length > 1) {
8191                            classNameIds = ArrayUtil.unique(classNameIds);
8192    
8193                            Arrays.sort(classNameIds);
8194                    }
8195    
8196                    if (classNameIds.length == 1) {
8197                            return findByU_C(userId, classNameIds[0], start, end,
8198                                    orderByComparator);
8199                    }
8200    
8201                    boolean pagination = true;
8202                    Object[] finderArgs = null;
8203    
8204                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8205                                    (orderByComparator == null)) {
8206                            pagination = false;
8207                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8208                    }
8209                    else {
8210                            finderArgs = new Object[] {
8211                                            userId, StringUtil.merge(classNameIds),
8212                                            
8213                                            start, end, orderByComparator
8214                                    };
8215                    }
8216    
8217                    List<MBMessage> list = null;
8218    
8219                    if (retrieveFromCache) {
8220                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8221                                            finderArgs, this);
8222    
8223                            if ((list != null) && !list.isEmpty()) {
8224                                    for (MBMessage mbMessage : list) {
8225                                            if ((userId != mbMessage.getUserId()) ||
8226                                                            !ArrayUtil.contains(classNameIds,
8227                                                                    mbMessage.getClassNameId())) {
8228                                                    list = null;
8229    
8230                                                    break;
8231                                            }
8232                                    }
8233                            }
8234                    }
8235    
8236                    if (list == null) {
8237                            StringBundler query = new StringBundler();
8238    
8239                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8240    
8241                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8242    
8243                            if (classNameIds.length > 0) {
8244                                    query.append(StringPool.OPEN_PARENTHESIS);
8245    
8246                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8247    
8248                                    query.append(StringUtil.merge(classNameIds));
8249    
8250                                    query.append(StringPool.CLOSE_PARENTHESIS);
8251    
8252                                    query.append(StringPool.CLOSE_PARENTHESIS);
8253                            }
8254    
8255                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8256                                                    1)), query.index() - 1);
8257    
8258                            if (orderByComparator != null) {
8259                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8260                                            orderByComparator);
8261                            }
8262                            else
8263                             if (pagination) {
8264                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8265                            }
8266    
8267                            String sql = query.toString();
8268    
8269                            Session session = null;
8270    
8271                            try {
8272                                    session = openSession();
8273    
8274                                    Query q = session.createQuery(sql);
8275    
8276                                    QueryPos qPos = QueryPos.getInstance(q);
8277    
8278                                    qPos.add(userId);
8279    
8280                                    if (!pagination) {
8281                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8282                                                            start, end, false);
8283    
8284                                            Collections.sort(list);
8285    
8286                                            list = Collections.unmodifiableList(list);
8287                                    }
8288                                    else {
8289                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8290                                                            start, end);
8291                                    }
8292    
8293                                    cacheResult(list);
8294    
8295                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8296                                            finderArgs, list);
8297                            }
8298                            catch (Exception e) {
8299                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8300                                            finderArgs);
8301    
8302                                    throw processException(e);
8303                            }
8304                            finally {
8305                                    closeSession(session);
8306                            }
8307                    }
8308    
8309                    return list;
8310            }
8311    
8312            /**
8313             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8314             *
8315             * @param userId the user ID
8316             * @param classNameId the class name ID
8317             */
8318            @Override
8319            public void removeByU_C(long userId, long classNameId) {
8320                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8321                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8322                            remove(mbMessage);
8323                    }
8324            }
8325    
8326            /**
8327             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8328             *
8329             * @param userId the user ID
8330             * @param classNameId the class name ID
8331             * @return the number of matching message-boards messages
8332             */
8333            @Override
8334            public int countByU_C(long userId, long classNameId) {
8335                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8336    
8337                    Object[] finderArgs = new Object[] { userId, classNameId };
8338    
8339                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8340    
8341                    if (count == null) {
8342                            StringBundler query = new StringBundler(3);
8343    
8344                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8345    
8346                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8347    
8348                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8349    
8350                            String sql = query.toString();
8351    
8352                            Session session = null;
8353    
8354                            try {
8355                                    session = openSession();
8356    
8357                                    Query q = session.createQuery(sql);
8358    
8359                                    QueryPos qPos = QueryPos.getInstance(q);
8360    
8361                                    qPos.add(userId);
8362    
8363                                    qPos.add(classNameId);
8364    
8365                                    count = (Long)q.uniqueResult();
8366    
8367                                    finderCache.putResult(finderPath, finderArgs, count);
8368                            }
8369                            catch (Exception e) {
8370                                    finderCache.removeResult(finderPath, finderArgs);
8371    
8372                                    throw processException(e);
8373                            }
8374                            finally {
8375                                    closeSession(session);
8376                            }
8377                    }
8378    
8379                    return count.intValue();
8380            }
8381    
8382            /**
8383             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8384             *
8385             * @param userId the user ID
8386             * @param classNameIds the class name IDs
8387             * @return the number of matching message-boards messages
8388             */
8389            @Override
8390            public int countByU_C(long userId, long[] classNameIds) {
8391                    if (classNameIds == null) {
8392                            classNameIds = new long[0];
8393                    }
8394                    else if (classNameIds.length > 1) {
8395                            classNameIds = ArrayUtil.unique(classNameIds);
8396    
8397                            Arrays.sort(classNameIds);
8398                    }
8399    
8400                    Object[] finderArgs = new Object[] {
8401                                    userId, StringUtil.merge(classNameIds)
8402                            };
8403    
8404                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8405                                    finderArgs, this);
8406    
8407                    if (count == null) {
8408                            StringBundler query = new StringBundler();
8409    
8410                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8411    
8412                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8413    
8414                            if (classNameIds.length > 0) {
8415                                    query.append(StringPool.OPEN_PARENTHESIS);
8416    
8417                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8418    
8419                                    query.append(StringUtil.merge(classNameIds));
8420    
8421                                    query.append(StringPool.CLOSE_PARENTHESIS);
8422    
8423                                    query.append(StringPool.CLOSE_PARENTHESIS);
8424                            }
8425    
8426                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8427                                                    1)), query.index() - 1);
8428    
8429                            String sql = query.toString();
8430    
8431                            Session session = null;
8432    
8433                            try {
8434                                    session = openSession();
8435    
8436                                    Query q = session.createQuery(sql);
8437    
8438                                    QueryPos qPos = QueryPos.getInstance(q);
8439    
8440                                    qPos.add(userId);
8441    
8442                                    count = (Long)q.uniqueResult();
8443    
8444                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8445                                            finderArgs, count);
8446                            }
8447                            catch (Exception e) {
8448                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8449                                            finderArgs);
8450    
8451                                    throw processException(e);
8452                            }
8453                            finally {
8454                                    closeSession(session);
8455                            }
8456                    }
8457    
8458                    return count.intValue();
8459            }
8460    
8461            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8462            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8463            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8464            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8465                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8466                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8467                            new String[] {
8468                                    Long.class.getName(), Long.class.getName(),
8469                                    
8470                            Integer.class.getName(), Integer.class.getName(),
8471                                    OrderByComparator.class.getName()
8472                            });
8473            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8474                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8475                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8476                            new String[] { Long.class.getName(), Long.class.getName() },
8477                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8478                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8479                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8480            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8481                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8482                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8483                            new String[] { Long.class.getName(), Long.class.getName() });
8484    
8485            /**
8486             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8487             *
8488             * @param classNameId the class name ID
8489             * @param classPK the class p k
8490             * @return the matching message-boards messages
8491             */
8492            @Override
8493            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8494                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8495                            QueryUtil.ALL_POS, null);
8496            }
8497    
8498            /**
8499             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8500             *
8501             * <p>
8502             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8503             * </p>
8504             *
8505             * @param classNameId the class name ID
8506             * @param classPK the class p k
8507             * @param start the lower bound of the range of message-boards messages
8508             * @param end the upper bound of the range of message-boards messages (not inclusive)
8509             * @return the range of matching message-boards messages
8510             */
8511            @Override
8512            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8513                    int end) {
8514                    return findByC_C(classNameId, classPK, start, end, null);
8515            }
8516    
8517            /**
8518             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8519             *
8520             * <p>
8521             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8522             * </p>
8523             *
8524             * @param classNameId the class name ID
8525             * @param classPK the class p k
8526             * @param start the lower bound of the range of message-boards messages
8527             * @param end the upper bound of the range of message-boards messages (not inclusive)
8528             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8529             * @return the ordered range of matching message-boards messages
8530             */
8531            @Override
8532            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8533                    int end, OrderByComparator<MBMessage> orderByComparator) {
8534                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
8535                            true);
8536            }
8537    
8538            /**
8539             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8540             *
8541             * <p>
8542             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
8543             * </p>
8544             *
8545             * @param classNameId the class name ID
8546             * @param classPK the class p k
8547             * @param start the lower bound of the range of message-boards messages
8548             * @param end the upper bound of the range of message-boards messages (not inclusive)
8549             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8550             * @param retrieveFromCache whether to retrieve from the finder cache
8551             * @return the ordered range of matching message-boards messages
8552             */
8553            @Override
8554            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8555                    int end, OrderByComparator<MBMessage> orderByComparator,
8556                    boolean retrieveFromCache) {
8557                    boolean pagination = true;
8558                    FinderPath finderPath = null;
8559                    Object[] finderArgs = null;
8560    
8561                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8562                                    (orderByComparator == null)) {
8563                            pagination = false;
8564                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8565                            finderArgs = new Object[] { classNameId, classPK };
8566                    }
8567                    else {
8568                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8569                            finderArgs = new Object[] {
8570                                            classNameId, classPK,
8571                                            
8572                                            start, end, orderByComparator
8573                                    };
8574                    }
8575    
8576                    List<MBMessage> list = null;
8577    
8578                    if (retrieveFromCache) {
8579                            list = (List<MBMessage>)finderCache.getResult(finderPath,
8580                                            finderArgs, this);
8581    
8582                            if ((list != null) && !list.isEmpty()) {
8583                                    for (MBMessage mbMessage : list) {
8584                                            if ((classNameId != mbMessage.getClassNameId()) ||
8585                                                            (classPK != mbMessage.getClassPK())) {
8586                                                    list = null;
8587    
8588                                                    break;
8589                                            }
8590                                    }
8591                            }
8592                    }
8593    
8594                    if (list == null) {
8595                            StringBundler query = null;
8596    
8597                            if (orderByComparator != null) {
8598                                    query = new StringBundler(4 +
8599                                                    (orderByComparator.getOrderByFields().length * 3));
8600                            }
8601                            else {
8602                                    query = new StringBundler(4);
8603                            }
8604    
8605                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8606    
8607                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8608    
8609                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8610    
8611                            if (orderByComparator != null) {
8612                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8613                                            orderByComparator);
8614                            }
8615                            else
8616                             if (pagination) {
8617                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8618                            }
8619    
8620                            String sql = query.toString();
8621    
8622                            Session session = null;
8623    
8624                            try {
8625                                    session = openSession();
8626    
8627                                    Query q = session.createQuery(sql);
8628    
8629                                    QueryPos qPos = QueryPos.getInstance(q);
8630    
8631                                    qPos.add(classNameId);
8632    
8633                                    qPos.add(classPK);
8634    
8635                                    if (!pagination) {
8636                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8637                                                            start, end, false);
8638    
8639                                            Collections.sort(list);
8640    
8641                                            list = Collections.unmodifiableList(list);
8642                                    }
8643                                    else {
8644                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8645                                                            start, end);
8646                                    }
8647    
8648                                    cacheResult(list);
8649    
8650                                    finderCache.putResult(finderPath, finderArgs, list);
8651                            }
8652                            catch (Exception e) {
8653                                    finderCache.removeResult(finderPath, finderArgs);
8654    
8655                                    throw processException(e);
8656                            }
8657                            finally {
8658                                    closeSession(session);
8659                            }
8660                    }
8661    
8662                    return list;
8663            }
8664    
8665            /**
8666             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8667             *
8668             * @param classNameId the class name ID
8669             * @param classPK the class p k
8670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8671             * @return the first matching message-boards message
8672             * @throws NoSuchMessageException if a matching message-boards message could not be found
8673             */
8674            @Override
8675            public MBMessage findByC_C_First(long classNameId, long classPK,
8676                    OrderByComparator<MBMessage> orderByComparator)
8677                    throws NoSuchMessageException {
8678                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8679                                    orderByComparator);
8680    
8681                    if (mbMessage != null) {
8682                            return mbMessage;
8683                    }
8684    
8685                    StringBundler msg = new StringBundler(6);
8686    
8687                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8688    
8689                    msg.append("classNameId=");
8690                    msg.append(classNameId);
8691    
8692                    msg.append(", classPK=");
8693                    msg.append(classPK);
8694    
8695                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8696    
8697                    throw new NoSuchMessageException(msg.toString());
8698            }
8699    
8700            /**
8701             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8702             *
8703             * @param classNameId the class name ID
8704             * @param classPK the class p k
8705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8706             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8707             */
8708            @Override
8709            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8710                    OrderByComparator<MBMessage> orderByComparator) {
8711                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8712                                    orderByComparator);
8713    
8714                    if (!list.isEmpty()) {
8715                            return list.get(0);
8716                    }
8717    
8718                    return null;
8719            }
8720    
8721            /**
8722             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8723             *
8724             * @param classNameId the class name ID
8725             * @param classPK the class p k
8726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8727             * @return the last matching message-boards message
8728             * @throws NoSuchMessageException if a matching message-boards message could not be found
8729             */
8730            @Override
8731            public MBMessage findByC_C_Last(long classNameId, long classPK,
8732                    OrderByComparator<MBMessage> orderByComparator)
8733                    throws NoSuchMessageException {
8734                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8735                                    orderByComparator);
8736    
8737                    if (mbMessage != null) {
8738                            return mbMessage;
8739                    }
8740    
8741                    StringBundler msg = new StringBundler(6);
8742    
8743                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8744    
8745                    msg.append("classNameId=");
8746                    msg.append(classNameId);
8747    
8748                    msg.append(", classPK=");
8749                    msg.append(classPK);
8750    
8751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8752    
8753                    throw new NoSuchMessageException(msg.toString());
8754            }
8755    
8756            /**
8757             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8758             *
8759             * @param classNameId the class name ID
8760             * @param classPK the class p k
8761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8762             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8763             */
8764            @Override
8765            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8766                    OrderByComparator<MBMessage> orderByComparator) {
8767                    int count = countByC_C(classNameId, classPK);
8768    
8769                    if (count == 0) {
8770                            return null;
8771                    }
8772    
8773                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8774                                    count, orderByComparator);
8775    
8776                    if (!list.isEmpty()) {
8777                            return list.get(0);
8778                    }
8779    
8780                    return null;
8781            }
8782    
8783            /**
8784             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8785             *
8786             * @param messageId the primary key of the current message-boards message
8787             * @param classNameId the class name ID
8788             * @param classPK the class p k
8789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8790             * @return the previous, current, and next message-boards message
8791             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8792             */
8793            @Override
8794            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8795                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8796                    throws NoSuchMessageException {
8797                    MBMessage mbMessage = findByPrimaryKey(messageId);
8798    
8799                    Session session = null;
8800    
8801                    try {
8802                            session = openSession();
8803    
8804                            MBMessage[] array = new MBMessageImpl[3];
8805    
8806                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8807                                            classPK, orderByComparator, true);
8808    
8809                            array[1] = mbMessage;
8810    
8811                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8812                                            classPK, orderByComparator, false);
8813    
8814                            return array;
8815                    }
8816                    catch (Exception e) {
8817                            throw processException(e);
8818                    }
8819                    finally {
8820                            closeSession(session);
8821                    }
8822            }
8823    
8824            protected MBMessage getByC_C_PrevAndNext(Session session,
8825                    MBMessage mbMessage, long classNameId, long classPK,
8826                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8827                    StringBundler query = null;
8828    
8829                    if (orderByComparator != null) {
8830                            query = new StringBundler(6 +
8831                                            (orderByComparator.getOrderByFields().length * 6));
8832                    }
8833                    else {
8834                            query = new StringBundler(3);
8835                    }
8836    
8837                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8838    
8839                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8840    
8841                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8842    
8843                    if (orderByComparator != null) {
8844                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8845    
8846                            if (orderByConditionFields.length > 0) {
8847                                    query.append(WHERE_AND);
8848                            }
8849    
8850                            for (int i = 0; i < orderByConditionFields.length; i++) {
8851                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8852                                    query.append(orderByConditionFields[i]);
8853    
8854                                    if ((i + 1) < orderByConditionFields.length) {
8855                                            if (orderByComparator.isAscending() ^ previous) {
8856                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8857                                            }
8858                                            else {
8859                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8860                                            }
8861                                    }
8862                                    else {
8863                                            if (orderByComparator.isAscending() ^ previous) {
8864                                                    query.append(WHERE_GREATER_THAN);
8865                                            }
8866                                            else {
8867                                                    query.append(WHERE_LESSER_THAN);
8868                                            }
8869                                    }
8870                            }
8871    
8872                            query.append(ORDER_BY_CLAUSE);
8873    
8874                            String[] orderByFields = orderByComparator.getOrderByFields();
8875    
8876                            for (int i = 0; i < orderByFields.length; i++) {
8877                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8878                                    query.append(orderByFields[i]);
8879    
8880                                    if ((i + 1) < orderByFields.length) {
8881                                            if (orderByComparator.isAscending() ^ previous) {
8882                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8883                                            }
8884                                            else {
8885                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8886                                            }
8887                                    }
8888                                    else {
8889                                            if (orderByComparator.isAscending() ^ previous) {
8890                                                    query.append(ORDER_BY_ASC);
8891                                            }
8892                                            else {
8893                                                    query.append(ORDER_BY_DESC);
8894                                            }
8895                                    }
8896                            }
8897                    }
8898                    else {
8899                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8900                    }
8901    
8902                    String sql = query.toString();
8903    
8904                    Query q = session.createQuery(sql);
8905    
8906                    q.setFirstResult(0);
8907                    q.setMaxResults(2);
8908    
8909                    QueryPos qPos = QueryPos.getInstance(q);
8910    
8911                    qPos.add(classNameId);
8912    
8913                    qPos.add(classPK);
8914    
8915                    if (orderByComparator != null) {
8916                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8917    
8918                            for (Object value : values) {
8919                                    qPos.add(value);
8920                            }
8921                    }
8922    
8923                    List<MBMessage> list = q.list();
8924    
8925                    if (list.size() == 2) {
8926                            return list.get(1);
8927                    }
8928                    else {
8929                            return null;
8930                    }
8931            }
8932    
8933            /**
8934             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8935             *
8936             * @param classNameId the class name ID
8937             * @param classPK the class p k
8938             */
8939            @Override
8940            public void removeByC_C(long classNameId, long classPK) {
8941                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8942                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8943                            remove(mbMessage);
8944                    }
8945            }
8946    
8947            /**
8948             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8949             *
8950             * @param classNameId the class name ID
8951             * @param classPK the class p k
8952             * @return the number of matching message-boards messages
8953             */
8954            @Override
8955            public int countByC_C(long classNameId, long classPK) {
8956                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8957    
8958                    Object[] finderArgs = new Object[] { classNameId, classPK };
8959    
8960                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8961    
8962                    if (count == null) {
8963                            StringBundler query = new StringBundler(3);
8964    
8965                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8966    
8967                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8968    
8969                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8970    
8971                            String sql = query.toString();
8972    
8973                            Session session = null;
8974    
8975                            try {
8976                                    session = openSession();
8977    
8978                                    Query q = session.createQuery(sql);
8979    
8980                                    QueryPos qPos = QueryPos.getInstance(q);
8981    
8982                                    qPos.add(classNameId);
8983    
8984                                    qPos.add(classPK);
8985    
8986                                    count = (Long)q.uniqueResult();
8987    
8988                                    finderCache.putResult(finderPath, finderArgs, count);
8989                            }
8990                            catch (Exception e) {
8991                                    finderCache.removeResult(finderPath, finderArgs);
8992    
8993                                    throw processException(e);
8994                            }
8995                            finally {
8996                                    closeSession(session);
8997                            }
8998                    }
8999    
9000                    return count.intValue();
9001            }
9002    
9003            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
9004            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
9005            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9006                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9007                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
9008                            new String[] {
9009                                    Long.class.getName(), Long.class.getName(),
9010                                    
9011                            Integer.class.getName(), Integer.class.getName(),
9012                                    OrderByComparator.class.getName()
9013                            });
9014            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9015                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9016                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
9017                            new String[] { Long.class.getName(), Long.class.getName() },
9018                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9019                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
9020                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9021            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9022                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9023                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
9024                            new String[] { Long.class.getName(), Long.class.getName() });
9025    
9026            /**
9027             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9028             *
9029             * @param threadId the thread ID
9030             * @param parentMessageId the parent message ID
9031             * @return the matching message-boards messages
9032             */
9033            @Override
9034            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
9035                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
9036                            QueryUtil.ALL_POS, null);
9037            }
9038    
9039            /**
9040             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9041             *
9042             * <p>
9043             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9044             * </p>
9045             *
9046             * @param threadId the thread ID
9047             * @param parentMessageId the parent message ID
9048             * @param start the lower bound of the range of message-boards messages
9049             * @param end the upper bound of the range of message-boards messages (not inclusive)
9050             * @return the range of matching message-boards messages
9051             */
9052            @Override
9053            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9054                    int start, int end) {
9055                    return findByT_P(threadId, parentMessageId, start, end, null);
9056            }
9057    
9058            /**
9059             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9060             *
9061             * <p>
9062             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9063             * </p>
9064             *
9065             * @param threadId the thread ID
9066             * @param parentMessageId the parent message ID
9067             * @param start the lower bound of the range of message-boards messages
9068             * @param end the upper bound of the range of message-boards messages (not inclusive)
9069             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9070             * @return the ordered range of matching message-boards messages
9071             */
9072            @Override
9073            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9074                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
9075                    return findByT_P(threadId, parentMessageId, start, end,
9076                            orderByComparator, true);
9077            }
9078    
9079            /**
9080             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9081             *
9082             * <p>
9083             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9084             * </p>
9085             *
9086             * @param threadId the thread ID
9087             * @param parentMessageId the parent message ID
9088             * @param start the lower bound of the range of message-boards messages
9089             * @param end the upper bound of the range of message-boards messages (not inclusive)
9090             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9091             * @param retrieveFromCache whether to retrieve from the finder cache
9092             * @return the ordered range of matching message-boards messages
9093             */
9094            @Override
9095            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9096                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
9097                    boolean retrieveFromCache) {
9098                    boolean pagination = true;
9099                    FinderPath finderPath = null;
9100                    Object[] finderArgs = null;
9101    
9102                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9103                                    (orderByComparator == null)) {
9104                            pagination = false;
9105                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
9106                            finderArgs = new Object[] { threadId, parentMessageId };
9107                    }
9108                    else {
9109                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
9110                            finderArgs = new Object[] {
9111                                            threadId, parentMessageId,
9112                                            
9113                                            start, end, orderByComparator
9114                                    };
9115                    }
9116    
9117                    List<MBMessage> list = null;
9118    
9119                    if (retrieveFromCache) {
9120                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9121                                            finderArgs, this);
9122    
9123                            if ((list != null) && !list.isEmpty()) {
9124                                    for (MBMessage mbMessage : list) {
9125                                            if ((threadId != mbMessage.getThreadId()) ||
9126                                                            (parentMessageId != mbMessage.getParentMessageId())) {
9127                                                    list = null;
9128    
9129                                                    break;
9130                                            }
9131                                    }
9132                            }
9133                    }
9134    
9135                    if (list == null) {
9136                            StringBundler query = null;
9137    
9138                            if (orderByComparator != null) {
9139                                    query = new StringBundler(4 +
9140                                                    (orderByComparator.getOrderByFields().length * 3));
9141                            }
9142                            else {
9143                                    query = new StringBundler(4);
9144                            }
9145    
9146                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9147    
9148                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9149    
9150                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9151    
9152                            if (orderByComparator != null) {
9153                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9154                                            orderByComparator);
9155                            }
9156                            else
9157                             if (pagination) {
9158                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9159                            }
9160    
9161                            String sql = query.toString();
9162    
9163                            Session session = null;
9164    
9165                            try {
9166                                    session = openSession();
9167    
9168                                    Query q = session.createQuery(sql);
9169    
9170                                    QueryPos qPos = QueryPos.getInstance(q);
9171    
9172                                    qPos.add(threadId);
9173    
9174                                    qPos.add(parentMessageId);
9175    
9176                                    if (!pagination) {
9177                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9178                                                            start, end, false);
9179    
9180                                            Collections.sort(list);
9181    
9182                                            list = Collections.unmodifiableList(list);
9183                                    }
9184                                    else {
9185                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9186                                                            start, end);
9187                                    }
9188    
9189                                    cacheResult(list);
9190    
9191                                    finderCache.putResult(finderPath, finderArgs, list);
9192                            }
9193                            catch (Exception e) {
9194                                    finderCache.removeResult(finderPath, finderArgs);
9195    
9196                                    throw processException(e);
9197                            }
9198                            finally {
9199                                    closeSession(session);
9200                            }
9201                    }
9202    
9203                    return list;
9204            }
9205    
9206            /**
9207             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9208             *
9209             * @param threadId the thread ID
9210             * @param parentMessageId the parent message ID
9211             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9212             * @return the first matching message-boards message
9213             * @throws NoSuchMessageException if a matching message-boards message could not be found
9214             */
9215            @Override
9216            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9217                    OrderByComparator<MBMessage> orderByComparator)
9218                    throws NoSuchMessageException {
9219                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9220                                    orderByComparator);
9221    
9222                    if (mbMessage != null) {
9223                            return mbMessage;
9224                    }
9225    
9226                    StringBundler msg = new StringBundler(6);
9227    
9228                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9229    
9230                    msg.append("threadId=");
9231                    msg.append(threadId);
9232    
9233                    msg.append(", parentMessageId=");
9234                    msg.append(parentMessageId);
9235    
9236                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9237    
9238                    throw new NoSuchMessageException(msg.toString());
9239            }
9240    
9241            /**
9242             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9243             *
9244             * @param threadId the thread ID
9245             * @param parentMessageId the parent message ID
9246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9247             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9248             */
9249            @Override
9250            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9251                    OrderByComparator<MBMessage> orderByComparator) {
9252                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9253                                    orderByComparator);
9254    
9255                    if (!list.isEmpty()) {
9256                            return list.get(0);
9257                    }
9258    
9259                    return null;
9260            }
9261    
9262            /**
9263             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9264             *
9265             * @param threadId the thread ID
9266             * @param parentMessageId the parent message ID
9267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9268             * @return the last matching message-boards message
9269             * @throws NoSuchMessageException if a matching message-boards message could not be found
9270             */
9271            @Override
9272            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9273                    OrderByComparator<MBMessage> orderByComparator)
9274                    throws NoSuchMessageException {
9275                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9276                                    orderByComparator);
9277    
9278                    if (mbMessage != null) {
9279                            return mbMessage;
9280                    }
9281    
9282                    StringBundler msg = new StringBundler(6);
9283    
9284                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9285    
9286                    msg.append("threadId=");
9287                    msg.append(threadId);
9288    
9289                    msg.append(", parentMessageId=");
9290                    msg.append(parentMessageId);
9291    
9292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9293    
9294                    throw new NoSuchMessageException(msg.toString());
9295            }
9296    
9297            /**
9298             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9299             *
9300             * @param threadId the thread ID
9301             * @param parentMessageId the parent message ID
9302             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9303             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9304             */
9305            @Override
9306            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9307                    OrderByComparator<MBMessage> orderByComparator) {
9308                    int count = countByT_P(threadId, parentMessageId);
9309    
9310                    if (count == 0) {
9311                            return null;
9312                    }
9313    
9314                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9315                                    count, orderByComparator);
9316    
9317                    if (!list.isEmpty()) {
9318                            return list.get(0);
9319                    }
9320    
9321                    return null;
9322            }
9323    
9324            /**
9325             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9326             *
9327             * @param messageId the primary key of the current message-boards message
9328             * @param threadId the thread ID
9329             * @param parentMessageId the parent message ID
9330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9331             * @return the previous, current, and next message-boards message
9332             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9333             */
9334            @Override
9335            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9336                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
9337                    throws NoSuchMessageException {
9338                    MBMessage mbMessage = findByPrimaryKey(messageId);
9339    
9340                    Session session = null;
9341    
9342                    try {
9343                            session = openSession();
9344    
9345                            MBMessage[] array = new MBMessageImpl[3];
9346    
9347                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9348                                            parentMessageId, orderByComparator, true);
9349    
9350                            array[1] = mbMessage;
9351    
9352                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9353                                            parentMessageId, orderByComparator, false);
9354    
9355                            return array;
9356                    }
9357                    catch (Exception e) {
9358                            throw processException(e);
9359                    }
9360                    finally {
9361                            closeSession(session);
9362                    }
9363            }
9364    
9365            protected MBMessage getByT_P_PrevAndNext(Session session,
9366                    MBMessage mbMessage, long threadId, long parentMessageId,
9367                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9368                    StringBundler query = null;
9369    
9370                    if (orderByComparator != null) {
9371                            query = new StringBundler(6 +
9372                                            (orderByComparator.getOrderByFields().length * 6));
9373                    }
9374                    else {
9375                            query = new StringBundler(3);
9376                    }
9377    
9378                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9379    
9380                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9381    
9382                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9383    
9384                    if (orderByComparator != null) {
9385                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9386    
9387                            if (orderByConditionFields.length > 0) {
9388                                    query.append(WHERE_AND);
9389                            }
9390    
9391                            for (int i = 0; i < orderByConditionFields.length; i++) {
9392                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9393                                    query.append(orderByConditionFields[i]);
9394    
9395                                    if ((i + 1) < orderByConditionFields.length) {
9396                                            if (orderByComparator.isAscending() ^ previous) {
9397                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9398                                            }
9399                                            else {
9400                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9401                                            }
9402                                    }
9403                                    else {
9404                                            if (orderByComparator.isAscending() ^ previous) {
9405                                                    query.append(WHERE_GREATER_THAN);
9406                                            }
9407                                            else {
9408                                                    query.append(WHERE_LESSER_THAN);
9409                                            }
9410                                    }
9411                            }
9412    
9413                            query.append(ORDER_BY_CLAUSE);
9414    
9415                            String[] orderByFields = orderByComparator.getOrderByFields();
9416    
9417                            for (int i = 0; i < orderByFields.length; i++) {
9418                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9419                                    query.append(orderByFields[i]);
9420    
9421                                    if ((i + 1) < orderByFields.length) {
9422                                            if (orderByComparator.isAscending() ^ previous) {
9423                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9424                                            }
9425                                            else {
9426                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9427                                            }
9428                                    }
9429                                    else {
9430                                            if (orderByComparator.isAscending() ^ previous) {
9431                                                    query.append(ORDER_BY_ASC);
9432                                            }
9433                                            else {
9434                                                    query.append(ORDER_BY_DESC);
9435                                            }
9436                                    }
9437                            }
9438                    }
9439                    else {
9440                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9441                    }
9442    
9443                    String sql = query.toString();
9444    
9445                    Query q = session.createQuery(sql);
9446    
9447                    q.setFirstResult(0);
9448                    q.setMaxResults(2);
9449    
9450                    QueryPos qPos = QueryPos.getInstance(q);
9451    
9452                    qPos.add(threadId);
9453    
9454                    qPos.add(parentMessageId);
9455    
9456                    if (orderByComparator != null) {
9457                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9458    
9459                            for (Object value : values) {
9460                                    qPos.add(value);
9461                            }
9462                    }
9463    
9464                    List<MBMessage> list = q.list();
9465    
9466                    if (list.size() == 2) {
9467                            return list.get(1);
9468                    }
9469                    else {
9470                            return null;
9471                    }
9472            }
9473    
9474            /**
9475             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9476             *
9477             * @param threadId the thread ID
9478             * @param parentMessageId the parent message ID
9479             */
9480            @Override
9481            public void removeByT_P(long threadId, long parentMessageId) {
9482                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9483                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9484                            remove(mbMessage);
9485                    }
9486            }
9487    
9488            /**
9489             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9490             *
9491             * @param threadId the thread ID
9492             * @param parentMessageId the parent message ID
9493             * @return the number of matching message-boards messages
9494             */
9495            @Override
9496            public int countByT_P(long threadId, long parentMessageId) {
9497                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9498    
9499                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9500    
9501                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9502    
9503                    if (count == null) {
9504                            StringBundler query = new StringBundler(3);
9505    
9506                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9507    
9508                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9509    
9510                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9511    
9512                            String sql = query.toString();
9513    
9514                            Session session = null;
9515    
9516                            try {
9517                                    session = openSession();
9518    
9519                                    Query q = session.createQuery(sql);
9520    
9521                                    QueryPos qPos = QueryPos.getInstance(q);
9522    
9523                                    qPos.add(threadId);
9524    
9525                                    qPos.add(parentMessageId);
9526    
9527                                    count = (Long)q.uniqueResult();
9528    
9529                                    finderCache.putResult(finderPath, finderArgs, count);
9530                            }
9531                            catch (Exception e) {
9532                                    finderCache.removeResult(finderPath, finderArgs);
9533    
9534                                    throw processException(e);
9535                            }
9536                            finally {
9537                                    closeSession(session);
9538                            }
9539                    }
9540    
9541                    return count.intValue();
9542            }
9543    
9544            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9545            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9546            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9547                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9548                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9549                            new String[] {
9550                                    Long.class.getName(), Boolean.class.getName(),
9551                                    
9552                            Integer.class.getName(), Integer.class.getName(),
9553                                    OrderByComparator.class.getName()
9554                            });
9555            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9556                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9557                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9558                            new String[] { Long.class.getName(), Boolean.class.getName() },
9559                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9560                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9561                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9562            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9563                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9564                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9565                            new String[] { Long.class.getName(), Boolean.class.getName() });
9566    
9567            /**
9568             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9569             *
9570             * @param threadId the thread ID
9571             * @param answer the answer
9572             * @return the matching message-boards messages
9573             */
9574            @Override
9575            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9576                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9577                            QueryUtil.ALL_POS, null);
9578            }
9579    
9580            /**
9581             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9582             *
9583             * <p>
9584             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9585             * </p>
9586             *
9587             * @param threadId the thread ID
9588             * @param answer the answer
9589             * @param start the lower bound of the range of message-boards messages
9590             * @param end the upper bound of the range of message-boards messages (not inclusive)
9591             * @return the range of matching message-boards messages
9592             */
9593            @Override
9594            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9595                    int end) {
9596                    return findByT_A(threadId, answer, start, end, null);
9597            }
9598    
9599            /**
9600             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9601             *
9602             * <p>
9603             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9604             * </p>
9605             *
9606             * @param threadId the thread ID
9607             * @param answer the answer
9608             * @param start the lower bound of the range of message-boards messages
9609             * @param end the upper bound of the range of message-boards messages (not inclusive)
9610             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9611             * @return the ordered range of matching message-boards messages
9612             */
9613            @Override
9614            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9615                    int end, OrderByComparator<MBMessage> orderByComparator) {
9616                    return findByT_A(threadId, answer, start, end, orderByComparator, true);
9617            }
9618    
9619            /**
9620             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9621             *
9622             * <p>
9623             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
9624             * </p>
9625             *
9626             * @param threadId the thread ID
9627             * @param answer the answer
9628             * @param start the lower bound of the range of message-boards messages
9629             * @param end the upper bound of the range of message-boards messages (not inclusive)
9630             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9631             * @param retrieveFromCache whether to retrieve from the finder cache
9632             * @return the ordered range of matching message-boards messages
9633             */
9634            @Override
9635            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9636                    int end, OrderByComparator<MBMessage> orderByComparator,
9637                    boolean retrieveFromCache) {
9638                    boolean pagination = true;
9639                    FinderPath finderPath = null;
9640                    Object[] finderArgs = null;
9641    
9642                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9643                                    (orderByComparator == null)) {
9644                            pagination = false;
9645                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9646                            finderArgs = new Object[] { threadId, answer };
9647                    }
9648                    else {
9649                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9650                            finderArgs = new Object[] {
9651                                            threadId, answer,
9652                                            
9653                                            start, end, orderByComparator
9654                                    };
9655                    }
9656    
9657                    List<MBMessage> list = null;
9658    
9659                    if (retrieveFromCache) {
9660                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9661                                            finderArgs, this);
9662    
9663                            if ((list != null) && !list.isEmpty()) {
9664                                    for (MBMessage mbMessage : list) {
9665                                            if ((threadId != mbMessage.getThreadId()) ||
9666                                                            (answer != mbMessage.getAnswer())) {
9667                                                    list = null;
9668    
9669                                                    break;
9670                                            }
9671                                    }
9672                            }
9673                    }
9674    
9675                    if (list == null) {
9676                            StringBundler query = null;
9677    
9678                            if (orderByComparator != null) {
9679                                    query = new StringBundler(4 +
9680                                                    (orderByComparator.getOrderByFields().length * 3));
9681                            }
9682                            else {
9683                                    query = new StringBundler(4);
9684                            }
9685    
9686                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9687    
9688                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9689    
9690                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9691    
9692                            if (orderByComparator != null) {
9693                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9694                                            orderByComparator);
9695                            }
9696                            else
9697                             if (pagination) {
9698                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9699                            }
9700    
9701                            String sql = query.toString();
9702    
9703                            Session session = null;
9704    
9705                            try {
9706                                    session = openSession();
9707    
9708                                    Query q = session.createQuery(sql);
9709    
9710                                    QueryPos qPos = QueryPos.getInstance(q);
9711    
9712                                    qPos.add(threadId);
9713    
9714                                    qPos.add(answer);
9715    
9716                                    if (!pagination) {
9717                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9718                                                            start, end, false);
9719    
9720                                            Collections.sort(list);
9721    
9722                                            list = Collections.unmodifiableList(list);
9723                                    }
9724                                    else {
9725                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9726                                                            start, end);
9727                                    }
9728    
9729                                    cacheResult(list);
9730    
9731                                    finderCache.putResult(finderPath, finderArgs, list);
9732                            }
9733                            catch (Exception e) {
9734                                    finderCache.removeResult(finderPath, finderArgs);
9735    
9736                                    throw processException(e);
9737                            }
9738                            finally {
9739                                    closeSession(session);
9740                            }
9741                    }
9742    
9743                    return list;
9744            }
9745    
9746            /**
9747             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9748             *
9749             * @param threadId the thread ID
9750             * @param answer the answer
9751             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9752             * @return the first matching message-boards message
9753             * @throws NoSuchMessageException if a matching message-boards message could not be found
9754             */
9755            @Override
9756            public MBMessage findByT_A_First(long threadId, boolean answer,
9757                    OrderByComparator<MBMessage> orderByComparator)
9758                    throws NoSuchMessageException {
9759                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9760                                    orderByComparator);
9761    
9762                    if (mbMessage != null) {
9763                            return mbMessage;
9764                    }
9765    
9766                    StringBundler msg = new StringBundler(6);
9767    
9768                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9769    
9770                    msg.append("threadId=");
9771                    msg.append(threadId);
9772    
9773                    msg.append(", answer=");
9774                    msg.append(answer);
9775    
9776                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9777    
9778                    throw new NoSuchMessageException(msg.toString());
9779            }
9780    
9781            /**
9782             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9783             *
9784             * @param threadId the thread ID
9785             * @param answer the answer
9786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9787             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9788             */
9789            @Override
9790            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9791                    OrderByComparator<MBMessage> orderByComparator) {
9792                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9793                                    orderByComparator);
9794    
9795                    if (!list.isEmpty()) {
9796                            return list.get(0);
9797                    }
9798    
9799                    return null;
9800            }
9801    
9802            /**
9803             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9804             *
9805             * @param threadId the thread ID
9806             * @param answer the answer
9807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9808             * @return the last matching message-boards message
9809             * @throws NoSuchMessageException if a matching message-boards message could not be found
9810             */
9811            @Override
9812            public MBMessage findByT_A_Last(long threadId, boolean answer,
9813                    OrderByComparator<MBMessage> orderByComparator)
9814                    throws NoSuchMessageException {
9815                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9816                                    orderByComparator);
9817    
9818                    if (mbMessage != null) {
9819                            return mbMessage;
9820                    }
9821    
9822                    StringBundler msg = new StringBundler(6);
9823    
9824                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9825    
9826                    msg.append("threadId=");
9827                    msg.append(threadId);
9828    
9829                    msg.append(", answer=");
9830                    msg.append(answer);
9831    
9832                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9833    
9834                    throw new NoSuchMessageException(msg.toString());
9835            }
9836    
9837            /**
9838             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9839             *
9840             * @param threadId the thread ID
9841             * @param answer the answer
9842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9843             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9844             */
9845            @Override
9846            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9847                    OrderByComparator<MBMessage> orderByComparator) {
9848                    int count = countByT_A(threadId, answer);
9849    
9850                    if (count == 0) {
9851                            return null;
9852                    }
9853    
9854                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9855                                    orderByComparator);
9856    
9857                    if (!list.isEmpty()) {
9858                            return list.get(0);
9859                    }
9860    
9861                    return null;
9862            }
9863    
9864            /**
9865             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9866             *
9867             * @param messageId the primary key of the current message-boards message
9868             * @param threadId the thread ID
9869             * @param answer the answer
9870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9871             * @return the previous, current, and next message-boards message
9872             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9873             */
9874            @Override
9875            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9876                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9877                    throws NoSuchMessageException {
9878                    MBMessage mbMessage = findByPrimaryKey(messageId);
9879    
9880                    Session session = null;
9881    
9882                    try {
9883                            session = openSession();
9884    
9885                            MBMessage[] array = new MBMessageImpl[3];
9886    
9887                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9888                                            answer, orderByComparator, true);
9889    
9890                            array[1] = mbMessage;
9891    
9892                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9893                                            answer, orderByComparator, false);
9894    
9895                            return array;
9896                    }
9897                    catch (Exception e) {
9898                            throw processException(e);
9899                    }
9900                    finally {
9901                            closeSession(session);
9902                    }
9903            }
9904    
9905            protected MBMessage getByT_A_PrevAndNext(Session session,
9906                    MBMessage mbMessage, long threadId, boolean answer,
9907                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9908                    StringBundler query = null;
9909    
9910                    if (orderByComparator != null) {
9911                            query = new StringBundler(6 +
9912                                            (orderByComparator.getOrderByFields().length * 6));
9913                    }
9914                    else {
9915                            query = new StringBundler(3);
9916                    }
9917    
9918                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9919    
9920                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9921    
9922                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9923    
9924                    if (orderByComparator != null) {
9925                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9926    
9927                            if (orderByConditionFields.length > 0) {
9928                                    query.append(WHERE_AND);
9929                            }
9930    
9931                            for (int i = 0; i < orderByConditionFields.length; i++) {
9932                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9933                                    query.append(orderByConditionFields[i]);
9934    
9935                                    if ((i + 1) < orderByConditionFields.length) {
9936                                            if (orderByComparator.isAscending() ^ previous) {
9937                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9938                                            }
9939                                            else {
9940                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9941                                            }
9942                                    }
9943                                    else {
9944                                            if (orderByComparator.isAscending() ^ previous) {
9945                                                    query.append(WHERE_GREATER_THAN);
9946                                            }
9947                                            else {
9948                                                    query.append(WHERE_LESSER_THAN);
9949                                            }
9950                                    }
9951                            }
9952    
9953                            query.append(ORDER_BY_CLAUSE);
9954    
9955                            String[] orderByFields = orderByComparator.getOrderByFields();
9956    
9957                            for (int i = 0; i < orderByFields.length; i++) {
9958                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9959                                    query.append(orderByFields[i]);
9960    
9961                                    if ((i + 1) < orderByFields.length) {
9962                                            if (orderByComparator.isAscending() ^ previous) {
9963                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9964                                            }
9965                                            else {
9966                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9967                                            }
9968                                    }
9969                                    else {
9970                                            if (orderByComparator.isAscending() ^ previous) {
9971                                                    query.append(ORDER_BY_ASC);
9972                                            }
9973                                            else {
9974                                                    query.append(ORDER_BY_DESC);
9975                                            }
9976                                    }
9977                            }
9978                    }
9979                    else {
9980                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9981                    }
9982    
9983                    String sql = query.toString();
9984    
9985                    Query q = session.createQuery(sql);
9986    
9987                    q.setFirstResult(0);
9988                    q.setMaxResults(2);
9989    
9990                    QueryPos qPos = QueryPos.getInstance(q);
9991    
9992                    qPos.add(threadId);
9993    
9994                    qPos.add(answer);
9995    
9996                    if (orderByComparator != null) {
9997                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9998    
9999                            for (Object value : values) {
10000                                    qPos.add(value);
10001                            }
10002                    }
10003    
10004                    List<MBMessage> list = q.list();
10005    
10006                    if (list.size() == 2) {
10007                            return list.get(1);
10008                    }
10009                    else {
10010                            return null;
10011                    }
10012            }
10013    
10014            /**
10015             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
10016             *
10017             * @param threadId the thread ID
10018             * @param answer the answer
10019             */
10020            @Override
10021            public void removeByT_A(long threadId, boolean answer) {
10022                    for (MBMessage mbMessage : findByT_A(threadId, answer,
10023                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10024                            remove(mbMessage);
10025                    }
10026            }
10027    
10028            /**
10029             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
10030             *
10031             * @param threadId the thread ID
10032             * @param answer the answer
10033             * @return the number of matching message-boards messages
10034             */
10035            @Override
10036            public int countByT_A(long threadId, boolean answer) {
10037                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
10038    
10039                    Object[] finderArgs = new Object[] { threadId, answer };
10040    
10041                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10042    
10043                    if (count == null) {
10044                            StringBundler query = new StringBundler(3);
10045    
10046                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10047    
10048                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
10049    
10050                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
10051    
10052                            String sql = query.toString();
10053    
10054                            Session session = null;
10055    
10056                            try {
10057                                    session = openSession();
10058    
10059                                    Query q = session.createQuery(sql);
10060    
10061                                    QueryPos qPos = QueryPos.getInstance(q);
10062    
10063                                    qPos.add(threadId);
10064    
10065                                    qPos.add(answer);
10066    
10067                                    count = (Long)q.uniqueResult();
10068    
10069                                    finderCache.putResult(finderPath, finderArgs, count);
10070                            }
10071                            catch (Exception e) {
10072                                    finderCache.removeResult(finderPath, finderArgs);
10073    
10074                                    throw processException(e);
10075                            }
10076                            finally {
10077                                    closeSession(session);
10078                            }
10079                    }
10080    
10081                    return count.intValue();
10082            }
10083    
10084            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
10085            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
10086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10087                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
10089                            new String[] {
10090                                    Long.class.getName(), Integer.class.getName(),
10091                                    
10092                            Integer.class.getName(), Integer.class.getName(),
10093                                    OrderByComparator.class.getName()
10094                            });
10095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
10098                            new String[] { Long.class.getName(), Integer.class.getName() },
10099                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10100                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10101                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10102            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10103                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
10105                            new String[] { Long.class.getName(), Integer.class.getName() });
10106    
10107            /**
10108             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10109             *
10110             * @param threadId the thread ID
10111             * @param status the status
10112             * @return the matching message-boards messages
10113             */
10114            @Override
10115            public List<MBMessage> findByT_S(long threadId, int status) {
10116                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
10117                            QueryUtil.ALL_POS, null);
10118            }
10119    
10120            /**
10121             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10122             *
10123             * <p>
10124             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10125             * </p>
10126             *
10127             * @param threadId the thread ID
10128             * @param status the status
10129             * @param start the lower bound of the range of message-boards messages
10130             * @param end the upper bound of the range of message-boards messages (not inclusive)
10131             * @return the range of matching message-boards messages
10132             */
10133            @Override
10134            public List<MBMessage> findByT_S(long threadId, int status, int start,
10135                    int end) {
10136                    return findByT_S(threadId, status, start, end, null);
10137            }
10138    
10139            /**
10140             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10141             *
10142             * <p>
10143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10144             * </p>
10145             *
10146             * @param threadId the thread ID
10147             * @param status the status
10148             * @param start the lower bound of the range of message-boards messages
10149             * @param end the upper bound of the range of message-boards messages (not inclusive)
10150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10151             * @return the ordered range of matching message-boards messages
10152             */
10153            @Override
10154            public List<MBMessage> findByT_S(long threadId, int status, int start,
10155                    int end, OrderByComparator<MBMessage> orderByComparator) {
10156                    return findByT_S(threadId, status, start, end, orderByComparator, true);
10157            }
10158    
10159            /**
10160             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10161             *
10162             * <p>
10163             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10164             * </p>
10165             *
10166             * @param threadId the thread ID
10167             * @param status the status
10168             * @param start the lower bound of the range of message-boards messages
10169             * @param end the upper bound of the range of message-boards messages (not inclusive)
10170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10171             * @param retrieveFromCache whether to retrieve from the finder cache
10172             * @return the ordered range of matching message-boards messages
10173             */
10174            @Override
10175            public List<MBMessage> findByT_S(long threadId, int status, int start,
10176                    int end, OrderByComparator<MBMessage> orderByComparator,
10177                    boolean retrieveFromCache) {
10178                    boolean pagination = true;
10179                    FinderPath finderPath = null;
10180                    Object[] finderArgs = null;
10181    
10182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10183                                    (orderByComparator == null)) {
10184                            pagination = false;
10185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10186                            finderArgs = new Object[] { threadId, status };
10187                    }
10188                    else {
10189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10190                            finderArgs = new Object[] {
10191                                            threadId, status,
10192                                            
10193                                            start, end, orderByComparator
10194                                    };
10195                    }
10196    
10197                    List<MBMessage> list = null;
10198    
10199                    if (retrieveFromCache) {
10200                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10201                                            finderArgs, this);
10202    
10203                            if ((list != null) && !list.isEmpty()) {
10204                                    for (MBMessage mbMessage : list) {
10205                                            if ((threadId != mbMessage.getThreadId()) ||
10206                                                            (status != mbMessage.getStatus())) {
10207                                                    list = null;
10208    
10209                                                    break;
10210                                            }
10211                                    }
10212                            }
10213                    }
10214    
10215                    if (list == null) {
10216                            StringBundler query = null;
10217    
10218                            if (orderByComparator != null) {
10219                                    query = new StringBundler(4 +
10220                                                    (orderByComparator.getOrderByFields().length * 3));
10221                            }
10222                            else {
10223                                    query = new StringBundler(4);
10224                            }
10225    
10226                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10227    
10228                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10229    
10230                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10231    
10232                            if (orderByComparator != null) {
10233                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10234                                            orderByComparator);
10235                            }
10236                            else
10237                             if (pagination) {
10238                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10239                            }
10240    
10241                            String sql = query.toString();
10242    
10243                            Session session = null;
10244    
10245                            try {
10246                                    session = openSession();
10247    
10248                                    Query q = session.createQuery(sql);
10249    
10250                                    QueryPos qPos = QueryPos.getInstance(q);
10251    
10252                                    qPos.add(threadId);
10253    
10254                                    qPos.add(status);
10255    
10256                                    if (!pagination) {
10257                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10258                                                            start, end, false);
10259    
10260                                            Collections.sort(list);
10261    
10262                                            list = Collections.unmodifiableList(list);
10263                                    }
10264                                    else {
10265                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10266                                                            start, end);
10267                                    }
10268    
10269                                    cacheResult(list);
10270    
10271                                    finderCache.putResult(finderPath, finderArgs, list);
10272                            }
10273                            catch (Exception e) {
10274                                    finderCache.removeResult(finderPath, finderArgs);
10275    
10276                                    throw processException(e);
10277                            }
10278                            finally {
10279                                    closeSession(session);
10280                            }
10281                    }
10282    
10283                    return list;
10284            }
10285    
10286            /**
10287             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10288             *
10289             * @param threadId the thread ID
10290             * @param status the status
10291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10292             * @return the first matching message-boards message
10293             * @throws NoSuchMessageException if a matching message-boards message could not be found
10294             */
10295            @Override
10296            public MBMessage findByT_S_First(long threadId, int status,
10297                    OrderByComparator<MBMessage> orderByComparator)
10298                    throws NoSuchMessageException {
10299                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10300                                    orderByComparator);
10301    
10302                    if (mbMessage != null) {
10303                            return mbMessage;
10304                    }
10305    
10306                    StringBundler msg = new StringBundler(6);
10307    
10308                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10309    
10310                    msg.append("threadId=");
10311                    msg.append(threadId);
10312    
10313                    msg.append(", status=");
10314                    msg.append(status);
10315    
10316                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10317    
10318                    throw new NoSuchMessageException(msg.toString());
10319            }
10320    
10321            /**
10322             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10323             *
10324             * @param threadId the thread ID
10325             * @param status the status
10326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10327             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10328             */
10329            @Override
10330            public MBMessage fetchByT_S_First(long threadId, int status,
10331                    OrderByComparator<MBMessage> orderByComparator) {
10332                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10333                                    orderByComparator);
10334    
10335                    if (!list.isEmpty()) {
10336                            return list.get(0);
10337                    }
10338    
10339                    return null;
10340            }
10341    
10342            /**
10343             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10344             *
10345             * @param threadId the thread ID
10346             * @param status the status
10347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10348             * @return the last matching message-boards message
10349             * @throws NoSuchMessageException if a matching message-boards message could not be found
10350             */
10351            @Override
10352            public MBMessage findByT_S_Last(long threadId, int status,
10353                    OrderByComparator<MBMessage> orderByComparator)
10354                    throws NoSuchMessageException {
10355                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10356                                    orderByComparator);
10357    
10358                    if (mbMessage != null) {
10359                            return mbMessage;
10360                    }
10361    
10362                    StringBundler msg = new StringBundler(6);
10363    
10364                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10365    
10366                    msg.append("threadId=");
10367                    msg.append(threadId);
10368    
10369                    msg.append(", status=");
10370                    msg.append(status);
10371    
10372                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10373    
10374                    throw new NoSuchMessageException(msg.toString());
10375            }
10376    
10377            /**
10378             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10379             *
10380             * @param threadId the thread ID
10381             * @param status the status
10382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10383             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10384             */
10385            @Override
10386            public MBMessage fetchByT_S_Last(long threadId, int status,
10387                    OrderByComparator<MBMessage> orderByComparator) {
10388                    int count = countByT_S(threadId, status);
10389    
10390                    if (count == 0) {
10391                            return null;
10392                    }
10393    
10394                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10395                                    orderByComparator);
10396    
10397                    if (!list.isEmpty()) {
10398                            return list.get(0);
10399                    }
10400    
10401                    return null;
10402            }
10403    
10404            /**
10405             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10406             *
10407             * @param messageId the primary key of the current message-boards message
10408             * @param threadId the thread ID
10409             * @param status the status
10410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10411             * @return the previous, current, and next message-boards message
10412             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10413             */
10414            @Override
10415            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10416                    int status, OrderByComparator<MBMessage> orderByComparator)
10417                    throws NoSuchMessageException {
10418                    MBMessage mbMessage = findByPrimaryKey(messageId);
10419    
10420                    Session session = null;
10421    
10422                    try {
10423                            session = openSession();
10424    
10425                            MBMessage[] array = new MBMessageImpl[3];
10426    
10427                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10428                                            status, orderByComparator, true);
10429    
10430                            array[1] = mbMessage;
10431    
10432                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10433                                            status, orderByComparator, false);
10434    
10435                            return array;
10436                    }
10437                    catch (Exception e) {
10438                            throw processException(e);
10439                    }
10440                    finally {
10441                            closeSession(session);
10442                    }
10443            }
10444    
10445            protected MBMessage getByT_S_PrevAndNext(Session session,
10446                    MBMessage mbMessage, long threadId, int status,
10447                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10448                    StringBundler query = null;
10449    
10450                    if (orderByComparator != null) {
10451                            query = new StringBundler(6 +
10452                                            (orderByComparator.getOrderByFields().length * 6));
10453                    }
10454                    else {
10455                            query = new StringBundler(3);
10456                    }
10457    
10458                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10459    
10460                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10461    
10462                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10463    
10464                    if (orderByComparator != null) {
10465                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10466    
10467                            if (orderByConditionFields.length > 0) {
10468                                    query.append(WHERE_AND);
10469                            }
10470    
10471                            for (int i = 0; i < orderByConditionFields.length; i++) {
10472                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10473                                    query.append(orderByConditionFields[i]);
10474    
10475                                    if ((i + 1) < orderByConditionFields.length) {
10476                                            if (orderByComparator.isAscending() ^ previous) {
10477                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10478                                            }
10479                                            else {
10480                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10481                                            }
10482                                    }
10483                                    else {
10484                                            if (orderByComparator.isAscending() ^ previous) {
10485                                                    query.append(WHERE_GREATER_THAN);
10486                                            }
10487                                            else {
10488                                                    query.append(WHERE_LESSER_THAN);
10489                                            }
10490                                    }
10491                            }
10492    
10493                            query.append(ORDER_BY_CLAUSE);
10494    
10495                            String[] orderByFields = orderByComparator.getOrderByFields();
10496    
10497                            for (int i = 0; i < orderByFields.length; i++) {
10498                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10499                                    query.append(orderByFields[i]);
10500    
10501                                    if ((i + 1) < orderByFields.length) {
10502                                            if (orderByComparator.isAscending() ^ previous) {
10503                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10504                                            }
10505                                            else {
10506                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10507                                            }
10508                                    }
10509                                    else {
10510                                            if (orderByComparator.isAscending() ^ previous) {
10511                                                    query.append(ORDER_BY_ASC);
10512                                            }
10513                                            else {
10514                                                    query.append(ORDER_BY_DESC);
10515                                            }
10516                                    }
10517                            }
10518                    }
10519                    else {
10520                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10521                    }
10522    
10523                    String sql = query.toString();
10524    
10525                    Query q = session.createQuery(sql);
10526    
10527                    q.setFirstResult(0);
10528                    q.setMaxResults(2);
10529    
10530                    QueryPos qPos = QueryPos.getInstance(q);
10531    
10532                    qPos.add(threadId);
10533    
10534                    qPos.add(status);
10535    
10536                    if (orderByComparator != null) {
10537                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10538    
10539                            for (Object value : values) {
10540                                    qPos.add(value);
10541                            }
10542                    }
10543    
10544                    List<MBMessage> list = q.list();
10545    
10546                    if (list.size() == 2) {
10547                            return list.get(1);
10548                    }
10549                    else {
10550                            return null;
10551                    }
10552            }
10553    
10554            /**
10555             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10556             *
10557             * @param threadId the thread ID
10558             * @param status the status
10559             */
10560            @Override
10561            public void removeByT_S(long threadId, int status) {
10562                    for (MBMessage mbMessage : findByT_S(threadId, status,
10563                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10564                            remove(mbMessage);
10565                    }
10566            }
10567    
10568            /**
10569             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10570             *
10571             * @param threadId the thread ID
10572             * @param status the status
10573             * @return the number of matching message-boards messages
10574             */
10575            @Override
10576            public int countByT_S(long threadId, int status) {
10577                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10578    
10579                    Object[] finderArgs = new Object[] { threadId, status };
10580    
10581                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10582    
10583                    if (count == null) {
10584                            StringBundler query = new StringBundler(3);
10585    
10586                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10587    
10588                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10589    
10590                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10591    
10592                            String sql = query.toString();
10593    
10594                            Session session = null;
10595    
10596                            try {
10597                                    session = openSession();
10598    
10599                                    Query q = session.createQuery(sql);
10600    
10601                                    QueryPos qPos = QueryPos.getInstance(q);
10602    
10603                                    qPos.add(threadId);
10604    
10605                                    qPos.add(status);
10606    
10607                                    count = (Long)q.uniqueResult();
10608    
10609                                    finderCache.putResult(finderPath, finderArgs, count);
10610                            }
10611                            catch (Exception e) {
10612                                    finderCache.removeResult(finderPath, finderArgs);
10613    
10614                                    throw processException(e);
10615                            }
10616                            finally {
10617                                    closeSession(session);
10618                            }
10619                    }
10620    
10621                    return count.intValue();
10622            }
10623    
10624            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10625            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10626            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10627                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10628                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10629                            new String[] {
10630                                    Long.class.getName(), Integer.class.getName(),
10631                                    
10632                            Integer.class.getName(), Integer.class.getName(),
10633                                    OrderByComparator.class.getName()
10634                            });
10635            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10636                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10637                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10638                            new String[] { Long.class.getName(), Integer.class.getName() },
10639                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10640                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10641                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10642            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10643                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10644                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10645                            new String[] { Long.class.getName(), Integer.class.getName() });
10646    
10647            /**
10648             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10649             *
10650             * @param threadId the thread ID
10651             * @param status the status
10652             * @return the matching message-boards messages
10653             */
10654            @Override
10655            public List<MBMessage> findByTR_S(long threadId, int status) {
10656                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10657                            QueryUtil.ALL_POS, null);
10658            }
10659    
10660            /**
10661             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10662             *
10663             * <p>
10664             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10665             * </p>
10666             *
10667             * @param threadId the thread ID
10668             * @param status the status
10669             * @param start the lower bound of the range of message-boards messages
10670             * @param end the upper bound of the range of message-boards messages (not inclusive)
10671             * @return the range of matching message-boards messages
10672             */
10673            @Override
10674            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10675                    int end) {
10676                    return findByTR_S(threadId, status, start, end, null);
10677            }
10678    
10679            /**
10680             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10681             *
10682             * <p>
10683             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10684             * </p>
10685             *
10686             * @param threadId the thread ID
10687             * @param status the status
10688             * @param start the lower bound of the range of message-boards messages
10689             * @param end the upper bound of the range of message-boards messages (not inclusive)
10690             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10691             * @return the ordered range of matching message-boards messages
10692             */
10693            @Override
10694            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10695                    int end, OrderByComparator<MBMessage> orderByComparator) {
10696                    return findByTR_S(threadId, status, start, end, orderByComparator, true);
10697            }
10698    
10699            /**
10700             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10701             *
10702             * <p>
10703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
10704             * </p>
10705             *
10706             * @param threadId the thread ID
10707             * @param status the status
10708             * @param start the lower bound of the range of message-boards messages
10709             * @param end the upper bound of the range of message-boards messages (not inclusive)
10710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10711             * @param retrieveFromCache whether to retrieve from the finder cache
10712             * @return the ordered range of matching message-boards messages
10713             */
10714            @Override
10715            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10716                    int end, OrderByComparator<MBMessage> orderByComparator,
10717                    boolean retrieveFromCache) {
10718                    boolean pagination = true;
10719                    FinderPath finderPath = null;
10720                    Object[] finderArgs = null;
10721    
10722                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10723                                    (orderByComparator == null)) {
10724                            pagination = false;
10725                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10726                            finderArgs = new Object[] { threadId, status };
10727                    }
10728                    else {
10729                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10730                            finderArgs = new Object[] {
10731                                            threadId, status,
10732                                            
10733                                            start, end, orderByComparator
10734                                    };
10735                    }
10736    
10737                    List<MBMessage> list = null;
10738    
10739                    if (retrieveFromCache) {
10740                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10741                                            finderArgs, this);
10742    
10743                            if ((list != null) && !list.isEmpty()) {
10744                                    for (MBMessage mbMessage : list) {
10745                                            if ((threadId != mbMessage.getThreadId()) ||
10746                                                            (status != mbMessage.getStatus())) {
10747                                                    list = null;
10748    
10749                                                    break;
10750                                            }
10751                                    }
10752                            }
10753                    }
10754    
10755                    if (list == null) {
10756                            StringBundler query = null;
10757    
10758                            if (orderByComparator != null) {
10759                                    query = new StringBundler(4 +
10760                                                    (orderByComparator.getOrderByFields().length * 3));
10761                            }
10762                            else {
10763                                    query = new StringBundler(4);
10764                            }
10765    
10766                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10767    
10768                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10769    
10770                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10771    
10772                            if (orderByComparator != null) {
10773                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10774                                            orderByComparator);
10775                            }
10776                            else
10777                             if (pagination) {
10778                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10779                            }
10780    
10781                            String sql = query.toString();
10782    
10783                            Session session = null;
10784    
10785                            try {
10786                                    session = openSession();
10787    
10788                                    Query q = session.createQuery(sql);
10789    
10790                                    QueryPos qPos = QueryPos.getInstance(q);
10791    
10792                                    qPos.add(threadId);
10793    
10794                                    qPos.add(status);
10795    
10796                                    if (!pagination) {
10797                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10798                                                            start, end, false);
10799    
10800                                            Collections.sort(list);
10801    
10802                                            list = Collections.unmodifiableList(list);
10803                                    }
10804                                    else {
10805                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10806                                                            start, end);
10807                                    }
10808    
10809                                    cacheResult(list);
10810    
10811                                    finderCache.putResult(finderPath, finderArgs, list);
10812                            }
10813                            catch (Exception e) {
10814                                    finderCache.removeResult(finderPath, finderArgs);
10815    
10816                                    throw processException(e);
10817                            }
10818                            finally {
10819                                    closeSession(session);
10820                            }
10821                    }
10822    
10823                    return list;
10824            }
10825    
10826            /**
10827             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10828             *
10829             * @param threadId the thread ID
10830             * @param status the status
10831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10832             * @return the first matching message-boards message
10833             * @throws NoSuchMessageException if a matching message-boards message could not be found
10834             */
10835            @Override
10836            public MBMessage findByTR_S_First(long threadId, int status,
10837                    OrderByComparator<MBMessage> orderByComparator)
10838                    throws NoSuchMessageException {
10839                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10840                                    orderByComparator);
10841    
10842                    if (mbMessage != null) {
10843                            return mbMessage;
10844                    }
10845    
10846                    StringBundler msg = new StringBundler(6);
10847    
10848                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10849    
10850                    msg.append("threadId=");
10851                    msg.append(threadId);
10852    
10853                    msg.append(", status=");
10854                    msg.append(status);
10855    
10856                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10857    
10858                    throw new NoSuchMessageException(msg.toString());
10859            }
10860    
10861            /**
10862             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10863             *
10864             * @param threadId the thread ID
10865             * @param status the status
10866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10867             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10868             */
10869            @Override
10870            public MBMessage fetchByTR_S_First(long threadId, int status,
10871                    OrderByComparator<MBMessage> orderByComparator) {
10872                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10873                                    orderByComparator);
10874    
10875                    if (!list.isEmpty()) {
10876                            return list.get(0);
10877                    }
10878    
10879                    return null;
10880            }
10881    
10882            /**
10883             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10884             *
10885             * @param threadId the thread ID
10886             * @param status the status
10887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10888             * @return the last matching message-boards message
10889             * @throws NoSuchMessageException if a matching message-boards message could not be found
10890             */
10891            @Override
10892            public MBMessage findByTR_S_Last(long threadId, int status,
10893                    OrderByComparator<MBMessage> orderByComparator)
10894                    throws NoSuchMessageException {
10895                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10896                                    orderByComparator);
10897    
10898                    if (mbMessage != null) {
10899                            return mbMessage;
10900                    }
10901    
10902                    StringBundler msg = new StringBundler(6);
10903    
10904                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10905    
10906                    msg.append("threadId=");
10907                    msg.append(threadId);
10908    
10909                    msg.append(", status=");
10910                    msg.append(status);
10911    
10912                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10913    
10914                    throw new NoSuchMessageException(msg.toString());
10915            }
10916    
10917            /**
10918             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10919             *
10920             * @param threadId the thread ID
10921             * @param status the status
10922             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10923             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10924             */
10925            @Override
10926            public MBMessage fetchByTR_S_Last(long threadId, int status,
10927                    OrderByComparator<MBMessage> orderByComparator) {
10928                    int count = countByTR_S(threadId, status);
10929    
10930                    if (count == 0) {
10931                            return null;
10932                    }
10933    
10934                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10935                                    orderByComparator);
10936    
10937                    if (!list.isEmpty()) {
10938                            return list.get(0);
10939                    }
10940    
10941                    return null;
10942            }
10943    
10944            /**
10945             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10946             *
10947             * @param messageId the primary key of the current message-boards message
10948             * @param threadId the thread ID
10949             * @param status the status
10950             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10951             * @return the previous, current, and next message-boards message
10952             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10953             */
10954            @Override
10955            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10956                    int status, OrderByComparator<MBMessage> orderByComparator)
10957                    throws NoSuchMessageException {
10958                    MBMessage mbMessage = findByPrimaryKey(messageId);
10959    
10960                    Session session = null;
10961    
10962                    try {
10963                            session = openSession();
10964    
10965                            MBMessage[] array = new MBMessageImpl[3];
10966    
10967                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10968                                            status, orderByComparator, true);
10969    
10970                            array[1] = mbMessage;
10971    
10972                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10973                                            status, orderByComparator, false);
10974    
10975                            return array;
10976                    }
10977                    catch (Exception e) {
10978                            throw processException(e);
10979                    }
10980                    finally {
10981                            closeSession(session);
10982                    }
10983            }
10984    
10985            protected MBMessage getByTR_S_PrevAndNext(Session session,
10986                    MBMessage mbMessage, long threadId, int status,
10987                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10988                    StringBundler query = null;
10989    
10990                    if (orderByComparator != null) {
10991                            query = new StringBundler(6 +
10992                                            (orderByComparator.getOrderByFields().length * 6));
10993                    }
10994                    else {
10995                            query = new StringBundler(3);
10996                    }
10997    
10998                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10999    
11000                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11001    
11002                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11003    
11004                    if (orderByComparator != null) {
11005                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11006    
11007                            if (orderByConditionFields.length > 0) {
11008                                    query.append(WHERE_AND);
11009                            }
11010    
11011                            for (int i = 0; i < orderByConditionFields.length; i++) {
11012                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11013                                    query.append(orderByConditionFields[i]);
11014    
11015                                    if ((i + 1) < orderByConditionFields.length) {
11016                                            if (orderByComparator.isAscending() ^ previous) {
11017                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11018                                            }
11019                                            else {
11020                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11021                                            }
11022                                    }
11023                                    else {
11024                                            if (orderByComparator.isAscending() ^ previous) {
11025                                                    query.append(WHERE_GREATER_THAN);
11026                                            }
11027                                            else {
11028                                                    query.append(WHERE_LESSER_THAN);
11029                                            }
11030                                    }
11031                            }
11032    
11033                            query.append(ORDER_BY_CLAUSE);
11034    
11035                            String[] orderByFields = orderByComparator.getOrderByFields();
11036    
11037                            for (int i = 0; i < orderByFields.length; i++) {
11038                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11039                                    query.append(orderByFields[i]);
11040    
11041                                    if ((i + 1) < orderByFields.length) {
11042                                            if (orderByComparator.isAscending() ^ previous) {
11043                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11044                                            }
11045                                            else {
11046                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11047                                            }
11048                                    }
11049                                    else {
11050                                            if (orderByComparator.isAscending() ^ previous) {
11051                                                    query.append(ORDER_BY_ASC);
11052                                            }
11053                                            else {
11054                                                    query.append(ORDER_BY_DESC);
11055                                            }
11056                                    }
11057                            }
11058                    }
11059                    else {
11060                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11061                    }
11062    
11063                    String sql = query.toString();
11064    
11065                    Query q = session.createQuery(sql);
11066    
11067                    q.setFirstResult(0);
11068                    q.setMaxResults(2);
11069    
11070                    QueryPos qPos = QueryPos.getInstance(q);
11071    
11072                    qPos.add(threadId);
11073    
11074                    qPos.add(status);
11075    
11076                    if (orderByComparator != null) {
11077                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11078    
11079                            for (Object value : values) {
11080                                    qPos.add(value);
11081                            }
11082                    }
11083    
11084                    List<MBMessage> list = q.list();
11085    
11086                    if (list.size() == 2) {
11087                            return list.get(1);
11088                    }
11089                    else {
11090                            return null;
11091                    }
11092            }
11093    
11094            /**
11095             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
11096             *
11097             * @param threadId the thread ID
11098             * @param status the status
11099             */
11100            @Override
11101            public void removeByTR_S(long threadId, int status) {
11102                    for (MBMessage mbMessage : findByTR_S(threadId, status,
11103                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11104                            remove(mbMessage);
11105                    }
11106            }
11107    
11108            /**
11109             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
11110             *
11111             * @param threadId the thread ID
11112             * @param status the status
11113             * @return the number of matching message-boards messages
11114             */
11115            @Override
11116            public int countByTR_S(long threadId, int status) {
11117                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
11118    
11119                    Object[] finderArgs = new Object[] { threadId, status };
11120    
11121                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
11122    
11123                    if (count == null) {
11124                            StringBundler query = new StringBundler(3);
11125    
11126                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11127    
11128                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11129    
11130                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11131    
11132                            String sql = query.toString();
11133    
11134                            Session session = null;
11135    
11136                            try {
11137                                    session = openSession();
11138    
11139                                    Query q = session.createQuery(sql);
11140    
11141                                    QueryPos qPos = QueryPos.getInstance(q);
11142    
11143                                    qPos.add(threadId);
11144    
11145                                    qPos.add(status);
11146    
11147                                    count = (Long)q.uniqueResult();
11148    
11149                                    finderCache.putResult(finderPath, finderArgs, count);
11150                            }
11151                            catch (Exception e) {
11152                                    finderCache.removeResult(finderPath, finderArgs);
11153    
11154                                    throw processException(e);
11155                            }
11156                            finally {
11157                                    closeSession(session);
11158                            }
11159                    }
11160    
11161                    return count.intValue();
11162            }
11163    
11164            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11165            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11166            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11167                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11168                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
11169                            new String[] {
11170                                    Long.class.getName(), Long.class.getName(),
11171                                    Integer.class.getName(),
11172                                    
11173                            Integer.class.getName(), Integer.class.getName(),
11174                                    OrderByComparator.class.getName()
11175                            });
11176            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11177                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11178                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
11179                            new String[] {
11180                                    Long.class.getName(), Long.class.getName(),
11181                                    Integer.class.getName()
11182                            },
11183                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11184                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
11185                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
11186                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11187            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11188                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11189                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
11190                            new String[] {
11191                                    Long.class.getName(), Long.class.getName(),
11192                                    Integer.class.getName()
11193                            });
11194    
11195            /**
11196             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11197             *
11198             * @param groupId the group ID
11199             * @param userId the user ID
11200             * @param status the status
11201             * @return the matching message-boards messages
11202             */
11203            @Override
11204            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
11205                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11206                            QueryUtil.ALL_POS, null);
11207            }
11208    
11209            /**
11210             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11211             *
11212             * <p>
11213             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11214             * </p>
11215             *
11216             * @param groupId the group ID
11217             * @param userId the user ID
11218             * @param status the status
11219             * @param start the lower bound of the range of message-boards messages
11220             * @param end the upper bound of the range of message-boards messages (not inclusive)
11221             * @return the range of matching message-boards messages
11222             */
11223            @Override
11224            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11225                    int start, int end) {
11226                    return findByG_U_S(groupId, userId, status, start, end, null);
11227            }
11228    
11229            /**
11230             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11231             *
11232             * <p>
11233             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11234             * </p>
11235             *
11236             * @param groupId the group ID
11237             * @param userId the user ID
11238             * @param status the status
11239             * @param start the lower bound of the range of message-boards messages
11240             * @param end the upper bound of the range of message-boards messages (not inclusive)
11241             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11242             * @return the ordered range of matching message-boards messages
11243             */
11244            @Override
11245            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11246                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
11247                    return findByG_U_S(groupId, userId, status, start, end,
11248                            orderByComparator, true);
11249            }
11250    
11251            /**
11252             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11253             *
11254             * <p>
11255             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11256             * </p>
11257             *
11258             * @param groupId the group ID
11259             * @param userId the user ID
11260             * @param status the status
11261             * @param start the lower bound of the range of message-boards messages
11262             * @param end the upper bound of the range of message-boards messages (not inclusive)
11263             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11264             * @param retrieveFromCache whether to retrieve from the finder cache
11265             * @return the ordered range of matching message-boards messages
11266             */
11267            @Override
11268            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11269                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
11270                    boolean retrieveFromCache) {
11271                    boolean pagination = true;
11272                    FinderPath finderPath = null;
11273                    Object[] finderArgs = null;
11274    
11275                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11276                                    (orderByComparator == null)) {
11277                            pagination = false;
11278                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11279                            finderArgs = new Object[] { groupId, userId, status };
11280                    }
11281                    else {
11282                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11283                            finderArgs = new Object[] {
11284                                            groupId, userId, status,
11285                                            
11286                                            start, end, orderByComparator
11287                                    };
11288                    }
11289    
11290                    List<MBMessage> list = null;
11291    
11292                    if (retrieveFromCache) {
11293                            list = (List<MBMessage>)finderCache.getResult(finderPath,
11294                                            finderArgs, this);
11295    
11296                            if ((list != null) && !list.isEmpty()) {
11297                                    for (MBMessage mbMessage : list) {
11298                                            if ((groupId != mbMessage.getGroupId()) ||
11299                                                            (userId != mbMessage.getUserId()) ||
11300                                                            (status != mbMessage.getStatus())) {
11301                                                    list = null;
11302    
11303                                                    break;
11304                                            }
11305                                    }
11306                            }
11307                    }
11308    
11309                    if (list == null) {
11310                            StringBundler query = null;
11311    
11312                            if (orderByComparator != null) {
11313                                    query = new StringBundler(5 +
11314                                                    (orderByComparator.getOrderByFields().length * 3));
11315                            }
11316                            else {
11317                                    query = new StringBundler(5);
11318                            }
11319    
11320                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11321    
11322                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11323    
11324                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11325    
11326                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11327    
11328                            if (orderByComparator != null) {
11329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11330                                            orderByComparator);
11331                            }
11332                            else
11333                             if (pagination) {
11334                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11335                            }
11336    
11337                            String sql = query.toString();
11338    
11339                            Session session = null;
11340    
11341                            try {
11342                                    session = openSession();
11343    
11344                                    Query q = session.createQuery(sql);
11345    
11346                                    QueryPos qPos = QueryPos.getInstance(q);
11347    
11348                                    qPos.add(groupId);
11349    
11350                                    qPos.add(userId);
11351    
11352                                    qPos.add(status);
11353    
11354                                    if (!pagination) {
11355                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11356                                                            start, end, false);
11357    
11358                                            Collections.sort(list);
11359    
11360                                            list = Collections.unmodifiableList(list);
11361                                    }
11362                                    else {
11363                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11364                                                            start, end);
11365                                    }
11366    
11367                                    cacheResult(list);
11368    
11369                                    finderCache.putResult(finderPath, finderArgs, list);
11370                            }
11371                            catch (Exception e) {
11372                                    finderCache.removeResult(finderPath, finderArgs);
11373    
11374                                    throw processException(e);
11375                            }
11376                            finally {
11377                                    closeSession(session);
11378                            }
11379                    }
11380    
11381                    return list;
11382            }
11383    
11384            /**
11385             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11386             *
11387             * @param groupId the group ID
11388             * @param userId the user ID
11389             * @param status the status
11390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11391             * @return the first matching message-boards message
11392             * @throws NoSuchMessageException if a matching message-boards message could not be found
11393             */
11394            @Override
11395            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11396                    OrderByComparator<MBMessage> orderByComparator)
11397                    throws NoSuchMessageException {
11398                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11399                                    orderByComparator);
11400    
11401                    if (mbMessage != null) {
11402                            return mbMessage;
11403                    }
11404    
11405                    StringBundler msg = new StringBundler(8);
11406    
11407                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11408    
11409                    msg.append("groupId=");
11410                    msg.append(groupId);
11411    
11412                    msg.append(", userId=");
11413                    msg.append(userId);
11414    
11415                    msg.append(", status=");
11416                    msg.append(status);
11417    
11418                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11419    
11420                    throw new NoSuchMessageException(msg.toString());
11421            }
11422    
11423            /**
11424             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11425             *
11426             * @param groupId the group ID
11427             * @param userId the user ID
11428             * @param status the status
11429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11430             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11431             */
11432            @Override
11433            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11434                    OrderByComparator<MBMessage> orderByComparator) {
11435                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11436                                    orderByComparator);
11437    
11438                    if (!list.isEmpty()) {
11439                            return list.get(0);
11440                    }
11441    
11442                    return null;
11443            }
11444    
11445            /**
11446             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11447             *
11448             * @param groupId the group ID
11449             * @param userId the user ID
11450             * @param status the status
11451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11452             * @return the last matching message-boards message
11453             * @throws NoSuchMessageException if a matching message-boards message could not be found
11454             */
11455            @Override
11456            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11457                    OrderByComparator<MBMessage> orderByComparator)
11458                    throws NoSuchMessageException {
11459                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11460                                    orderByComparator);
11461    
11462                    if (mbMessage != null) {
11463                            return mbMessage;
11464                    }
11465    
11466                    StringBundler msg = new StringBundler(8);
11467    
11468                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11469    
11470                    msg.append("groupId=");
11471                    msg.append(groupId);
11472    
11473                    msg.append(", userId=");
11474                    msg.append(userId);
11475    
11476                    msg.append(", status=");
11477                    msg.append(status);
11478    
11479                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11480    
11481                    throw new NoSuchMessageException(msg.toString());
11482            }
11483    
11484            /**
11485             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11486             *
11487             * @param groupId the group ID
11488             * @param userId the user ID
11489             * @param status the status
11490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11491             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11492             */
11493            @Override
11494            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11495                    OrderByComparator<MBMessage> orderByComparator) {
11496                    int count = countByG_U_S(groupId, userId, status);
11497    
11498                    if (count == 0) {
11499                            return null;
11500                    }
11501    
11502                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11503                                    count, orderByComparator);
11504    
11505                    if (!list.isEmpty()) {
11506                            return list.get(0);
11507                    }
11508    
11509                    return null;
11510            }
11511    
11512            /**
11513             * 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;.
11514             *
11515             * @param messageId the primary key of the current message-boards message
11516             * @param groupId the group ID
11517             * @param userId the user ID
11518             * @param status the status
11519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11520             * @return the previous, current, and next message-boards message
11521             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11522             */
11523            @Override
11524            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11525                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11526                    throws NoSuchMessageException {
11527                    MBMessage mbMessage = findByPrimaryKey(messageId);
11528    
11529                    Session session = null;
11530    
11531                    try {
11532                            session = openSession();
11533    
11534                            MBMessage[] array = new MBMessageImpl[3];
11535    
11536                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11537                                            userId, status, orderByComparator, true);
11538    
11539                            array[1] = mbMessage;
11540    
11541                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11542                                            userId, status, orderByComparator, false);
11543    
11544                            return array;
11545                    }
11546                    catch (Exception e) {
11547                            throw processException(e);
11548                    }
11549                    finally {
11550                            closeSession(session);
11551                    }
11552            }
11553    
11554            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11555                    MBMessage mbMessage, long groupId, long userId, int status,
11556                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11557                    StringBundler query = null;
11558    
11559                    if (orderByComparator != null) {
11560                            query = new StringBundler(6 +
11561                                            (orderByComparator.getOrderByFields().length * 6));
11562                    }
11563                    else {
11564                            query = new StringBundler(3);
11565                    }
11566    
11567                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11568    
11569                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11570    
11571                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11572    
11573                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11574    
11575                    if (orderByComparator != null) {
11576                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11577    
11578                            if (orderByConditionFields.length > 0) {
11579                                    query.append(WHERE_AND);
11580                            }
11581    
11582                            for (int i = 0; i < orderByConditionFields.length; i++) {
11583                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11584                                    query.append(orderByConditionFields[i]);
11585    
11586                                    if ((i + 1) < orderByConditionFields.length) {
11587                                            if (orderByComparator.isAscending() ^ previous) {
11588                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11589                                            }
11590                                            else {
11591                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11592                                            }
11593                                    }
11594                                    else {
11595                                            if (orderByComparator.isAscending() ^ previous) {
11596                                                    query.append(WHERE_GREATER_THAN);
11597                                            }
11598                                            else {
11599                                                    query.append(WHERE_LESSER_THAN);
11600                                            }
11601                                    }
11602                            }
11603    
11604                            query.append(ORDER_BY_CLAUSE);
11605    
11606                            String[] orderByFields = orderByComparator.getOrderByFields();
11607    
11608                            for (int i = 0; i < orderByFields.length; i++) {
11609                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11610                                    query.append(orderByFields[i]);
11611    
11612                                    if ((i + 1) < orderByFields.length) {
11613                                            if (orderByComparator.isAscending() ^ previous) {
11614                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11615                                            }
11616                                            else {
11617                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11618                                            }
11619                                    }
11620                                    else {
11621                                            if (orderByComparator.isAscending() ^ previous) {
11622                                                    query.append(ORDER_BY_ASC);
11623                                            }
11624                                            else {
11625                                                    query.append(ORDER_BY_DESC);
11626                                            }
11627                                    }
11628                            }
11629                    }
11630                    else {
11631                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11632                    }
11633    
11634                    String sql = query.toString();
11635    
11636                    Query q = session.createQuery(sql);
11637    
11638                    q.setFirstResult(0);
11639                    q.setMaxResults(2);
11640    
11641                    QueryPos qPos = QueryPos.getInstance(q);
11642    
11643                    qPos.add(groupId);
11644    
11645                    qPos.add(userId);
11646    
11647                    qPos.add(status);
11648    
11649                    if (orderByComparator != null) {
11650                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11651    
11652                            for (Object value : values) {
11653                                    qPos.add(value);
11654                            }
11655                    }
11656    
11657                    List<MBMessage> list = q.list();
11658    
11659                    if (list.size() == 2) {
11660                            return list.get(1);
11661                    }
11662                    else {
11663                            return null;
11664                    }
11665            }
11666    
11667            /**
11668             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11669             *
11670             * @param groupId the group ID
11671             * @param userId the user ID
11672             * @param status the status
11673             * @return the matching message-boards messages that the user has permission to view
11674             */
11675            @Override
11676            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11677                    int status) {
11678                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11679                            QueryUtil.ALL_POS, null);
11680            }
11681    
11682            /**
11683             * 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;.
11684             *
11685             * <p>
11686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11687             * </p>
11688             *
11689             * @param groupId the group ID
11690             * @param userId the user ID
11691             * @param status the status
11692             * @param start the lower bound of the range of message-boards messages
11693             * @param end the upper bound of the range of message-boards messages (not inclusive)
11694             * @return the range of matching message-boards messages that the user has permission to view
11695             */
11696            @Override
11697            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11698                    int status, int start, int end) {
11699                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11700            }
11701    
11702            /**
11703             * 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;.
11704             *
11705             * <p>
11706             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
11707             * </p>
11708             *
11709             * @param groupId the group ID
11710             * @param userId the user ID
11711             * @param status the status
11712             * @param start the lower bound of the range of message-boards messages
11713             * @param end the upper bound of the range of message-boards messages (not inclusive)
11714             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11715             * @return the ordered range of matching message-boards messages that the user has permission to view
11716             */
11717            @Override
11718            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11719                    int status, int start, int end,
11720                    OrderByComparator<MBMessage> orderByComparator) {
11721                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11722                            return findByG_U_S(groupId, userId, status, start, end,
11723                                    orderByComparator);
11724                    }
11725    
11726                    StringBundler query = null;
11727    
11728                    if (orderByComparator != null) {
11729                            query = new StringBundler(5 +
11730                                            (orderByComparator.getOrderByFields().length * 3));
11731                    }
11732                    else {
11733                            query = new StringBundler(5);
11734                    }
11735    
11736                    if (getDB().isSupportsInlineDistinct()) {
11737                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11738                    }
11739                    else {
11740                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11741                    }
11742    
11743                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11744    
11745                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11746    
11747                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11748    
11749                    if (!getDB().isSupportsInlineDistinct()) {
11750                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11751                    }
11752    
11753                    if (orderByComparator != null) {
11754                            if (getDB().isSupportsInlineDistinct()) {
11755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11756                                            orderByComparator, true);
11757                            }
11758                            else {
11759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11760                                            orderByComparator, true);
11761                            }
11762                    }
11763                    else {
11764                            if (getDB().isSupportsInlineDistinct()) {
11765                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11766                            }
11767                            else {
11768                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11769                            }
11770                    }
11771    
11772                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11773                                    MBMessage.class.getName(),
11774                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11775    
11776                    Session session = null;
11777    
11778                    try {
11779                            session = openSession();
11780    
11781                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11782    
11783                            if (getDB().isSupportsInlineDistinct()) {
11784                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11785                            }
11786                            else {
11787                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11788                            }
11789    
11790                            QueryPos qPos = QueryPos.getInstance(q);
11791    
11792                            qPos.add(groupId);
11793    
11794                            qPos.add(userId);
11795    
11796                            qPos.add(status);
11797    
11798                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11799                    }
11800                    catch (Exception e) {
11801                            throw processException(e);
11802                    }
11803                    finally {
11804                            closeSession(session);
11805                    }
11806            }
11807    
11808            /**
11809             * 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;.
11810             *
11811             * @param messageId the primary key of the current message-boards message
11812             * @param groupId the group ID
11813             * @param userId the user ID
11814             * @param status the status
11815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11816             * @return the previous, current, and next message-boards message
11817             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11818             */
11819            @Override
11820            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11821                    long groupId, long userId, int status,
11822                    OrderByComparator<MBMessage> orderByComparator)
11823                    throws NoSuchMessageException {
11824                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11825                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11826                                    orderByComparator);
11827                    }
11828    
11829                    MBMessage mbMessage = findByPrimaryKey(messageId);
11830    
11831                    Session session = null;
11832    
11833                    try {
11834                            session = openSession();
11835    
11836                            MBMessage[] array = new MBMessageImpl[3];
11837    
11838                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11839                                            groupId, userId, status, orderByComparator, true);
11840    
11841                            array[1] = mbMessage;
11842    
11843                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11844                                            groupId, userId, status, orderByComparator, false);
11845    
11846                            return array;
11847                    }
11848                    catch (Exception e) {
11849                            throw processException(e);
11850                    }
11851                    finally {
11852                            closeSession(session);
11853                    }
11854            }
11855    
11856            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11857                    MBMessage mbMessage, long groupId, long userId, int status,
11858                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11859                    StringBundler query = null;
11860    
11861                    if (orderByComparator != null) {
11862                            query = new StringBundler(6 +
11863                                            (orderByComparator.getOrderByFields().length * 6));
11864                    }
11865                    else {
11866                            query = new StringBundler(3);
11867                    }
11868    
11869                    if (getDB().isSupportsInlineDistinct()) {
11870                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11871                    }
11872                    else {
11873                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11874                    }
11875    
11876                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11877    
11878                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11879    
11880                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11881    
11882                    if (!getDB().isSupportsInlineDistinct()) {
11883                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11884                    }
11885    
11886                    if (orderByComparator != null) {
11887                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11888    
11889                            if (orderByConditionFields.length > 0) {
11890                                    query.append(WHERE_AND);
11891                            }
11892    
11893                            for (int i = 0; i < orderByConditionFields.length; i++) {
11894                                    if (getDB().isSupportsInlineDistinct()) {
11895                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11896                                    }
11897                                    else {
11898                                            query.append(_ORDER_BY_ENTITY_TABLE);
11899                                    }
11900    
11901                                    query.append(orderByConditionFields[i]);
11902    
11903                                    if ((i + 1) < orderByConditionFields.length) {
11904                                            if (orderByComparator.isAscending() ^ previous) {
11905                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11906                                            }
11907                                            else {
11908                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11909                                            }
11910                                    }
11911                                    else {
11912                                            if (orderByComparator.isAscending() ^ previous) {
11913                                                    query.append(WHERE_GREATER_THAN);
11914                                            }
11915                                            else {
11916                                                    query.append(WHERE_LESSER_THAN);
11917                                            }
11918                                    }
11919                            }
11920    
11921                            query.append(ORDER_BY_CLAUSE);
11922    
11923                            String[] orderByFields = orderByComparator.getOrderByFields();
11924    
11925                            for (int i = 0; i < orderByFields.length; i++) {
11926                                    if (getDB().isSupportsInlineDistinct()) {
11927                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11928                                    }
11929                                    else {
11930                                            query.append(_ORDER_BY_ENTITY_TABLE);
11931                                    }
11932    
11933                                    query.append(orderByFields[i]);
11934    
11935                                    if ((i + 1) < orderByFields.length) {
11936                                            if (orderByComparator.isAscending() ^ previous) {
11937                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11938                                            }
11939                                            else {
11940                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11941                                            }
11942                                    }
11943                                    else {
11944                                            if (orderByComparator.isAscending() ^ previous) {
11945                                                    query.append(ORDER_BY_ASC);
11946                                            }
11947                                            else {
11948                                                    query.append(ORDER_BY_DESC);
11949                                            }
11950                                    }
11951                            }
11952                    }
11953                    else {
11954                            if (getDB().isSupportsInlineDistinct()) {
11955                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11956                            }
11957                            else {
11958                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11959                            }
11960                    }
11961    
11962                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11963                                    MBMessage.class.getName(),
11964                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11965    
11966                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11967    
11968                    q.setFirstResult(0);
11969                    q.setMaxResults(2);
11970    
11971                    if (getDB().isSupportsInlineDistinct()) {
11972                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11973                    }
11974                    else {
11975                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11976                    }
11977    
11978                    QueryPos qPos = QueryPos.getInstance(q);
11979    
11980                    qPos.add(groupId);
11981    
11982                    qPos.add(userId);
11983    
11984                    qPos.add(status);
11985    
11986                    if (orderByComparator != null) {
11987                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11988    
11989                            for (Object value : values) {
11990                                    qPos.add(value);
11991                            }
11992                    }
11993    
11994                    List<MBMessage> list = q.list();
11995    
11996                    if (list.size() == 2) {
11997                            return list.get(1);
11998                    }
11999                    else {
12000                            return null;
12001                    }
12002            }
12003    
12004            /**
12005             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
12006             *
12007             * @param groupId the group ID
12008             * @param userId the user ID
12009             * @param status the status
12010             */
12011            @Override
12012            public void removeByG_U_S(long groupId, long userId, int status) {
12013                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
12014                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12015                            remove(mbMessage);
12016                    }
12017            }
12018    
12019            /**
12020             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
12021             *
12022             * @param groupId the group ID
12023             * @param userId the user ID
12024             * @param status the status
12025             * @return the number of matching message-boards messages
12026             */
12027            @Override
12028            public int countByG_U_S(long groupId, long userId, int status) {
12029                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
12030    
12031                    Object[] finderArgs = new Object[] { groupId, userId, status };
12032    
12033                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12034    
12035                    if (count == null) {
12036                            StringBundler query = new StringBundler(4);
12037    
12038                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12039    
12040                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12041    
12042                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12043    
12044                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12045    
12046                            String sql = query.toString();
12047    
12048                            Session session = null;
12049    
12050                            try {
12051                                    session = openSession();
12052    
12053                                    Query q = session.createQuery(sql);
12054    
12055                                    QueryPos qPos = QueryPos.getInstance(q);
12056    
12057                                    qPos.add(groupId);
12058    
12059                                    qPos.add(userId);
12060    
12061                                    qPos.add(status);
12062    
12063                                    count = (Long)q.uniqueResult();
12064    
12065                                    finderCache.putResult(finderPath, finderArgs, count);
12066                            }
12067                            catch (Exception e) {
12068                                    finderCache.removeResult(finderPath, finderArgs);
12069    
12070                                    throw processException(e);
12071                            }
12072                            finally {
12073                                    closeSession(session);
12074                            }
12075                    }
12076    
12077                    return count.intValue();
12078            }
12079    
12080            /**
12081             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
12082             *
12083             * @param groupId the group ID
12084             * @param userId the user ID
12085             * @param status the status
12086             * @return the number of matching message-boards messages that the user has permission to view
12087             */
12088            @Override
12089            public int filterCountByG_U_S(long groupId, long userId, int status) {
12090                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12091                            return countByG_U_S(groupId, userId, status);
12092                    }
12093    
12094                    StringBundler query = new StringBundler(4);
12095    
12096                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12097    
12098                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12099    
12100                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12101    
12102                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12103    
12104                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12105                                    MBMessage.class.getName(),
12106                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12107    
12108                    Session session = null;
12109    
12110                    try {
12111                            session = openSession();
12112    
12113                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12114    
12115                            q.addScalar(COUNT_COLUMN_NAME,
12116                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12117    
12118                            QueryPos qPos = QueryPos.getInstance(q);
12119    
12120                            qPos.add(groupId);
12121    
12122                            qPos.add(userId);
12123    
12124                            qPos.add(status);
12125    
12126                            Long count = (Long)q.uniqueResult();
12127    
12128                            return count.intValue();
12129                    }
12130                    catch (Exception e) {
12131                            throw processException(e);
12132                    }
12133                    finally {
12134                            closeSession(session);
12135                    }
12136            }
12137    
12138            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
12139            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
12140            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
12141            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12142                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12143                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
12144                            new String[] {
12145                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12146                                    
12147                            Integer.class.getName(), Integer.class.getName(),
12148                                    OrderByComparator.class.getName()
12149                            });
12150            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12151                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12152                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
12153                            new String[] {
12154                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12155                            },
12156                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12157                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12158                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
12159                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12160            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12161                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12162                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
12163                            new String[] {
12164                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12165                            });
12166    
12167            /**
12168             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12169             *
12170             * @param groupId the group ID
12171             * @param categoryId the category ID
12172             * @param threadId the thread ID
12173             * @return the matching message-boards messages
12174             */
12175            @Override
12176            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12177                    long threadId) {
12178                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
12179                            QueryUtil.ALL_POS, null);
12180            }
12181    
12182            /**
12183             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12184             *
12185             * <p>
12186             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12187             * </p>
12188             *
12189             * @param groupId the group ID
12190             * @param categoryId the category ID
12191             * @param threadId the thread ID
12192             * @param start the lower bound of the range of message-boards messages
12193             * @param end the upper bound of the range of message-boards messages (not inclusive)
12194             * @return the range of matching message-boards messages
12195             */
12196            @Override
12197            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12198                    long threadId, int start, int end) {
12199                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
12200            }
12201    
12202            /**
12203             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12204             *
12205             * <p>
12206             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12207             * </p>
12208             *
12209             * @param groupId the group ID
12210             * @param categoryId the category ID
12211             * @param threadId the thread ID
12212             * @param start the lower bound of the range of message-boards messages
12213             * @param end the upper bound of the range of message-boards messages (not inclusive)
12214             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12215             * @return the ordered range of matching message-boards messages
12216             */
12217            @Override
12218            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12219                    long threadId, int start, int end,
12220                    OrderByComparator<MBMessage> orderByComparator) {
12221                    return findByG_C_T(groupId, categoryId, threadId, start, end,
12222                            orderByComparator, true);
12223            }
12224    
12225            /**
12226             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12227             *
12228             * <p>
12229             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12230             * </p>
12231             *
12232             * @param groupId the group ID
12233             * @param categoryId the category ID
12234             * @param threadId the thread ID
12235             * @param start the lower bound of the range of message-boards messages
12236             * @param end the upper bound of the range of message-boards messages (not inclusive)
12237             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12238             * @param retrieveFromCache whether to retrieve from the finder cache
12239             * @return the ordered range of matching message-boards messages
12240             */
12241            @Override
12242            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12243                    long threadId, int start, int end,
12244                    OrderByComparator<MBMessage> orderByComparator,
12245                    boolean retrieveFromCache) {
12246                    boolean pagination = true;
12247                    FinderPath finderPath = null;
12248                    Object[] finderArgs = null;
12249    
12250                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12251                                    (orderByComparator == null)) {
12252                            pagination = false;
12253                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12254                            finderArgs = new Object[] { groupId, categoryId, threadId };
12255                    }
12256                    else {
12257                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12258                            finderArgs = new Object[] {
12259                                            groupId, categoryId, threadId,
12260                                            
12261                                            start, end, orderByComparator
12262                                    };
12263                    }
12264    
12265                    List<MBMessage> list = null;
12266    
12267                    if (retrieveFromCache) {
12268                            list = (List<MBMessage>)finderCache.getResult(finderPath,
12269                                            finderArgs, this);
12270    
12271                            if ((list != null) && !list.isEmpty()) {
12272                                    for (MBMessage mbMessage : list) {
12273                                            if ((groupId != mbMessage.getGroupId()) ||
12274                                                            (categoryId != mbMessage.getCategoryId()) ||
12275                                                            (threadId != mbMessage.getThreadId())) {
12276                                                    list = null;
12277    
12278                                                    break;
12279                                            }
12280                                    }
12281                            }
12282                    }
12283    
12284                    if (list == null) {
12285                            StringBundler query = null;
12286    
12287                            if (orderByComparator != null) {
12288                                    query = new StringBundler(5 +
12289                                                    (orderByComparator.getOrderByFields().length * 3));
12290                            }
12291                            else {
12292                                    query = new StringBundler(5);
12293                            }
12294    
12295                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12296    
12297                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12298    
12299                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12300    
12301                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12302    
12303                            if (orderByComparator != null) {
12304                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12305                                            orderByComparator);
12306                            }
12307                            else
12308                             if (pagination) {
12309                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12310                            }
12311    
12312                            String sql = query.toString();
12313    
12314                            Session session = null;
12315    
12316                            try {
12317                                    session = openSession();
12318    
12319                                    Query q = session.createQuery(sql);
12320    
12321                                    QueryPos qPos = QueryPos.getInstance(q);
12322    
12323                                    qPos.add(groupId);
12324    
12325                                    qPos.add(categoryId);
12326    
12327                                    qPos.add(threadId);
12328    
12329                                    if (!pagination) {
12330                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12331                                                            start, end, false);
12332    
12333                                            Collections.sort(list);
12334    
12335                                            list = Collections.unmodifiableList(list);
12336                                    }
12337                                    else {
12338                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12339                                                            start, end);
12340                                    }
12341    
12342                                    cacheResult(list);
12343    
12344                                    finderCache.putResult(finderPath, finderArgs, list);
12345                            }
12346                            catch (Exception e) {
12347                                    finderCache.removeResult(finderPath, finderArgs);
12348    
12349                                    throw processException(e);
12350                            }
12351                            finally {
12352                                    closeSession(session);
12353                            }
12354                    }
12355    
12356                    return list;
12357            }
12358    
12359            /**
12360             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12361             *
12362             * @param groupId the group ID
12363             * @param categoryId the category ID
12364             * @param threadId the thread ID
12365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12366             * @return the first matching message-boards message
12367             * @throws NoSuchMessageException if a matching message-boards message could not be found
12368             */
12369            @Override
12370            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12371                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12372                    throws NoSuchMessageException {
12373                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12374                                    orderByComparator);
12375    
12376                    if (mbMessage != null) {
12377                            return mbMessage;
12378                    }
12379    
12380                    StringBundler msg = new StringBundler(8);
12381    
12382                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12383    
12384                    msg.append("groupId=");
12385                    msg.append(groupId);
12386    
12387                    msg.append(", categoryId=");
12388                    msg.append(categoryId);
12389    
12390                    msg.append(", threadId=");
12391                    msg.append(threadId);
12392    
12393                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12394    
12395                    throw new NoSuchMessageException(msg.toString());
12396            }
12397    
12398            /**
12399             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12400             *
12401             * @param groupId the group ID
12402             * @param categoryId the category ID
12403             * @param threadId the thread ID
12404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12405             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12406             */
12407            @Override
12408            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12409                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12410                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12411                                    orderByComparator);
12412    
12413                    if (!list.isEmpty()) {
12414                            return list.get(0);
12415                    }
12416    
12417                    return null;
12418            }
12419    
12420            /**
12421             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12422             *
12423             * @param groupId the group ID
12424             * @param categoryId the category ID
12425             * @param threadId the thread ID
12426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12427             * @return the last matching message-boards message
12428             * @throws NoSuchMessageException if a matching message-boards message could not be found
12429             */
12430            @Override
12431            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12432                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12433                    throws NoSuchMessageException {
12434                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12435                                    orderByComparator);
12436    
12437                    if (mbMessage != null) {
12438                            return mbMessage;
12439                    }
12440    
12441                    StringBundler msg = new StringBundler(8);
12442    
12443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12444    
12445                    msg.append("groupId=");
12446                    msg.append(groupId);
12447    
12448                    msg.append(", categoryId=");
12449                    msg.append(categoryId);
12450    
12451                    msg.append(", threadId=");
12452                    msg.append(threadId);
12453    
12454                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12455    
12456                    throw new NoSuchMessageException(msg.toString());
12457            }
12458    
12459            /**
12460             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12461             *
12462             * @param groupId the group ID
12463             * @param categoryId the category ID
12464             * @param threadId the thread ID
12465             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12466             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12467             */
12468            @Override
12469            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12470                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12471                    int count = countByG_C_T(groupId, categoryId, threadId);
12472    
12473                    if (count == 0) {
12474                            return null;
12475                    }
12476    
12477                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12478                                    count - 1, count, orderByComparator);
12479    
12480                    if (!list.isEmpty()) {
12481                            return list.get(0);
12482                    }
12483    
12484                    return null;
12485            }
12486    
12487            /**
12488             * 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;.
12489             *
12490             * @param messageId the primary key of the current message-boards message
12491             * @param groupId the group ID
12492             * @param categoryId the category ID
12493             * @param threadId the thread ID
12494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12495             * @return the previous, current, and next message-boards message
12496             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12497             */
12498            @Override
12499            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12500                    long categoryId, long threadId,
12501                    OrderByComparator<MBMessage> orderByComparator)
12502                    throws NoSuchMessageException {
12503                    MBMessage mbMessage = findByPrimaryKey(messageId);
12504    
12505                    Session session = null;
12506    
12507                    try {
12508                            session = openSession();
12509    
12510                            MBMessage[] array = new MBMessageImpl[3];
12511    
12512                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12513                                            categoryId, threadId, orderByComparator, true);
12514    
12515                            array[1] = mbMessage;
12516    
12517                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12518                                            categoryId, threadId, orderByComparator, false);
12519    
12520                            return array;
12521                    }
12522                    catch (Exception e) {
12523                            throw processException(e);
12524                    }
12525                    finally {
12526                            closeSession(session);
12527                    }
12528            }
12529    
12530            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12531                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12532                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12533                    StringBundler query = null;
12534    
12535                    if (orderByComparator != null) {
12536                            query = new StringBundler(6 +
12537                                            (orderByComparator.getOrderByFields().length * 6));
12538                    }
12539                    else {
12540                            query = new StringBundler(3);
12541                    }
12542    
12543                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12544    
12545                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12546    
12547                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12548    
12549                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12550    
12551                    if (orderByComparator != null) {
12552                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12553    
12554                            if (orderByConditionFields.length > 0) {
12555                                    query.append(WHERE_AND);
12556                            }
12557    
12558                            for (int i = 0; i < orderByConditionFields.length; i++) {
12559                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12560                                    query.append(orderByConditionFields[i]);
12561    
12562                                    if ((i + 1) < orderByConditionFields.length) {
12563                                            if (orderByComparator.isAscending() ^ previous) {
12564                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12565                                            }
12566                                            else {
12567                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12568                                            }
12569                                    }
12570                                    else {
12571                                            if (orderByComparator.isAscending() ^ previous) {
12572                                                    query.append(WHERE_GREATER_THAN);
12573                                            }
12574                                            else {
12575                                                    query.append(WHERE_LESSER_THAN);
12576                                            }
12577                                    }
12578                            }
12579    
12580                            query.append(ORDER_BY_CLAUSE);
12581    
12582                            String[] orderByFields = orderByComparator.getOrderByFields();
12583    
12584                            for (int i = 0; i < orderByFields.length; i++) {
12585                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12586                                    query.append(orderByFields[i]);
12587    
12588                                    if ((i + 1) < orderByFields.length) {
12589                                            if (orderByComparator.isAscending() ^ previous) {
12590                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12591                                            }
12592                                            else {
12593                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12594                                            }
12595                                    }
12596                                    else {
12597                                            if (orderByComparator.isAscending() ^ previous) {
12598                                                    query.append(ORDER_BY_ASC);
12599                                            }
12600                                            else {
12601                                                    query.append(ORDER_BY_DESC);
12602                                            }
12603                                    }
12604                            }
12605                    }
12606                    else {
12607                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12608                    }
12609    
12610                    String sql = query.toString();
12611    
12612                    Query q = session.createQuery(sql);
12613    
12614                    q.setFirstResult(0);
12615                    q.setMaxResults(2);
12616    
12617                    QueryPos qPos = QueryPos.getInstance(q);
12618    
12619                    qPos.add(groupId);
12620    
12621                    qPos.add(categoryId);
12622    
12623                    qPos.add(threadId);
12624    
12625                    if (orderByComparator != null) {
12626                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12627    
12628                            for (Object value : values) {
12629                                    qPos.add(value);
12630                            }
12631                    }
12632    
12633                    List<MBMessage> list = q.list();
12634    
12635                    if (list.size() == 2) {
12636                            return list.get(1);
12637                    }
12638                    else {
12639                            return null;
12640                    }
12641            }
12642    
12643            /**
12644             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12645             *
12646             * @param groupId the group ID
12647             * @param categoryId the category ID
12648             * @param threadId the thread ID
12649             * @return the matching message-boards messages that the user has permission to view
12650             */
12651            @Override
12652            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12653                    long threadId) {
12654                    return filterFindByG_C_T(groupId, categoryId, threadId,
12655                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12656            }
12657    
12658            /**
12659             * 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;.
12660             *
12661             * <p>
12662             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12663             * </p>
12664             *
12665             * @param groupId the group ID
12666             * @param categoryId the category ID
12667             * @param threadId the thread ID
12668             * @param start the lower bound of the range of message-boards messages
12669             * @param end the upper bound of the range of message-boards messages (not inclusive)
12670             * @return the range of matching message-boards messages that the user has permission to view
12671             */
12672            @Override
12673            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12674                    long threadId, int start, int end) {
12675                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12676            }
12677    
12678            /**
12679             * 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;.
12680             *
12681             * <p>
12682             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
12683             * </p>
12684             *
12685             * @param groupId the group ID
12686             * @param categoryId the category ID
12687             * @param threadId the thread ID
12688             * @param start the lower bound of the range of message-boards messages
12689             * @param end the upper bound of the range of message-boards messages (not inclusive)
12690             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12691             * @return the ordered range of matching message-boards messages that the user has permission to view
12692             */
12693            @Override
12694            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12695                    long threadId, int start, int end,
12696                    OrderByComparator<MBMessage> orderByComparator) {
12697                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12698                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12699                                    orderByComparator);
12700                    }
12701    
12702                    StringBundler query = null;
12703    
12704                    if (orderByComparator != null) {
12705                            query = new StringBundler(5 +
12706                                            (orderByComparator.getOrderByFields().length * 3));
12707                    }
12708                    else {
12709                            query = new StringBundler(5);
12710                    }
12711    
12712                    if (getDB().isSupportsInlineDistinct()) {
12713                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12714                    }
12715                    else {
12716                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12717                    }
12718    
12719                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12720    
12721                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12722    
12723                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12724    
12725                    if (!getDB().isSupportsInlineDistinct()) {
12726                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12727                    }
12728    
12729                    if (orderByComparator != null) {
12730                            if (getDB().isSupportsInlineDistinct()) {
12731                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12732                                            orderByComparator, true);
12733                            }
12734                            else {
12735                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12736                                            orderByComparator, true);
12737                            }
12738                    }
12739                    else {
12740                            if (getDB().isSupportsInlineDistinct()) {
12741                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12742                            }
12743                            else {
12744                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12745                            }
12746                    }
12747    
12748                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12749                                    MBMessage.class.getName(),
12750                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12751    
12752                    Session session = null;
12753    
12754                    try {
12755                            session = openSession();
12756    
12757                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12758    
12759                            if (getDB().isSupportsInlineDistinct()) {
12760                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12761                            }
12762                            else {
12763                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12764                            }
12765    
12766                            QueryPos qPos = QueryPos.getInstance(q);
12767    
12768                            qPos.add(groupId);
12769    
12770                            qPos.add(categoryId);
12771    
12772                            qPos.add(threadId);
12773    
12774                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12775                    }
12776                    catch (Exception e) {
12777                            throw processException(e);
12778                    }
12779                    finally {
12780                            closeSession(session);
12781                    }
12782            }
12783    
12784            /**
12785             * 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;.
12786             *
12787             * @param messageId the primary key of the current message-boards message
12788             * @param groupId the group ID
12789             * @param categoryId the category ID
12790             * @param threadId the thread ID
12791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12792             * @return the previous, current, and next message-boards message
12793             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12794             */
12795            @Override
12796            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12797                    long groupId, long categoryId, long threadId,
12798                    OrderByComparator<MBMessage> orderByComparator)
12799                    throws NoSuchMessageException {
12800                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12801                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12802                                    threadId, orderByComparator);
12803                    }
12804    
12805                    MBMessage mbMessage = findByPrimaryKey(messageId);
12806    
12807                    Session session = null;
12808    
12809                    try {
12810                            session = openSession();
12811    
12812                            MBMessage[] array = new MBMessageImpl[3];
12813    
12814                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12815                                            groupId, categoryId, threadId, orderByComparator, true);
12816    
12817                            array[1] = mbMessage;
12818    
12819                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12820                                            groupId, categoryId, threadId, orderByComparator, false);
12821    
12822                            return array;
12823                    }
12824                    catch (Exception e) {
12825                            throw processException(e);
12826                    }
12827                    finally {
12828                            closeSession(session);
12829                    }
12830            }
12831    
12832            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12833                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12834                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12835                    StringBundler query = null;
12836    
12837                    if (orderByComparator != null) {
12838                            query = new StringBundler(6 +
12839                                            (orderByComparator.getOrderByFields().length * 6));
12840                    }
12841                    else {
12842                            query = new StringBundler(3);
12843                    }
12844    
12845                    if (getDB().isSupportsInlineDistinct()) {
12846                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12847                    }
12848                    else {
12849                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12850                    }
12851    
12852                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12853    
12854                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12855    
12856                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12857    
12858                    if (!getDB().isSupportsInlineDistinct()) {
12859                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12860                    }
12861    
12862                    if (orderByComparator != null) {
12863                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12864    
12865                            if (orderByConditionFields.length > 0) {
12866                                    query.append(WHERE_AND);
12867                            }
12868    
12869                            for (int i = 0; i < orderByConditionFields.length; i++) {
12870                                    if (getDB().isSupportsInlineDistinct()) {
12871                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12872                                    }
12873                                    else {
12874                                            query.append(_ORDER_BY_ENTITY_TABLE);
12875                                    }
12876    
12877                                    query.append(orderByConditionFields[i]);
12878    
12879                                    if ((i + 1) < orderByConditionFields.length) {
12880                                            if (orderByComparator.isAscending() ^ previous) {
12881                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12882                                            }
12883                                            else {
12884                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12885                                            }
12886                                    }
12887                                    else {
12888                                            if (orderByComparator.isAscending() ^ previous) {
12889                                                    query.append(WHERE_GREATER_THAN);
12890                                            }
12891                                            else {
12892                                                    query.append(WHERE_LESSER_THAN);
12893                                            }
12894                                    }
12895                            }
12896    
12897                            query.append(ORDER_BY_CLAUSE);
12898    
12899                            String[] orderByFields = orderByComparator.getOrderByFields();
12900    
12901                            for (int i = 0; i < orderByFields.length; i++) {
12902                                    if (getDB().isSupportsInlineDistinct()) {
12903                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12904                                    }
12905                                    else {
12906                                            query.append(_ORDER_BY_ENTITY_TABLE);
12907                                    }
12908    
12909                                    query.append(orderByFields[i]);
12910    
12911                                    if ((i + 1) < orderByFields.length) {
12912                                            if (orderByComparator.isAscending() ^ previous) {
12913                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12914                                            }
12915                                            else {
12916                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12917                                            }
12918                                    }
12919                                    else {
12920                                            if (orderByComparator.isAscending() ^ previous) {
12921                                                    query.append(ORDER_BY_ASC);
12922                                            }
12923                                            else {
12924                                                    query.append(ORDER_BY_DESC);
12925                                            }
12926                                    }
12927                            }
12928                    }
12929                    else {
12930                            if (getDB().isSupportsInlineDistinct()) {
12931                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12932                            }
12933                            else {
12934                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12935                            }
12936                    }
12937    
12938                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12939                                    MBMessage.class.getName(),
12940                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12941    
12942                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12943    
12944                    q.setFirstResult(0);
12945                    q.setMaxResults(2);
12946    
12947                    if (getDB().isSupportsInlineDistinct()) {
12948                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12949                    }
12950                    else {
12951                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12952                    }
12953    
12954                    QueryPos qPos = QueryPos.getInstance(q);
12955    
12956                    qPos.add(groupId);
12957    
12958                    qPos.add(categoryId);
12959    
12960                    qPos.add(threadId);
12961    
12962                    if (orderByComparator != null) {
12963                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12964    
12965                            for (Object value : values) {
12966                                    qPos.add(value);
12967                            }
12968                    }
12969    
12970                    List<MBMessage> list = q.list();
12971    
12972                    if (list.size() == 2) {
12973                            return list.get(1);
12974                    }
12975                    else {
12976                            return null;
12977                    }
12978            }
12979    
12980            /**
12981             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12982             *
12983             * @param groupId the group ID
12984             * @param categoryId the category ID
12985             * @param threadId the thread ID
12986             */
12987            @Override
12988            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
12989                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12990                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12991                            remove(mbMessage);
12992                    }
12993            }
12994    
12995            /**
12996             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12997             *
12998             * @param groupId the group ID
12999             * @param categoryId the category ID
13000             * @param threadId the thread ID
13001             * @return the number of matching message-boards messages
13002             */
13003            @Override
13004            public int countByG_C_T(long groupId, long categoryId, long threadId) {
13005                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
13006    
13007                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
13008    
13009                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13010    
13011                    if (count == null) {
13012                            StringBundler query = new StringBundler(4);
13013    
13014                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13015    
13016                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13017    
13018                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13019    
13020                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13021    
13022                            String sql = query.toString();
13023    
13024                            Session session = null;
13025    
13026                            try {
13027                                    session = openSession();
13028    
13029                                    Query q = session.createQuery(sql);
13030    
13031                                    QueryPos qPos = QueryPos.getInstance(q);
13032    
13033                                    qPos.add(groupId);
13034    
13035                                    qPos.add(categoryId);
13036    
13037                                    qPos.add(threadId);
13038    
13039                                    count = (Long)q.uniqueResult();
13040    
13041                                    finderCache.putResult(finderPath, finderArgs, count);
13042                            }
13043                            catch (Exception e) {
13044                                    finderCache.removeResult(finderPath, finderArgs);
13045    
13046                                    throw processException(e);
13047                            }
13048                            finally {
13049                                    closeSession(session);
13050                            }
13051                    }
13052    
13053                    return count.intValue();
13054            }
13055    
13056            /**
13057             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13058             *
13059             * @param groupId the group ID
13060             * @param categoryId the category ID
13061             * @param threadId the thread ID
13062             * @return the number of matching message-boards messages that the user has permission to view
13063             */
13064            @Override
13065            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
13066                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13067                            return countByG_C_T(groupId, categoryId, threadId);
13068                    }
13069    
13070                    StringBundler query = new StringBundler(4);
13071    
13072                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13073    
13074                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13075    
13076                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13077    
13078                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13079    
13080                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13081                                    MBMessage.class.getName(),
13082                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13083    
13084                    Session session = null;
13085    
13086                    try {
13087                            session = openSession();
13088    
13089                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13090    
13091                            q.addScalar(COUNT_COLUMN_NAME,
13092                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13093    
13094                            QueryPos qPos = QueryPos.getInstance(q);
13095    
13096                            qPos.add(groupId);
13097    
13098                            qPos.add(categoryId);
13099    
13100                            qPos.add(threadId);
13101    
13102                            Long count = (Long)q.uniqueResult();
13103    
13104                            return count.intValue();
13105                    }
13106                    catch (Exception e) {
13107                            throw processException(e);
13108                    }
13109                    finally {
13110                            closeSession(session);
13111                    }
13112            }
13113    
13114            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
13115            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13116            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
13117            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13118                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13119                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
13120                            new String[] {
13121                                    Long.class.getName(), Long.class.getName(),
13122                                    Integer.class.getName(),
13123                                    
13124                            Integer.class.getName(), Integer.class.getName(),
13125                                    OrderByComparator.class.getName()
13126                            });
13127            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13128                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
13130                            new String[] {
13131                                    Long.class.getName(), Long.class.getName(),
13132                                    Integer.class.getName()
13133                            },
13134                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
13135                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
13136                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
13137                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13138            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13139                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
13141                            new String[] {
13142                                    Long.class.getName(), Long.class.getName(),
13143                                    Integer.class.getName()
13144                            });
13145    
13146            /**
13147             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13148             *
13149             * @param groupId the group ID
13150             * @param categoryId the category ID
13151             * @param status the status
13152             * @return the matching message-boards messages
13153             */
13154            @Override
13155            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
13156                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
13157                            QueryUtil.ALL_POS, null);
13158            }
13159    
13160            /**
13161             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13162             *
13163             * <p>
13164             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13165             * </p>
13166             *
13167             * @param groupId the group ID
13168             * @param categoryId the category ID
13169             * @param status the status
13170             * @param start the lower bound of the range of message-boards messages
13171             * @param end the upper bound of the range of message-boards messages (not inclusive)
13172             * @return the range of matching message-boards messages
13173             */
13174            @Override
13175            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13176                    int status, int start, int end) {
13177                    return findByG_C_S(groupId, categoryId, status, start, end, null);
13178            }
13179    
13180            /**
13181             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13182             *
13183             * <p>
13184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13185             * </p>
13186             *
13187             * @param groupId the group ID
13188             * @param categoryId the category ID
13189             * @param status the status
13190             * @param start the lower bound of the range of message-boards messages
13191             * @param end the upper bound of the range of message-boards messages (not inclusive)
13192             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13193             * @return the ordered range of matching message-boards messages
13194             */
13195            @Override
13196            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13197                    int status, int start, int end,
13198                    OrderByComparator<MBMessage> orderByComparator) {
13199                    return findByG_C_S(groupId, categoryId, status, start, end,
13200                            orderByComparator, true);
13201            }
13202    
13203            /**
13204             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13205             *
13206             * <p>
13207             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13208             * </p>
13209             *
13210             * @param groupId the group ID
13211             * @param categoryId the category ID
13212             * @param status the status
13213             * @param start the lower bound of the range of message-boards messages
13214             * @param end the upper bound of the range of message-boards messages (not inclusive)
13215             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13216             * @param retrieveFromCache whether to retrieve from the finder cache
13217             * @return the ordered range of matching message-boards messages
13218             */
13219            @Override
13220            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13221                    int status, int start, int end,
13222                    OrderByComparator<MBMessage> orderByComparator,
13223                    boolean retrieveFromCache) {
13224                    boolean pagination = true;
13225                    FinderPath finderPath = null;
13226                    Object[] finderArgs = null;
13227    
13228                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13229                                    (orderByComparator == null)) {
13230                            pagination = false;
13231                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13232                            finderArgs = new Object[] { groupId, categoryId, status };
13233                    }
13234                    else {
13235                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13236                            finderArgs = new Object[] {
13237                                            groupId, categoryId, status,
13238                                            
13239                                            start, end, orderByComparator
13240                                    };
13241                    }
13242    
13243                    List<MBMessage> list = null;
13244    
13245                    if (retrieveFromCache) {
13246                            list = (List<MBMessage>)finderCache.getResult(finderPath,
13247                                            finderArgs, this);
13248    
13249                            if ((list != null) && !list.isEmpty()) {
13250                                    for (MBMessage mbMessage : list) {
13251                                            if ((groupId != mbMessage.getGroupId()) ||
13252                                                            (categoryId != mbMessage.getCategoryId()) ||
13253                                                            (status != mbMessage.getStatus())) {
13254                                                    list = null;
13255    
13256                                                    break;
13257                                            }
13258                                    }
13259                            }
13260                    }
13261    
13262                    if (list == null) {
13263                            StringBundler query = null;
13264    
13265                            if (orderByComparator != null) {
13266                                    query = new StringBundler(5 +
13267                                                    (orderByComparator.getOrderByFields().length * 3));
13268                            }
13269                            else {
13270                                    query = new StringBundler(5);
13271                            }
13272    
13273                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13274    
13275                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13276    
13277                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13278    
13279                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13280    
13281                            if (orderByComparator != null) {
13282                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13283                                            orderByComparator);
13284                            }
13285                            else
13286                             if (pagination) {
13287                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13288                            }
13289    
13290                            String sql = query.toString();
13291    
13292                            Session session = null;
13293    
13294                            try {
13295                                    session = openSession();
13296    
13297                                    Query q = session.createQuery(sql);
13298    
13299                                    QueryPos qPos = QueryPos.getInstance(q);
13300    
13301                                    qPos.add(groupId);
13302    
13303                                    qPos.add(categoryId);
13304    
13305                                    qPos.add(status);
13306    
13307                                    if (!pagination) {
13308                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13309                                                            start, end, false);
13310    
13311                                            Collections.sort(list);
13312    
13313                                            list = Collections.unmodifiableList(list);
13314                                    }
13315                                    else {
13316                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13317                                                            start, end);
13318                                    }
13319    
13320                                    cacheResult(list);
13321    
13322                                    finderCache.putResult(finderPath, finderArgs, list);
13323                            }
13324                            catch (Exception e) {
13325                                    finderCache.removeResult(finderPath, finderArgs);
13326    
13327                                    throw processException(e);
13328                            }
13329                            finally {
13330                                    closeSession(session);
13331                            }
13332                    }
13333    
13334                    return list;
13335            }
13336    
13337            /**
13338             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13339             *
13340             * @param groupId the group ID
13341             * @param categoryId the category ID
13342             * @param status the status
13343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13344             * @return the first matching message-boards message
13345             * @throws NoSuchMessageException if a matching message-boards message could not be found
13346             */
13347            @Override
13348            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13349                    int status, OrderByComparator<MBMessage> orderByComparator)
13350                    throws NoSuchMessageException {
13351                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13352                                    orderByComparator);
13353    
13354                    if (mbMessage != null) {
13355                            return mbMessage;
13356                    }
13357    
13358                    StringBundler msg = new StringBundler(8);
13359    
13360                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13361    
13362                    msg.append("groupId=");
13363                    msg.append(groupId);
13364    
13365                    msg.append(", categoryId=");
13366                    msg.append(categoryId);
13367    
13368                    msg.append(", status=");
13369                    msg.append(status);
13370    
13371                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13372    
13373                    throw new NoSuchMessageException(msg.toString());
13374            }
13375    
13376            /**
13377             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13378             *
13379             * @param groupId the group ID
13380             * @param categoryId the category ID
13381             * @param status the status
13382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13383             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13384             */
13385            @Override
13386            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13387                    int status, OrderByComparator<MBMessage> orderByComparator) {
13388                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13389                                    orderByComparator);
13390    
13391                    if (!list.isEmpty()) {
13392                            return list.get(0);
13393                    }
13394    
13395                    return null;
13396            }
13397    
13398            /**
13399             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13400             *
13401             * @param groupId the group ID
13402             * @param categoryId the category ID
13403             * @param status the status
13404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13405             * @return the last matching message-boards message
13406             * @throws NoSuchMessageException if a matching message-boards message could not be found
13407             */
13408            @Override
13409            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13410                    int status, OrderByComparator<MBMessage> orderByComparator)
13411                    throws NoSuchMessageException {
13412                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13413                                    orderByComparator);
13414    
13415                    if (mbMessage != null) {
13416                            return mbMessage;
13417                    }
13418    
13419                    StringBundler msg = new StringBundler(8);
13420    
13421                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13422    
13423                    msg.append("groupId=");
13424                    msg.append(groupId);
13425    
13426                    msg.append(", categoryId=");
13427                    msg.append(categoryId);
13428    
13429                    msg.append(", status=");
13430                    msg.append(status);
13431    
13432                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13433    
13434                    throw new NoSuchMessageException(msg.toString());
13435            }
13436    
13437            /**
13438             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13439             *
13440             * @param groupId the group ID
13441             * @param categoryId the category ID
13442             * @param status the status
13443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13444             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13445             */
13446            @Override
13447            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13448                    int status, OrderByComparator<MBMessage> orderByComparator) {
13449                    int count = countByG_C_S(groupId, categoryId, status);
13450    
13451                    if (count == 0) {
13452                            return null;
13453                    }
13454    
13455                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13456                                    count - 1, count, orderByComparator);
13457    
13458                    if (!list.isEmpty()) {
13459                            return list.get(0);
13460                    }
13461    
13462                    return null;
13463            }
13464    
13465            /**
13466             * 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;.
13467             *
13468             * @param messageId the primary key of the current message-boards message
13469             * @param groupId the group ID
13470             * @param categoryId the category ID
13471             * @param status the status
13472             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13473             * @return the previous, current, and next message-boards message
13474             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13475             */
13476            @Override
13477            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13478                    long categoryId, int status,
13479                    OrderByComparator<MBMessage> orderByComparator)
13480                    throws NoSuchMessageException {
13481                    MBMessage mbMessage = findByPrimaryKey(messageId);
13482    
13483                    Session session = null;
13484    
13485                    try {
13486                            session = openSession();
13487    
13488                            MBMessage[] array = new MBMessageImpl[3];
13489    
13490                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13491                                            categoryId, status, orderByComparator, true);
13492    
13493                            array[1] = mbMessage;
13494    
13495                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13496                                            categoryId, status, orderByComparator, false);
13497    
13498                            return array;
13499                    }
13500                    catch (Exception e) {
13501                            throw processException(e);
13502                    }
13503                    finally {
13504                            closeSession(session);
13505                    }
13506            }
13507    
13508            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13509                    MBMessage mbMessage, long groupId, long categoryId, int status,
13510                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13511                    StringBundler query = null;
13512    
13513                    if (orderByComparator != null) {
13514                            query = new StringBundler(6 +
13515                                            (orderByComparator.getOrderByFields().length * 6));
13516                    }
13517                    else {
13518                            query = new StringBundler(3);
13519                    }
13520    
13521                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13522    
13523                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13524    
13525                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13526    
13527                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13528    
13529                    if (orderByComparator != null) {
13530                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13531    
13532                            if (orderByConditionFields.length > 0) {
13533                                    query.append(WHERE_AND);
13534                            }
13535    
13536                            for (int i = 0; i < orderByConditionFields.length; i++) {
13537                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13538                                    query.append(orderByConditionFields[i]);
13539    
13540                                    if ((i + 1) < orderByConditionFields.length) {
13541                                            if (orderByComparator.isAscending() ^ previous) {
13542                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13543                                            }
13544                                            else {
13545                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13546                                            }
13547                                    }
13548                                    else {
13549                                            if (orderByComparator.isAscending() ^ previous) {
13550                                                    query.append(WHERE_GREATER_THAN);
13551                                            }
13552                                            else {
13553                                                    query.append(WHERE_LESSER_THAN);
13554                                            }
13555                                    }
13556                            }
13557    
13558                            query.append(ORDER_BY_CLAUSE);
13559    
13560                            String[] orderByFields = orderByComparator.getOrderByFields();
13561    
13562                            for (int i = 0; i < orderByFields.length; i++) {
13563                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13564                                    query.append(orderByFields[i]);
13565    
13566                                    if ((i + 1) < orderByFields.length) {
13567                                            if (orderByComparator.isAscending() ^ previous) {
13568                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13569                                            }
13570                                            else {
13571                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13572                                            }
13573                                    }
13574                                    else {
13575                                            if (orderByComparator.isAscending() ^ previous) {
13576                                                    query.append(ORDER_BY_ASC);
13577                                            }
13578                                            else {
13579                                                    query.append(ORDER_BY_DESC);
13580                                            }
13581                                    }
13582                            }
13583                    }
13584                    else {
13585                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13586                    }
13587    
13588                    String sql = query.toString();
13589    
13590                    Query q = session.createQuery(sql);
13591    
13592                    q.setFirstResult(0);
13593                    q.setMaxResults(2);
13594    
13595                    QueryPos qPos = QueryPos.getInstance(q);
13596    
13597                    qPos.add(groupId);
13598    
13599                    qPos.add(categoryId);
13600    
13601                    qPos.add(status);
13602    
13603                    if (orderByComparator != null) {
13604                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13605    
13606                            for (Object value : values) {
13607                                    qPos.add(value);
13608                            }
13609                    }
13610    
13611                    List<MBMessage> list = q.list();
13612    
13613                    if (list.size() == 2) {
13614                            return list.get(1);
13615                    }
13616                    else {
13617                            return null;
13618                    }
13619            }
13620    
13621            /**
13622             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13623             *
13624             * @param groupId the group ID
13625             * @param categoryId the category ID
13626             * @param status the status
13627             * @return the matching message-boards messages that the user has permission to view
13628             */
13629            @Override
13630            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13631                    int status) {
13632                    return filterFindByG_C_S(groupId, categoryId, status,
13633                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13634            }
13635    
13636            /**
13637             * 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;.
13638             *
13639             * <p>
13640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13641             * </p>
13642             *
13643             * @param groupId the group ID
13644             * @param categoryId the category ID
13645             * @param status the status
13646             * @param start the lower bound of the range of message-boards messages
13647             * @param end the upper bound of the range of message-boards messages (not inclusive)
13648             * @return the range of matching message-boards messages that the user has permission to view
13649             */
13650            @Override
13651            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13652                    int status, int start, int end) {
13653                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13654            }
13655    
13656            /**
13657             * 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;.
13658             *
13659             * <p>
13660             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
13661             * </p>
13662             *
13663             * @param groupId the group ID
13664             * @param categoryId the category ID
13665             * @param status the status
13666             * @param start the lower bound of the range of message-boards messages
13667             * @param end the upper bound of the range of message-boards messages (not inclusive)
13668             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13669             * @return the ordered range of matching message-boards messages that the user has permission to view
13670             */
13671            @Override
13672            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13673                    int status, int start, int end,
13674                    OrderByComparator<MBMessage> orderByComparator) {
13675                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13676                            return findByG_C_S(groupId, categoryId, status, start, end,
13677                                    orderByComparator);
13678                    }
13679    
13680                    StringBundler query = null;
13681    
13682                    if (orderByComparator != null) {
13683                            query = new StringBundler(5 +
13684                                            (orderByComparator.getOrderByFields().length * 3));
13685                    }
13686                    else {
13687                            query = new StringBundler(5);
13688                    }
13689    
13690                    if (getDB().isSupportsInlineDistinct()) {
13691                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13692                    }
13693                    else {
13694                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13695                    }
13696    
13697                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13698    
13699                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13700    
13701                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13702    
13703                    if (!getDB().isSupportsInlineDistinct()) {
13704                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13705                    }
13706    
13707                    if (orderByComparator != null) {
13708                            if (getDB().isSupportsInlineDistinct()) {
13709                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13710                                            orderByComparator, true);
13711                            }
13712                            else {
13713                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13714                                            orderByComparator, true);
13715                            }
13716                    }
13717                    else {
13718                            if (getDB().isSupportsInlineDistinct()) {
13719                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13720                            }
13721                            else {
13722                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13723                            }
13724                    }
13725    
13726                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13727                                    MBMessage.class.getName(),
13728                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13729    
13730                    Session session = null;
13731    
13732                    try {
13733                            session = openSession();
13734    
13735                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13736    
13737                            if (getDB().isSupportsInlineDistinct()) {
13738                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13739                            }
13740                            else {
13741                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13742                            }
13743    
13744                            QueryPos qPos = QueryPos.getInstance(q);
13745    
13746                            qPos.add(groupId);
13747    
13748                            qPos.add(categoryId);
13749    
13750                            qPos.add(status);
13751    
13752                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13753                    }
13754                    catch (Exception e) {
13755                            throw processException(e);
13756                    }
13757                    finally {
13758                            closeSession(session);
13759                    }
13760            }
13761    
13762            /**
13763             * 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;.
13764             *
13765             * @param messageId the primary key of the current message-boards message
13766             * @param groupId the group ID
13767             * @param categoryId the category ID
13768             * @param status the status
13769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13770             * @return the previous, current, and next message-boards message
13771             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13772             */
13773            @Override
13774            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13775                    long groupId, long categoryId, int status,
13776                    OrderByComparator<MBMessage> orderByComparator)
13777                    throws NoSuchMessageException {
13778                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13779                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13780                                    status, orderByComparator);
13781                    }
13782    
13783                    MBMessage mbMessage = findByPrimaryKey(messageId);
13784    
13785                    Session session = null;
13786    
13787                    try {
13788                            session = openSession();
13789    
13790                            MBMessage[] array = new MBMessageImpl[3];
13791    
13792                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13793                                            groupId, categoryId, status, orderByComparator, true);
13794    
13795                            array[1] = mbMessage;
13796    
13797                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13798                                            groupId, categoryId, status, orderByComparator, false);
13799    
13800                            return array;
13801                    }
13802                    catch (Exception e) {
13803                            throw processException(e);
13804                    }
13805                    finally {
13806                            closeSession(session);
13807                    }
13808            }
13809    
13810            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13811                    MBMessage mbMessage, long groupId, long categoryId, int status,
13812                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13813                    StringBundler query = null;
13814    
13815                    if (orderByComparator != null) {
13816                            query = new StringBundler(6 +
13817                                            (orderByComparator.getOrderByFields().length * 6));
13818                    }
13819                    else {
13820                            query = new StringBundler(3);
13821                    }
13822    
13823                    if (getDB().isSupportsInlineDistinct()) {
13824                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13825                    }
13826                    else {
13827                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13828                    }
13829    
13830                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13831    
13832                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13833    
13834                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13835    
13836                    if (!getDB().isSupportsInlineDistinct()) {
13837                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13838                    }
13839    
13840                    if (orderByComparator != null) {
13841                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13842    
13843                            if (orderByConditionFields.length > 0) {
13844                                    query.append(WHERE_AND);
13845                            }
13846    
13847                            for (int i = 0; i < orderByConditionFields.length; i++) {
13848                                    if (getDB().isSupportsInlineDistinct()) {
13849                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13850                                    }
13851                                    else {
13852                                            query.append(_ORDER_BY_ENTITY_TABLE);
13853                                    }
13854    
13855                                    query.append(orderByConditionFields[i]);
13856    
13857                                    if ((i + 1) < orderByConditionFields.length) {
13858                                            if (orderByComparator.isAscending() ^ previous) {
13859                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13860                                            }
13861                                            else {
13862                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13863                                            }
13864                                    }
13865                                    else {
13866                                            if (orderByComparator.isAscending() ^ previous) {
13867                                                    query.append(WHERE_GREATER_THAN);
13868                                            }
13869                                            else {
13870                                                    query.append(WHERE_LESSER_THAN);
13871                                            }
13872                                    }
13873                            }
13874    
13875                            query.append(ORDER_BY_CLAUSE);
13876    
13877                            String[] orderByFields = orderByComparator.getOrderByFields();
13878    
13879                            for (int i = 0; i < orderByFields.length; i++) {
13880                                    if (getDB().isSupportsInlineDistinct()) {
13881                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13882                                    }
13883                                    else {
13884                                            query.append(_ORDER_BY_ENTITY_TABLE);
13885                                    }
13886    
13887                                    query.append(orderByFields[i]);
13888    
13889                                    if ((i + 1) < orderByFields.length) {
13890                                            if (orderByComparator.isAscending() ^ previous) {
13891                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13892                                            }
13893                                            else {
13894                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13895                                            }
13896                                    }
13897                                    else {
13898                                            if (orderByComparator.isAscending() ^ previous) {
13899                                                    query.append(ORDER_BY_ASC);
13900                                            }
13901                                            else {
13902                                                    query.append(ORDER_BY_DESC);
13903                                            }
13904                                    }
13905                            }
13906                    }
13907                    else {
13908                            if (getDB().isSupportsInlineDistinct()) {
13909                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13910                            }
13911                            else {
13912                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13913                            }
13914                    }
13915    
13916                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13917                                    MBMessage.class.getName(),
13918                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13919    
13920                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13921    
13922                    q.setFirstResult(0);
13923                    q.setMaxResults(2);
13924    
13925                    if (getDB().isSupportsInlineDistinct()) {
13926                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13927                    }
13928                    else {
13929                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13930                    }
13931    
13932                    QueryPos qPos = QueryPos.getInstance(q);
13933    
13934                    qPos.add(groupId);
13935    
13936                    qPos.add(categoryId);
13937    
13938                    qPos.add(status);
13939    
13940                    if (orderByComparator != null) {
13941                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13942    
13943                            for (Object value : values) {
13944                                    qPos.add(value);
13945                            }
13946                    }
13947    
13948                    List<MBMessage> list = q.list();
13949    
13950                    if (list.size() == 2) {
13951                            return list.get(1);
13952                    }
13953                    else {
13954                            return null;
13955                    }
13956            }
13957    
13958            /**
13959             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13960             *
13961             * @param groupId the group ID
13962             * @param categoryId the category ID
13963             * @param status the status
13964             */
13965            @Override
13966            public void removeByG_C_S(long groupId, long categoryId, int status) {
13967                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13968                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13969                            remove(mbMessage);
13970                    }
13971            }
13972    
13973            /**
13974             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13975             *
13976             * @param groupId the group ID
13977             * @param categoryId the category ID
13978             * @param status the status
13979             * @return the number of matching message-boards messages
13980             */
13981            @Override
13982            public int countByG_C_S(long groupId, long categoryId, int status) {
13983                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13984    
13985                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13986    
13987                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13988    
13989                    if (count == null) {
13990                            StringBundler query = new StringBundler(4);
13991    
13992                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13993    
13994                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13995    
13996                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13997    
13998                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13999    
14000                            String sql = query.toString();
14001    
14002                            Session session = null;
14003    
14004                            try {
14005                                    session = openSession();
14006    
14007                                    Query q = session.createQuery(sql);
14008    
14009                                    QueryPos qPos = QueryPos.getInstance(q);
14010    
14011                                    qPos.add(groupId);
14012    
14013                                    qPos.add(categoryId);
14014    
14015                                    qPos.add(status);
14016    
14017                                    count = (Long)q.uniqueResult();
14018    
14019                                    finderCache.putResult(finderPath, finderArgs, count);
14020                            }
14021                            catch (Exception e) {
14022                                    finderCache.removeResult(finderPath, finderArgs);
14023    
14024                                    throw processException(e);
14025                            }
14026                            finally {
14027                                    closeSession(session);
14028                            }
14029                    }
14030    
14031                    return count.intValue();
14032            }
14033    
14034            /**
14035             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
14036             *
14037             * @param groupId the group ID
14038             * @param categoryId the category ID
14039             * @param status the status
14040             * @return the number of matching message-boards messages that the user has permission to view
14041             */
14042            @Override
14043            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
14044                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14045                            return countByG_C_S(groupId, categoryId, status);
14046                    }
14047    
14048                    StringBundler query = new StringBundler(4);
14049    
14050                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
14051    
14052                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14053    
14054                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14055    
14056                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14057    
14058                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14059                                    MBMessage.class.getName(),
14060                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14061    
14062                    Session session = null;
14063    
14064                    try {
14065                            session = openSession();
14066    
14067                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
14068    
14069                            q.addScalar(COUNT_COLUMN_NAME,
14070                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14071    
14072                            QueryPos qPos = QueryPos.getInstance(q);
14073    
14074                            qPos.add(groupId);
14075    
14076                            qPos.add(categoryId);
14077    
14078                            qPos.add(status);
14079    
14080                            Long count = (Long)q.uniqueResult();
14081    
14082                            return count.intValue();
14083                    }
14084                    catch (Exception e) {
14085                            throw processException(e);
14086                    }
14087                    finally {
14088                            closeSession(session);
14089                    }
14090            }
14091    
14092            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
14093            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
14094            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
14095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
14098                            new String[] {
14099                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14100                                    
14101                            Integer.class.getName(), Integer.class.getName(),
14102                                    OrderByComparator.class.getName()
14103                            });
14104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14105                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
14107                            new String[] {
14108                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14109                            },
14110                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14111                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14112                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14113                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14114            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
14117                            new String[] {
14118                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14119                            });
14120    
14121            /**
14122             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14123             *
14124             * @param userId the user ID
14125             * @param classNameId the class name ID
14126             * @param classPK the class p k
14127             * @return the matching message-boards messages
14128             */
14129            @Override
14130            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14131                    long classPK) {
14132                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
14133                            QueryUtil.ALL_POS, null);
14134            }
14135    
14136            /**
14137             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14138             *
14139             * <p>
14140             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14141             * </p>
14142             *
14143             * @param userId the user ID
14144             * @param classNameId the class name ID
14145             * @param classPK the class p k
14146             * @param start the lower bound of the range of message-boards messages
14147             * @param end the upper bound of the range of message-boards messages (not inclusive)
14148             * @return the range of matching message-boards messages
14149             */
14150            @Override
14151            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14152                    long classPK, int start, int end) {
14153                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
14154            }
14155    
14156            /**
14157             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14158             *
14159             * <p>
14160             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14161             * </p>
14162             *
14163             * @param userId the user ID
14164             * @param classNameId the class name ID
14165             * @param classPK the class p k
14166             * @param start the lower bound of the range of message-boards messages
14167             * @param end the upper bound of the range of message-boards messages (not inclusive)
14168             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14169             * @return the ordered range of matching message-boards messages
14170             */
14171            @Override
14172            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14173                    long classPK, int start, int end,
14174                    OrderByComparator<MBMessage> orderByComparator) {
14175                    return findByU_C_C(userId, classNameId, classPK, start, end,
14176                            orderByComparator, true);
14177            }
14178    
14179            /**
14180             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14181             *
14182             * <p>
14183             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14184             * </p>
14185             *
14186             * @param userId the user ID
14187             * @param classNameId the class name ID
14188             * @param classPK the class p k
14189             * @param start the lower bound of the range of message-boards messages
14190             * @param end the upper bound of the range of message-boards messages (not inclusive)
14191             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14192             * @param retrieveFromCache whether to retrieve from the finder cache
14193             * @return the ordered range of matching message-boards messages
14194             */
14195            @Override
14196            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14197                    long classPK, int start, int end,
14198                    OrderByComparator<MBMessage> orderByComparator,
14199                    boolean retrieveFromCache) {
14200                    boolean pagination = true;
14201                    FinderPath finderPath = null;
14202                    Object[] finderArgs = null;
14203    
14204                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14205                                    (orderByComparator == null)) {
14206                            pagination = false;
14207                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
14208                            finderArgs = new Object[] { userId, classNameId, classPK };
14209                    }
14210                    else {
14211                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
14212                            finderArgs = new Object[] {
14213                                            userId, classNameId, classPK,
14214                                            
14215                                            start, end, orderByComparator
14216                                    };
14217                    }
14218    
14219                    List<MBMessage> list = null;
14220    
14221                    if (retrieveFromCache) {
14222                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14223                                            finderArgs, this);
14224    
14225                            if ((list != null) && !list.isEmpty()) {
14226                                    for (MBMessage mbMessage : list) {
14227                                            if ((userId != mbMessage.getUserId()) ||
14228                                                            (classNameId != mbMessage.getClassNameId()) ||
14229                                                            (classPK != mbMessage.getClassPK())) {
14230                                                    list = null;
14231    
14232                                                    break;
14233                                            }
14234                                    }
14235                            }
14236                    }
14237    
14238                    if (list == null) {
14239                            StringBundler query = null;
14240    
14241                            if (orderByComparator != null) {
14242                                    query = new StringBundler(5 +
14243                                                    (orderByComparator.getOrderByFields().length * 3));
14244                            }
14245                            else {
14246                                    query = new StringBundler(5);
14247                            }
14248    
14249                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14250    
14251                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14252    
14253                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14254    
14255                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14256    
14257                            if (orderByComparator != null) {
14258                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14259                                            orderByComparator);
14260                            }
14261                            else
14262                             if (pagination) {
14263                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14264                            }
14265    
14266                            String sql = query.toString();
14267    
14268                            Session session = null;
14269    
14270                            try {
14271                                    session = openSession();
14272    
14273                                    Query q = session.createQuery(sql);
14274    
14275                                    QueryPos qPos = QueryPos.getInstance(q);
14276    
14277                                    qPos.add(userId);
14278    
14279                                    qPos.add(classNameId);
14280    
14281                                    qPos.add(classPK);
14282    
14283                                    if (!pagination) {
14284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14285                                                            start, end, false);
14286    
14287                                            Collections.sort(list);
14288    
14289                                            list = Collections.unmodifiableList(list);
14290                                    }
14291                                    else {
14292                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14293                                                            start, end);
14294                                    }
14295    
14296                                    cacheResult(list);
14297    
14298                                    finderCache.putResult(finderPath, finderArgs, list);
14299                            }
14300                            catch (Exception e) {
14301                                    finderCache.removeResult(finderPath, finderArgs);
14302    
14303                                    throw processException(e);
14304                            }
14305                            finally {
14306                                    closeSession(session);
14307                            }
14308                    }
14309    
14310                    return list;
14311            }
14312    
14313            /**
14314             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14315             *
14316             * @param userId the user ID
14317             * @param classNameId the class name ID
14318             * @param classPK the class p k
14319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14320             * @return the first matching message-boards message
14321             * @throws NoSuchMessageException if a matching message-boards message could not be found
14322             */
14323            @Override
14324            public MBMessage findByU_C_C_First(long userId, long classNameId,
14325                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14326                    throws NoSuchMessageException {
14327                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14328                                    orderByComparator);
14329    
14330                    if (mbMessage != null) {
14331                            return mbMessage;
14332                    }
14333    
14334                    StringBundler msg = new StringBundler(8);
14335    
14336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14337    
14338                    msg.append("userId=");
14339                    msg.append(userId);
14340    
14341                    msg.append(", classNameId=");
14342                    msg.append(classNameId);
14343    
14344                    msg.append(", classPK=");
14345                    msg.append(classPK);
14346    
14347                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14348    
14349                    throw new NoSuchMessageException(msg.toString());
14350            }
14351    
14352            /**
14353             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14354             *
14355             * @param userId the user ID
14356             * @param classNameId the class name ID
14357             * @param classPK the class p k
14358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14359             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14360             */
14361            @Override
14362            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14363                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14364                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14365                                    orderByComparator);
14366    
14367                    if (!list.isEmpty()) {
14368                            return list.get(0);
14369                    }
14370    
14371                    return null;
14372            }
14373    
14374            /**
14375             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14376             *
14377             * @param userId the user ID
14378             * @param classNameId the class name ID
14379             * @param classPK the class p k
14380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14381             * @return the last matching message-boards message
14382             * @throws NoSuchMessageException if a matching message-boards message could not be found
14383             */
14384            @Override
14385            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14386                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14387                    throws NoSuchMessageException {
14388                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14389                                    orderByComparator);
14390    
14391                    if (mbMessage != null) {
14392                            return mbMessage;
14393                    }
14394    
14395                    StringBundler msg = new StringBundler(8);
14396    
14397                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14398    
14399                    msg.append("userId=");
14400                    msg.append(userId);
14401    
14402                    msg.append(", classNameId=");
14403                    msg.append(classNameId);
14404    
14405                    msg.append(", classPK=");
14406                    msg.append(classPK);
14407    
14408                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14409    
14410                    throw new NoSuchMessageException(msg.toString());
14411            }
14412    
14413            /**
14414             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14415             *
14416             * @param userId the user ID
14417             * @param classNameId the class name ID
14418             * @param classPK the class p k
14419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14420             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14421             */
14422            @Override
14423            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14424                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14425                    int count = countByU_C_C(userId, classNameId, classPK);
14426    
14427                    if (count == 0) {
14428                            return null;
14429                    }
14430    
14431                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14432                                    count - 1, count, orderByComparator);
14433    
14434                    if (!list.isEmpty()) {
14435                            return list.get(0);
14436                    }
14437    
14438                    return null;
14439            }
14440    
14441            /**
14442             * 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;.
14443             *
14444             * @param messageId the primary key of the current message-boards message
14445             * @param userId the user ID
14446             * @param classNameId the class name ID
14447             * @param classPK the class p k
14448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14449             * @return the previous, current, and next message-boards message
14450             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14451             */
14452            @Override
14453            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14454                    long classNameId, long classPK,
14455                    OrderByComparator<MBMessage> orderByComparator)
14456                    throws NoSuchMessageException {
14457                    MBMessage mbMessage = findByPrimaryKey(messageId);
14458    
14459                    Session session = null;
14460    
14461                    try {
14462                            session = openSession();
14463    
14464                            MBMessage[] array = new MBMessageImpl[3];
14465    
14466                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14467                                            classNameId, classPK, orderByComparator, true);
14468    
14469                            array[1] = mbMessage;
14470    
14471                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14472                                            classNameId, classPK, orderByComparator, false);
14473    
14474                            return array;
14475                    }
14476                    catch (Exception e) {
14477                            throw processException(e);
14478                    }
14479                    finally {
14480                            closeSession(session);
14481                    }
14482            }
14483    
14484            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14485                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14486                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14487                    StringBundler query = null;
14488    
14489                    if (orderByComparator != null) {
14490                            query = new StringBundler(6 +
14491                                            (orderByComparator.getOrderByFields().length * 6));
14492                    }
14493                    else {
14494                            query = new StringBundler(3);
14495                    }
14496    
14497                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14498    
14499                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14500    
14501                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14502    
14503                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14504    
14505                    if (orderByComparator != null) {
14506                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14507    
14508                            if (orderByConditionFields.length > 0) {
14509                                    query.append(WHERE_AND);
14510                            }
14511    
14512                            for (int i = 0; i < orderByConditionFields.length; i++) {
14513                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14514                                    query.append(orderByConditionFields[i]);
14515    
14516                                    if ((i + 1) < orderByConditionFields.length) {
14517                                            if (orderByComparator.isAscending() ^ previous) {
14518                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14519                                            }
14520                                            else {
14521                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14522                                            }
14523                                    }
14524                                    else {
14525                                            if (orderByComparator.isAscending() ^ previous) {
14526                                                    query.append(WHERE_GREATER_THAN);
14527                                            }
14528                                            else {
14529                                                    query.append(WHERE_LESSER_THAN);
14530                                            }
14531                                    }
14532                            }
14533    
14534                            query.append(ORDER_BY_CLAUSE);
14535    
14536                            String[] orderByFields = orderByComparator.getOrderByFields();
14537    
14538                            for (int i = 0; i < orderByFields.length; i++) {
14539                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14540                                    query.append(orderByFields[i]);
14541    
14542                                    if ((i + 1) < orderByFields.length) {
14543                                            if (orderByComparator.isAscending() ^ previous) {
14544                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14545                                            }
14546                                            else {
14547                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14548                                            }
14549                                    }
14550                                    else {
14551                                            if (orderByComparator.isAscending() ^ previous) {
14552                                                    query.append(ORDER_BY_ASC);
14553                                            }
14554                                            else {
14555                                                    query.append(ORDER_BY_DESC);
14556                                            }
14557                                    }
14558                            }
14559                    }
14560                    else {
14561                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14562                    }
14563    
14564                    String sql = query.toString();
14565    
14566                    Query q = session.createQuery(sql);
14567    
14568                    q.setFirstResult(0);
14569                    q.setMaxResults(2);
14570    
14571                    QueryPos qPos = QueryPos.getInstance(q);
14572    
14573                    qPos.add(userId);
14574    
14575                    qPos.add(classNameId);
14576    
14577                    qPos.add(classPK);
14578    
14579                    if (orderByComparator != null) {
14580                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14581    
14582                            for (Object value : values) {
14583                                    qPos.add(value);
14584                            }
14585                    }
14586    
14587                    List<MBMessage> list = q.list();
14588    
14589                    if (list.size() == 2) {
14590                            return list.get(1);
14591                    }
14592                    else {
14593                            return null;
14594                    }
14595            }
14596    
14597            /**
14598             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14599             *
14600             * @param userId the user ID
14601             * @param classNameId the class name ID
14602             * @param classPK the class p k
14603             */
14604            @Override
14605            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14606                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14607                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14608                            remove(mbMessage);
14609                    }
14610            }
14611    
14612            /**
14613             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14614             *
14615             * @param userId the user ID
14616             * @param classNameId the class name ID
14617             * @param classPK the class p k
14618             * @return the number of matching message-boards messages
14619             */
14620            @Override
14621            public int countByU_C_C(long userId, long classNameId, long classPK) {
14622                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14623    
14624                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14625    
14626                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14627    
14628                    if (count == null) {
14629                            StringBundler query = new StringBundler(4);
14630    
14631                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14632    
14633                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14634    
14635                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14636    
14637                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14638    
14639                            String sql = query.toString();
14640    
14641                            Session session = null;
14642    
14643                            try {
14644                                    session = openSession();
14645    
14646                                    Query q = session.createQuery(sql);
14647    
14648                                    QueryPos qPos = QueryPos.getInstance(q);
14649    
14650                                    qPos.add(userId);
14651    
14652                                    qPos.add(classNameId);
14653    
14654                                    qPos.add(classPK);
14655    
14656                                    count = (Long)q.uniqueResult();
14657    
14658                                    finderCache.putResult(finderPath, finderArgs, count);
14659                            }
14660                            catch (Exception e) {
14661                                    finderCache.removeResult(finderPath, finderArgs);
14662    
14663                                    throw processException(e);
14664                            }
14665                            finally {
14666                                    closeSession(session);
14667                            }
14668                    }
14669    
14670                    return count.intValue();
14671            }
14672    
14673            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14674            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14675            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14676            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14677                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14678                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14679                            new String[] {
14680                                    Long.class.getName(), Long.class.getName(),
14681                                    Integer.class.getName(),
14682                                    
14683                            Integer.class.getName(), Integer.class.getName(),
14684                                    OrderByComparator.class.getName()
14685                            });
14686            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14687                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14688                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14689                            new String[] {
14690                                    Long.class.getName(), Long.class.getName(),
14691                                    Integer.class.getName()
14692                            },
14693                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14694                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14695                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14696                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14697            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14698                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14699                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14700                            new String[] {
14701                                    Long.class.getName(), Long.class.getName(),
14702                                    Integer.class.getName()
14703                            });
14704            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14705                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14706                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14707                            new String[] {
14708                                    Long.class.getName(), Long.class.getName(),
14709                                    Integer.class.getName()
14710                            });
14711    
14712            /**
14713             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14714             *
14715             * @param userId the user ID
14716             * @param classNameId the class name ID
14717             * @param status the status
14718             * @return the matching message-boards messages
14719             */
14720            @Override
14721            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14722                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14723                            QueryUtil.ALL_POS, null);
14724            }
14725    
14726            /**
14727             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14728             *
14729             * <p>
14730             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14731             * </p>
14732             *
14733             * @param userId the user ID
14734             * @param classNameId the class name ID
14735             * @param status the status
14736             * @param start the lower bound of the range of message-boards messages
14737             * @param end the upper bound of the range of message-boards messages (not inclusive)
14738             * @return the range of matching message-boards messages
14739             */
14740            @Override
14741            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14742                    int status, int start, int end) {
14743                    return findByU_C_S(userId, classNameId, status, start, end, null);
14744            }
14745    
14746            /**
14747             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14748             *
14749             * <p>
14750             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14751             * </p>
14752             *
14753             * @param userId the user ID
14754             * @param classNameId the class name ID
14755             * @param status the status
14756             * @param start the lower bound of the range of message-boards messages
14757             * @param end the upper bound of the range of message-boards messages (not inclusive)
14758             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14759             * @return the ordered range of matching message-boards messages
14760             */
14761            @Override
14762            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14763                    int status, int start, int end,
14764                    OrderByComparator<MBMessage> orderByComparator) {
14765                    return findByU_C_S(userId, classNameId, status, start, end,
14766                            orderByComparator, true);
14767            }
14768    
14769            /**
14770             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14771             *
14772             * <p>
14773             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
14774             * </p>
14775             *
14776             * @param userId the user ID
14777             * @param classNameId the class name ID
14778             * @param status the status
14779             * @param start the lower bound of the range of message-boards messages
14780             * @param end the upper bound of the range of message-boards messages (not inclusive)
14781             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14782             * @param retrieveFromCache whether to retrieve from the finder cache
14783             * @return the ordered range of matching message-boards messages
14784             */
14785            @Override
14786            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14787                    int status, int start, int end,
14788                    OrderByComparator<MBMessage> orderByComparator,
14789                    boolean retrieveFromCache) {
14790                    boolean pagination = true;
14791                    FinderPath finderPath = null;
14792                    Object[] finderArgs = null;
14793    
14794                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14795                                    (orderByComparator == null)) {
14796                            pagination = false;
14797                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14798                            finderArgs = new Object[] { userId, classNameId, status };
14799                    }
14800                    else {
14801                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14802                            finderArgs = new Object[] {
14803                                            userId, classNameId, status,
14804                                            
14805                                            start, end, orderByComparator
14806                                    };
14807                    }
14808    
14809                    List<MBMessage> list = null;
14810    
14811                    if (retrieveFromCache) {
14812                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14813                                            finderArgs, this);
14814    
14815                            if ((list != null) && !list.isEmpty()) {
14816                                    for (MBMessage mbMessage : list) {
14817                                            if ((userId != mbMessage.getUserId()) ||
14818                                                            (classNameId != mbMessage.getClassNameId()) ||
14819                                                            (status != mbMessage.getStatus())) {
14820                                                    list = null;
14821    
14822                                                    break;
14823                                            }
14824                                    }
14825                            }
14826                    }
14827    
14828                    if (list == null) {
14829                            StringBundler query = null;
14830    
14831                            if (orderByComparator != null) {
14832                                    query = new StringBundler(5 +
14833                                                    (orderByComparator.getOrderByFields().length * 3));
14834                            }
14835                            else {
14836                                    query = new StringBundler(5);
14837                            }
14838    
14839                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14840    
14841                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14842    
14843                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14844    
14845                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14846    
14847                            if (orderByComparator != null) {
14848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14849                                            orderByComparator);
14850                            }
14851                            else
14852                             if (pagination) {
14853                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14854                            }
14855    
14856                            String sql = query.toString();
14857    
14858                            Session session = null;
14859    
14860                            try {
14861                                    session = openSession();
14862    
14863                                    Query q = session.createQuery(sql);
14864    
14865                                    QueryPos qPos = QueryPos.getInstance(q);
14866    
14867                                    qPos.add(userId);
14868    
14869                                    qPos.add(classNameId);
14870    
14871                                    qPos.add(status);
14872    
14873                                    if (!pagination) {
14874                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14875                                                            start, end, false);
14876    
14877                                            Collections.sort(list);
14878    
14879                                            list = Collections.unmodifiableList(list);
14880                                    }
14881                                    else {
14882                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14883                                                            start, end);
14884                                    }
14885    
14886                                    cacheResult(list);
14887    
14888                                    finderCache.putResult(finderPath, finderArgs, list);
14889                            }
14890                            catch (Exception e) {
14891                                    finderCache.removeResult(finderPath, finderArgs);
14892    
14893                                    throw processException(e);
14894                            }
14895                            finally {
14896                                    closeSession(session);
14897                            }
14898                    }
14899    
14900                    return list;
14901            }
14902    
14903            /**
14904             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14905             *
14906             * @param userId the user ID
14907             * @param classNameId the class name ID
14908             * @param status the status
14909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14910             * @return the first matching message-boards message
14911             * @throws NoSuchMessageException if a matching message-boards message could not be found
14912             */
14913            @Override
14914            public MBMessage findByU_C_S_First(long userId, long classNameId,
14915                    int status, OrderByComparator<MBMessage> orderByComparator)
14916                    throws NoSuchMessageException {
14917                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14918                                    orderByComparator);
14919    
14920                    if (mbMessage != null) {
14921                            return mbMessage;
14922                    }
14923    
14924                    StringBundler msg = new StringBundler(8);
14925    
14926                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14927    
14928                    msg.append("userId=");
14929                    msg.append(userId);
14930    
14931                    msg.append(", classNameId=");
14932                    msg.append(classNameId);
14933    
14934                    msg.append(", status=");
14935                    msg.append(status);
14936    
14937                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14938    
14939                    throw new NoSuchMessageException(msg.toString());
14940            }
14941    
14942            /**
14943             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14944             *
14945             * @param userId the user ID
14946             * @param classNameId the class name ID
14947             * @param status the status
14948             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14949             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14950             */
14951            @Override
14952            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14953                    int status, OrderByComparator<MBMessage> orderByComparator) {
14954                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14955                                    orderByComparator);
14956    
14957                    if (!list.isEmpty()) {
14958                            return list.get(0);
14959                    }
14960    
14961                    return null;
14962            }
14963    
14964            /**
14965             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14966             *
14967             * @param userId the user ID
14968             * @param classNameId the class name ID
14969             * @param status the status
14970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14971             * @return the last matching message-boards message
14972             * @throws NoSuchMessageException if a matching message-boards message could not be found
14973             */
14974            @Override
14975            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14976                    int status, OrderByComparator<MBMessage> orderByComparator)
14977                    throws NoSuchMessageException {
14978                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14979                                    orderByComparator);
14980    
14981                    if (mbMessage != null) {
14982                            return mbMessage;
14983                    }
14984    
14985                    StringBundler msg = new StringBundler(8);
14986    
14987                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14988    
14989                    msg.append("userId=");
14990                    msg.append(userId);
14991    
14992                    msg.append(", classNameId=");
14993                    msg.append(classNameId);
14994    
14995                    msg.append(", status=");
14996                    msg.append(status);
14997    
14998                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14999    
15000                    throw new NoSuchMessageException(msg.toString());
15001            }
15002    
15003            /**
15004             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
15005             *
15006             * @param userId the user ID
15007             * @param classNameId the class name ID
15008             * @param status the status
15009             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15010             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15011             */
15012            @Override
15013            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
15014                    int status, OrderByComparator<MBMessage> orderByComparator) {
15015                    int count = countByU_C_S(userId, classNameId, status);
15016    
15017                    if (count == 0) {
15018                            return null;
15019                    }
15020    
15021                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
15022                                    count - 1, count, orderByComparator);
15023    
15024                    if (!list.isEmpty()) {
15025                            return list.get(0);
15026                    }
15027    
15028                    return null;
15029            }
15030    
15031            /**
15032             * 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;.
15033             *
15034             * @param messageId the primary key of the current message-boards message
15035             * @param userId the user ID
15036             * @param classNameId the class name ID
15037             * @param status the status
15038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15039             * @return the previous, current, and next message-boards message
15040             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15041             */
15042            @Override
15043            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
15044                    long classNameId, int status,
15045                    OrderByComparator<MBMessage> orderByComparator)
15046                    throws NoSuchMessageException {
15047                    MBMessage mbMessage = findByPrimaryKey(messageId);
15048    
15049                    Session session = null;
15050    
15051                    try {
15052                            session = openSession();
15053    
15054                            MBMessage[] array = new MBMessageImpl[3];
15055    
15056                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15057                                            classNameId, status, orderByComparator, true);
15058    
15059                            array[1] = mbMessage;
15060    
15061                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15062                                            classNameId, status, orderByComparator, false);
15063    
15064                            return array;
15065                    }
15066                    catch (Exception e) {
15067                            throw processException(e);
15068                    }
15069                    finally {
15070                            closeSession(session);
15071                    }
15072            }
15073    
15074            protected MBMessage getByU_C_S_PrevAndNext(Session session,
15075                    MBMessage mbMessage, long userId, long classNameId, int status,
15076                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15077                    StringBundler query = null;
15078    
15079                    if (orderByComparator != null) {
15080                            query = new StringBundler(6 +
15081                                            (orderByComparator.getOrderByFields().length * 6));
15082                    }
15083                    else {
15084                            query = new StringBundler(3);
15085                    }
15086    
15087                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15088    
15089                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15090    
15091                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15092    
15093                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15094    
15095                    if (orderByComparator != null) {
15096                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15097    
15098                            if (orderByConditionFields.length > 0) {
15099                                    query.append(WHERE_AND);
15100                            }
15101    
15102                            for (int i = 0; i < orderByConditionFields.length; i++) {
15103                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15104                                    query.append(orderByConditionFields[i]);
15105    
15106                                    if ((i + 1) < orderByConditionFields.length) {
15107                                            if (orderByComparator.isAscending() ^ previous) {
15108                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15109                                            }
15110                                            else {
15111                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15112                                            }
15113                                    }
15114                                    else {
15115                                            if (orderByComparator.isAscending() ^ previous) {
15116                                                    query.append(WHERE_GREATER_THAN);
15117                                            }
15118                                            else {
15119                                                    query.append(WHERE_LESSER_THAN);
15120                                            }
15121                                    }
15122                            }
15123    
15124                            query.append(ORDER_BY_CLAUSE);
15125    
15126                            String[] orderByFields = orderByComparator.getOrderByFields();
15127    
15128                            for (int i = 0; i < orderByFields.length; i++) {
15129                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15130                                    query.append(orderByFields[i]);
15131    
15132                                    if ((i + 1) < orderByFields.length) {
15133                                            if (orderByComparator.isAscending() ^ previous) {
15134                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15135                                            }
15136                                            else {
15137                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15138                                            }
15139                                    }
15140                                    else {
15141                                            if (orderByComparator.isAscending() ^ previous) {
15142                                                    query.append(ORDER_BY_ASC);
15143                                            }
15144                                            else {
15145                                                    query.append(ORDER_BY_DESC);
15146                                            }
15147                                    }
15148                            }
15149                    }
15150                    else {
15151                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15152                    }
15153    
15154                    String sql = query.toString();
15155    
15156                    Query q = session.createQuery(sql);
15157    
15158                    q.setFirstResult(0);
15159                    q.setMaxResults(2);
15160    
15161                    QueryPos qPos = QueryPos.getInstance(q);
15162    
15163                    qPos.add(userId);
15164    
15165                    qPos.add(classNameId);
15166    
15167                    qPos.add(status);
15168    
15169                    if (orderByComparator != null) {
15170                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15171    
15172                            for (Object value : values) {
15173                                    qPos.add(value);
15174                            }
15175                    }
15176    
15177                    List<MBMessage> list = q.list();
15178    
15179                    if (list.size() == 2) {
15180                            return list.get(1);
15181                    }
15182                    else {
15183                            return null;
15184                    }
15185            }
15186    
15187            /**
15188             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15189             *
15190             * <p>
15191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15192             * </p>
15193             *
15194             * @param userId the user ID
15195             * @param classNameIds the class name IDs
15196             * @param status the status
15197             * @return the matching message-boards messages
15198             */
15199            @Override
15200            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15201                    int status) {
15202                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
15203                            QueryUtil.ALL_POS, null);
15204            }
15205    
15206            /**
15207             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15208             *
15209             * <p>
15210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15211             * </p>
15212             *
15213             * @param userId the user ID
15214             * @param classNameIds the class name IDs
15215             * @param status the status
15216             * @param start the lower bound of the range of message-boards messages
15217             * @param end the upper bound of the range of message-boards messages (not inclusive)
15218             * @return the range of matching message-boards messages
15219             */
15220            @Override
15221            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15222                    int status, int start, int end) {
15223                    return findByU_C_S(userId, classNameIds, status, start, end, null);
15224            }
15225    
15226            /**
15227             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15228             *
15229             * <p>
15230             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15231             * </p>
15232             *
15233             * @param userId the user ID
15234             * @param classNameIds the class name IDs
15235             * @param status the status
15236             * @param start the lower bound of the range of message-boards messages
15237             * @param end the upper bound of the range of message-boards messages (not inclusive)
15238             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15239             * @return the ordered range of matching message-boards messages
15240             */
15241            @Override
15242            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15243                    int status, int start, int end,
15244                    OrderByComparator<MBMessage> orderByComparator) {
15245                    return findByU_C_S(userId, classNameIds, status, start, end,
15246                            orderByComparator, true);
15247            }
15248    
15249            /**
15250             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;, optionally using the finder cache.
15251             *
15252             * <p>
15253             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15254             * </p>
15255             *
15256             * @param userId the user ID
15257             * @param classNameId the class name ID
15258             * @param status the status
15259             * @param start the lower bound of the range of message-boards messages
15260             * @param end the upper bound of the range of message-boards messages (not inclusive)
15261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15262             * @param retrieveFromCache whether to retrieve from the finder cache
15263             * @return the ordered range of matching message-boards messages
15264             */
15265            @Override
15266            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15267                    int status, int start, int end,
15268                    OrderByComparator<MBMessage> orderByComparator,
15269                    boolean retrieveFromCache) {
15270                    if (classNameIds == null) {
15271                            classNameIds = new long[0];
15272                    }
15273                    else if (classNameIds.length > 1) {
15274                            classNameIds = ArrayUtil.unique(classNameIds);
15275    
15276                            Arrays.sort(classNameIds);
15277                    }
15278    
15279                    if (classNameIds.length == 1) {
15280                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15281                                    orderByComparator);
15282                    }
15283    
15284                    boolean pagination = true;
15285                    Object[] finderArgs = null;
15286    
15287                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15288                                    (orderByComparator == null)) {
15289                            pagination = false;
15290                            finderArgs = new Object[] {
15291                                            userId, StringUtil.merge(classNameIds), status
15292                                    };
15293                    }
15294                    else {
15295                            finderArgs = new Object[] {
15296                                            userId, StringUtil.merge(classNameIds), status,
15297                                            
15298                                            start, end, orderByComparator
15299                                    };
15300                    }
15301    
15302                    List<MBMessage> list = null;
15303    
15304                    if (retrieveFromCache) {
15305                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15306                                            finderArgs, this);
15307    
15308                            if ((list != null) && !list.isEmpty()) {
15309                                    for (MBMessage mbMessage : list) {
15310                                            if ((userId != mbMessage.getUserId()) ||
15311                                                            !ArrayUtil.contains(classNameIds,
15312                                                                    mbMessage.getClassNameId()) ||
15313                                                            (status != mbMessage.getStatus())) {
15314                                                    list = null;
15315    
15316                                                    break;
15317                                            }
15318                                    }
15319                            }
15320                    }
15321    
15322                    if (list == null) {
15323                            StringBundler query = new StringBundler();
15324    
15325                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15326    
15327                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15328    
15329                            if (classNameIds.length > 0) {
15330                                    query.append(StringPool.OPEN_PARENTHESIS);
15331    
15332                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15333    
15334                                    query.append(StringUtil.merge(classNameIds));
15335    
15336                                    query.append(StringPool.CLOSE_PARENTHESIS);
15337    
15338                                    query.append(StringPool.CLOSE_PARENTHESIS);
15339    
15340                                    query.append(WHERE_AND);
15341                            }
15342    
15343                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15344    
15345                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15346                                                    1)), query.index() - 1);
15347    
15348                            if (orderByComparator != null) {
15349                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15350                                            orderByComparator);
15351                            }
15352                            else
15353                             if (pagination) {
15354                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15355                            }
15356    
15357                            String sql = query.toString();
15358    
15359                            Session session = null;
15360    
15361                            try {
15362                                    session = openSession();
15363    
15364                                    Query q = session.createQuery(sql);
15365    
15366                                    QueryPos qPos = QueryPos.getInstance(q);
15367    
15368                                    qPos.add(userId);
15369    
15370                                    qPos.add(status);
15371    
15372                                    if (!pagination) {
15373                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15374                                                            start, end, false);
15375    
15376                                            Collections.sort(list);
15377    
15378                                            list = Collections.unmodifiableList(list);
15379                                    }
15380                                    else {
15381                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15382                                                            start, end);
15383                                    }
15384    
15385                                    cacheResult(list);
15386    
15387                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15388                                            finderArgs, list);
15389                            }
15390                            catch (Exception e) {
15391                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15392                                            finderArgs);
15393    
15394                                    throw processException(e);
15395                            }
15396                            finally {
15397                                    closeSession(session);
15398                            }
15399                    }
15400    
15401                    return list;
15402            }
15403    
15404            /**
15405             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15406             *
15407             * @param userId the user ID
15408             * @param classNameId the class name ID
15409             * @param status the status
15410             */
15411            @Override
15412            public void removeByU_C_S(long userId, long classNameId, int status) {
15413                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15414                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15415                            remove(mbMessage);
15416                    }
15417            }
15418    
15419            /**
15420             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15421             *
15422             * @param userId the user ID
15423             * @param classNameId the class name ID
15424             * @param status the status
15425             * @return the number of matching message-boards messages
15426             */
15427            @Override
15428            public int countByU_C_S(long userId, long classNameId, int status) {
15429                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15430    
15431                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15432    
15433                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
15434    
15435                    if (count == null) {
15436                            StringBundler query = new StringBundler(4);
15437    
15438                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15439    
15440                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15441    
15442                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15443    
15444                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15445    
15446                            String sql = query.toString();
15447    
15448                            Session session = null;
15449    
15450                            try {
15451                                    session = openSession();
15452    
15453                                    Query q = session.createQuery(sql);
15454    
15455                                    QueryPos qPos = QueryPos.getInstance(q);
15456    
15457                                    qPos.add(userId);
15458    
15459                                    qPos.add(classNameId);
15460    
15461                                    qPos.add(status);
15462    
15463                                    count = (Long)q.uniqueResult();
15464    
15465                                    finderCache.putResult(finderPath, finderArgs, count);
15466                            }
15467                            catch (Exception e) {
15468                                    finderCache.removeResult(finderPath, finderArgs);
15469    
15470                                    throw processException(e);
15471                            }
15472                            finally {
15473                                    closeSession(session);
15474                            }
15475                    }
15476    
15477                    return count.intValue();
15478            }
15479    
15480            /**
15481             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15482             *
15483             * @param userId the user ID
15484             * @param classNameIds the class name IDs
15485             * @param status the status
15486             * @return the number of matching message-boards messages
15487             */
15488            @Override
15489            public int countByU_C_S(long userId, long[] classNameIds, int status) {
15490                    if (classNameIds == null) {
15491                            classNameIds = new long[0];
15492                    }
15493                    else if (classNameIds.length > 1) {
15494                            classNameIds = ArrayUtil.unique(classNameIds);
15495    
15496                            Arrays.sort(classNameIds);
15497                    }
15498    
15499                    Object[] finderArgs = new Object[] {
15500                                    userId, StringUtil.merge(classNameIds), status
15501                            };
15502    
15503                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15504                                    finderArgs, this);
15505    
15506                    if (count == null) {
15507                            StringBundler query = new StringBundler();
15508    
15509                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15510    
15511                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15512    
15513                            if (classNameIds.length > 0) {
15514                                    query.append(StringPool.OPEN_PARENTHESIS);
15515    
15516                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15517    
15518                                    query.append(StringUtil.merge(classNameIds));
15519    
15520                                    query.append(StringPool.CLOSE_PARENTHESIS);
15521    
15522                                    query.append(StringPool.CLOSE_PARENTHESIS);
15523    
15524                                    query.append(WHERE_AND);
15525                            }
15526    
15527                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15528    
15529                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15530                                                    1)), query.index() - 1);
15531    
15532                            String sql = query.toString();
15533    
15534                            Session session = null;
15535    
15536                            try {
15537                                    session = openSession();
15538    
15539                                    Query q = session.createQuery(sql);
15540    
15541                                    QueryPos qPos = QueryPos.getInstance(q);
15542    
15543                                    qPos.add(userId);
15544    
15545                                    qPos.add(status);
15546    
15547                                    count = (Long)q.uniqueResult();
15548    
15549                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15550                                            finderArgs, count);
15551                            }
15552                            catch (Exception e) {
15553                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15554                                            finderArgs);
15555    
15556                                    throw processException(e);
15557                            }
15558                            finally {
15559                                    closeSession(session);
15560                            }
15561                    }
15562    
15563                    return count.intValue();
15564            }
15565    
15566            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15567            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15568            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
15569            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15570            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15571                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15572                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15573                            new String[] {
15574                                    Long.class.getName(), Long.class.getName(),
15575                                    Integer.class.getName(),
15576                                    
15577                            Integer.class.getName(), Integer.class.getName(),
15578                                    OrderByComparator.class.getName()
15579                            });
15580            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15581                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15582                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15583                            new String[] {
15584                                    Long.class.getName(), Long.class.getName(),
15585                                    Integer.class.getName()
15586                            },
15587                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15588                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15589                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15590                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15591            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15592                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15593                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15594                            new String[] {
15595                                    Long.class.getName(), Long.class.getName(),
15596                                    Integer.class.getName()
15597                            });
15598    
15599            /**
15600             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15601             *
15602             * @param classNameId the class name ID
15603             * @param classPK the class p k
15604             * @param status the status
15605             * @return the matching message-boards messages
15606             */
15607            @Override
15608            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15609                    int status) {
15610                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15611                            QueryUtil.ALL_POS, null);
15612            }
15613    
15614            /**
15615             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15616             *
15617             * <p>
15618             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15619             * </p>
15620             *
15621             * @param classNameId the class name ID
15622             * @param classPK the class p k
15623             * @param status the status
15624             * @param start the lower bound of the range of message-boards messages
15625             * @param end the upper bound of the range of message-boards messages (not inclusive)
15626             * @return the range of matching message-boards messages
15627             */
15628            @Override
15629            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15630                    int status, int start, int end) {
15631                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15632            }
15633    
15634            /**
15635             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15636             *
15637             * <p>
15638             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15639             * </p>
15640             *
15641             * @param classNameId the class name ID
15642             * @param classPK the class p k
15643             * @param status the status
15644             * @param start the lower bound of the range of message-boards messages
15645             * @param end the upper bound of the range of message-boards messages (not inclusive)
15646             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15647             * @return the ordered range of matching message-boards messages
15648             */
15649            @Override
15650            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15651                    int status, int start, int end,
15652                    OrderByComparator<MBMessage> orderByComparator) {
15653                    return findByC_C_S(classNameId, classPK, status, start, end,
15654                            orderByComparator, true);
15655            }
15656    
15657            /**
15658             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15659             *
15660             * <p>
15661             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
15662             * </p>
15663             *
15664             * @param classNameId the class name ID
15665             * @param classPK the class p k
15666             * @param status the status
15667             * @param start the lower bound of the range of message-boards messages
15668             * @param end the upper bound of the range of message-boards messages (not inclusive)
15669             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15670             * @param retrieveFromCache whether to retrieve from the finder cache
15671             * @return the ordered range of matching message-boards messages
15672             */
15673            @Override
15674            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15675                    int status, int start, int end,
15676                    OrderByComparator<MBMessage> orderByComparator,
15677                    boolean retrieveFromCache) {
15678                    boolean pagination = true;
15679                    FinderPath finderPath = null;
15680                    Object[] finderArgs = null;
15681    
15682                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15683                                    (orderByComparator == null)) {
15684                            pagination = false;
15685                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15686                            finderArgs = new Object[] { classNameId, classPK, status };
15687                    }
15688                    else {
15689                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15690                            finderArgs = new Object[] {
15691                                            classNameId, classPK, status,
15692                                            
15693                                            start, end, orderByComparator
15694                                    };
15695                    }
15696    
15697                    List<MBMessage> list = null;
15698    
15699                    if (retrieveFromCache) {
15700                            list = (List<MBMessage>)finderCache.getResult(finderPath,
15701                                            finderArgs, this);
15702    
15703                            if ((list != null) && !list.isEmpty()) {
15704                                    for (MBMessage mbMessage : list) {
15705                                            if ((classNameId != mbMessage.getClassNameId()) ||
15706                                                            (classPK != mbMessage.getClassPK()) ||
15707                                                            (status != mbMessage.getStatus())) {
15708                                                    list = null;
15709    
15710                                                    break;
15711                                            }
15712                                    }
15713                            }
15714                    }
15715    
15716                    if (list == null) {
15717                            StringBundler query = null;
15718    
15719                            if (orderByComparator != null) {
15720                                    query = new StringBundler(5 +
15721                                                    (orderByComparator.getOrderByFields().length * 3));
15722                            }
15723                            else {
15724                                    query = new StringBundler(5);
15725                            }
15726    
15727                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15728    
15729                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15730    
15731                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15732    
15733                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15734    
15735                            if (orderByComparator != null) {
15736                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15737                                            orderByComparator);
15738                            }
15739                            else
15740                             if (pagination) {
15741                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15742                            }
15743    
15744                            String sql = query.toString();
15745    
15746                            Session session = null;
15747    
15748                            try {
15749                                    session = openSession();
15750    
15751                                    Query q = session.createQuery(sql);
15752    
15753                                    QueryPos qPos = QueryPos.getInstance(q);
15754    
15755                                    qPos.add(classNameId);
15756    
15757                                    qPos.add(classPK);
15758    
15759                                    qPos.add(status);
15760    
15761                                    if (!pagination) {
15762                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15763                                                            start, end, false);
15764    
15765                                            Collections.sort(list);
15766    
15767                                            list = Collections.unmodifiableList(list);
15768                                    }
15769                                    else {
15770                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15771                                                            start, end);
15772                                    }
15773    
15774                                    cacheResult(list);
15775    
15776                                    finderCache.putResult(finderPath, finderArgs, list);
15777                            }
15778                            catch (Exception e) {
15779                                    finderCache.removeResult(finderPath, finderArgs);
15780    
15781                                    throw processException(e);
15782                            }
15783                            finally {
15784                                    closeSession(session);
15785                            }
15786                    }
15787    
15788                    return list;
15789            }
15790    
15791            /**
15792             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15793             *
15794             * @param classNameId the class name ID
15795             * @param classPK the class p k
15796             * @param status the status
15797             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15798             * @return the first matching message-boards message
15799             * @throws NoSuchMessageException if a matching message-boards message could not be found
15800             */
15801            @Override
15802            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15803                    int status, OrderByComparator<MBMessage> orderByComparator)
15804                    throws NoSuchMessageException {
15805                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15806                                    orderByComparator);
15807    
15808                    if (mbMessage != null) {
15809                            return mbMessage;
15810                    }
15811    
15812                    StringBundler msg = new StringBundler(8);
15813    
15814                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15815    
15816                    msg.append("classNameId=");
15817                    msg.append(classNameId);
15818    
15819                    msg.append(", classPK=");
15820                    msg.append(classPK);
15821    
15822                    msg.append(", status=");
15823                    msg.append(status);
15824    
15825                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15826    
15827                    throw new NoSuchMessageException(msg.toString());
15828            }
15829    
15830            /**
15831             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15832             *
15833             * @param classNameId the class name ID
15834             * @param classPK the class p k
15835             * @param status the status
15836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15837             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15838             */
15839            @Override
15840            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15841                    int status, OrderByComparator<MBMessage> orderByComparator) {
15842                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15843                                    orderByComparator);
15844    
15845                    if (!list.isEmpty()) {
15846                            return list.get(0);
15847                    }
15848    
15849                    return null;
15850            }
15851    
15852            /**
15853             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15854             *
15855             * @param classNameId the class name ID
15856             * @param classPK the class p k
15857             * @param status the status
15858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15859             * @return the last matching message-boards message
15860             * @throws NoSuchMessageException if a matching message-boards message could not be found
15861             */
15862            @Override
15863            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15864                    int status, OrderByComparator<MBMessage> orderByComparator)
15865                    throws NoSuchMessageException {
15866                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15867                                    orderByComparator);
15868    
15869                    if (mbMessage != null) {
15870                            return mbMessage;
15871                    }
15872    
15873                    StringBundler msg = new StringBundler(8);
15874    
15875                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15876    
15877                    msg.append("classNameId=");
15878                    msg.append(classNameId);
15879    
15880                    msg.append(", classPK=");
15881                    msg.append(classPK);
15882    
15883                    msg.append(", status=");
15884                    msg.append(status);
15885    
15886                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15887    
15888                    throw new NoSuchMessageException(msg.toString());
15889            }
15890    
15891            /**
15892             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15893             *
15894             * @param classNameId the class name ID
15895             * @param classPK the class p k
15896             * @param status the status
15897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15898             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15899             */
15900            @Override
15901            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15902                    int status, OrderByComparator<MBMessage> orderByComparator) {
15903                    int count = countByC_C_S(classNameId, classPK, status);
15904    
15905                    if (count == 0) {
15906                            return null;
15907                    }
15908    
15909                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15910                                    count - 1, count, orderByComparator);
15911    
15912                    if (!list.isEmpty()) {
15913                            return list.get(0);
15914                    }
15915    
15916                    return null;
15917            }
15918    
15919            /**
15920             * 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;.
15921             *
15922             * @param messageId the primary key of the current message-boards message
15923             * @param classNameId the class name ID
15924             * @param classPK the class p k
15925             * @param status the status
15926             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15927             * @return the previous, current, and next message-boards message
15928             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15929             */
15930            @Override
15931            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15932                    long classNameId, long classPK, int status,
15933                    OrderByComparator<MBMessage> orderByComparator)
15934                    throws NoSuchMessageException {
15935                    MBMessage mbMessage = findByPrimaryKey(messageId);
15936    
15937                    Session session = null;
15938    
15939                    try {
15940                            session = openSession();
15941    
15942                            MBMessage[] array = new MBMessageImpl[3];
15943    
15944                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15945                                            classPK, status, orderByComparator, true);
15946    
15947                            array[1] = mbMessage;
15948    
15949                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15950                                            classPK, status, orderByComparator, false);
15951    
15952                            return array;
15953                    }
15954                    catch (Exception e) {
15955                            throw processException(e);
15956                    }
15957                    finally {
15958                            closeSession(session);
15959                    }
15960            }
15961    
15962            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15963                    MBMessage mbMessage, long classNameId, long classPK, int status,
15964                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15965                    StringBundler query = null;
15966    
15967                    if (orderByComparator != null) {
15968                            query = new StringBundler(6 +
15969                                            (orderByComparator.getOrderByFields().length * 6));
15970                    }
15971                    else {
15972                            query = new StringBundler(3);
15973                    }
15974    
15975                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15976    
15977                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15978    
15979                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15980    
15981                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15982    
15983                    if (orderByComparator != null) {
15984                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15985    
15986                            if (orderByConditionFields.length > 0) {
15987                                    query.append(WHERE_AND);
15988                            }
15989    
15990                            for (int i = 0; i < orderByConditionFields.length; i++) {
15991                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15992                                    query.append(orderByConditionFields[i]);
15993    
15994                                    if ((i + 1) < orderByConditionFields.length) {
15995                                            if (orderByComparator.isAscending() ^ previous) {
15996                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15997                                            }
15998                                            else {
15999                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16000                                            }
16001                                    }
16002                                    else {
16003                                            if (orderByComparator.isAscending() ^ previous) {
16004                                                    query.append(WHERE_GREATER_THAN);
16005                                            }
16006                                            else {
16007                                                    query.append(WHERE_LESSER_THAN);
16008                                            }
16009                                    }
16010                            }
16011    
16012                            query.append(ORDER_BY_CLAUSE);
16013    
16014                            String[] orderByFields = orderByComparator.getOrderByFields();
16015    
16016                            for (int i = 0; i < orderByFields.length; i++) {
16017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16018                                    query.append(orderByFields[i]);
16019    
16020                                    if ((i + 1) < orderByFields.length) {
16021                                            if (orderByComparator.isAscending() ^ previous) {
16022                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16023                                            }
16024                                            else {
16025                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16026                                            }
16027                                    }
16028                                    else {
16029                                            if (orderByComparator.isAscending() ^ previous) {
16030                                                    query.append(ORDER_BY_ASC);
16031                                            }
16032                                            else {
16033                                                    query.append(ORDER_BY_DESC);
16034                                            }
16035                                    }
16036                            }
16037                    }
16038                    else {
16039                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16040                    }
16041    
16042                    String sql = query.toString();
16043    
16044                    Query q = session.createQuery(sql);
16045    
16046                    q.setFirstResult(0);
16047                    q.setMaxResults(2);
16048    
16049                    QueryPos qPos = QueryPos.getInstance(q);
16050    
16051                    qPos.add(classNameId);
16052    
16053                    qPos.add(classPK);
16054    
16055                    qPos.add(status);
16056    
16057                    if (orderByComparator != null) {
16058                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16059    
16060                            for (Object value : values) {
16061                                    qPos.add(value);
16062                            }
16063                    }
16064    
16065                    List<MBMessage> list = q.list();
16066    
16067                    if (list.size() == 2) {
16068                            return list.get(1);
16069                    }
16070                    else {
16071                            return null;
16072                    }
16073            }
16074    
16075            /**
16076             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16077             *
16078             * @param classNameId the class name ID
16079             * @param classPK the class p k
16080             * @param status the status
16081             */
16082            @Override
16083            public void removeByC_C_S(long classNameId, long classPK, int status) {
16084                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
16085                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16086                            remove(mbMessage);
16087                    }
16088            }
16089    
16090            /**
16091             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16092             *
16093             * @param classNameId the class name ID
16094             * @param classPK the class p k
16095             * @param status the status
16096             * @return the number of matching message-boards messages
16097             */
16098            @Override
16099            public int countByC_C_S(long classNameId, long classPK, int status) {
16100                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
16101    
16102                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16103    
16104                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
16105    
16106                    if (count == null) {
16107                            StringBundler query = new StringBundler(4);
16108    
16109                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16110    
16111                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16112    
16113                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16114    
16115                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16116    
16117                            String sql = query.toString();
16118    
16119                            Session session = null;
16120    
16121                            try {
16122                                    session = openSession();
16123    
16124                                    Query q = session.createQuery(sql);
16125    
16126                                    QueryPos qPos = QueryPos.getInstance(q);
16127    
16128                                    qPos.add(classNameId);
16129    
16130                                    qPos.add(classPK);
16131    
16132                                    qPos.add(status);
16133    
16134                                    count = (Long)q.uniqueResult();
16135    
16136                                    finderCache.putResult(finderPath, finderArgs, count);
16137                            }
16138                            catch (Exception e) {
16139                                    finderCache.removeResult(finderPath, finderArgs);
16140    
16141                                    throw processException(e);
16142                            }
16143                            finally {
16144                                    closeSession(session);
16145                            }
16146                    }
16147    
16148                    return count.intValue();
16149            }
16150    
16151            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
16152            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
16153            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
16154            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16155                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16156                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
16157                            new String[] {
16158                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16159                                    Boolean.class.getName(),
16160                                    
16161                            Integer.class.getName(), Integer.class.getName(),
16162                                    OrderByComparator.class.getName()
16163                            });
16164            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
16165                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
16168                            new String[] {
16169                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16170                                    Boolean.class.getName()
16171                            },
16172                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16173                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16174                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16175                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
16176                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16177            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16178                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16179                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
16180                            new String[] {
16181                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16182                                    Boolean.class.getName()
16183                            });
16184    
16185            /**
16186             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16187             *
16188             * @param groupId the group ID
16189             * @param categoryId the category ID
16190             * @param threadId the thread ID
16191             * @param answer the answer
16192             * @return the matching message-boards messages
16193             */
16194            @Override
16195            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16196                    long threadId, boolean answer) {
16197                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
16198                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16199            }
16200    
16201            /**
16202             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16203             *
16204             * <p>
16205             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16206             * </p>
16207             *
16208             * @param groupId the group ID
16209             * @param categoryId the category ID
16210             * @param threadId the thread ID
16211             * @param answer the answer
16212             * @param start the lower bound of the range of message-boards messages
16213             * @param end the upper bound of the range of message-boards messages (not inclusive)
16214             * @return the range of matching message-boards messages
16215             */
16216            @Override
16217            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16218                    long threadId, boolean answer, int start, int end) {
16219                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16220                            null);
16221            }
16222    
16223            /**
16224             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16225             *
16226             * <p>
16227             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16228             * </p>
16229             *
16230             * @param groupId the group ID
16231             * @param categoryId the category ID
16232             * @param threadId the thread ID
16233             * @param answer the answer
16234             * @param start the lower bound of the range of message-boards messages
16235             * @param end the upper bound of the range of message-boards messages (not inclusive)
16236             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16237             * @return the ordered range of matching message-boards messages
16238             */
16239            @Override
16240            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16241                    long threadId, boolean answer, int start, int end,
16242                    OrderByComparator<MBMessage> orderByComparator) {
16243                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16244                            orderByComparator, true);
16245            }
16246    
16247            /**
16248             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16249             *
16250             * <p>
16251             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16252             * </p>
16253             *
16254             * @param groupId the group ID
16255             * @param categoryId the category ID
16256             * @param threadId the thread ID
16257             * @param answer the answer
16258             * @param start the lower bound of the range of message-boards messages
16259             * @param end the upper bound of the range of message-boards messages (not inclusive)
16260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16261             * @param retrieveFromCache whether to retrieve from the finder cache
16262             * @return the ordered range of matching message-boards messages
16263             */
16264            @Override
16265            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16266                    long threadId, boolean answer, int start, int end,
16267                    OrderByComparator<MBMessage> orderByComparator,
16268                    boolean retrieveFromCache) {
16269                    boolean pagination = true;
16270                    FinderPath finderPath = null;
16271                    Object[] finderArgs = null;
16272    
16273                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16274                                    (orderByComparator == null)) {
16275                            pagination = false;
16276                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16277                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16278                    }
16279                    else {
16280                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16281                            finderArgs = new Object[] {
16282                                            groupId, categoryId, threadId, answer,
16283                                            
16284                                            start, end, orderByComparator
16285                                    };
16286                    }
16287    
16288                    List<MBMessage> list = null;
16289    
16290                    if (retrieveFromCache) {
16291                            list = (List<MBMessage>)finderCache.getResult(finderPath,
16292                                            finderArgs, this);
16293    
16294                            if ((list != null) && !list.isEmpty()) {
16295                                    for (MBMessage mbMessage : list) {
16296                                            if ((groupId != mbMessage.getGroupId()) ||
16297                                                            (categoryId != mbMessage.getCategoryId()) ||
16298                                                            (threadId != mbMessage.getThreadId()) ||
16299                                                            (answer != mbMessage.getAnswer())) {
16300                                                    list = null;
16301    
16302                                                    break;
16303                                            }
16304                                    }
16305                            }
16306                    }
16307    
16308                    if (list == null) {
16309                            StringBundler query = null;
16310    
16311                            if (orderByComparator != null) {
16312                                    query = new StringBundler(6 +
16313                                                    (orderByComparator.getOrderByFields().length * 3));
16314                            }
16315                            else {
16316                                    query = new StringBundler(6);
16317                            }
16318    
16319                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16320    
16321                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16322    
16323                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16324    
16325                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16326    
16327                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16328    
16329                            if (orderByComparator != null) {
16330                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16331                                            orderByComparator);
16332                            }
16333                            else
16334                             if (pagination) {
16335                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16336                            }
16337    
16338                            String sql = query.toString();
16339    
16340                            Session session = null;
16341    
16342                            try {
16343                                    session = openSession();
16344    
16345                                    Query q = session.createQuery(sql);
16346    
16347                                    QueryPos qPos = QueryPos.getInstance(q);
16348    
16349                                    qPos.add(groupId);
16350    
16351                                    qPos.add(categoryId);
16352    
16353                                    qPos.add(threadId);
16354    
16355                                    qPos.add(answer);
16356    
16357                                    if (!pagination) {
16358                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16359                                                            start, end, false);
16360    
16361                                            Collections.sort(list);
16362    
16363                                            list = Collections.unmodifiableList(list);
16364                                    }
16365                                    else {
16366                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16367                                                            start, end);
16368                                    }
16369    
16370                                    cacheResult(list);
16371    
16372                                    finderCache.putResult(finderPath, finderArgs, list);
16373                            }
16374                            catch (Exception e) {
16375                                    finderCache.removeResult(finderPath, finderArgs);
16376    
16377                                    throw processException(e);
16378                            }
16379                            finally {
16380                                    closeSession(session);
16381                            }
16382                    }
16383    
16384                    return list;
16385            }
16386    
16387            /**
16388             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16389             *
16390             * @param groupId the group ID
16391             * @param categoryId the category ID
16392             * @param threadId the thread ID
16393             * @param answer the answer
16394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16395             * @return the first matching message-boards message
16396             * @throws NoSuchMessageException if a matching message-boards message could not be found
16397             */
16398            @Override
16399            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16400                    long threadId, boolean answer,
16401                    OrderByComparator<MBMessage> orderByComparator)
16402                    throws NoSuchMessageException {
16403                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16404                                    threadId, answer, orderByComparator);
16405    
16406                    if (mbMessage != null) {
16407                            return mbMessage;
16408                    }
16409    
16410                    StringBundler msg = new StringBundler(10);
16411    
16412                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16413    
16414                    msg.append("groupId=");
16415                    msg.append(groupId);
16416    
16417                    msg.append(", categoryId=");
16418                    msg.append(categoryId);
16419    
16420                    msg.append(", threadId=");
16421                    msg.append(threadId);
16422    
16423                    msg.append(", answer=");
16424                    msg.append(answer);
16425    
16426                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16427    
16428                    throw new NoSuchMessageException(msg.toString());
16429            }
16430    
16431            /**
16432             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16433             *
16434             * @param groupId the group ID
16435             * @param categoryId the category ID
16436             * @param threadId the thread ID
16437             * @param answer the answer
16438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16439             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16440             */
16441            @Override
16442            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16443                    long threadId, boolean answer,
16444                    OrderByComparator<MBMessage> orderByComparator) {
16445                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16446                                    answer, 0, 1, orderByComparator);
16447    
16448                    if (!list.isEmpty()) {
16449                            return list.get(0);
16450                    }
16451    
16452                    return null;
16453            }
16454    
16455            /**
16456             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16457             *
16458             * @param groupId the group ID
16459             * @param categoryId the category ID
16460             * @param threadId the thread ID
16461             * @param answer the answer
16462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16463             * @return the last matching message-boards message
16464             * @throws NoSuchMessageException if a matching message-boards message could not be found
16465             */
16466            @Override
16467            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16468                    long threadId, boolean answer,
16469                    OrderByComparator<MBMessage> orderByComparator)
16470                    throws NoSuchMessageException {
16471                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16472                                    threadId, answer, orderByComparator);
16473    
16474                    if (mbMessage != null) {
16475                            return mbMessage;
16476                    }
16477    
16478                    StringBundler msg = new StringBundler(10);
16479    
16480                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16481    
16482                    msg.append("groupId=");
16483                    msg.append(groupId);
16484    
16485                    msg.append(", categoryId=");
16486                    msg.append(categoryId);
16487    
16488                    msg.append(", threadId=");
16489                    msg.append(threadId);
16490    
16491                    msg.append(", answer=");
16492                    msg.append(answer);
16493    
16494                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16495    
16496                    throw new NoSuchMessageException(msg.toString());
16497            }
16498    
16499            /**
16500             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16501             *
16502             * @param groupId the group ID
16503             * @param categoryId the category ID
16504             * @param threadId the thread ID
16505             * @param answer the answer
16506             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16507             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16508             */
16509            @Override
16510            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16511                    long threadId, boolean answer,
16512                    OrderByComparator<MBMessage> orderByComparator) {
16513                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16514    
16515                    if (count == 0) {
16516                            return null;
16517                    }
16518    
16519                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16520                                    answer, count - 1, count, orderByComparator);
16521    
16522                    if (!list.isEmpty()) {
16523                            return list.get(0);
16524                    }
16525    
16526                    return null;
16527            }
16528    
16529            /**
16530             * 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;.
16531             *
16532             * @param messageId the primary key of the current message-boards message
16533             * @param groupId the group ID
16534             * @param categoryId the category ID
16535             * @param threadId the thread ID
16536             * @param answer the answer
16537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16538             * @return the previous, current, and next message-boards message
16539             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16540             */
16541            @Override
16542            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16543                    long categoryId, long threadId, boolean answer,
16544                    OrderByComparator<MBMessage> orderByComparator)
16545                    throws NoSuchMessageException {
16546                    MBMessage mbMessage = findByPrimaryKey(messageId);
16547    
16548                    Session session = null;
16549    
16550                    try {
16551                            session = openSession();
16552    
16553                            MBMessage[] array = new MBMessageImpl[3];
16554    
16555                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16556                                            categoryId, threadId, answer, orderByComparator, true);
16557    
16558                            array[1] = mbMessage;
16559    
16560                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16561                                            categoryId, threadId, answer, orderByComparator, false);
16562    
16563                            return array;
16564                    }
16565                    catch (Exception e) {
16566                            throw processException(e);
16567                    }
16568                    finally {
16569                            closeSession(session);
16570                    }
16571            }
16572    
16573            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16574                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16575                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16576                    boolean previous) {
16577                    StringBundler query = null;
16578    
16579                    if (orderByComparator != null) {
16580                            query = new StringBundler(6 +
16581                                            (orderByComparator.getOrderByFields().length * 6));
16582                    }
16583                    else {
16584                            query = new StringBundler(3);
16585                    }
16586    
16587                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16588    
16589                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16590    
16591                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16592    
16593                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16594    
16595                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16596    
16597                    if (orderByComparator != null) {
16598                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16599    
16600                            if (orderByConditionFields.length > 0) {
16601                                    query.append(WHERE_AND);
16602                            }
16603    
16604                            for (int i = 0; i < orderByConditionFields.length; i++) {
16605                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16606                                    query.append(orderByConditionFields[i]);
16607    
16608                                    if ((i + 1) < orderByConditionFields.length) {
16609                                            if (orderByComparator.isAscending() ^ previous) {
16610                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16611                                            }
16612                                            else {
16613                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16614                                            }
16615                                    }
16616                                    else {
16617                                            if (orderByComparator.isAscending() ^ previous) {
16618                                                    query.append(WHERE_GREATER_THAN);
16619                                            }
16620                                            else {
16621                                                    query.append(WHERE_LESSER_THAN);
16622                                            }
16623                                    }
16624                            }
16625    
16626                            query.append(ORDER_BY_CLAUSE);
16627    
16628                            String[] orderByFields = orderByComparator.getOrderByFields();
16629    
16630                            for (int i = 0; i < orderByFields.length; i++) {
16631                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16632                                    query.append(orderByFields[i]);
16633    
16634                                    if ((i + 1) < orderByFields.length) {
16635                                            if (orderByComparator.isAscending() ^ previous) {
16636                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16637                                            }
16638                                            else {
16639                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16640                                            }
16641                                    }
16642                                    else {
16643                                            if (orderByComparator.isAscending() ^ previous) {
16644                                                    query.append(ORDER_BY_ASC);
16645                                            }
16646                                            else {
16647                                                    query.append(ORDER_BY_DESC);
16648                                            }
16649                                    }
16650                            }
16651                    }
16652                    else {
16653                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16654                    }
16655    
16656                    String sql = query.toString();
16657    
16658                    Query q = session.createQuery(sql);
16659    
16660                    q.setFirstResult(0);
16661                    q.setMaxResults(2);
16662    
16663                    QueryPos qPos = QueryPos.getInstance(q);
16664    
16665                    qPos.add(groupId);
16666    
16667                    qPos.add(categoryId);
16668    
16669                    qPos.add(threadId);
16670    
16671                    qPos.add(answer);
16672    
16673                    if (orderByComparator != null) {
16674                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16675    
16676                            for (Object value : values) {
16677                                    qPos.add(value);
16678                            }
16679                    }
16680    
16681                    List<MBMessage> list = q.list();
16682    
16683                    if (list.size() == 2) {
16684                            return list.get(1);
16685                    }
16686                    else {
16687                            return null;
16688                    }
16689            }
16690    
16691            /**
16692             * 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;.
16693             *
16694             * @param groupId the group ID
16695             * @param categoryId the category ID
16696             * @param threadId the thread ID
16697             * @param answer the answer
16698             * @return the matching message-boards messages that the user has permission to view
16699             */
16700            @Override
16701            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16702                    long threadId, boolean answer) {
16703                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16704                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16705            }
16706    
16707            /**
16708             * 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;.
16709             *
16710             * <p>
16711             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16712             * </p>
16713             *
16714             * @param groupId the group ID
16715             * @param categoryId the category ID
16716             * @param threadId the thread ID
16717             * @param answer the answer
16718             * @param start the lower bound of the range of message-boards messages
16719             * @param end the upper bound of the range of message-boards messages (not inclusive)
16720             * @return the range of matching message-boards messages that the user has permission to view
16721             */
16722            @Override
16723            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16724                    long threadId, boolean answer, int start, int end) {
16725                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16726                            start, end, null);
16727            }
16728    
16729            /**
16730             * 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;.
16731             *
16732             * <p>
16733             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
16734             * </p>
16735             *
16736             * @param groupId the group ID
16737             * @param categoryId the category ID
16738             * @param threadId the thread ID
16739             * @param answer the answer
16740             * @param start the lower bound of the range of message-boards messages
16741             * @param end the upper bound of the range of message-boards messages (not inclusive)
16742             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16743             * @return the ordered range of matching message-boards messages that the user has permission to view
16744             */
16745            @Override
16746            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16747                    long threadId, boolean answer, int start, int end,
16748                    OrderByComparator<MBMessage> orderByComparator) {
16749                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16750                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16751                                    end, orderByComparator);
16752                    }
16753    
16754                    StringBundler query = null;
16755    
16756                    if (orderByComparator != null) {
16757                            query = new StringBundler(6 +
16758                                            (orderByComparator.getOrderByFields().length * 3));
16759                    }
16760                    else {
16761                            query = new StringBundler(6);
16762                    }
16763    
16764                    if (getDB().isSupportsInlineDistinct()) {
16765                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16766                    }
16767                    else {
16768                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16769                    }
16770    
16771                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16772    
16773                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16774    
16775                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16776    
16777                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16778    
16779                    if (!getDB().isSupportsInlineDistinct()) {
16780                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16781                    }
16782    
16783                    if (orderByComparator != null) {
16784                            if (getDB().isSupportsInlineDistinct()) {
16785                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16786                                            orderByComparator, true);
16787                            }
16788                            else {
16789                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16790                                            orderByComparator, true);
16791                            }
16792                    }
16793                    else {
16794                            if (getDB().isSupportsInlineDistinct()) {
16795                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16796                            }
16797                            else {
16798                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16799                            }
16800                    }
16801    
16802                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16803                                    MBMessage.class.getName(),
16804                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16805    
16806                    Session session = null;
16807    
16808                    try {
16809                            session = openSession();
16810    
16811                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16812    
16813                            if (getDB().isSupportsInlineDistinct()) {
16814                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16815                            }
16816                            else {
16817                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16818                            }
16819    
16820                            QueryPos qPos = QueryPos.getInstance(q);
16821    
16822                            qPos.add(groupId);
16823    
16824                            qPos.add(categoryId);
16825    
16826                            qPos.add(threadId);
16827    
16828                            qPos.add(answer);
16829    
16830                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16831                    }
16832                    catch (Exception e) {
16833                            throw processException(e);
16834                    }
16835                    finally {
16836                            closeSession(session);
16837                    }
16838            }
16839    
16840            /**
16841             * 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;.
16842             *
16843             * @param messageId the primary key of the current message-boards message
16844             * @param groupId the group ID
16845             * @param categoryId the category ID
16846             * @param threadId the thread ID
16847             * @param answer the answer
16848             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16849             * @return the previous, current, and next message-boards message
16850             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16851             */
16852            @Override
16853            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16854                    long groupId, long categoryId, long threadId, boolean answer,
16855                    OrderByComparator<MBMessage> orderByComparator)
16856                    throws NoSuchMessageException {
16857                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16858                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16859                                    threadId, answer, orderByComparator);
16860                    }
16861    
16862                    MBMessage mbMessage = findByPrimaryKey(messageId);
16863    
16864                    Session session = null;
16865    
16866                    try {
16867                            session = openSession();
16868    
16869                            MBMessage[] array = new MBMessageImpl[3];
16870    
16871                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16872                                            groupId, categoryId, threadId, answer, orderByComparator,
16873                                            true);
16874    
16875                            array[1] = mbMessage;
16876    
16877                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16878                                            groupId, categoryId, threadId, answer, orderByComparator,
16879                                            false);
16880    
16881                            return array;
16882                    }
16883                    catch (Exception e) {
16884                            throw processException(e);
16885                    }
16886                    finally {
16887                            closeSession(session);
16888                    }
16889            }
16890    
16891            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16892                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16893                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16894                    boolean previous) {
16895                    StringBundler query = null;
16896    
16897                    if (orderByComparator != null) {
16898                            query = new StringBundler(6 +
16899                                            (orderByComparator.getOrderByFields().length * 6));
16900                    }
16901                    else {
16902                            query = new StringBundler(3);
16903                    }
16904    
16905                    if (getDB().isSupportsInlineDistinct()) {
16906                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16907                    }
16908                    else {
16909                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16910                    }
16911    
16912                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16913    
16914                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16915    
16916                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16917    
16918                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16919    
16920                    if (!getDB().isSupportsInlineDistinct()) {
16921                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16922                    }
16923    
16924                    if (orderByComparator != null) {
16925                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16926    
16927                            if (orderByConditionFields.length > 0) {
16928                                    query.append(WHERE_AND);
16929                            }
16930    
16931                            for (int i = 0; i < orderByConditionFields.length; i++) {
16932                                    if (getDB().isSupportsInlineDistinct()) {
16933                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16934                                    }
16935                                    else {
16936                                            query.append(_ORDER_BY_ENTITY_TABLE);
16937                                    }
16938    
16939                                    query.append(orderByConditionFields[i]);
16940    
16941                                    if ((i + 1) < orderByConditionFields.length) {
16942                                            if (orderByComparator.isAscending() ^ previous) {
16943                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16944                                            }
16945                                            else {
16946                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16947                                            }
16948                                    }
16949                                    else {
16950                                            if (orderByComparator.isAscending() ^ previous) {
16951                                                    query.append(WHERE_GREATER_THAN);
16952                                            }
16953                                            else {
16954                                                    query.append(WHERE_LESSER_THAN);
16955                                            }
16956                                    }
16957                            }
16958    
16959                            query.append(ORDER_BY_CLAUSE);
16960    
16961                            String[] orderByFields = orderByComparator.getOrderByFields();
16962    
16963                            for (int i = 0; i < orderByFields.length; i++) {
16964                                    if (getDB().isSupportsInlineDistinct()) {
16965                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16966                                    }
16967                                    else {
16968                                            query.append(_ORDER_BY_ENTITY_TABLE);
16969                                    }
16970    
16971                                    query.append(orderByFields[i]);
16972    
16973                                    if ((i + 1) < orderByFields.length) {
16974                                            if (orderByComparator.isAscending() ^ previous) {
16975                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16976                                            }
16977                                            else {
16978                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16979                                            }
16980                                    }
16981                                    else {
16982                                            if (orderByComparator.isAscending() ^ previous) {
16983                                                    query.append(ORDER_BY_ASC);
16984                                            }
16985                                            else {
16986                                                    query.append(ORDER_BY_DESC);
16987                                            }
16988                                    }
16989                            }
16990                    }
16991                    else {
16992                            if (getDB().isSupportsInlineDistinct()) {
16993                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16994                            }
16995                            else {
16996                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16997                            }
16998                    }
16999    
17000                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17001                                    MBMessage.class.getName(),
17002                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17003    
17004                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17005    
17006                    q.setFirstResult(0);
17007                    q.setMaxResults(2);
17008    
17009                    if (getDB().isSupportsInlineDistinct()) {
17010                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17011                    }
17012                    else {
17013                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17014                    }
17015    
17016                    QueryPos qPos = QueryPos.getInstance(q);
17017    
17018                    qPos.add(groupId);
17019    
17020                    qPos.add(categoryId);
17021    
17022                    qPos.add(threadId);
17023    
17024                    qPos.add(answer);
17025    
17026                    if (orderByComparator != null) {
17027                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17028    
17029                            for (Object value : values) {
17030                                    qPos.add(value);
17031                            }
17032                    }
17033    
17034                    List<MBMessage> list = q.list();
17035    
17036                    if (list.size() == 2) {
17037                            return list.get(1);
17038                    }
17039                    else {
17040                            return null;
17041                    }
17042            }
17043    
17044            /**
17045             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
17046             *
17047             * @param groupId the group ID
17048             * @param categoryId the category ID
17049             * @param threadId the thread ID
17050             * @param answer the answer
17051             */
17052            @Override
17053            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
17054                    boolean answer) {
17055                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
17056                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17057                            remove(mbMessage);
17058                    }
17059            }
17060    
17061            /**
17062             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17063             *
17064             * @param groupId the group ID
17065             * @param categoryId the category ID
17066             * @param threadId the thread ID
17067             * @param answer the answer
17068             * @return the number of matching message-boards messages
17069             */
17070            @Override
17071            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17072                    boolean answer) {
17073                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
17074    
17075                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17076    
17077                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
17078    
17079                    if (count == null) {
17080                            StringBundler query = new StringBundler(5);
17081    
17082                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17083    
17084                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17085    
17086                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17087    
17088                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17089    
17090                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17091    
17092                            String sql = query.toString();
17093    
17094                            Session session = null;
17095    
17096                            try {
17097                                    session = openSession();
17098    
17099                                    Query q = session.createQuery(sql);
17100    
17101                                    QueryPos qPos = QueryPos.getInstance(q);
17102    
17103                                    qPos.add(groupId);
17104    
17105                                    qPos.add(categoryId);
17106    
17107                                    qPos.add(threadId);
17108    
17109                                    qPos.add(answer);
17110    
17111                                    count = (Long)q.uniqueResult();
17112    
17113                                    finderCache.putResult(finderPath, finderArgs, count);
17114                            }
17115                            catch (Exception e) {
17116                                    finderCache.removeResult(finderPath, finderArgs);
17117    
17118                                    throw processException(e);
17119                            }
17120                            finally {
17121                                    closeSession(session);
17122                            }
17123                    }
17124    
17125                    return count.intValue();
17126            }
17127    
17128            /**
17129             * 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;.
17130             *
17131             * @param groupId the group ID
17132             * @param categoryId the category ID
17133             * @param threadId the thread ID
17134             * @param answer the answer
17135             * @return the number of matching message-boards messages that the user has permission to view
17136             */
17137            @Override
17138            public int filterCountByG_C_T_A(long groupId, long categoryId,
17139                    long threadId, boolean answer) {
17140                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17141                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17142                    }
17143    
17144                    StringBundler query = new StringBundler(5);
17145    
17146                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17147    
17148                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17149    
17150                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17151    
17152                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17153    
17154                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17155    
17156                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17157                                    MBMessage.class.getName(),
17158                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17159    
17160                    Session session = null;
17161    
17162                    try {
17163                            session = openSession();
17164    
17165                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17166    
17167                            q.addScalar(COUNT_COLUMN_NAME,
17168                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17169    
17170                            QueryPos qPos = QueryPos.getInstance(q);
17171    
17172                            qPos.add(groupId);
17173    
17174                            qPos.add(categoryId);
17175    
17176                            qPos.add(threadId);
17177    
17178                            qPos.add(answer);
17179    
17180                            Long count = (Long)q.uniqueResult();
17181    
17182                            return count.intValue();
17183                    }
17184                    catch (Exception e) {
17185                            throw processException(e);
17186                    }
17187                    finally {
17188                            closeSession(session);
17189                    }
17190            }
17191    
17192            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17193            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17194            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17195            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17196            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17197                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17198                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
17199                            new String[] {
17200                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17201                                    Integer.class.getName(),
17202                                    
17203                            Integer.class.getName(), Integer.class.getName(),
17204                                    OrderByComparator.class.getName()
17205                            });
17206            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
17207                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
17210                            new String[] {
17211                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17212                                    Integer.class.getName()
17213                            },
17214                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17215                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17216                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17217                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17218                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17219            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17220                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17221                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
17222                            new String[] {
17223                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17224                                    Integer.class.getName()
17225                            });
17226    
17227            /**
17228             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17229             *
17230             * @param groupId the group ID
17231             * @param categoryId the category ID
17232             * @param threadId the thread ID
17233             * @param status the status
17234             * @return the matching message-boards messages
17235             */
17236            @Override
17237            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17238                    long threadId, int status) {
17239                    return findByG_C_T_S(groupId, categoryId, threadId, status,
17240                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17241            }
17242    
17243            /**
17244             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17245             *
17246             * <p>
17247             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17248             * </p>
17249             *
17250             * @param groupId the group ID
17251             * @param categoryId the category ID
17252             * @param threadId the thread ID
17253             * @param status the status
17254             * @param start the lower bound of the range of message-boards messages
17255             * @param end the upper bound of the range of message-boards messages (not inclusive)
17256             * @return the range of matching message-boards messages
17257             */
17258            @Override
17259            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17260                    long threadId, int status, int start, int end) {
17261                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17262                            null);
17263            }
17264    
17265            /**
17266             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17267             *
17268             * <p>
17269             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17270             * </p>
17271             *
17272             * @param groupId the group ID
17273             * @param categoryId the category ID
17274             * @param threadId the thread ID
17275             * @param status the status
17276             * @param start the lower bound of the range of message-boards messages
17277             * @param end the upper bound of the range of message-boards messages (not inclusive)
17278             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17279             * @return the ordered range of matching message-boards messages
17280             */
17281            @Override
17282            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17283                    long threadId, int status, int start, int end,
17284                    OrderByComparator<MBMessage> orderByComparator) {
17285                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17286                            orderByComparator, true);
17287            }
17288    
17289            /**
17290             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17291             *
17292             * <p>
17293             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17294             * </p>
17295             *
17296             * @param groupId the group ID
17297             * @param categoryId the category ID
17298             * @param threadId the thread ID
17299             * @param status the status
17300             * @param start the lower bound of the range of message-boards messages
17301             * @param end the upper bound of the range of message-boards messages (not inclusive)
17302             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17303             * @param retrieveFromCache whether to retrieve from the finder cache
17304             * @return the ordered range of matching message-boards messages
17305             */
17306            @Override
17307            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17308                    long threadId, int status, int start, int end,
17309                    OrderByComparator<MBMessage> orderByComparator,
17310                    boolean retrieveFromCache) {
17311                    boolean pagination = true;
17312                    FinderPath finderPath = null;
17313                    Object[] finderArgs = null;
17314    
17315                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17316                                    (orderByComparator == null)) {
17317                            pagination = false;
17318                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17319                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17320                    }
17321                    else {
17322                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17323                            finderArgs = new Object[] {
17324                                            groupId, categoryId, threadId, status,
17325                                            
17326                                            start, end, orderByComparator
17327                                    };
17328                    }
17329    
17330                    List<MBMessage> list = null;
17331    
17332                    if (retrieveFromCache) {
17333                            list = (List<MBMessage>)finderCache.getResult(finderPath,
17334                                            finderArgs, this);
17335    
17336                            if ((list != null) && !list.isEmpty()) {
17337                                    for (MBMessage mbMessage : list) {
17338                                            if ((groupId != mbMessage.getGroupId()) ||
17339                                                            (categoryId != mbMessage.getCategoryId()) ||
17340                                                            (threadId != mbMessage.getThreadId()) ||
17341                                                            (status != mbMessage.getStatus())) {
17342                                                    list = null;
17343    
17344                                                    break;
17345                                            }
17346                                    }
17347                            }
17348                    }
17349    
17350                    if (list == null) {
17351                            StringBundler query = null;
17352    
17353                            if (orderByComparator != null) {
17354                                    query = new StringBundler(6 +
17355                                                    (orderByComparator.getOrderByFields().length * 3));
17356                            }
17357                            else {
17358                                    query = new StringBundler(6);
17359                            }
17360    
17361                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17362    
17363                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17364    
17365                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17366    
17367                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17368    
17369                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17370    
17371                            if (orderByComparator != null) {
17372                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17373                                            orderByComparator);
17374                            }
17375                            else
17376                             if (pagination) {
17377                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17378                            }
17379    
17380                            String sql = query.toString();
17381    
17382                            Session session = null;
17383    
17384                            try {
17385                                    session = openSession();
17386    
17387                                    Query q = session.createQuery(sql);
17388    
17389                                    QueryPos qPos = QueryPos.getInstance(q);
17390    
17391                                    qPos.add(groupId);
17392    
17393                                    qPos.add(categoryId);
17394    
17395                                    qPos.add(threadId);
17396    
17397                                    qPos.add(status);
17398    
17399                                    if (!pagination) {
17400                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17401                                                            start, end, false);
17402    
17403                                            Collections.sort(list);
17404    
17405                                            list = Collections.unmodifiableList(list);
17406                                    }
17407                                    else {
17408                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17409                                                            start, end);
17410                                    }
17411    
17412                                    cacheResult(list);
17413    
17414                                    finderCache.putResult(finderPath, finderArgs, list);
17415                            }
17416                            catch (Exception e) {
17417                                    finderCache.removeResult(finderPath, finderArgs);
17418    
17419                                    throw processException(e);
17420                            }
17421                            finally {
17422                                    closeSession(session);
17423                            }
17424                    }
17425    
17426                    return list;
17427            }
17428    
17429            /**
17430             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17431             *
17432             * @param groupId the group ID
17433             * @param categoryId the category ID
17434             * @param threadId the thread ID
17435             * @param status the status
17436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17437             * @return the first matching message-boards message
17438             * @throws NoSuchMessageException if a matching message-boards message could not be found
17439             */
17440            @Override
17441            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17442                    long threadId, int status,
17443                    OrderByComparator<MBMessage> orderByComparator)
17444                    throws NoSuchMessageException {
17445                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17446                                    threadId, status, orderByComparator);
17447    
17448                    if (mbMessage != null) {
17449                            return mbMessage;
17450                    }
17451    
17452                    StringBundler msg = new StringBundler(10);
17453    
17454                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17455    
17456                    msg.append("groupId=");
17457                    msg.append(groupId);
17458    
17459                    msg.append(", categoryId=");
17460                    msg.append(categoryId);
17461    
17462                    msg.append(", threadId=");
17463                    msg.append(threadId);
17464    
17465                    msg.append(", status=");
17466                    msg.append(status);
17467    
17468                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17469    
17470                    throw new NoSuchMessageException(msg.toString());
17471            }
17472    
17473            /**
17474             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17475             *
17476             * @param groupId the group ID
17477             * @param categoryId the category ID
17478             * @param threadId the thread ID
17479             * @param status the status
17480             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17481             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17482             */
17483            @Override
17484            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17485                    long threadId, int status,
17486                    OrderByComparator<MBMessage> orderByComparator) {
17487                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17488                                    status, 0, 1, orderByComparator);
17489    
17490                    if (!list.isEmpty()) {
17491                            return list.get(0);
17492                    }
17493    
17494                    return null;
17495            }
17496    
17497            /**
17498             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17499             *
17500             * @param groupId the group ID
17501             * @param categoryId the category ID
17502             * @param threadId the thread ID
17503             * @param status the status
17504             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17505             * @return the last matching message-boards message
17506             * @throws NoSuchMessageException if a matching message-boards message could not be found
17507             */
17508            @Override
17509            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17510                    long threadId, int status,
17511                    OrderByComparator<MBMessage> orderByComparator)
17512                    throws NoSuchMessageException {
17513                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17514                                    threadId, status, orderByComparator);
17515    
17516                    if (mbMessage != null) {
17517                            return mbMessage;
17518                    }
17519    
17520                    StringBundler msg = new StringBundler(10);
17521    
17522                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17523    
17524                    msg.append("groupId=");
17525                    msg.append(groupId);
17526    
17527                    msg.append(", categoryId=");
17528                    msg.append(categoryId);
17529    
17530                    msg.append(", threadId=");
17531                    msg.append(threadId);
17532    
17533                    msg.append(", status=");
17534                    msg.append(status);
17535    
17536                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17537    
17538                    throw new NoSuchMessageException(msg.toString());
17539            }
17540    
17541            /**
17542             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17543             *
17544             * @param groupId the group ID
17545             * @param categoryId the category ID
17546             * @param threadId the thread ID
17547             * @param status the status
17548             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17549             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17550             */
17551            @Override
17552            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17553                    long threadId, int status,
17554                    OrderByComparator<MBMessage> orderByComparator) {
17555                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17556    
17557                    if (count == 0) {
17558                            return null;
17559                    }
17560    
17561                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17562                                    status, count - 1, count, orderByComparator);
17563    
17564                    if (!list.isEmpty()) {
17565                            return list.get(0);
17566                    }
17567    
17568                    return null;
17569            }
17570    
17571            /**
17572             * 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;.
17573             *
17574             * @param messageId the primary key of the current message-boards message
17575             * @param groupId the group ID
17576             * @param categoryId the category ID
17577             * @param threadId the thread ID
17578             * @param status the status
17579             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17580             * @return the previous, current, and next message-boards message
17581             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17582             */
17583            @Override
17584            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17585                    long categoryId, long threadId, int status,
17586                    OrderByComparator<MBMessage> orderByComparator)
17587                    throws NoSuchMessageException {
17588                    MBMessage mbMessage = findByPrimaryKey(messageId);
17589    
17590                    Session session = null;
17591    
17592                    try {
17593                            session = openSession();
17594    
17595                            MBMessage[] array = new MBMessageImpl[3];
17596    
17597                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17598                                            categoryId, threadId, status, orderByComparator, true);
17599    
17600                            array[1] = mbMessage;
17601    
17602                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17603                                            categoryId, threadId, status, orderByComparator, false);
17604    
17605                            return array;
17606                    }
17607                    catch (Exception e) {
17608                            throw processException(e);
17609                    }
17610                    finally {
17611                            closeSession(session);
17612                    }
17613            }
17614    
17615            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17616                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17617                    int status, OrderByComparator<MBMessage> orderByComparator,
17618                    boolean previous) {
17619                    StringBundler query = null;
17620    
17621                    if (orderByComparator != null) {
17622                            query = new StringBundler(6 +
17623                                            (orderByComparator.getOrderByFields().length * 6));
17624                    }
17625                    else {
17626                            query = new StringBundler(3);
17627                    }
17628    
17629                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17630    
17631                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17632    
17633                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17634    
17635                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17636    
17637                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17638    
17639                    if (orderByComparator != null) {
17640                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17641    
17642                            if (orderByConditionFields.length > 0) {
17643                                    query.append(WHERE_AND);
17644                            }
17645    
17646                            for (int i = 0; i < orderByConditionFields.length; i++) {
17647                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17648                                    query.append(orderByConditionFields[i]);
17649    
17650                                    if ((i + 1) < orderByConditionFields.length) {
17651                                            if (orderByComparator.isAscending() ^ previous) {
17652                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17653                                            }
17654                                            else {
17655                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17656                                            }
17657                                    }
17658                                    else {
17659                                            if (orderByComparator.isAscending() ^ previous) {
17660                                                    query.append(WHERE_GREATER_THAN);
17661                                            }
17662                                            else {
17663                                                    query.append(WHERE_LESSER_THAN);
17664                                            }
17665                                    }
17666                            }
17667    
17668                            query.append(ORDER_BY_CLAUSE);
17669    
17670                            String[] orderByFields = orderByComparator.getOrderByFields();
17671    
17672                            for (int i = 0; i < orderByFields.length; i++) {
17673                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17674                                    query.append(orderByFields[i]);
17675    
17676                                    if ((i + 1) < orderByFields.length) {
17677                                            if (orderByComparator.isAscending() ^ previous) {
17678                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17679                                            }
17680                                            else {
17681                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17682                                            }
17683                                    }
17684                                    else {
17685                                            if (orderByComparator.isAscending() ^ previous) {
17686                                                    query.append(ORDER_BY_ASC);
17687                                            }
17688                                            else {
17689                                                    query.append(ORDER_BY_DESC);
17690                                            }
17691                                    }
17692                            }
17693                    }
17694                    else {
17695                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17696                    }
17697    
17698                    String sql = query.toString();
17699    
17700                    Query q = session.createQuery(sql);
17701    
17702                    q.setFirstResult(0);
17703                    q.setMaxResults(2);
17704    
17705                    QueryPos qPos = QueryPos.getInstance(q);
17706    
17707                    qPos.add(groupId);
17708    
17709                    qPos.add(categoryId);
17710    
17711                    qPos.add(threadId);
17712    
17713                    qPos.add(status);
17714    
17715                    if (orderByComparator != null) {
17716                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17717    
17718                            for (Object value : values) {
17719                                    qPos.add(value);
17720                            }
17721                    }
17722    
17723                    List<MBMessage> list = q.list();
17724    
17725                    if (list.size() == 2) {
17726                            return list.get(1);
17727                    }
17728                    else {
17729                            return null;
17730                    }
17731            }
17732    
17733            /**
17734             * 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;.
17735             *
17736             * @param groupId the group ID
17737             * @param categoryId the category ID
17738             * @param threadId the thread ID
17739             * @param status the status
17740             * @return the matching message-boards messages that the user has permission to view
17741             */
17742            @Override
17743            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17744                    long threadId, int status) {
17745                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17746                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17747            }
17748    
17749            /**
17750             * 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;.
17751             *
17752             * <p>
17753             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17754             * </p>
17755             *
17756             * @param groupId the group ID
17757             * @param categoryId the category ID
17758             * @param threadId the thread ID
17759             * @param status the status
17760             * @param start the lower bound of the range of message-boards messages
17761             * @param end the upper bound of the range of message-boards messages (not inclusive)
17762             * @return the range of matching message-boards messages that the user has permission to view
17763             */
17764            @Override
17765            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17766                    long threadId, int status, int start, int end) {
17767                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17768                            start, end, null);
17769            }
17770    
17771            /**
17772             * 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;.
17773             *
17774             * <p>
17775             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
17776             * </p>
17777             *
17778             * @param groupId the group ID
17779             * @param categoryId the category ID
17780             * @param threadId the thread ID
17781             * @param status the status
17782             * @param start the lower bound of the range of message-boards messages
17783             * @param end the upper bound of the range of message-boards messages (not inclusive)
17784             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17785             * @return the ordered range of matching message-boards messages that the user has permission to view
17786             */
17787            @Override
17788            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17789                    long threadId, int status, int start, int end,
17790                    OrderByComparator<MBMessage> orderByComparator) {
17791                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17792                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17793                                    end, orderByComparator);
17794                    }
17795    
17796                    StringBundler query = null;
17797    
17798                    if (orderByComparator != null) {
17799                            query = new StringBundler(6 +
17800                                            (orderByComparator.getOrderByFields().length * 3));
17801                    }
17802                    else {
17803                            query = new StringBundler(6);
17804                    }
17805    
17806                    if (getDB().isSupportsInlineDistinct()) {
17807                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17808                    }
17809                    else {
17810                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17811                    }
17812    
17813                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17814    
17815                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17816    
17817                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17818    
17819                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17820    
17821                    if (!getDB().isSupportsInlineDistinct()) {
17822                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17823                    }
17824    
17825                    if (orderByComparator != null) {
17826                            if (getDB().isSupportsInlineDistinct()) {
17827                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17828                                            orderByComparator, true);
17829                            }
17830                            else {
17831                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17832                                            orderByComparator, true);
17833                            }
17834                    }
17835                    else {
17836                            if (getDB().isSupportsInlineDistinct()) {
17837                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17838                            }
17839                            else {
17840                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17841                            }
17842                    }
17843    
17844                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17845                                    MBMessage.class.getName(),
17846                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17847    
17848                    Session session = null;
17849    
17850                    try {
17851                            session = openSession();
17852    
17853                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17854    
17855                            if (getDB().isSupportsInlineDistinct()) {
17856                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17857                            }
17858                            else {
17859                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17860                            }
17861    
17862                            QueryPos qPos = QueryPos.getInstance(q);
17863    
17864                            qPos.add(groupId);
17865    
17866                            qPos.add(categoryId);
17867    
17868                            qPos.add(threadId);
17869    
17870                            qPos.add(status);
17871    
17872                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17873                    }
17874                    catch (Exception e) {
17875                            throw processException(e);
17876                    }
17877                    finally {
17878                            closeSession(session);
17879                    }
17880            }
17881    
17882            /**
17883             * 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;.
17884             *
17885             * @param messageId the primary key of the current message-boards message
17886             * @param groupId the group ID
17887             * @param categoryId the category ID
17888             * @param threadId the thread ID
17889             * @param status the status
17890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17891             * @return the previous, current, and next message-boards message
17892             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17893             */
17894            @Override
17895            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17896                    long groupId, long categoryId, long threadId, int status,
17897                    OrderByComparator<MBMessage> orderByComparator)
17898                    throws NoSuchMessageException {
17899                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17900                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17901                                    threadId, status, orderByComparator);
17902                    }
17903    
17904                    MBMessage mbMessage = findByPrimaryKey(messageId);
17905    
17906                    Session session = null;
17907    
17908                    try {
17909                            session = openSession();
17910    
17911                            MBMessage[] array = new MBMessageImpl[3];
17912    
17913                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17914                                            groupId, categoryId, threadId, status, orderByComparator,
17915                                            true);
17916    
17917                            array[1] = mbMessage;
17918    
17919                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17920                                            groupId, categoryId, threadId, status, orderByComparator,
17921                                            false);
17922    
17923                            return array;
17924                    }
17925                    catch (Exception e) {
17926                            throw processException(e);
17927                    }
17928                    finally {
17929                            closeSession(session);
17930                    }
17931            }
17932    
17933            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17934                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17935                    int status, OrderByComparator<MBMessage> orderByComparator,
17936                    boolean previous) {
17937                    StringBundler query = null;
17938    
17939                    if (orderByComparator != null) {
17940                            query = new StringBundler(6 +
17941                                            (orderByComparator.getOrderByFields().length * 6));
17942                    }
17943                    else {
17944                            query = new StringBundler(3);
17945                    }
17946    
17947                    if (getDB().isSupportsInlineDistinct()) {
17948                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17949                    }
17950                    else {
17951                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17952                    }
17953    
17954                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17955    
17956                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17957    
17958                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17959    
17960                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17961    
17962                    if (!getDB().isSupportsInlineDistinct()) {
17963                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17964                    }
17965    
17966                    if (orderByComparator != null) {
17967                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17968    
17969                            if (orderByConditionFields.length > 0) {
17970                                    query.append(WHERE_AND);
17971                            }
17972    
17973                            for (int i = 0; i < orderByConditionFields.length; i++) {
17974                                    if (getDB().isSupportsInlineDistinct()) {
17975                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17976                                    }
17977                                    else {
17978                                            query.append(_ORDER_BY_ENTITY_TABLE);
17979                                    }
17980    
17981                                    query.append(orderByConditionFields[i]);
17982    
17983                                    if ((i + 1) < orderByConditionFields.length) {
17984                                            if (orderByComparator.isAscending() ^ previous) {
17985                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17986                                            }
17987                                            else {
17988                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17989                                            }
17990                                    }
17991                                    else {
17992                                            if (orderByComparator.isAscending() ^ previous) {
17993                                                    query.append(WHERE_GREATER_THAN);
17994                                            }
17995                                            else {
17996                                                    query.append(WHERE_LESSER_THAN);
17997                                            }
17998                                    }
17999                            }
18000    
18001                            query.append(ORDER_BY_CLAUSE);
18002    
18003                            String[] orderByFields = orderByComparator.getOrderByFields();
18004    
18005                            for (int i = 0; i < orderByFields.length; i++) {
18006                                    if (getDB().isSupportsInlineDistinct()) {
18007                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18008                                    }
18009                                    else {
18010                                            query.append(_ORDER_BY_ENTITY_TABLE);
18011                                    }
18012    
18013                                    query.append(orderByFields[i]);
18014    
18015                                    if ((i + 1) < orderByFields.length) {
18016                                            if (orderByComparator.isAscending() ^ previous) {
18017                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18018                                            }
18019                                            else {
18020                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18021                                            }
18022                                    }
18023                                    else {
18024                                            if (orderByComparator.isAscending() ^ previous) {
18025                                                    query.append(ORDER_BY_ASC);
18026                                            }
18027                                            else {
18028                                                    query.append(ORDER_BY_DESC);
18029                                            }
18030                                    }
18031                            }
18032                    }
18033                    else {
18034                            if (getDB().isSupportsInlineDistinct()) {
18035                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18036                            }
18037                            else {
18038                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18039                            }
18040                    }
18041    
18042                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18043                                    MBMessage.class.getName(),
18044                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18045    
18046                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
18047    
18048                    q.setFirstResult(0);
18049                    q.setMaxResults(2);
18050    
18051                    if (getDB().isSupportsInlineDistinct()) {
18052                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18053                    }
18054                    else {
18055                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18056                    }
18057    
18058                    QueryPos qPos = QueryPos.getInstance(q);
18059    
18060                    qPos.add(groupId);
18061    
18062                    qPos.add(categoryId);
18063    
18064                    qPos.add(threadId);
18065    
18066                    qPos.add(status);
18067    
18068                    if (orderByComparator != null) {
18069                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18070    
18071                            for (Object value : values) {
18072                                    qPos.add(value);
18073                            }
18074                    }
18075    
18076                    List<MBMessage> list = q.list();
18077    
18078                    if (list.size() == 2) {
18079                            return list.get(1);
18080                    }
18081                    else {
18082                            return null;
18083                    }
18084            }
18085    
18086            /**
18087             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
18088             *
18089             * @param groupId the group ID
18090             * @param categoryId the category ID
18091             * @param threadId the thread ID
18092             * @param status the status
18093             */
18094            @Override
18095            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
18096                    int status) {
18097                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
18098                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18099                            remove(mbMessage);
18100                    }
18101            }
18102    
18103            /**
18104             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18105             *
18106             * @param groupId the group ID
18107             * @param categoryId the category ID
18108             * @param threadId the thread ID
18109             * @param status the status
18110             * @return the number of matching message-boards messages
18111             */
18112            @Override
18113            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18114                    int status) {
18115                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
18116    
18117                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18118    
18119                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18120    
18121                    if (count == null) {
18122                            StringBundler query = new StringBundler(5);
18123    
18124                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18125    
18126                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18127    
18128                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18129    
18130                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18131    
18132                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18133    
18134                            String sql = query.toString();
18135    
18136                            Session session = null;
18137    
18138                            try {
18139                                    session = openSession();
18140    
18141                                    Query q = session.createQuery(sql);
18142    
18143                                    QueryPos qPos = QueryPos.getInstance(q);
18144    
18145                                    qPos.add(groupId);
18146    
18147                                    qPos.add(categoryId);
18148    
18149                                    qPos.add(threadId);
18150    
18151                                    qPos.add(status);
18152    
18153                                    count = (Long)q.uniqueResult();
18154    
18155                                    finderCache.putResult(finderPath, finderArgs, count);
18156                            }
18157                            catch (Exception e) {
18158                                    finderCache.removeResult(finderPath, finderArgs);
18159    
18160                                    throw processException(e);
18161                            }
18162                            finally {
18163                                    closeSession(session);
18164                            }
18165                    }
18166    
18167                    return count.intValue();
18168            }
18169    
18170            /**
18171             * 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;.
18172             *
18173             * @param groupId the group ID
18174             * @param categoryId the category ID
18175             * @param threadId the thread ID
18176             * @param status the status
18177             * @return the number of matching message-boards messages that the user has permission to view
18178             */
18179            @Override
18180            public int filterCountByG_C_T_S(long groupId, long categoryId,
18181                    long threadId, int status) {
18182                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18183                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18184                    }
18185    
18186                    StringBundler query = new StringBundler(5);
18187    
18188                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18189    
18190                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18191    
18192                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18193    
18194                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18195    
18196                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18197    
18198                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18199                                    MBMessage.class.getName(),
18200                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18201    
18202                    Session session = null;
18203    
18204                    try {
18205                            session = openSession();
18206    
18207                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
18208    
18209                            q.addScalar(COUNT_COLUMN_NAME,
18210                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18211    
18212                            QueryPos qPos = QueryPos.getInstance(q);
18213    
18214                            qPos.add(groupId);
18215    
18216                            qPos.add(categoryId);
18217    
18218                            qPos.add(threadId);
18219    
18220                            qPos.add(status);
18221    
18222                            Long count = (Long)q.uniqueResult();
18223    
18224                            return count.intValue();
18225                    }
18226                    catch (Exception e) {
18227                            throw processException(e);
18228                    }
18229                    finally {
18230                            closeSession(session);
18231                    }
18232            }
18233    
18234            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18235            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18236            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18237            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18238            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18239                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18240                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
18241                            new String[] {
18242                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18243                                    Integer.class.getName(),
18244                                    
18245                            Integer.class.getName(), Integer.class.getName(),
18246                                    OrderByComparator.class.getName()
18247                            });
18248            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
18249                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18250                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18251                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
18252                            new String[] {
18253                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18254                                    Integer.class.getName()
18255                            },
18256                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
18257                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
18258                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
18259                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18260                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18261            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18262                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18263                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
18264                            new String[] {
18265                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18266                                    Integer.class.getName()
18267                            });
18268    
18269            /**
18270             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18271             *
18272             * @param userId the user ID
18273             * @param classNameId the class name ID
18274             * @param classPK the class p k
18275             * @param status the status
18276             * @return the matching message-boards messages
18277             */
18278            @Override
18279            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18280                    long classPK, int status) {
18281                    return findByU_C_C_S(userId, classNameId, classPK, status,
18282                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18283            }
18284    
18285            /**
18286             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18287             *
18288             * <p>
18289             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
18290             * </p>
18291             *
18292             * @param userId the user ID
18293             * @param classNameId the class name ID
18294             * @param classPK the class p k
18295             * @param status the status
18296             * @param start the lower bound of the range of message-boards messages
18297             * @param end the upper bound of the range of message-boards messages (not inclusive)
18298             * @return the range of matching message-boards messages
18299             */
18300            @Override
18301            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18302                    long classPK, int status, int start, int end) {
18303                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18304                            null);
18305            }
18306    
18307            /**
18308             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18309             *
18310             * <p>
18311             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
18312             * </p>
18313             *
18314             * @param userId the user ID
18315             * @param classNameId the class name ID
18316             * @param classPK the class p k
18317             * @param status the status
18318             * @param start the lower bound of the range of message-boards messages
18319             * @param end the upper bound of the range of message-boards messages (not inclusive)
18320             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18321             * @return the ordered range of matching message-boards messages
18322             */
18323            @Override
18324            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18325                    long classPK, int status, int start, int end,
18326                    OrderByComparator<MBMessage> orderByComparator) {
18327                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18328                            orderByComparator, true);
18329            }
18330    
18331            /**
18332             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18333             *
18334             * <p>
18335             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
18336             * </p>
18337             *
18338             * @param userId the user ID
18339             * @param classNameId the class name ID
18340             * @param classPK the class p k
18341             * @param status the status
18342             * @param start the lower bound of the range of message-boards messages
18343             * @param end the upper bound of the range of message-boards messages (not inclusive)
18344             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18345             * @param retrieveFromCache whether to retrieve from the finder cache
18346             * @return the ordered range of matching message-boards messages
18347             */
18348            @Override
18349            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18350                    long classPK, int status, int start, int end,
18351                    OrderByComparator<MBMessage> orderByComparator,
18352                    boolean retrieveFromCache) {
18353                    boolean pagination = true;
18354                    FinderPath finderPath = null;
18355                    Object[] finderArgs = null;
18356    
18357                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18358                                    (orderByComparator == null)) {
18359                            pagination = false;
18360                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18361                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18362                    }
18363                    else {
18364                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18365                            finderArgs = new Object[] {
18366                                            userId, classNameId, classPK, status,
18367                                            
18368                                            start, end, orderByComparator
18369                                    };
18370                    }
18371    
18372                    List<MBMessage> list = null;
18373    
18374                    if (retrieveFromCache) {
18375                            list = (List<MBMessage>)finderCache.getResult(finderPath,
18376                                            finderArgs, this);
18377    
18378                            if ((list != null) && !list.isEmpty()) {
18379                                    for (MBMessage mbMessage : list) {
18380                                            if ((userId != mbMessage.getUserId()) ||
18381                                                            (classNameId != mbMessage.getClassNameId()) ||
18382                                                            (classPK != mbMessage.getClassPK()) ||
18383                                                            (status != mbMessage.getStatus())) {
18384                                                    list = null;
18385    
18386                                                    break;
18387                                            }
18388                                    }
18389                            }
18390                    }
18391    
18392                    if (list == null) {
18393                            StringBundler query = null;
18394    
18395                            if (orderByComparator != null) {
18396                                    query = new StringBundler(6 +
18397                                                    (orderByComparator.getOrderByFields().length * 3));
18398                            }
18399                            else {
18400                                    query = new StringBundler(6);
18401                            }
18402    
18403                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18404    
18405                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18406    
18407                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18408    
18409                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18410    
18411                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18412    
18413                            if (orderByComparator != null) {
18414                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18415                                            orderByComparator);
18416                            }
18417                            else
18418                             if (pagination) {
18419                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18420                            }
18421    
18422                            String sql = query.toString();
18423    
18424                            Session session = null;
18425    
18426                            try {
18427                                    session = openSession();
18428    
18429                                    Query q = session.createQuery(sql);
18430    
18431                                    QueryPos qPos = QueryPos.getInstance(q);
18432    
18433                                    qPos.add(userId);
18434    
18435                                    qPos.add(classNameId);
18436    
18437                                    qPos.add(classPK);
18438    
18439                                    qPos.add(status);
18440    
18441                                    if (!pagination) {
18442                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18443                                                            start, end, false);
18444    
18445                                            Collections.sort(list);
18446    
18447                                            list = Collections.unmodifiableList(list);
18448                                    }
18449                                    else {
18450                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18451                                                            start, end);
18452                                    }
18453    
18454                                    cacheResult(list);
18455    
18456                                    finderCache.putResult(finderPath, finderArgs, list);
18457                            }
18458                            catch (Exception e) {
18459                                    finderCache.removeResult(finderPath, finderArgs);
18460    
18461                                    throw processException(e);
18462                            }
18463                            finally {
18464                                    closeSession(session);
18465                            }
18466                    }
18467    
18468                    return list;
18469            }
18470    
18471            /**
18472             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18473             *
18474             * @param userId the user ID
18475             * @param classNameId the class name ID
18476             * @param classPK the class p k
18477             * @param status the status
18478             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18479             * @return the first matching message-boards message
18480             * @throws NoSuchMessageException if a matching message-boards message could not be found
18481             */
18482            @Override
18483            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18484                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18485                    throws NoSuchMessageException {
18486                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18487                                    classPK, status, orderByComparator);
18488    
18489                    if (mbMessage != null) {
18490                            return mbMessage;
18491                    }
18492    
18493                    StringBundler msg = new StringBundler(10);
18494    
18495                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18496    
18497                    msg.append("userId=");
18498                    msg.append(userId);
18499    
18500                    msg.append(", classNameId=");
18501                    msg.append(classNameId);
18502    
18503                    msg.append(", classPK=");
18504                    msg.append(classPK);
18505    
18506                    msg.append(", status=");
18507                    msg.append(status);
18508    
18509                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18510    
18511                    throw new NoSuchMessageException(msg.toString());
18512            }
18513    
18514            /**
18515             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18516             *
18517             * @param userId the user ID
18518             * @param classNameId the class name ID
18519             * @param classPK the class p k
18520             * @param status the status
18521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18522             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18523             */
18524            @Override
18525            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18526                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18527                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18528                                    status, 0, 1, orderByComparator);
18529    
18530                    if (!list.isEmpty()) {
18531                            return list.get(0);
18532                    }
18533    
18534                    return null;
18535            }
18536    
18537            /**
18538             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18539             *
18540             * @param userId the user ID
18541             * @param classNameId the class name ID
18542             * @param classPK the class p k
18543             * @param status the status
18544             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18545             * @return the last matching message-boards message
18546             * @throws NoSuchMessageException if a matching message-boards message could not be found
18547             */
18548            @Override
18549            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18550                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18551                    throws NoSuchMessageException {
18552                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18553                                    status, orderByComparator);
18554    
18555                    if (mbMessage != null) {
18556                            return mbMessage;
18557                    }
18558    
18559                    StringBundler msg = new StringBundler(10);
18560    
18561                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18562    
18563                    msg.append("userId=");
18564                    msg.append(userId);
18565    
18566                    msg.append(", classNameId=");
18567                    msg.append(classNameId);
18568    
18569                    msg.append(", classPK=");
18570                    msg.append(classPK);
18571    
18572                    msg.append(", status=");
18573                    msg.append(status);
18574    
18575                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18576    
18577                    throw new NoSuchMessageException(msg.toString());
18578            }
18579    
18580            /**
18581             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18582             *
18583             * @param userId the user ID
18584             * @param classNameId the class name ID
18585             * @param classPK the class p k
18586             * @param status the status
18587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18588             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18589             */
18590            @Override
18591            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18592                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18593                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18594    
18595                    if (count == 0) {
18596                            return null;
18597                    }
18598    
18599                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18600                                    status, count - 1, count, orderByComparator);
18601    
18602                    if (!list.isEmpty()) {
18603                            return list.get(0);
18604                    }
18605    
18606                    return null;
18607            }
18608    
18609            /**
18610             * 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;.
18611             *
18612             * @param messageId the primary key of the current message-boards message
18613             * @param userId the user ID
18614             * @param classNameId the class name ID
18615             * @param classPK the class p k
18616             * @param status the status
18617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18618             * @return the previous, current, and next message-boards message
18619             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18620             */
18621            @Override
18622            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18623                    long classNameId, long classPK, int status,
18624                    OrderByComparator<MBMessage> orderByComparator)
18625                    throws NoSuchMessageException {
18626                    MBMessage mbMessage = findByPrimaryKey(messageId);
18627    
18628                    Session session = null;
18629    
18630                    try {
18631                            session = openSession();
18632    
18633                            MBMessage[] array = new MBMessageImpl[3];
18634    
18635                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18636                                            classNameId, classPK, status, orderByComparator, true);
18637    
18638                            array[1] = mbMessage;
18639    
18640                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18641                                            classNameId, classPK, status, orderByComparator, false);
18642    
18643                            return array;
18644                    }
18645                    catch (Exception e) {
18646                            throw processException(e);
18647                    }
18648                    finally {
18649                            closeSession(session);
18650                    }
18651            }
18652    
18653            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18654                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18655                    int status, OrderByComparator<MBMessage> orderByComparator,
18656                    boolean previous) {
18657                    StringBundler query = null;
18658    
18659                    if (orderByComparator != null) {
18660                            query = new StringBundler(6 +
18661                                            (orderByComparator.getOrderByFields().length * 6));
18662                    }
18663                    else {
18664                            query = new StringBundler(3);
18665                    }
18666    
18667                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18668    
18669                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18670    
18671                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18672    
18673                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18674    
18675                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18676    
18677                    if (orderByComparator != null) {
18678                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18679    
18680                            if (orderByConditionFields.length > 0) {
18681                                    query.append(WHERE_AND);
18682                            }
18683    
18684                            for (int i = 0; i < orderByConditionFields.length; i++) {
18685                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18686                                    query.append(orderByConditionFields[i]);
18687    
18688                                    if ((i + 1) < orderByConditionFields.length) {
18689                                            if (orderByComparator.isAscending() ^ previous) {
18690                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18691                                            }
18692                                            else {
18693                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18694                                            }
18695                                    }
18696                                    else {
18697                                            if (orderByComparator.isAscending() ^ previous) {
18698                                                    query.append(WHERE_GREATER_THAN);
18699                                            }
18700                                            else {
18701                                                    query.append(WHERE_LESSER_THAN);
18702                                            }
18703                                    }
18704                            }
18705    
18706                            query.append(ORDER_BY_CLAUSE);
18707    
18708                            String[] orderByFields = orderByComparator.getOrderByFields();
18709    
18710                            for (int i = 0; i < orderByFields.length; i++) {
18711                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18712                                    query.append(orderByFields[i]);
18713    
18714                                    if ((i + 1) < orderByFields.length) {
18715                                            if (orderByComparator.isAscending() ^ previous) {
18716                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18717                                            }
18718                                            else {
18719                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18720                                            }
18721                                    }
18722                                    else {
18723                                            if (orderByComparator.isAscending() ^ previous) {
18724                                                    query.append(ORDER_BY_ASC);
18725                                            }
18726                                            else {
18727                                                    query.append(ORDER_BY_DESC);
18728                                            }
18729                                    }
18730                            }
18731                    }
18732                    else {
18733                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18734                    }
18735    
18736                    String sql = query.toString();
18737    
18738                    Query q = session.createQuery(sql);
18739    
18740                    q.setFirstResult(0);
18741                    q.setMaxResults(2);
18742    
18743                    QueryPos qPos = QueryPos.getInstance(q);
18744    
18745                    qPos.add(userId);
18746    
18747                    qPos.add(classNameId);
18748    
18749                    qPos.add(classPK);
18750    
18751                    qPos.add(status);
18752    
18753                    if (orderByComparator != null) {
18754                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18755    
18756                            for (Object value : values) {
18757                                    qPos.add(value);
18758                            }
18759                    }
18760    
18761                    List<MBMessage> list = q.list();
18762    
18763                    if (list.size() == 2) {
18764                            return list.get(1);
18765                    }
18766                    else {
18767                            return null;
18768                    }
18769            }
18770    
18771            /**
18772             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18773             *
18774             * @param userId the user ID
18775             * @param classNameId the class name ID
18776             * @param classPK the class p k
18777             * @param status the status
18778             */
18779            @Override
18780            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18781                    int status) {
18782                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18783                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18784                            remove(mbMessage);
18785                    }
18786            }
18787    
18788            /**
18789             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18790             *
18791             * @param userId the user ID
18792             * @param classNameId the class name ID
18793             * @param classPK the class p k
18794             * @param status the status
18795             * @return the number of matching message-boards messages
18796             */
18797            @Override
18798            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18799                    int status) {
18800                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18801    
18802                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18803    
18804                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18805    
18806                    if (count == null) {
18807                            StringBundler query = new StringBundler(5);
18808    
18809                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18810    
18811                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18812    
18813                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18814    
18815                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18816    
18817                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18818    
18819                            String sql = query.toString();
18820    
18821                            Session session = null;
18822    
18823                            try {
18824                                    session = openSession();
18825    
18826                                    Query q = session.createQuery(sql);
18827    
18828                                    QueryPos qPos = QueryPos.getInstance(q);
18829    
18830                                    qPos.add(userId);
18831    
18832                                    qPos.add(classNameId);
18833    
18834                                    qPos.add(classPK);
18835    
18836                                    qPos.add(status);
18837    
18838                                    count = (Long)q.uniqueResult();
18839    
18840                                    finderCache.putResult(finderPath, finderArgs, count);
18841                            }
18842                            catch (Exception e) {
18843                                    finderCache.removeResult(finderPath, finderArgs);
18844    
18845                                    throw processException(e);
18846                            }
18847                            finally {
18848                                    closeSession(session);
18849                            }
18850                    }
18851    
18852                    return count.intValue();
18853            }
18854    
18855            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18856            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18857            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18858            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18859    
18860            public MBMessagePersistenceImpl() {
18861                    setModelClass(MBMessage.class);
18862            }
18863    
18864            /**
18865             * Caches the message-boards message in the entity cache if it is enabled.
18866             *
18867             * @param mbMessage the message-boards message
18868             */
18869            @Override
18870            public void cacheResult(MBMessage mbMessage) {
18871                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18872                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18873    
18874                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18875                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18876                            mbMessage);
18877    
18878                    mbMessage.resetOriginalValues();
18879            }
18880    
18881            /**
18882             * Caches the message-boards messages in the entity cache if it is enabled.
18883             *
18884             * @param mbMessages the message-boards messages
18885             */
18886            @Override
18887            public void cacheResult(List<MBMessage> mbMessages) {
18888                    for (MBMessage mbMessage : mbMessages) {
18889                            if (entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18890                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18891                                    cacheResult(mbMessage);
18892                            }
18893                            else {
18894                                    mbMessage.resetOriginalValues();
18895                            }
18896                    }
18897            }
18898    
18899            /**
18900             * Clears the cache for all message-boards messages.
18901             *
18902             * <p>
18903             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18904             * </p>
18905             */
18906            @Override
18907            public void clearCache() {
18908                    entityCache.clearCache(MBMessageImpl.class);
18909    
18910                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
18911                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18912                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18913            }
18914    
18915            /**
18916             * Clears the cache for the message-boards message.
18917             *
18918             * <p>
18919             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18920             * </p>
18921             */
18922            @Override
18923            public void clearCache(MBMessage mbMessage) {
18924                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18925                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18926    
18927                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18928                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18929    
18930                    clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18931            }
18932    
18933            @Override
18934            public void clearCache(List<MBMessage> mbMessages) {
18935                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18936                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18937    
18938                    for (MBMessage mbMessage : mbMessages) {
18939                            entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18940                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18941    
18942                            clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18943                    }
18944            }
18945    
18946            protected void cacheUniqueFindersCache(
18947                    MBMessageModelImpl mbMessageModelImpl, boolean isNew) {
18948                    if (isNew) {
18949                            Object[] args = new Object[] {
18950                                            mbMessageModelImpl.getUuid(),
18951                                            mbMessageModelImpl.getGroupId()
18952                                    };
18953    
18954                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18955                                    Long.valueOf(1));
18956                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18957                                    mbMessageModelImpl);
18958                    }
18959                    else {
18960                            if ((mbMessageModelImpl.getColumnBitmask() &
18961                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18962                                    Object[] args = new Object[] {
18963                                                    mbMessageModelImpl.getUuid(),
18964                                                    mbMessageModelImpl.getGroupId()
18965                                            };
18966    
18967                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18968                                            Long.valueOf(1));
18969                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18970                                            mbMessageModelImpl);
18971                            }
18972                    }
18973            }
18974    
18975            protected void clearUniqueFindersCache(
18976                    MBMessageModelImpl mbMessageModelImpl) {
18977                    Object[] args = new Object[] {
18978                                    mbMessageModelImpl.getUuid(), mbMessageModelImpl.getGroupId()
18979                            };
18980    
18981                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18982                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18983    
18984                    if ((mbMessageModelImpl.getColumnBitmask() &
18985                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18986                            args = new Object[] {
18987                                            mbMessageModelImpl.getOriginalUuid(),
18988                                            mbMessageModelImpl.getOriginalGroupId()
18989                                    };
18990    
18991                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18992                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18993                    }
18994            }
18995    
18996            /**
18997             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18998             *
18999             * @param messageId the primary key for the new message-boards message
19000             * @return the new message-boards message
19001             */
19002            @Override
19003            public MBMessage create(long messageId) {
19004                    MBMessage mbMessage = new MBMessageImpl();
19005    
19006                    mbMessage.setNew(true);
19007                    mbMessage.setPrimaryKey(messageId);
19008    
19009                    String uuid = PortalUUIDUtil.generate();
19010    
19011                    mbMessage.setUuid(uuid);
19012    
19013                    mbMessage.setCompanyId(companyProvider.getCompanyId());
19014    
19015                    return mbMessage;
19016            }
19017    
19018            /**
19019             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19020             *
19021             * @param messageId the primary key of the message-boards message
19022             * @return the message-boards message that was removed
19023             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19024             */
19025            @Override
19026            public MBMessage remove(long messageId) throws NoSuchMessageException {
19027                    return remove((Serializable)messageId);
19028            }
19029    
19030            /**
19031             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19032             *
19033             * @param primaryKey the primary key of the message-boards message
19034             * @return the message-boards message that was removed
19035             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19036             */
19037            @Override
19038            public MBMessage remove(Serializable primaryKey)
19039                    throws NoSuchMessageException {
19040                    Session session = null;
19041    
19042                    try {
19043                            session = openSession();
19044    
19045                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19046                                            primaryKey);
19047    
19048                            if (mbMessage == null) {
19049                                    if (_log.isWarnEnabled()) {
19050                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19051                                    }
19052    
19053                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19054                                            primaryKey);
19055                            }
19056    
19057                            return remove(mbMessage);
19058                    }
19059                    catch (NoSuchMessageException nsee) {
19060                            throw nsee;
19061                    }
19062                    catch (Exception e) {
19063                            throw processException(e);
19064                    }
19065                    finally {
19066                            closeSession(session);
19067                    }
19068            }
19069    
19070            @Override
19071            protected MBMessage removeImpl(MBMessage mbMessage) {
19072                    mbMessage = toUnwrappedModel(mbMessage);
19073    
19074                    Session session = null;
19075    
19076                    try {
19077                            session = openSession();
19078    
19079                            if (!session.contains(mbMessage)) {
19080                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19081                                                    mbMessage.getPrimaryKeyObj());
19082                            }
19083    
19084                            if (mbMessage != null) {
19085                                    session.delete(mbMessage);
19086                            }
19087                    }
19088                    catch (Exception e) {
19089                            throw processException(e);
19090                    }
19091                    finally {
19092                            closeSession(session);
19093                    }
19094    
19095                    if (mbMessage != null) {
19096                            clearCache(mbMessage);
19097                    }
19098    
19099                    return mbMessage;
19100            }
19101    
19102            @Override
19103            public MBMessage updateImpl(MBMessage mbMessage) {
19104                    mbMessage = toUnwrappedModel(mbMessage);
19105    
19106                    boolean isNew = mbMessage.isNew();
19107    
19108                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19109    
19110                    if (Validator.isNull(mbMessage.getUuid())) {
19111                            String uuid = PortalUUIDUtil.generate();
19112    
19113                            mbMessage.setUuid(uuid);
19114                    }
19115    
19116                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
19117    
19118                    Date now = new Date();
19119    
19120                    if (isNew && (mbMessage.getCreateDate() == null)) {
19121                            if (serviceContext == null) {
19122                                    mbMessage.setCreateDate(now);
19123                            }
19124                            else {
19125                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
19126                            }
19127                    }
19128    
19129                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
19130                            if (serviceContext == null) {
19131                                    mbMessage.setModifiedDate(now);
19132                            }
19133                            else {
19134                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
19135                            }
19136                    }
19137    
19138                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
19139    
19140                    if (userId > 0) {
19141                            long companyId = mbMessage.getCompanyId();
19142    
19143                            long groupId = mbMessage.getGroupId();
19144    
19145                            long messageId = 0;
19146    
19147                            if (!isNew) {
19148                                    messageId = mbMessage.getPrimaryKey();
19149                            }
19150    
19151                            try {
19152                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
19153                                                    userId,
19154                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
19155                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
19156                                                    mbMessage.getSubject(), null));
19157                            }
19158                            catch (SanitizerException se) {
19159                                    throw new SystemException(se);
19160                            }
19161                    }
19162    
19163                    Session session = null;
19164    
19165                    try {
19166                            session = openSession();
19167    
19168                            if (mbMessage.isNew()) {
19169                                    session.save(mbMessage);
19170    
19171                                    mbMessage.setNew(false);
19172                            }
19173                            else {
19174                                    mbMessage = (MBMessage)session.merge(mbMessage);
19175                            }
19176                    }
19177                    catch (Exception e) {
19178                            throw processException(e);
19179                    }
19180                    finally {
19181                            closeSession(session);
19182                    }
19183    
19184                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19185    
19186                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
19187                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19188                    }
19189    
19190                    else {
19191                            if ((mbMessageModelImpl.getColumnBitmask() &
19192                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
19193                                    Object[] args = new Object[] {
19194                                                    mbMessageModelImpl.getOriginalUuid()
19195                                            };
19196    
19197                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19198                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19199                                            args);
19200    
19201                                    args = new Object[] { mbMessageModelImpl.getUuid() };
19202    
19203                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19204                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19205                                            args);
19206                            }
19207    
19208                            if ((mbMessageModelImpl.getColumnBitmask() &
19209                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
19210                                    Object[] args = new Object[] {
19211                                                    mbMessageModelImpl.getOriginalUuid(),
19212                                                    mbMessageModelImpl.getOriginalCompanyId()
19213                                            };
19214    
19215                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19216                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19217                                            args);
19218    
19219                                    args = new Object[] {
19220                                                    mbMessageModelImpl.getUuid(),
19221                                                    mbMessageModelImpl.getCompanyId()
19222                                            };
19223    
19224                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19225                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19226                                            args);
19227                            }
19228    
19229                            if ((mbMessageModelImpl.getColumnBitmask() &
19230                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
19231                                    Object[] args = new Object[] {
19232                                                    mbMessageModelImpl.getOriginalGroupId()
19233                                            };
19234    
19235                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19236                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19237                                            args);
19238    
19239                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
19240    
19241                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19242                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19243                                            args);
19244                            }
19245    
19246                            if ((mbMessageModelImpl.getColumnBitmask() &
19247                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
19248                                    Object[] args = new Object[] {
19249                                                    mbMessageModelImpl.getOriginalCompanyId()
19250                                            };
19251    
19252                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19253                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19254                                            args);
19255    
19256                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
19257    
19258                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19259                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19260                                            args);
19261                            }
19262    
19263                            if ((mbMessageModelImpl.getColumnBitmask() &
19264                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
19265                                    Object[] args = new Object[] {
19266                                                    mbMessageModelImpl.getOriginalUserId()
19267                                            };
19268    
19269                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19270                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19271                                            args);
19272    
19273                                    args = new Object[] { mbMessageModelImpl.getUserId() };
19274    
19275                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19276                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19277                                            args);
19278                            }
19279    
19280                            if ((mbMessageModelImpl.getColumnBitmask() &
19281                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
19282                                    Object[] args = new Object[] {
19283                                                    mbMessageModelImpl.getOriginalThreadId()
19284                                            };
19285    
19286                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19287                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19288                                            args);
19289    
19290                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19291    
19292                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19293                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19294                                            args);
19295                            }
19296    
19297                            if ((mbMessageModelImpl.getColumnBitmask() &
19298                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
19299                                    Object[] args = new Object[] {
19300                                                    mbMessageModelImpl.getOriginalThreadId()
19301                                            };
19302    
19303                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19304                                            args);
19305                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19306                                            args);
19307    
19308                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19309    
19310                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19311                                            args);
19312                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19313                                            args);
19314                            }
19315    
19316                            if ((mbMessageModelImpl.getColumnBitmask() &
19317                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19318                                    Object[] args = new Object[] {
19319                                                    mbMessageModelImpl.getOriginalGroupId(),
19320                                                    mbMessageModelImpl.getOriginalUserId()
19321                                            };
19322    
19323                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19324                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19325                                            args);
19326    
19327                                    args = new Object[] {
19328                                                    mbMessageModelImpl.getGroupId(),
19329                                                    mbMessageModelImpl.getUserId()
19330                                            };
19331    
19332                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19333                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19334                                            args);
19335                            }
19336    
19337                            if ((mbMessageModelImpl.getColumnBitmask() &
19338                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19339                                    Object[] args = new Object[] {
19340                                                    mbMessageModelImpl.getOriginalGroupId(),
19341                                                    mbMessageModelImpl.getOriginalCategoryId()
19342                                            };
19343    
19344                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19345                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19346                                            args);
19347    
19348                                    args = new Object[] {
19349                                                    mbMessageModelImpl.getGroupId(),
19350                                                    mbMessageModelImpl.getCategoryId()
19351                                            };
19352    
19353                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19354                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19355                                            args);
19356                            }
19357    
19358                            if ((mbMessageModelImpl.getColumnBitmask() &
19359                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19360                                    Object[] args = new Object[] {
19361                                                    mbMessageModelImpl.getOriginalGroupId(),
19362                                                    mbMessageModelImpl.getOriginalStatus()
19363                                            };
19364    
19365                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19366                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19367                                            args);
19368    
19369                                    args = new Object[] {
19370                                                    mbMessageModelImpl.getGroupId(),
19371                                                    mbMessageModelImpl.getStatus()
19372                                            };
19373    
19374                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19375                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19376                                            args);
19377                            }
19378    
19379                            if ((mbMessageModelImpl.getColumnBitmask() &
19380                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19381                                    Object[] args = new Object[] {
19382                                                    mbMessageModelImpl.getOriginalCompanyId(),
19383                                                    mbMessageModelImpl.getOriginalStatus()
19384                                            };
19385    
19386                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19387                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19388                                            args);
19389    
19390                                    args = new Object[] {
19391                                                    mbMessageModelImpl.getCompanyId(),
19392                                                    mbMessageModelImpl.getStatus()
19393                                            };
19394    
19395                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19396                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19397                                            args);
19398                            }
19399    
19400                            if ((mbMessageModelImpl.getColumnBitmask() &
19401                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19402                                    Object[] args = new Object[] {
19403                                                    mbMessageModelImpl.getOriginalUserId(),
19404                                                    mbMessageModelImpl.getOriginalClassNameId()
19405                                            };
19406    
19407                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19408                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19409                                            args);
19410    
19411                                    args = new Object[] {
19412                                                    mbMessageModelImpl.getUserId(),
19413                                                    mbMessageModelImpl.getClassNameId()
19414                                            };
19415    
19416                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19417                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19418                                            args);
19419                            }
19420    
19421                            if ((mbMessageModelImpl.getColumnBitmask() &
19422                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19423                                    Object[] args = new Object[] {
19424                                                    mbMessageModelImpl.getOriginalClassNameId(),
19425                                                    mbMessageModelImpl.getOriginalClassPK()
19426                                            };
19427    
19428                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19429                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19430                                            args);
19431    
19432                                    args = new Object[] {
19433                                                    mbMessageModelImpl.getClassNameId(),
19434                                                    mbMessageModelImpl.getClassPK()
19435                                            };
19436    
19437                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19438                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19439                                            args);
19440                            }
19441    
19442                            if ((mbMessageModelImpl.getColumnBitmask() &
19443                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19444                                    Object[] args = new Object[] {
19445                                                    mbMessageModelImpl.getOriginalThreadId(),
19446                                                    mbMessageModelImpl.getOriginalParentMessageId()
19447                                            };
19448    
19449                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19450                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19451                                            args);
19452    
19453                                    args = new Object[] {
19454                                                    mbMessageModelImpl.getThreadId(),
19455                                                    mbMessageModelImpl.getParentMessageId()
19456                                            };
19457    
19458                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19459                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19460                                            args);
19461                            }
19462    
19463                            if ((mbMessageModelImpl.getColumnBitmask() &
19464                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19465                                    Object[] args = new Object[] {
19466                                                    mbMessageModelImpl.getOriginalThreadId(),
19467                                                    mbMessageModelImpl.getOriginalAnswer()
19468                                            };
19469    
19470                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19471                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19472                                            args);
19473    
19474                                    args = new Object[] {
19475                                                    mbMessageModelImpl.getThreadId(),
19476                                                    mbMessageModelImpl.getAnswer()
19477                                            };
19478    
19479                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19480                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19481                                            args);
19482                            }
19483    
19484                            if ((mbMessageModelImpl.getColumnBitmask() &
19485                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19486                                    Object[] args = new Object[] {
19487                                                    mbMessageModelImpl.getOriginalThreadId(),
19488                                                    mbMessageModelImpl.getOriginalStatus()
19489                                            };
19490    
19491                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19492                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19493                                            args);
19494    
19495                                    args = new Object[] {
19496                                                    mbMessageModelImpl.getThreadId(),
19497                                                    mbMessageModelImpl.getStatus()
19498                                            };
19499    
19500                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19501                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19502                                            args);
19503                            }
19504    
19505                            if ((mbMessageModelImpl.getColumnBitmask() &
19506                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19507                                    Object[] args = new Object[] {
19508                                                    mbMessageModelImpl.getOriginalThreadId(),
19509                                                    mbMessageModelImpl.getOriginalStatus()
19510                                            };
19511    
19512                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19513                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19514                                            args);
19515    
19516                                    args = new Object[] {
19517                                                    mbMessageModelImpl.getThreadId(),
19518                                                    mbMessageModelImpl.getStatus()
19519                                            };
19520    
19521                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19522                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19523                                            args);
19524                            }
19525    
19526                            if ((mbMessageModelImpl.getColumnBitmask() &
19527                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19528                                    Object[] args = new Object[] {
19529                                                    mbMessageModelImpl.getOriginalGroupId(),
19530                                                    mbMessageModelImpl.getOriginalUserId(),
19531                                                    mbMessageModelImpl.getOriginalStatus()
19532                                            };
19533    
19534                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19535                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19536                                            args);
19537    
19538                                    args = new Object[] {
19539                                                    mbMessageModelImpl.getGroupId(),
19540                                                    mbMessageModelImpl.getUserId(),
19541                                                    mbMessageModelImpl.getStatus()
19542                                            };
19543    
19544                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19545                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19546                                            args);
19547                            }
19548    
19549                            if ((mbMessageModelImpl.getColumnBitmask() &
19550                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19551                                    Object[] args = new Object[] {
19552                                                    mbMessageModelImpl.getOriginalGroupId(),
19553                                                    mbMessageModelImpl.getOriginalCategoryId(),
19554                                                    mbMessageModelImpl.getOriginalThreadId()
19555                                            };
19556    
19557                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19558                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19559                                            args);
19560    
19561                                    args = new Object[] {
19562                                                    mbMessageModelImpl.getGroupId(),
19563                                                    mbMessageModelImpl.getCategoryId(),
19564                                                    mbMessageModelImpl.getThreadId()
19565                                            };
19566    
19567                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19568                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19569                                            args);
19570                            }
19571    
19572                            if ((mbMessageModelImpl.getColumnBitmask() &
19573                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19574                                    Object[] args = new Object[] {
19575                                                    mbMessageModelImpl.getOriginalGroupId(),
19576                                                    mbMessageModelImpl.getOriginalCategoryId(),
19577                                                    mbMessageModelImpl.getOriginalStatus()
19578                                            };
19579    
19580                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19581                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19582                                            args);
19583    
19584                                    args = new Object[] {
19585                                                    mbMessageModelImpl.getGroupId(),
19586                                                    mbMessageModelImpl.getCategoryId(),
19587                                                    mbMessageModelImpl.getStatus()
19588                                            };
19589    
19590                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19591                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19592                                            args);
19593                            }
19594    
19595                            if ((mbMessageModelImpl.getColumnBitmask() &
19596                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19597                                    Object[] args = new Object[] {
19598                                                    mbMessageModelImpl.getOriginalUserId(),
19599                                                    mbMessageModelImpl.getOriginalClassNameId(),
19600                                                    mbMessageModelImpl.getOriginalClassPK()
19601                                            };
19602    
19603                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19604                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19605                                            args);
19606    
19607                                    args = new Object[] {
19608                                                    mbMessageModelImpl.getUserId(),
19609                                                    mbMessageModelImpl.getClassNameId(),
19610                                                    mbMessageModelImpl.getClassPK()
19611                                            };
19612    
19613                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19614                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19615                                            args);
19616                            }
19617    
19618                            if ((mbMessageModelImpl.getColumnBitmask() &
19619                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19620                                    Object[] args = new Object[] {
19621                                                    mbMessageModelImpl.getOriginalUserId(),
19622                                                    mbMessageModelImpl.getOriginalClassNameId(),
19623                                                    mbMessageModelImpl.getOriginalStatus()
19624                                            };
19625    
19626                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19627                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19628                                            args);
19629    
19630                                    args = new Object[] {
19631                                                    mbMessageModelImpl.getUserId(),
19632                                                    mbMessageModelImpl.getClassNameId(),
19633                                                    mbMessageModelImpl.getStatus()
19634                                            };
19635    
19636                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19637                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19638                                            args);
19639                            }
19640    
19641                            if ((mbMessageModelImpl.getColumnBitmask() &
19642                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19643                                    Object[] args = new Object[] {
19644                                                    mbMessageModelImpl.getOriginalClassNameId(),
19645                                                    mbMessageModelImpl.getOriginalClassPK(),
19646                                                    mbMessageModelImpl.getOriginalStatus()
19647                                            };
19648    
19649                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19650                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19651                                            args);
19652    
19653                                    args = new Object[] {
19654                                                    mbMessageModelImpl.getClassNameId(),
19655                                                    mbMessageModelImpl.getClassPK(),
19656                                                    mbMessageModelImpl.getStatus()
19657                                            };
19658    
19659                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19660                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19661                                            args);
19662                            }
19663    
19664                            if ((mbMessageModelImpl.getColumnBitmask() &
19665                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19666                                    Object[] args = new Object[] {
19667                                                    mbMessageModelImpl.getOriginalGroupId(),
19668                                                    mbMessageModelImpl.getOriginalCategoryId(),
19669                                                    mbMessageModelImpl.getOriginalThreadId(),
19670                                                    mbMessageModelImpl.getOriginalAnswer()
19671                                            };
19672    
19673                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19674                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19675                                            args);
19676    
19677                                    args = new Object[] {
19678                                                    mbMessageModelImpl.getGroupId(),
19679                                                    mbMessageModelImpl.getCategoryId(),
19680                                                    mbMessageModelImpl.getThreadId(),
19681                                                    mbMessageModelImpl.getAnswer()
19682                                            };
19683    
19684                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19685                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19686                                            args);
19687                            }
19688    
19689                            if ((mbMessageModelImpl.getColumnBitmask() &
19690                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19691                                    Object[] args = new Object[] {
19692                                                    mbMessageModelImpl.getOriginalGroupId(),
19693                                                    mbMessageModelImpl.getOriginalCategoryId(),
19694                                                    mbMessageModelImpl.getOriginalThreadId(),
19695                                                    mbMessageModelImpl.getOriginalStatus()
19696                                            };
19697    
19698                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19699                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19700                                            args);
19701    
19702                                    args = new Object[] {
19703                                                    mbMessageModelImpl.getGroupId(),
19704                                                    mbMessageModelImpl.getCategoryId(),
19705                                                    mbMessageModelImpl.getThreadId(),
19706                                                    mbMessageModelImpl.getStatus()
19707                                            };
19708    
19709                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19710                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19711                                            args);
19712                            }
19713    
19714                            if ((mbMessageModelImpl.getColumnBitmask() &
19715                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19716                                    Object[] args = new Object[] {
19717                                                    mbMessageModelImpl.getOriginalUserId(),
19718                                                    mbMessageModelImpl.getOriginalClassNameId(),
19719                                                    mbMessageModelImpl.getOriginalClassPK(),
19720                                                    mbMessageModelImpl.getOriginalStatus()
19721                                            };
19722    
19723                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19724                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19725                                            args);
19726    
19727                                    args = new Object[] {
19728                                                    mbMessageModelImpl.getUserId(),
19729                                                    mbMessageModelImpl.getClassNameId(),
19730                                                    mbMessageModelImpl.getClassPK(),
19731                                                    mbMessageModelImpl.getStatus()
19732                                            };
19733    
19734                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19735                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19736                                            args);
19737                            }
19738                    }
19739    
19740                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19741                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
19742    
19743                    clearUniqueFindersCache(mbMessageModelImpl);
19744                    cacheUniqueFindersCache(mbMessageModelImpl, isNew);
19745    
19746                    mbMessage.resetOriginalValues();
19747    
19748                    return mbMessage;
19749            }
19750    
19751            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19752                    if (mbMessage instanceof MBMessageImpl) {
19753                            return mbMessage;
19754                    }
19755    
19756                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19757    
19758                    mbMessageImpl.setNew(mbMessage.isNew());
19759                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19760    
19761                    mbMessageImpl.setUuid(mbMessage.getUuid());
19762                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19763                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19764                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19765                    mbMessageImpl.setUserId(mbMessage.getUserId());
19766                    mbMessageImpl.setUserName(mbMessage.getUserName());
19767                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19768                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19769                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19770                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19771                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19772                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19773                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19774                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19775                    mbMessageImpl.setSubject(mbMessage.getSubject());
19776                    mbMessageImpl.setBody(mbMessage.getBody());
19777                    mbMessageImpl.setFormat(mbMessage.getFormat());
19778                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19779                    mbMessageImpl.setPriority(mbMessage.getPriority());
19780                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19781                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19782                    mbMessageImpl.setLastPublishDate(mbMessage.getLastPublishDate());
19783                    mbMessageImpl.setStatus(mbMessage.getStatus());
19784                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19785                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19786                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19787    
19788                    return mbMessageImpl;
19789            }
19790    
19791            /**
19792             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
19793             *
19794             * @param primaryKey the primary key of the message-boards message
19795             * @return the message-boards message
19796             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19797             */
19798            @Override
19799            public MBMessage findByPrimaryKey(Serializable primaryKey)
19800                    throws NoSuchMessageException {
19801                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19802    
19803                    if (mbMessage == null) {
19804                            if (_log.isWarnEnabled()) {
19805                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19806                            }
19807    
19808                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19809                                    primaryKey);
19810                    }
19811    
19812                    return mbMessage;
19813            }
19814    
19815            /**
19816             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19817             *
19818             * @param messageId the primary key of the message-boards message
19819             * @return the message-boards message
19820             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19821             */
19822            @Override
19823            public MBMessage findByPrimaryKey(long messageId)
19824                    throws NoSuchMessageException {
19825                    return findByPrimaryKey((Serializable)messageId);
19826            }
19827    
19828            /**
19829             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19830             *
19831             * @param primaryKey the primary key of the message-boards message
19832             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19833             */
19834            @Override
19835            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19836                    MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19837                                    MBMessageImpl.class, primaryKey);
19838    
19839                    if (mbMessage == _nullMBMessage) {
19840                            return null;
19841                    }
19842    
19843                    if (mbMessage == null) {
19844                            Session session = null;
19845    
19846                            try {
19847                                    session = openSession();
19848    
19849                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19850                                                    primaryKey);
19851    
19852                                    if (mbMessage != null) {
19853                                            cacheResult(mbMessage);
19854                                    }
19855                                    else {
19856                                            entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19857                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19858                                    }
19859                            }
19860                            catch (Exception e) {
19861                                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19862                                            MBMessageImpl.class, primaryKey);
19863    
19864                                    throw processException(e);
19865                            }
19866                            finally {
19867                                    closeSession(session);
19868                            }
19869                    }
19870    
19871                    return mbMessage;
19872            }
19873    
19874            /**
19875             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19876             *
19877             * @param messageId the primary key of the message-boards message
19878             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19879             */
19880            @Override
19881            public MBMessage fetchByPrimaryKey(long messageId) {
19882                    return fetchByPrimaryKey((Serializable)messageId);
19883            }
19884    
19885            @Override
19886            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19887                    Set<Serializable> primaryKeys) {
19888                    if (primaryKeys.isEmpty()) {
19889                            return Collections.emptyMap();
19890                    }
19891    
19892                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19893    
19894                    if (primaryKeys.size() == 1) {
19895                            Iterator<Serializable> iterator = primaryKeys.iterator();
19896    
19897                            Serializable primaryKey = iterator.next();
19898    
19899                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19900    
19901                            if (mbMessage != null) {
19902                                    map.put(primaryKey, mbMessage);
19903                            }
19904    
19905                            return map;
19906                    }
19907    
19908                    Set<Serializable> uncachedPrimaryKeys = null;
19909    
19910                    for (Serializable primaryKey : primaryKeys) {
19911                            MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19912                                            MBMessageImpl.class, primaryKey);
19913    
19914                            if (mbMessage == null) {
19915                                    if (uncachedPrimaryKeys == null) {
19916                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19917                                    }
19918    
19919                                    uncachedPrimaryKeys.add(primaryKey);
19920                            }
19921                            else {
19922                                    map.put(primaryKey, mbMessage);
19923                            }
19924                    }
19925    
19926                    if (uncachedPrimaryKeys == null) {
19927                            return map;
19928                    }
19929    
19930                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19931                                    1);
19932    
19933                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19934    
19935                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19936                            query.append(String.valueOf(primaryKey));
19937    
19938                            query.append(StringPool.COMMA);
19939                    }
19940    
19941                    query.setIndex(query.index() - 1);
19942    
19943                    query.append(StringPool.CLOSE_PARENTHESIS);
19944    
19945                    String sql = query.toString();
19946    
19947                    Session session = null;
19948    
19949                    try {
19950                            session = openSession();
19951    
19952                            Query q = session.createQuery(sql);
19953    
19954                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19955                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19956    
19957                                    cacheResult(mbMessage);
19958    
19959                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19960                            }
19961    
19962                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19963                                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19964                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
19965                            }
19966                    }
19967                    catch (Exception e) {
19968                            throw processException(e);
19969                    }
19970                    finally {
19971                            closeSession(session);
19972                    }
19973    
19974                    return map;
19975            }
19976    
19977            /**
19978             * Returns all the message-boards messages.
19979             *
19980             * @return the message-boards messages
19981             */
19982            @Override
19983            public List<MBMessage> findAll() {
19984                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19985            }
19986    
19987            /**
19988             * Returns a range of all the message-boards messages.
19989             *
19990             * <p>
19991             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
19992             * </p>
19993             *
19994             * @param start the lower bound of the range of message-boards messages
19995             * @param end the upper bound of the range of message-boards messages (not inclusive)
19996             * @return the range of message-boards messages
19997             */
19998            @Override
19999            public List<MBMessage> findAll(int start, int end) {
20000                    return findAll(start, end, null);
20001            }
20002    
20003            /**
20004             * Returns an ordered range of all the message-boards messages.
20005             *
20006             * <p>
20007             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
20008             * </p>
20009             *
20010             * @param start the lower bound of the range of message-boards messages
20011             * @param end the upper bound of the range of message-boards messages (not inclusive)
20012             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20013             * @return the ordered range of message-boards messages
20014             */
20015            @Override
20016            public List<MBMessage> findAll(int start, int end,
20017                    OrderByComparator<MBMessage> orderByComparator) {
20018                    return findAll(start, end, orderByComparator, true);
20019            }
20020    
20021            /**
20022             * Returns an ordered range of all the message-boards messages.
20023             *
20024             * <p>
20025             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
20026             * </p>
20027             *
20028             * @param start the lower bound of the range of message-boards messages
20029             * @param end the upper bound of the range of message-boards messages (not inclusive)
20030             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20031             * @param retrieveFromCache whether to retrieve from the finder cache
20032             * @return the ordered range of message-boards messages
20033             */
20034            @Override
20035            public List<MBMessage> findAll(int start, int end,
20036                    OrderByComparator<MBMessage> orderByComparator,
20037                    boolean retrieveFromCache) {
20038                    boolean pagination = true;
20039                    FinderPath finderPath = null;
20040                    Object[] finderArgs = null;
20041    
20042                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20043                                    (orderByComparator == null)) {
20044                            pagination = false;
20045                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20046                            finderArgs = FINDER_ARGS_EMPTY;
20047                    }
20048                    else {
20049                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20050                            finderArgs = new Object[] { start, end, orderByComparator };
20051                    }
20052    
20053                    List<MBMessage> list = null;
20054    
20055                    if (retrieveFromCache) {
20056                            list = (List<MBMessage>)finderCache.getResult(finderPath,
20057                                            finderArgs, this);
20058                    }
20059    
20060                    if (list == null) {
20061                            StringBundler query = null;
20062                            String sql = null;
20063    
20064                            if (orderByComparator != null) {
20065                                    query = new StringBundler(2 +
20066                                                    (orderByComparator.getOrderByFields().length * 3));
20067    
20068                                    query.append(_SQL_SELECT_MBMESSAGE);
20069    
20070                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20071                                            orderByComparator);
20072    
20073                                    sql = query.toString();
20074                            }
20075                            else {
20076                                    sql = _SQL_SELECT_MBMESSAGE;
20077    
20078                                    if (pagination) {
20079                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20080                                    }
20081                            }
20082    
20083                            Session session = null;
20084    
20085                            try {
20086                                    session = openSession();
20087    
20088                                    Query q = session.createQuery(sql);
20089    
20090                                    if (!pagination) {
20091                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20092                                                            start, end, false);
20093    
20094                                            Collections.sort(list);
20095    
20096                                            list = Collections.unmodifiableList(list);
20097                                    }
20098                                    else {
20099                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20100                                                            start, end);
20101                                    }
20102    
20103                                    cacheResult(list);
20104    
20105                                    finderCache.putResult(finderPath, finderArgs, list);
20106                            }
20107                            catch (Exception e) {
20108                                    finderCache.removeResult(finderPath, finderArgs);
20109    
20110                                    throw processException(e);
20111                            }
20112                            finally {
20113                                    closeSession(session);
20114                            }
20115                    }
20116    
20117                    return list;
20118            }
20119    
20120            /**
20121             * Removes all the message-boards messages from the database.
20122             *
20123             */
20124            @Override
20125            public void removeAll() {
20126                    for (MBMessage mbMessage : findAll()) {
20127                            remove(mbMessage);
20128                    }
20129            }
20130    
20131            /**
20132             * Returns the number of message-boards messages.
20133             *
20134             * @return the number of message-boards messages
20135             */
20136            @Override
20137            public int countAll() {
20138                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
20139                                    FINDER_ARGS_EMPTY, this);
20140    
20141                    if (count == null) {
20142                            Session session = null;
20143    
20144                            try {
20145                                    session = openSession();
20146    
20147                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20148    
20149                                    count = (Long)q.uniqueResult();
20150    
20151                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
20152                                            count);
20153                            }
20154                            catch (Exception e) {
20155                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
20156                                            FINDER_ARGS_EMPTY);
20157    
20158                                    throw processException(e);
20159                            }
20160                            finally {
20161                                    closeSession(session);
20162                            }
20163                    }
20164    
20165                    return count.intValue();
20166            }
20167    
20168            @Override
20169            public Set<String> getBadColumnNames() {
20170                    return _badColumnNames;
20171            }
20172    
20173            @Override
20174            protected Map<String, Integer> getTableColumnsMap() {
20175                    return MBMessageModelImpl.TABLE_COLUMNS_MAP;
20176            }
20177    
20178            /**
20179             * Initializes the message-boards message persistence.
20180             */
20181            public void afterPropertiesSet() {
20182            }
20183    
20184            public void destroy() {
20185                    entityCache.removeCache(MBMessageImpl.class.getName());
20186                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
20187                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20188                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20189            }
20190    
20191            @BeanReference(type = CompanyProviderWrapper.class)
20192            protected CompanyProvider companyProvider;
20193            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
20194            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
20195            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
20196            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
20197            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
20198            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
20199            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
20200            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
20201            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
20202            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
20203                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
20204            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
20205                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
20206            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
20207            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
20208            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
20209            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
20210            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
20211            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
20212            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
20213            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
20214            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
20215                                    "uuid"
20216                            });
20217            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
20218                            @Override
20219                            public Object clone() {
20220                                    return this;
20221                            }
20222    
20223                            @Override
20224                            public CacheModel<MBMessage> toCacheModel() {
20225                                    return _nullMBMessageCacheModel;
20226                            }
20227                    };
20228    
20229            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
20230                            @Override
20231                            public MBMessage toEntityModel() {
20232                                    return _nullMBMessage;
20233                            }
20234                    };
20235    }