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.security.auth.PrincipalThreadLocal;
037    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
038    import com.liferay.portal.kernel.util.ArrayUtil;
039    import com.liferay.portal.kernel.util.ContentTypes;
040    import com.liferay.portal.kernel.util.GetterUtil;
041    import com.liferay.portal.kernel.util.OrderByComparator;
042    import com.liferay.portal.kernel.util.SetUtil;
043    import com.liferay.portal.kernel.util.StringBundler;
044    import com.liferay.portal.kernel.util.StringPool;
045    import com.liferay.portal.kernel.util.StringUtil;
046    import com.liferay.portal.kernel.util.Validator;
047    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
048    import com.liferay.portal.model.CacheModel;
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 * 2));
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(4 +
457                                            (orderByComparator.getOrderByConditionFields().length * 3) +
458                                            (orderByComparator.getOrderByFields().length * 3));
459                    }
460                    else {
461                            query = new StringBundler(3);
462                    }
463    
464                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
465    
466                    boolean bindUuid = false;
467    
468                    if (uuid == null) {
469                            query.append(_FINDER_COLUMN_UUID_UUID_1);
470                    }
471                    else if (uuid.equals(StringPool.BLANK)) {
472                            query.append(_FINDER_COLUMN_UUID_UUID_3);
473                    }
474                    else {
475                            bindUuid = true;
476    
477                            query.append(_FINDER_COLUMN_UUID_UUID_2);
478                    }
479    
480                    if (orderByComparator != null) {
481                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
482    
483                            if (orderByConditionFields.length > 0) {
484                                    query.append(WHERE_AND);
485                            }
486    
487                            for (int i = 0; i < orderByConditionFields.length; i++) {
488                                    query.append(_ORDER_BY_ENTITY_ALIAS);
489                                    query.append(orderByConditionFields[i]);
490    
491                                    if ((i + 1) < orderByConditionFields.length) {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
494                                            }
495                                            else {
496                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
497                                            }
498                                    }
499                                    else {
500                                            if (orderByComparator.isAscending() ^ previous) {
501                                                    query.append(WHERE_GREATER_THAN);
502                                            }
503                                            else {
504                                                    query.append(WHERE_LESSER_THAN);
505                                            }
506                                    }
507                            }
508    
509                            query.append(ORDER_BY_CLAUSE);
510    
511                            String[] orderByFields = orderByComparator.getOrderByFields();
512    
513                            for (int i = 0; i < orderByFields.length; i++) {
514                                    query.append(_ORDER_BY_ENTITY_ALIAS);
515                                    query.append(orderByFields[i]);
516    
517                                    if ((i + 1) < orderByFields.length) {
518                                            if (orderByComparator.isAscending() ^ previous) {
519                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
520                                            }
521                                            else {
522                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
523                                            }
524                                    }
525                                    else {
526                                            if (orderByComparator.isAscending() ^ previous) {
527                                                    query.append(ORDER_BY_ASC);
528                                            }
529                                            else {
530                                                    query.append(ORDER_BY_DESC);
531                                            }
532                                    }
533                            }
534                    }
535                    else {
536                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
537                    }
538    
539                    String sql = query.toString();
540    
541                    Query q = session.createQuery(sql);
542    
543                    q.setFirstResult(0);
544                    q.setMaxResults(2);
545    
546                    QueryPos qPos = QueryPos.getInstance(q);
547    
548                    if (bindUuid) {
549                            qPos.add(uuid);
550                    }
551    
552                    if (orderByComparator != null) {
553                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
554    
555                            for (Object value : values) {
556                                    qPos.add(value);
557                            }
558                    }
559    
560                    List<MBMessage> list = q.list();
561    
562                    if (list.size() == 2) {
563                            return list.get(1);
564                    }
565                    else {
566                            return null;
567                    }
568            }
569    
570            /**
571             * Removes all the message-boards messages where uuid = &#63; from the database.
572             *
573             * @param uuid the uuid
574             */
575            @Override
576            public void removeByUuid(String uuid) {
577                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
578                                    QueryUtil.ALL_POS, null)) {
579                            remove(mbMessage);
580                    }
581            }
582    
583            /**
584             * Returns the number of message-boards messages where uuid = &#63;.
585             *
586             * @param uuid the uuid
587             * @return the number of matching message-boards messages
588             */
589            @Override
590            public int countByUuid(String uuid) {
591                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
592    
593                    Object[] finderArgs = new Object[] { uuid };
594    
595                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
596    
597                    if (count == null) {
598                            StringBundler query = new StringBundler(2);
599    
600                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
601    
602                            boolean bindUuid = false;
603    
604                            if (uuid == null) {
605                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
606                            }
607                            else if (uuid.equals(StringPool.BLANK)) {
608                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
609                            }
610                            else {
611                                    bindUuid = true;
612    
613                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
614                            }
615    
616                            String sql = query.toString();
617    
618                            Session session = null;
619    
620                            try {
621                                    session = openSession();
622    
623                                    Query q = session.createQuery(sql);
624    
625                                    QueryPos qPos = QueryPos.getInstance(q);
626    
627                                    if (bindUuid) {
628                                            qPos.add(uuid);
629                                    }
630    
631                                    count = (Long)q.uniqueResult();
632    
633                                    finderCache.putResult(finderPath, finderArgs, count);
634                            }
635                            catch (Exception e) {
636                                    finderCache.removeResult(finderPath, finderArgs);
637    
638                                    throw processException(e);
639                            }
640                            finally {
641                                    closeSession(session);
642                            }
643                    }
644    
645                    return count.intValue();
646            }
647    
648            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
649            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
650            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
651            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
652                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
653                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
654                            new String[] { String.class.getName(), Long.class.getName() },
655                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
656                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
657            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
658                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
659                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
660                            new String[] { String.class.getName(), Long.class.getName() });
661    
662            /**
663             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
664             *
665             * @param uuid the uuid
666             * @param groupId the group ID
667             * @return the matching message-boards message
668             * @throws NoSuchMessageException if a matching message-boards message could not be found
669             */
670            @Override
671            public MBMessage findByUUID_G(String uuid, long groupId)
672                    throws NoSuchMessageException {
673                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
674    
675                    if (mbMessage == null) {
676                            StringBundler msg = new StringBundler(6);
677    
678                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
679    
680                            msg.append("uuid=");
681                            msg.append(uuid);
682    
683                            msg.append(", groupId=");
684                            msg.append(groupId);
685    
686                            msg.append(StringPool.CLOSE_CURLY_BRACE);
687    
688                            if (_log.isWarnEnabled()) {
689                                    _log.warn(msg.toString());
690                            }
691    
692                            throw new NoSuchMessageException(msg.toString());
693                    }
694    
695                    return mbMessage;
696            }
697    
698            /**
699             * 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.
700             *
701             * @param uuid the uuid
702             * @param groupId the group ID
703             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
704             */
705            @Override
706            public MBMessage fetchByUUID_G(String uuid, long groupId) {
707                    return fetchByUUID_G(uuid, groupId, true);
708            }
709    
710            /**
711             * 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.
712             *
713             * @param uuid the uuid
714             * @param groupId the group ID
715             * @param retrieveFromCache whether to retrieve from the finder cache
716             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
717             */
718            @Override
719            public MBMessage fetchByUUID_G(String uuid, long groupId,
720                    boolean retrieveFromCache) {
721                    Object[] finderArgs = new Object[] { uuid, groupId };
722    
723                    Object result = null;
724    
725                    if (retrieveFromCache) {
726                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
727                                            finderArgs, this);
728                    }
729    
730                    if (result instanceof MBMessage) {
731                            MBMessage mbMessage = (MBMessage)result;
732    
733                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
734                                            (groupId != mbMessage.getGroupId())) {
735                                    result = null;
736                            }
737                    }
738    
739                    if (result == null) {
740                            StringBundler query = new StringBundler(4);
741    
742                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
743    
744                            boolean bindUuid = false;
745    
746                            if (uuid == null) {
747                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
748                            }
749                            else if (uuid.equals(StringPool.BLANK)) {
750                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
751                            }
752                            else {
753                                    bindUuid = true;
754    
755                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
756                            }
757    
758                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
759    
760                            String sql = query.toString();
761    
762                            Session session = null;
763    
764                            try {
765                                    session = openSession();
766    
767                                    Query q = session.createQuery(sql);
768    
769                                    QueryPos qPos = QueryPos.getInstance(q);
770    
771                                    if (bindUuid) {
772                                            qPos.add(uuid);
773                                    }
774    
775                                    qPos.add(groupId);
776    
777                                    List<MBMessage> list = q.list();
778    
779                                    if (list.isEmpty()) {
780                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
781                                                    finderArgs, list);
782                                    }
783                                    else {
784                                            MBMessage mbMessage = list.get(0);
785    
786                                            result = mbMessage;
787    
788                                            cacheResult(mbMessage);
789    
790                                            if ((mbMessage.getUuid() == null) ||
791                                                            !mbMessage.getUuid().equals(uuid) ||
792                                                            (mbMessage.getGroupId() != groupId)) {
793                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
794                                                            finderArgs, mbMessage);
795                                            }
796                                    }
797                            }
798                            catch (Exception e) {
799                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
800    
801                                    throw processException(e);
802                            }
803                            finally {
804                                    closeSession(session);
805                            }
806                    }
807    
808                    if (result instanceof List<?>) {
809                            return null;
810                    }
811                    else {
812                            return (MBMessage)result;
813                    }
814            }
815    
816            /**
817             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
818             *
819             * @param uuid the uuid
820             * @param groupId the group ID
821             * @return the message-boards message that was removed
822             */
823            @Override
824            public MBMessage removeByUUID_G(String uuid, long groupId)
825                    throws NoSuchMessageException {
826                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
827    
828                    return remove(mbMessage);
829            }
830    
831            /**
832             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
833             *
834             * @param uuid the uuid
835             * @param groupId the group ID
836             * @return the number of matching message-boards messages
837             */
838            @Override
839            public int countByUUID_G(String uuid, long groupId) {
840                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
841    
842                    Object[] finderArgs = new Object[] { uuid, groupId };
843    
844                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
845    
846                    if (count == null) {
847                            StringBundler query = new StringBundler(3);
848    
849                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
850    
851                            boolean bindUuid = false;
852    
853                            if (uuid == null) {
854                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
855                            }
856                            else if (uuid.equals(StringPool.BLANK)) {
857                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
858                            }
859                            else {
860                                    bindUuid = true;
861    
862                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
863                            }
864    
865                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
866    
867                            String sql = query.toString();
868    
869                            Session session = null;
870    
871                            try {
872                                    session = openSession();
873    
874                                    Query q = session.createQuery(sql);
875    
876                                    QueryPos qPos = QueryPos.getInstance(q);
877    
878                                    if (bindUuid) {
879                                            qPos.add(uuid);
880                                    }
881    
882                                    qPos.add(groupId);
883    
884                                    count = (Long)q.uniqueResult();
885    
886                                    finderCache.putResult(finderPath, finderArgs, count);
887                            }
888                            catch (Exception e) {
889                                    finderCache.removeResult(finderPath, finderArgs);
890    
891                                    throw processException(e);
892                            }
893                            finally {
894                                    closeSession(session);
895                            }
896                    }
897    
898                    return count.intValue();
899            }
900    
901            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
902            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
903            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
904            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
905            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
906                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
907                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
908                            new String[] {
909                                    String.class.getName(), Long.class.getName(),
910                                    
911                            Integer.class.getName(), Integer.class.getName(),
912                                    OrderByComparator.class.getName()
913                            });
914            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
915                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
916                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
917                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
918                            new String[] { String.class.getName(), Long.class.getName() },
919                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
920                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
921                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
922            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
923                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
924                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
925                            new String[] { String.class.getName(), Long.class.getName() });
926    
927            /**
928             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
929             *
930             * @param uuid the uuid
931             * @param companyId the company ID
932             * @return the matching message-boards messages
933             */
934            @Override
935            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
936                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
937                            QueryUtil.ALL_POS, null);
938            }
939    
940            /**
941             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
942             *
943             * <p>
944             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
945             * </p>
946             *
947             * @param uuid the uuid
948             * @param companyId the company ID
949             * @param start the lower bound of the range of message-boards messages
950             * @param end the upper bound of the range of message-boards messages (not inclusive)
951             * @return the range of matching message-boards messages
952             */
953            @Override
954            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
955                    int end) {
956                    return findByUuid_C(uuid, companyId, start, end, null);
957            }
958    
959            /**
960             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
961             *
962             * <p>
963             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
964             * </p>
965             *
966             * @param uuid the uuid
967             * @param companyId the company ID
968             * @param start the lower bound of the range of message-boards messages
969             * @param end the upper bound of the range of message-boards messages (not inclusive)
970             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
971             * @return the ordered range of matching message-boards messages
972             */
973            @Override
974            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
975                    int end, OrderByComparator<MBMessage> orderByComparator) {
976                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
977            }
978    
979            /**
980             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
981             *
982             * <p>
983             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
984             * </p>
985             *
986             * @param uuid the uuid
987             * @param companyId the company ID
988             * @param start the lower bound of the range of message-boards messages
989             * @param end the upper bound of the range of message-boards messages (not inclusive)
990             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
991             * @param retrieveFromCache whether to retrieve from the finder cache
992             * @return the ordered range of matching message-boards messages
993             */
994            @Override
995            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
996                    int end, OrderByComparator<MBMessage> orderByComparator,
997                    boolean retrieveFromCache) {
998                    boolean pagination = true;
999                    FinderPath finderPath = null;
1000                    Object[] finderArgs = null;
1001    
1002                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1003                                    (orderByComparator == null)) {
1004                            pagination = false;
1005                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1006                            finderArgs = new Object[] { uuid, companyId };
1007                    }
1008                    else {
1009                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1010                            finderArgs = new Object[] {
1011                                            uuid, companyId,
1012                                            
1013                                            start, end, orderByComparator
1014                                    };
1015                    }
1016    
1017                    List<MBMessage> list = null;
1018    
1019                    if (retrieveFromCache) {
1020                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1021                                            finderArgs, this);
1022    
1023                            if ((list != null) && !list.isEmpty()) {
1024                                    for (MBMessage mbMessage : list) {
1025                                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
1026                                                            (companyId != mbMessage.getCompanyId())) {
1027                                                    list = null;
1028    
1029                                                    break;
1030                                            }
1031                                    }
1032                            }
1033                    }
1034    
1035                    if (list == null) {
1036                            StringBundler query = null;
1037    
1038                            if (orderByComparator != null) {
1039                                    query = new StringBundler(4 +
1040                                                    (orderByComparator.getOrderByFields().length * 2));
1041                            }
1042                            else {
1043                                    query = new StringBundler(4);
1044                            }
1045    
1046                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1047    
1048                            boolean bindUuid = false;
1049    
1050                            if (uuid == null) {
1051                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1052                            }
1053                            else if (uuid.equals(StringPool.BLANK)) {
1054                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1055                            }
1056                            else {
1057                                    bindUuid = true;
1058    
1059                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1060                            }
1061    
1062                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1063    
1064                            if (orderByComparator != null) {
1065                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1066                                            orderByComparator);
1067                            }
1068                            else
1069                             if (pagination) {
1070                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1071                            }
1072    
1073                            String sql = query.toString();
1074    
1075                            Session session = null;
1076    
1077                            try {
1078                                    session = openSession();
1079    
1080                                    Query q = session.createQuery(sql);
1081    
1082                                    QueryPos qPos = QueryPos.getInstance(q);
1083    
1084                                    if (bindUuid) {
1085                                            qPos.add(uuid);
1086                                    }
1087    
1088                                    qPos.add(companyId);
1089    
1090                                    if (!pagination) {
1091                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1092                                                            start, end, false);
1093    
1094                                            Collections.sort(list);
1095    
1096                                            list = Collections.unmodifiableList(list);
1097                                    }
1098                                    else {
1099                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1100                                                            start, end);
1101                                    }
1102    
1103                                    cacheResult(list);
1104    
1105                                    finderCache.putResult(finderPath, finderArgs, list);
1106                            }
1107                            catch (Exception e) {
1108                                    finderCache.removeResult(finderPath, finderArgs);
1109    
1110                                    throw processException(e);
1111                            }
1112                            finally {
1113                                    closeSession(session);
1114                            }
1115                    }
1116    
1117                    return list;
1118            }
1119    
1120            /**
1121             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1122             *
1123             * @param uuid the uuid
1124             * @param companyId the company ID
1125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1126             * @return the first matching message-boards message
1127             * @throws NoSuchMessageException if a matching message-boards message could not be found
1128             */
1129            @Override
1130            public MBMessage findByUuid_C_First(String uuid, long companyId,
1131                    OrderByComparator<MBMessage> orderByComparator)
1132                    throws NoSuchMessageException {
1133                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1134                                    orderByComparator);
1135    
1136                    if (mbMessage != null) {
1137                            return mbMessage;
1138                    }
1139    
1140                    StringBundler msg = new StringBundler(6);
1141    
1142                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1143    
1144                    msg.append("uuid=");
1145                    msg.append(uuid);
1146    
1147                    msg.append(", companyId=");
1148                    msg.append(companyId);
1149    
1150                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1151    
1152                    throw new NoSuchMessageException(msg.toString());
1153            }
1154    
1155            /**
1156             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1157             *
1158             * @param uuid the uuid
1159             * @param companyId the company ID
1160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1161             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1162             */
1163            @Override
1164            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1165                    OrderByComparator<MBMessage> orderByComparator) {
1166                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1167                                    orderByComparator);
1168    
1169                    if (!list.isEmpty()) {
1170                            return list.get(0);
1171                    }
1172    
1173                    return null;
1174            }
1175    
1176            /**
1177             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1178             *
1179             * @param uuid the uuid
1180             * @param companyId the company ID
1181             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1182             * @return the last matching message-boards message
1183             * @throws NoSuchMessageException if a matching message-boards message could not be found
1184             */
1185            @Override
1186            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1187                    OrderByComparator<MBMessage> orderByComparator)
1188                    throws NoSuchMessageException {
1189                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1190                                    orderByComparator);
1191    
1192                    if (mbMessage != null) {
1193                            return mbMessage;
1194                    }
1195    
1196                    StringBundler msg = new StringBundler(6);
1197    
1198                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1199    
1200                    msg.append("uuid=");
1201                    msg.append(uuid);
1202    
1203                    msg.append(", companyId=");
1204                    msg.append(companyId);
1205    
1206                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1207    
1208                    throw new NoSuchMessageException(msg.toString());
1209            }
1210    
1211            /**
1212             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1213             *
1214             * @param uuid the uuid
1215             * @param companyId the company ID
1216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1217             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1218             */
1219            @Override
1220            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1221                    OrderByComparator<MBMessage> orderByComparator) {
1222                    int count = countByUuid_C(uuid, companyId);
1223    
1224                    if (count == 0) {
1225                            return null;
1226                    }
1227    
1228                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1229                                    orderByComparator);
1230    
1231                    if (!list.isEmpty()) {
1232                            return list.get(0);
1233                    }
1234    
1235                    return null;
1236            }
1237    
1238            /**
1239             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1240             *
1241             * @param messageId the primary key of the current message-boards message
1242             * @param uuid the uuid
1243             * @param companyId the company ID
1244             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1245             * @return the previous, current, and next message-boards message
1246             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1247             */
1248            @Override
1249            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1250                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1251                    throws NoSuchMessageException {
1252                    MBMessage mbMessage = findByPrimaryKey(messageId);
1253    
1254                    Session session = null;
1255    
1256                    try {
1257                            session = openSession();
1258    
1259                            MBMessage[] array = new MBMessageImpl[3];
1260    
1261                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1262                                            companyId, orderByComparator, true);
1263    
1264                            array[1] = mbMessage;
1265    
1266                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1267                                            companyId, orderByComparator, false);
1268    
1269                            return array;
1270                    }
1271                    catch (Exception e) {
1272                            throw processException(e);
1273                    }
1274                    finally {
1275                            closeSession(session);
1276                    }
1277            }
1278    
1279            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1280                    MBMessage mbMessage, String uuid, long companyId,
1281                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1282                    StringBundler query = null;
1283    
1284                    if (orderByComparator != null) {
1285                            query = new StringBundler(5 +
1286                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1287                                            (orderByComparator.getOrderByFields().length * 3));
1288                    }
1289                    else {
1290                            query = new StringBundler(4);
1291                    }
1292    
1293                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1294    
1295                    boolean bindUuid = false;
1296    
1297                    if (uuid == null) {
1298                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1299                    }
1300                    else if (uuid.equals(StringPool.BLANK)) {
1301                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1302                    }
1303                    else {
1304                            bindUuid = true;
1305    
1306                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1307                    }
1308    
1309                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1310    
1311                    if (orderByComparator != null) {
1312                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1313    
1314                            if (orderByConditionFields.length > 0) {
1315                                    query.append(WHERE_AND);
1316                            }
1317    
1318                            for (int i = 0; i < orderByConditionFields.length; i++) {
1319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1320                                    query.append(orderByConditionFields[i]);
1321    
1322                                    if ((i + 1) < orderByConditionFields.length) {
1323                                            if (orderByComparator.isAscending() ^ previous) {
1324                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1325                                            }
1326                                            else {
1327                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1328                                            }
1329                                    }
1330                                    else {
1331                                            if (orderByComparator.isAscending() ^ previous) {
1332                                                    query.append(WHERE_GREATER_THAN);
1333                                            }
1334                                            else {
1335                                                    query.append(WHERE_LESSER_THAN);
1336                                            }
1337                                    }
1338                            }
1339    
1340                            query.append(ORDER_BY_CLAUSE);
1341    
1342                            String[] orderByFields = orderByComparator.getOrderByFields();
1343    
1344                            for (int i = 0; i < orderByFields.length; i++) {
1345                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1346                                    query.append(orderByFields[i]);
1347    
1348                                    if ((i + 1) < orderByFields.length) {
1349                                            if (orderByComparator.isAscending() ^ previous) {
1350                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1351                                            }
1352                                            else {
1353                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1354                                            }
1355                                    }
1356                                    else {
1357                                            if (orderByComparator.isAscending() ^ previous) {
1358                                                    query.append(ORDER_BY_ASC);
1359                                            }
1360                                            else {
1361                                                    query.append(ORDER_BY_DESC);
1362                                            }
1363                                    }
1364                            }
1365                    }
1366                    else {
1367                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1368                    }
1369    
1370                    String sql = query.toString();
1371    
1372                    Query q = session.createQuery(sql);
1373    
1374                    q.setFirstResult(0);
1375                    q.setMaxResults(2);
1376    
1377                    QueryPos qPos = QueryPos.getInstance(q);
1378    
1379                    if (bindUuid) {
1380                            qPos.add(uuid);
1381                    }
1382    
1383                    qPos.add(companyId);
1384    
1385                    if (orderByComparator != null) {
1386                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1387    
1388                            for (Object value : values) {
1389                                    qPos.add(value);
1390                            }
1391                    }
1392    
1393                    List<MBMessage> list = q.list();
1394    
1395                    if (list.size() == 2) {
1396                            return list.get(1);
1397                    }
1398                    else {
1399                            return null;
1400                    }
1401            }
1402    
1403            /**
1404             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1405             *
1406             * @param uuid the uuid
1407             * @param companyId the company ID
1408             */
1409            @Override
1410            public void removeByUuid_C(String uuid, long companyId) {
1411                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1412                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1413                            remove(mbMessage);
1414                    }
1415            }
1416    
1417            /**
1418             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1419             *
1420             * @param uuid the uuid
1421             * @param companyId the company ID
1422             * @return the number of matching message-boards messages
1423             */
1424            @Override
1425            public int countByUuid_C(String uuid, long companyId) {
1426                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1427    
1428                    Object[] finderArgs = new Object[] { uuid, companyId };
1429    
1430                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1431    
1432                    if (count == null) {
1433                            StringBundler query = new StringBundler(3);
1434    
1435                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1436    
1437                            boolean bindUuid = false;
1438    
1439                            if (uuid == null) {
1440                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1441                            }
1442                            else if (uuid.equals(StringPool.BLANK)) {
1443                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1444                            }
1445                            else {
1446                                    bindUuid = true;
1447    
1448                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1449                            }
1450    
1451                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1452    
1453                            String sql = query.toString();
1454    
1455                            Session session = null;
1456    
1457                            try {
1458                                    session = openSession();
1459    
1460                                    Query q = session.createQuery(sql);
1461    
1462                                    QueryPos qPos = QueryPos.getInstance(q);
1463    
1464                                    if (bindUuid) {
1465                                            qPos.add(uuid);
1466                                    }
1467    
1468                                    qPos.add(companyId);
1469    
1470                                    count = (Long)q.uniqueResult();
1471    
1472                                    finderCache.putResult(finderPath, finderArgs, count);
1473                            }
1474                            catch (Exception e) {
1475                                    finderCache.removeResult(finderPath, finderArgs);
1476    
1477                                    throw processException(e);
1478                            }
1479                            finally {
1480                                    closeSession(session);
1481                            }
1482                    }
1483    
1484                    return count.intValue();
1485            }
1486    
1487            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1488            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1489            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1490            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1491            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1492                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1493                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1494                            new String[] {
1495                                    Long.class.getName(),
1496                                    
1497                            Integer.class.getName(), Integer.class.getName(),
1498                                    OrderByComparator.class.getName()
1499                            });
1500            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1501                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1502                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1503                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1504                            new String[] { Long.class.getName() },
1505                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1506                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1507            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1508                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1509                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1510                            new String[] { Long.class.getName() });
1511    
1512            /**
1513             * Returns all the message-boards messages where groupId = &#63;.
1514             *
1515             * @param groupId the group ID
1516             * @return the matching message-boards messages
1517             */
1518            @Override
1519            public List<MBMessage> findByGroupId(long groupId) {
1520                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1521            }
1522    
1523            /**
1524             * Returns a range of all the message-boards messages where groupId = &#63;.
1525             *
1526             * <p>
1527             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1528             * </p>
1529             *
1530             * @param groupId the group ID
1531             * @param start the lower bound of the range of message-boards messages
1532             * @param end the upper bound of the range of message-boards messages (not inclusive)
1533             * @return the range of matching message-boards messages
1534             */
1535            @Override
1536            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1537                    return findByGroupId(groupId, start, end, null);
1538            }
1539    
1540            /**
1541             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1542             *
1543             * <p>
1544             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1545             * </p>
1546             *
1547             * @param groupId the group ID
1548             * @param start the lower bound of the range of message-boards messages
1549             * @param end the upper bound of the range of message-boards messages (not inclusive)
1550             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1551             * @return the ordered range of matching message-boards messages
1552             */
1553            @Override
1554            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1555                    OrderByComparator<MBMessage> orderByComparator) {
1556                    return findByGroupId(groupId, start, end, orderByComparator, true);
1557            }
1558    
1559            /**
1560             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1561             *
1562             * <p>
1563             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1564             * </p>
1565             *
1566             * @param groupId the group ID
1567             * @param start the lower bound of the range of message-boards messages
1568             * @param end the upper bound of the range of message-boards messages (not inclusive)
1569             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1570             * @param retrieveFromCache whether to retrieve from the finder cache
1571             * @return the ordered range of matching message-boards messages
1572             */
1573            @Override
1574            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1575                    OrderByComparator<MBMessage> orderByComparator,
1576                    boolean retrieveFromCache) {
1577                    boolean pagination = true;
1578                    FinderPath finderPath = null;
1579                    Object[] finderArgs = null;
1580    
1581                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1582                                    (orderByComparator == null)) {
1583                            pagination = false;
1584                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1585                            finderArgs = new Object[] { groupId };
1586                    }
1587                    else {
1588                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1589                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1590                    }
1591    
1592                    List<MBMessage> list = null;
1593    
1594                    if (retrieveFromCache) {
1595                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1596                                            finderArgs, this);
1597    
1598                            if ((list != null) && !list.isEmpty()) {
1599                                    for (MBMessage mbMessage : list) {
1600                                            if ((groupId != mbMessage.getGroupId())) {
1601                                                    list = null;
1602    
1603                                                    break;
1604                                            }
1605                                    }
1606                            }
1607                    }
1608    
1609                    if (list == null) {
1610                            StringBundler query = null;
1611    
1612                            if (orderByComparator != null) {
1613                                    query = new StringBundler(3 +
1614                                                    (orderByComparator.getOrderByFields().length * 2));
1615                            }
1616                            else {
1617                                    query = new StringBundler(3);
1618                            }
1619    
1620                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1621    
1622                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1623    
1624                            if (orderByComparator != null) {
1625                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1626                                            orderByComparator);
1627                            }
1628                            else
1629                             if (pagination) {
1630                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1631                            }
1632    
1633                            String sql = query.toString();
1634    
1635                            Session session = null;
1636    
1637                            try {
1638                                    session = openSession();
1639    
1640                                    Query q = session.createQuery(sql);
1641    
1642                                    QueryPos qPos = QueryPos.getInstance(q);
1643    
1644                                    qPos.add(groupId);
1645    
1646                                    if (!pagination) {
1647                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1648                                                            start, end, false);
1649    
1650                                            Collections.sort(list);
1651    
1652                                            list = Collections.unmodifiableList(list);
1653                                    }
1654                                    else {
1655                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1656                                                            start, end);
1657                                    }
1658    
1659                                    cacheResult(list);
1660    
1661                                    finderCache.putResult(finderPath, finderArgs, list);
1662                            }
1663                            catch (Exception e) {
1664                                    finderCache.removeResult(finderPath, finderArgs);
1665    
1666                                    throw processException(e);
1667                            }
1668                            finally {
1669                                    closeSession(session);
1670                            }
1671                    }
1672    
1673                    return list;
1674            }
1675    
1676            /**
1677             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1678             *
1679             * @param groupId the group ID
1680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1681             * @return the first matching message-boards message
1682             * @throws NoSuchMessageException if a matching message-boards message could not be found
1683             */
1684            @Override
1685            public MBMessage findByGroupId_First(long groupId,
1686                    OrderByComparator<MBMessage> orderByComparator)
1687                    throws NoSuchMessageException {
1688                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1689    
1690                    if (mbMessage != null) {
1691                            return mbMessage;
1692                    }
1693    
1694                    StringBundler msg = new StringBundler(4);
1695    
1696                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1697    
1698                    msg.append("groupId=");
1699                    msg.append(groupId);
1700    
1701                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1702    
1703                    throw new NoSuchMessageException(msg.toString());
1704            }
1705    
1706            /**
1707             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1708             *
1709             * @param groupId the group ID
1710             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1711             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1712             */
1713            @Override
1714            public MBMessage fetchByGroupId_First(long groupId,
1715                    OrderByComparator<MBMessage> orderByComparator) {
1716                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1717    
1718                    if (!list.isEmpty()) {
1719                            return list.get(0);
1720                    }
1721    
1722                    return null;
1723            }
1724    
1725            /**
1726             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1727             *
1728             * @param groupId the group ID
1729             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1730             * @return the last matching message-boards message
1731             * @throws NoSuchMessageException if a matching message-boards message could not be found
1732             */
1733            @Override
1734            public MBMessage findByGroupId_Last(long groupId,
1735                    OrderByComparator<MBMessage> orderByComparator)
1736                    throws NoSuchMessageException {
1737                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1738    
1739                    if (mbMessage != null) {
1740                            return mbMessage;
1741                    }
1742    
1743                    StringBundler msg = new StringBundler(4);
1744    
1745                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1746    
1747                    msg.append("groupId=");
1748                    msg.append(groupId);
1749    
1750                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1751    
1752                    throw new NoSuchMessageException(msg.toString());
1753            }
1754    
1755            /**
1756             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1757             *
1758             * @param groupId the group ID
1759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1760             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1761             */
1762            @Override
1763            public MBMessage fetchByGroupId_Last(long groupId,
1764                    OrderByComparator<MBMessage> orderByComparator) {
1765                    int count = countByGroupId(groupId);
1766    
1767                    if (count == 0) {
1768                            return null;
1769                    }
1770    
1771                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1772                                    orderByComparator);
1773    
1774                    if (!list.isEmpty()) {
1775                            return list.get(0);
1776                    }
1777    
1778                    return null;
1779            }
1780    
1781            /**
1782             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1783             *
1784             * @param messageId the primary key of the current message-boards message
1785             * @param groupId the group ID
1786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1787             * @return the previous, current, and next message-boards message
1788             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1789             */
1790            @Override
1791            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1792                    OrderByComparator<MBMessage> orderByComparator)
1793                    throws NoSuchMessageException {
1794                    MBMessage mbMessage = findByPrimaryKey(messageId);
1795    
1796                    Session session = null;
1797    
1798                    try {
1799                            session = openSession();
1800    
1801                            MBMessage[] array = new MBMessageImpl[3];
1802    
1803                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1804                                            orderByComparator, true);
1805    
1806                            array[1] = mbMessage;
1807    
1808                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1809                                            orderByComparator, false);
1810    
1811                            return array;
1812                    }
1813                    catch (Exception e) {
1814                            throw processException(e);
1815                    }
1816                    finally {
1817                            closeSession(session);
1818                    }
1819            }
1820    
1821            protected MBMessage getByGroupId_PrevAndNext(Session session,
1822                    MBMessage mbMessage, long groupId,
1823                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1824                    StringBundler query = null;
1825    
1826                    if (orderByComparator != null) {
1827                            query = new StringBundler(4 +
1828                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1829                                            (orderByComparator.getOrderByFields().length * 3));
1830                    }
1831                    else {
1832                            query = new StringBundler(3);
1833                    }
1834    
1835                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1836    
1837                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1838    
1839                    if (orderByComparator != null) {
1840                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1841    
1842                            if (orderByConditionFields.length > 0) {
1843                                    query.append(WHERE_AND);
1844                            }
1845    
1846                            for (int i = 0; i < orderByConditionFields.length; i++) {
1847                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1848                                    query.append(orderByConditionFields[i]);
1849    
1850                                    if ((i + 1) < orderByConditionFields.length) {
1851                                            if (orderByComparator.isAscending() ^ previous) {
1852                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1853                                            }
1854                                            else {
1855                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1856                                            }
1857                                    }
1858                                    else {
1859                                            if (orderByComparator.isAscending() ^ previous) {
1860                                                    query.append(WHERE_GREATER_THAN);
1861                                            }
1862                                            else {
1863                                                    query.append(WHERE_LESSER_THAN);
1864                                            }
1865                                    }
1866                            }
1867    
1868                            query.append(ORDER_BY_CLAUSE);
1869    
1870                            String[] orderByFields = orderByComparator.getOrderByFields();
1871    
1872                            for (int i = 0; i < orderByFields.length; i++) {
1873                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1874                                    query.append(orderByFields[i]);
1875    
1876                                    if ((i + 1) < orderByFields.length) {
1877                                            if (orderByComparator.isAscending() ^ previous) {
1878                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1879                                            }
1880                                            else {
1881                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1882                                            }
1883                                    }
1884                                    else {
1885                                            if (orderByComparator.isAscending() ^ previous) {
1886                                                    query.append(ORDER_BY_ASC);
1887                                            }
1888                                            else {
1889                                                    query.append(ORDER_BY_DESC);
1890                                            }
1891                                    }
1892                            }
1893                    }
1894                    else {
1895                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1896                    }
1897    
1898                    String sql = query.toString();
1899    
1900                    Query q = session.createQuery(sql);
1901    
1902                    q.setFirstResult(0);
1903                    q.setMaxResults(2);
1904    
1905                    QueryPos qPos = QueryPos.getInstance(q);
1906    
1907                    qPos.add(groupId);
1908    
1909                    if (orderByComparator != null) {
1910                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1911    
1912                            for (Object value : values) {
1913                                    qPos.add(value);
1914                            }
1915                    }
1916    
1917                    List<MBMessage> list = q.list();
1918    
1919                    if (list.size() == 2) {
1920                            return list.get(1);
1921                    }
1922                    else {
1923                            return null;
1924                    }
1925            }
1926    
1927            /**
1928             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1929             *
1930             * @param groupId the group ID
1931             * @return the matching message-boards messages that the user has permission to view
1932             */
1933            @Override
1934            public List<MBMessage> filterFindByGroupId(long groupId) {
1935                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1936                            QueryUtil.ALL_POS, null);
1937            }
1938    
1939            /**
1940             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1941             *
1942             * <p>
1943             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1944             * </p>
1945             *
1946             * @param groupId the group ID
1947             * @param start the lower bound of the range of message-boards messages
1948             * @param end the upper bound of the range of message-boards messages (not inclusive)
1949             * @return the range of matching message-boards messages that the user has permission to view
1950             */
1951            @Override
1952            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1953                    return filterFindByGroupId(groupId, start, end, null);
1954            }
1955    
1956            /**
1957             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1958             *
1959             * <p>
1960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1961             * </p>
1962             *
1963             * @param groupId the group ID
1964             * @param start the lower bound of the range of message-boards messages
1965             * @param end the upper bound of the range of message-boards messages (not inclusive)
1966             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1967             * @return the ordered range of matching message-boards messages that the user has permission to view
1968             */
1969            @Override
1970            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1971                    int end, OrderByComparator<MBMessage> orderByComparator) {
1972                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1973                            return findByGroupId(groupId, start, end, orderByComparator);
1974                    }
1975    
1976                    StringBundler query = null;
1977    
1978                    if (orderByComparator != null) {
1979                            query = new StringBundler(3 +
1980                                            (orderByComparator.getOrderByFields().length * 2));
1981                    }
1982                    else {
1983                            query = new StringBundler(4);
1984                    }
1985    
1986                    if (getDB().isSupportsInlineDistinct()) {
1987                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1988                    }
1989                    else {
1990                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1991                    }
1992    
1993                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1994    
1995                    if (!getDB().isSupportsInlineDistinct()) {
1996                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1997                    }
1998    
1999                    if (orderByComparator != null) {
2000                            if (getDB().isSupportsInlineDistinct()) {
2001                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2002                                            orderByComparator, true);
2003                            }
2004                            else {
2005                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2006                                            orderByComparator, true);
2007                            }
2008                    }
2009                    else {
2010                            if (getDB().isSupportsInlineDistinct()) {
2011                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2012                            }
2013                            else {
2014                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2015                            }
2016                    }
2017    
2018                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2019                                    MBMessage.class.getName(),
2020                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2021    
2022                    Session session = null;
2023    
2024                    try {
2025                            session = openSession();
2026    
2027                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2028    
2029                            if (getDB().isSupportsInlineDistinct()) {
2030                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2031                            }
2032                            else {
2033                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2034                            }
2035    
2036                            QueryPos qPos = QueryPos.getInstance(q);
2037    
2038                            qPos.add(groupId);
2039    
2040                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2041                    }
2042                    catch (Exception e) {
2043                            throw processException(e);
2044                    }
2045                    finally {
2046                            closeSession(session);
2047                    }
2048            }
2049    
2050            /**
2051             * 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;.
2052             *
2053             * @param messageId the primary key of the current message-boards message
2054             * @param groupId the group ID
2055             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2056             * @return the previous, current, and next message-boards message
2057             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2058             */
2059            @Override
2060            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2061                    long groupId, OrderByComparator<MBMessage> orderByComparator)
2062                    throws NoSuchMessageException {
2063                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2064                            return findByGroupId_PrevAndNext(messageId, groupId,
2065                                    orderByComparator);
2066                    }
2067    
2068                    MBMessage mbMessage = findByPrimaryKey(messageId);
2069    
2070                    Session session = null;
2071    
2072                    try {
2073                            session = openSession();
2074    
2075                            MBMessage[] array = new MBMessageImpl[3];
2076    
2077                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2078                                            groupId, orderByComparator, true);
2079    
2080                            array[1] = mbMessage;
2081    
2082                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2083                                            groupId, orderByComparator, false);
2084    
2085                            return array;
2086                    }
2087                    catch (Exception e) {
2088                            throw processException(e);
2089                    }
2090                    finally {
2091                            closeSession(session);
2092                    }
2093            }
2094    
2095            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2096                    MBMessage mbMessage, long groupId,
2097                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2098                    StringBundler query = null;
2099    
2100                    if (orderByComparator != null) {
2101                            query = new StringBundler(5 +
2102                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2103                                            (orderByComparator.getOrderByFields().length * 3));
2104                    }
2105                    else {
2106                            query = new StringBundler(4);
2107                    }
2108    
2109                    if (getDB().isSupportsInlineDistinct()) {
2110                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2111                    }
2112                    else {
2113                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2114                    }
2115    
2116                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2117    
2118                    if (!getDB().isSupportsInlineDistinct()) {
2119                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2120                    }
2121    
2122                    if (orderByComparator != null) {
2123                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2124    
2125                            if (orderByConditionFields.length > 0) {
2126                                    query.append(WHERE_AND);
2127                            }
2128    
2129                            for (int i = 0; i < orderByConditionFields.length; i++) {
2130                                    if (getDB().isSupportsInlineDistinct()) {
2131                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2132                                    }
2133                                    else {
2134                                            query.append(_ORDER_BY_ENTITY_TABLE);
2135                                    }
2136    
2137                                    query.append(orderByConditionFields[i]);
2138    
2139                                    if ((i + 1) < orderByConditionFields.length) {
2140                                            if (orderByComparator.isAscending() ^ previous) {
2141                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2142                                            }
2143                                            else {
2144                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2145                                            }
2146                                    }
2147                                    else {
2148                                            if (orderByComparator.isAscending() ^ previous) {
2149                                                    query.append(WHERE_GREATER_THAN);
2150                                            }
2151                                            else {
2152                                                    query.append(WHERE_LESSER_THAN);
2153                                            }
2154                                    }
2155                            }
2156    
2157                            query.append(ORDER_BY_CLAUSE);
2158    
2159                            String[] orderByFields = orderByComparator.getOrderByFields();
2160    
2161                            for (int i = 0; i < orderByFields.length; i++) {
2162                                    if (getDB().isSupportsInlineDistinct()) {
2163                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2164                                    }
2165                                    else {
2166                                            query.append(_ORDER_BY_ENTITY_TABLE);
2167                                    }
2168    
2169                                    query.append(orderByFields[i]);
2170    
2171                                    if ((i + 1) < orderByFields.length) {
2172                                            if (orderByComparator.isAscending() ^ previous) {
2173                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2174                                            }
2175                                            else {
2176                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2177                                            }
2178                                    }
2179                                    else {
2180                                            if (orderByComparator.isAscending() ^ previous) {
2181                                                    query.append(ORDER_BY_ASC);
2182                                            }
2183                                            else {
2184                                                    query.append(ORDER_BY_DESC);
2185                                            }
2186                                    }
2187                            }
2188                    }
2189                    else {
2190                            if (getDB().isSupportsInlineDistinct()) {
2191                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2192                            }
2193                            else {
2194                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2195                            }
2196                    }
2197    
2198                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2199                                    MBMessage.class.getName(),
2200                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2201    
2202                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2203    
2204                    q.setFirstResult(0);
2205                    q.setMaxResults(2);
2206    
2207                    if (getDB().isSupportsInlineDistinct()) {
2208                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2209                    }
2210                    else {
2211                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2212                    }
2213    
2214                    QueryPos qPos = QueryPos.getInstance(q);
2215    
2216                    qPos.add(groupId);
2217    
2218                    if (orderByComparator != null) {
2219                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2220    
2221                            for (Object value : values) {
2222                                    qPos.add(value);
2223                            }
2224                    }
2225    
2226                    List<MBMessage> list = q.list();
2227    
2228                    if (list.size() == 2) {
2229                            return list.get(1);
2230                    }
2231                    else {
2232                            return null;
2233                    }
2234            }
2235    
2236            /**
2237             * Removes all the message-boards messages where groupId = &#63; from the database.
2238             *
2239             * @param groupId the group ID
2240             */
2241            @Override
2242            public void removeByGroupId(long groupId) {
2243                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2244                                    QueryUtil.ALL_POS, null)) {
2245                            remove(mbMessage);
2246                    }
2247            }
2248    
2249            /**
2250             * Returns the number of message-boards messages where groupId = &#63;.
2251             *
2252             * @param groupId the group ID
2253             * @return the number of matching message-boards messages
2254             */
2255            @Override
2256            public int countByGroupId(long groupId) {
2257                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2258    
2259                    Object[] finderArgs = new Object[] { groupId };
2260    
2261                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2262    
2263                    if (count == null) {
2264                            StringBundler query = new StringBundler(2);
2265    
2266                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2267    
2268                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2269    
2270                            String sql = query.toString();
2271    
2272                            Session session = null;
2273    
2274                            try {
2275                                    session = openSession();
2276    
2277                                    Query q = session.createQuery(sql);
2278    
2279                                    QueryPos qPos = QueryPos.getInstance(q);
2280    
2281                                    qPos.add(groupId);
2282    
2283                                    count = (Long)q.uniqueResult();
2284    
2285                                    finderCache.putResult(finderPath, finderArgs, count);
2286                            }
2287                            catch (Exception e) {
2288                                    finderCache.removeResult(finderPath, finderArgs);
2289    
2290                                    throw processException(e);
2291                            }
2292                            finally {
2293                                    closeSession(session);
2294                            }
2295                    }
2296    
2297                    return count.intValue();
2298            }
2299    
2300            /**
2301             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2302             *
2303             * @param groupId the group ID
2304             * @return the number of matching message-boards messages that the user has permission to view
2305             */
2306            @Override
2307            public int filterCountByGroupId(long groupId) {
2308                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2309                            return countByGroupId(groupId);
2310                    }
2311    
2312                    StringBundler query = new StringBundler(2);
2313    
2314                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2315    
2316                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2317    
2318                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2319                                    MBMessage.class.getName(),
2320                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2321    
2322                    Session session = null;
2323    
2324                    try {
2325                            session = openSession();
2326    
2327                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2328    
2329                            q.addScalar(COUNT_COLUMN_NAME,
2330                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2331    
2332                            QueryPos qPos = QueryPos.getInstance(q);
2333    
2334                            qPos.add(groupId);
2335    
2336                            Long count = (Long)q.uniqueResult();
2337    
2338                            return count.intValue();
2339                    }
2340                    catch (Exception e) {
2341                            throw processException(e);
2342                    }
2343                    finally {
2344                            closeSession(session);
2345                    }
2346            }
2347    
2348            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2349            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2350                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2351                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2352                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2353                            new String[] {
2354                                    Long.class.getName(),
2355                                    
2356                            Integer.class.getName(), Integer.class.getName(),
2357                                    OrderByComparator.class.getName()
2358                            });
2359            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2360                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2361                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2362                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2363                            new String[] { Long.class.getName() },
2364                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2365                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2366            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2367                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2368                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2369                            new String[] { Long.class.getName() });
2370    
2371            /**
2372             * Returns all the message-boards messages where companyId = &#63;.
2373             *
2374             * @param companyId the company ID
2375             * @return the matching message-boards messages
2376             */
2377            @Override
2378            public List<MBMessage> findByCompanyId(long companyId) {
2379                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2380                            null);
2381            }
2382    
2383            /**
2384             * Returns a range of all the message-boards messages where companyId = &#63;.
2385             *
2386             * <p>
2387             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2388             * </p>
2389             *
2390             * @param companyId the company ID
2391             * @param start the lower bound of the range of message-boards messages
2392             * @param end the upper bound of the range of message-boards messages (not inclusive)
2393             * @return the range of matching message-boards messages
2394             */
2395            @Override
2396            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2397                    return findByCompanyId(companyId, start, end, null);
2398            }
2399    
2400            /**
2401             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2402             *
2403             * <p>
2404             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2405             * </p>
2406             *
2407             * @param companyId the company ID
2408             * @param start the lower bound of the range of message-boards messages
2409             * @param end the upper bound of the range of message-boards messages (not inclusive)
2410             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2411             * @return the ordered range of matching message-boards messages
2412             */
2413            @Override
2414            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2415                    OrderByComparator<MBMessage> orderByComparator) {
2416                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2417            }
2418    
2419            /**
2420             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2421             *
2422             * <p>
2423             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2424             * </p>
2425             *
2426             * @param companyId the company ID
2427             * @param start the lower bound of the range of message-boards messages
2428             * @param end the upper bound of the range of message-boards messages (not inclusive)
2429             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2430             * @param retrieveFromCache whether to retrieve from the finder cache
2431             * @return the ordered range of matching message-boards messages
2432             */
2433            @Override
2434            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2435                    OrderByComparator<MBMessage> orderByComparator,
2436                    boolean retrieveFromCache) {
2437                    boolean pagination = true;
2438                    FinderPath finderPath = null;
2439                    Object[] finderArgs = null;
2440    
2441                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2442                                    (orderByComparator == null)) {
2443                            pagination = false;
2444                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2445                            finderArgs = new Object[] { companyId };
2446                    }
2447                    else {
2448                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2449                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2450                    }
2451    
2452                    List<MBMessage> list = null;
2453    
2454                    if (retrieveFromCache) {
2455                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2456                                            finderArgs, this);
2457    
2458                            if ((list != null) && !list.isEmpty()) {
2459                                    for (MBMessage mbMessage : list) {
2460                                            if ((companyId != mbMessage.getCompanyId())) {
2461                                                    list = null;
2462    
2463                                                    break;
2464                                            }
2465                                    }
2466                            }
2467                    }
2468    
2469                    if (list == null) {
2470                            StringBundler query = null;
2471    
2472                            if (orderByComparator != null) {
2473                                    query = new StringBundler(3 +
2474                                                    (orderByComparator.getOrderByFields().length * 2));
2475                            }
2476                            else {
2477                                    query = new StringBundler(3);
2478                            }
2479    
2480                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2481    
2482                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2483    
2484                            if (orderByComparator != null) {
2485                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2486                                            orderByComparator);
2487                            }
2488                            else
2489                             if (pagination) {
2490                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2491                            }
2492    
2493                            String sql = query.toString();
2494    
2495                            Session session = null;
2496    
2497                            try {
2498                                    session = openSession();
2499    
2500                                    Query q = session.createQuery(sql);
2501    
2502                                    QueryPos qPos = QueryPos.getInstance(q);
2503    
2504                                    qPos.add(companyId);
2505    
2506                                    if (!pagination) {
2507                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2508                                                            start, end, false);
2509    
2510                                            Collections.sort(list);
2511    
2512                                            list = Collections.unmodifiableList(list);
2513                                    }
2514                                    else {
2515                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2516                                                            start, end);
2517                                    }
2518    
2519                                    cacheResult(list);
2520    
2521                                    finderCache.putResult(finderPath, finderArgs, list);
2522                            }
2523                            catch (Exception e) {
2524                                    finderCache.removeResult(finderPath, finderArgs);
2525    
2526                                    throw processException(e);
2527                            }
2528                            finally {
2529                                    closeSession(session);
2530                            }
2531                    }
2532    
2533                    return list;
2534            }
2535    
2536            /**
2537             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2538             *
2539             * @param companyId the company ID
2540             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2541             * @return the first matching message-boards message
2542             * @throws NoSuchMessageException if a matching message-boards message could not be found
2543             */
2544            @Override
2545            public MBMessage findByCompanyId_First(long companyId,
2546                    OrderByComparator<MBMessage> orderByComparator)
2547                    throws NoSuchMessageException {
2548                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2549                                    orderByComparator);
2550    
2551                    if (mbMessage != null) {
2552                            return mbMessage;
2553                    }
2554    
2555                    StringBundler msg = new StringBundler(4);
2556    
2557                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2558    
2559                    msg.append("companyId=");
2560                    msg.append(companyId);
2561    
2562                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2563    
2564                    throw new NoSuchMessageException(msg.toString());
2565            }
2566    
2567            /**
2568             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2569             *
2570             * @param companyId the company ID
2571             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2572             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2573             */
2574            @Override
2575            public MBMessage fetchByCompanyId_First(long companyId,
2576                    OrderByComparator<MBMessage> orderByComparator) {
2577                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2578                                    orderByComparator);
2579    
2580                    if (!list.isEmpty()) {
2581                            return list.get(0);
2582                    }
2583    
2584                    return null;
2585            }
2586    
2587            /**
2588             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2589             *
2590             * @param companyId the company ID
2591             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2592             * @return the last matching message-boards message
2593             * @throws NoSuchMessageException if a matching message-boards message could not be found
2594             */
2595            @Override
2596            public MBMessage findByCompanyId_Last(long companyId,
2597                    OrderByComparator<MBMessage> orderByComparator)
2598                    throws NoSuchMessageException {
2599                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2600    
2601                    if (mbMessage != null) {
2602                            return mbMessage;
2603                    }
2604    
2605                    StringBundler msg = new StringBundler(4);
2606    
2607                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2608    
2609                    msg.append("companyId=");
2610                    msg.append(companyId);
2611    
2612                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2613    
2614                    throw new NoSuchMessageException(msg.toString());
2615            }
2616    
2617            /**
2618             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2619             *
2620             * @param companyId the company ID
2621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2622             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2623             */
2624            @Override
2625            public MBMessage fetchByCompanyId_Last(long companyId,
2626                    OrderByComparator<MBMessage> orderByComparator) {
2627                    int count = countByCompanyId(companyId);
2628    
2629                    if (count == 0) {
2630                            return null;
2631                    }
2632    
2633                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2634                                    orderByComparator);
2635    
2636                    if (!list.isEmpty()) {
2637                            return list.get(0);
2638                    }
2639    
2640                    return null;
2641            }
2642    
2643            /**
2644             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2645             *
2646             * @param messageId the primary key of the current message-boards message
2647             * @param companyId the company ID
2648             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2649             * @return the previous, current, and next message-boards message
2650             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2651             */
2652            @Override
2653            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2654                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2655                    throws NoSuchMessageException {
2656                    MBMessage mbMessage = findByPrimaryKey(messageId);
2657    
2658                    Session session = null;
2659    
2660                    try {
2661                            session = openSession();
2662    
2663                            MBMessage[] array = new MBMessageImpl[3];
2664    
2665                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2666                                            companyId, orderByComparator, true);
2667    
2668                            array[1] = mbMessage;
2669    
2670                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2671                                            companyId, orderByComparator, false);
2672    
2673                            return array;
2674                    }
2675                    catch (Exception e) {
2676                            throw processException(e);
2677                    }
2678                    finally {
2679                            closeSession(session);
2680                    }
2681            }
2682    
2683            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2684                    MBMessage mbMessage, long companyId,
2685                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2686                    StringBundler query = null;
2687    
2688                    if (orderByComparator != null) {
2689                            query = new StringBundler(4 +
2690                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2691                                            (orderByComparator.getOrderByFields().length * 3));
2692                    }
2693                    else {
2694                            query = new StringBundler(3);
2695                    }
2696    
2697                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2698    
2699                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2700    
2701                    if (orderByComparator != null) {
2702                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2703    
2704                            if (orderByConditionFields.length > 0) {
2705                                    query.append(WHERE_AND);
2706                            }
2707    
2708                            for (int i = 0; i < orderByConditionFields.length; i++) {
2709                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2710                                    query.append(orderByConditionFields[i]);
2711    
2712                                    if ((i + 1) < orderByConditionFields.length) {
2713                                            if (orderByComparator.isAscending() ^ previous) {
2714                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2715                                            }
2716                                            else {
2717                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2718                                            }
2719                                    }
2720                                    else {
2721                                            if (orderByComparator.isAscending() ^ previous) {
2722                                                    query.append(WHERE_GREATER_THAN);
2723                                            }
2724                                            else {
2725                                                    query.append(WHERE_LESSER_THAN);
2726                                            }
2727                                    }
2728                            }
2729    
2730                            query.append(ORDER_BY_CLAUSE);
2731    
2732                            String[] orderByFields = orderByComparator.getOrderByFields();
2733    
2734                            for (int i = 0; i < orderByFields.length; i++) {
2735                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2736                                    query.append(orderByFields[i]);
2737    
2738                                    if ((i + 1) < orderByFields.length) {
2739                                            if (orderByComparator.isAscending() ^ previous) {
2740                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2741                                            }
2742                                            else {
2743                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2744                                            }
2745                                    }
2746                                    else {
2747                                            if (orderByComparator.isAscending() ^ previous) {
2748                                                    query.append(ORDER_BY_ASC);
2749                                            }
2750                                            else {
2751                                                    query.append(ORDER_BY_DESC);
2752                                            }
2753                                    }
2754                            }
2755                    }
2756                    else {
2757                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2758                    }
2759    
2760                    String sql = query.toString();
2761    
2762                    Query q = session.createQuery(sql);
2763    
2764                    q.setFirstResult(0);
2765                    q.setMaxResults(2);
2766    
2767                    QueryPos qPos = QueryPos.getInstance(q);
2768    
2769                    qPos.add(companyId);
2770    
2771                    if (orderByComparator != null) {
2772                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2773    
2774                            for (Object value : values) {
2775                                    qPos.add(value);
2776                            }
2777                    }
2778    
2779                    List<MBMessage> list = q.list();
2780    
2781                    if (list.size() == 2) {
2782                            return list.get(1);
2783                    }
2784                    else {
2785                            return null;
2786                    }
2787            }
2788    
2789            /**
2790             * Removes all the message-boards messages where companyId = &#63; from the database.
2791             *
2792             * @param companyId the company ID
2793             */
2794            @Override
2795            public void removeByCompanyId(long companyId) {
2796                    for (MBMessage mbMessage : findByCompanyId(companyId,
2797                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2798                            remove(mbMessage);
2799                    }
2800            }
2801    
2802            /**
2803             * Returns the number of message-boards messages where companyId = &#63;.
2804             *
2805             * @param companyId the company ID
2806             * @return the number of matching message-boards messages
2807             */
2808            @Override
2809            public int countByCompanyId(long companyId) {
2810                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2811    
2812                    Object[] finderArgs = new Object[] { companyId };
2813    
2814                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2815    
2816                    if (count == null) {
2817                            StringBundler query = new StringBundler(2);
2818    
2819                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2820    
2821                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2822    
2823                            String sql = query.toString();
2824    
2825                            Session session = null;
2826    
2827                            try {
2828                                    session = openSession();
2829    
2830                                    Query q = session.createQuery(sql);
2831    
2832                                    QueryPos qPos = QueryPos.getInstance(q);
2833    
2834                                    qPos.add(companyId);
2835    
2836                                    count = (Long)q.uniqueResult();
2837    
2838                                    finderCache.putResult(finderPath, finderArgs, count);
2839                            }
2840                            catch (Exception e) {
2841                                    finderCache.removeResult(finderPath, finderArgs);
2842    
2843                                    throw processException(e);
2844                            }
2845                            finally {
2846                                    closeSession(session);
2847                            }
2848                    }
2849    
2850                    return count.intValue();
2851            }
2852    
2853            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2854            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2855                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2856                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2857                            new String[] {
2858                                    Long.class.getName(),
2859                                    
2860                            Integer.class.getName(), Integer.class.getName(),
2861                                    OrderByComparator.class.getName()
2862                            });
2863            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2864                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2865                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2866                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2867                            new String[] { Long.class.getName() },
2868                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2869                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2870            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2871                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2872                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2873                            new String[] { Long.class.getName() });
2874    
2875            /**
2876             * Returns all the message-boards messages where userId = &#63;.
2877             *
2878             * @param userId the user ID
2879             * @return the matching message-boards messages
2880             */
2881            @Override
2882            public List<MBMessage> findByUserId(long userId) {
2883                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2884            }
2885    
2886            /**
2887             * Returns a range of all the message-boards messages where userId = &#63;.
2888             *
2889             * <p>
2890             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2891             * </p>
2892             *
2893             * @param userId the user ID
2894             * @param start the lower bound of the range of message-boards messages
2895             * @param end the upper bound of the range of message-boards messages (not inclusive)
2896             * @return the range of matching message-boards messages
2897             */
2898            @Override
2899            public List<MBMessage> findByUserId(long userId, int start, int end) {
2900                    return findByUserId(userId, start, end, null);
2901            }
2902    
2903            /**
2904             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2905             *
2906             * <p>
2907             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2908             * </p>
2909             *
2910             * @param userId the user ID
2911             * @param start the lower bound of the range of message-boards messages
2912             * @param end the upper bound of the range of message-boards messages (not inclusive)
2913             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2914             * @return the ordered range of matching message-boards messages
2915             */
2916            @Override
2917            public List<MBMessage> findByUserId(long userId, int start, int end,
2918                    OrderByComparator<MBMessage> orderByComparator) {
2919                    return findByUserId(userId, start, end, orderByComparator, true);
2920            }
2921    
2922            /**
2923             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2924             *
2925             * <p>
2926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2927             * </p>
2928             *
2929             * @param userId the user ID
2930             * @param start the lower bound of the range of message-boards messages
2931             * @param end the upper bound of the range of message-boards messages (not inclusive)
2932             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2933             * @param retrieveFromCache whether to retrieve from the finder cache
2934             * @return the ordered range of matching message-boards messages
2935             */
2936            @Override
2937            public List<MBMessage> findByUserId(long userId, int start, int end,
2938                    OrderByComparator<MBMessage> orderByComparator,
2939                    boolean retrieveFromCache) {
2940                    boolean pagination = true;
2941                    FinderPath finderPath = null;
2942                    Object[] finderArgs = null;
2943    
2944                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2945                                    (orderByComparator == null)) {
2946                            pagination = false;
2947                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2948                            finderArgs = new Object[] { userId };
2949                    }
2950                    else {
2951                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2952                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2953                    }
2954    
2955                    List<MBMessage> list = null;
2956    
2957                    if (retrieveFromCache) {
2958                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2959                                            finderArgs, this);
2960    
2961                            if ((list != null) && !list.isEmpty()) {
2962                                    for (MBMessage mbMessage : list) {
2963                                            if ((userId != mbMessage.getUserId())) {
2964                                                    list = null;
2965    
2966                                                    break;
2967                                            }
2968                                    }
2969                            }
2970                    }
2971    
2972                    if (list == null) {
2973                            StringBundler query = null;
2974    
2975                            if (orderByComparator != null) {
2976                                    query = new StringBundler(3 +
2977                                                    (orderByComparator.getOrderByFields().length * 2));
2978                            }
2979                            else {
2980                                    query = new StringBundler(3);
2981                            }
2982    
2983                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2984    
2985                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2986    
2987                            if (orderByComparator != null) {
2988                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2989                                            orderByComparator);
2990                            }
2991                            else
2992                             if (pagination) {
2993                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2994                            }
2995    
2996                            String sql = query.toString();
2997    
2998                            Session session = null;
2999    
3000                            try {
3001                                    session = openSession();
3002    
3003                                    Query q = session.createQuery(sql);
3004    
3005                                    QueryPos qPos = QueryPos.getInstance(q);
3006    
3007                                    qPos.add(userId);
3008    
3009                                    if (!pagination) {
3010                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3011                                                            start, end, false);
3012    
3013                                            Collections.sort(list);
3014    
3015                                            list = Collections.unmodifiableList(list);
3016                                    }
3017                                    else {
3018                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3019                                                            start, end);
3020                                    }
3021    
3022                                    cacheResult(list);
3023    
3024                                    finderCache.putResult(finderPath, finderArgs, list);
3025                            }
3026                            catch (Exception e) {
3027                                    finderCache.removeResult(finderPath, finderArgs);
3028    
3029                                    throw processException(e);
3030                            }
3031                            finally {
3032                                    closeSession(session);
3033                            }
3034                    }
3035    
3036                    return list;
3037            }
3038    
3039            /**
3040             * Returns the first message-boards message in the ordered set where userId = &#63;.
3041             *
3042             * @param userId the user ID
3043             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3044             * @return the first matching message-boards message
3045             * @throws NoSuchMessageException if a matching message-boards message could not be found
3046             */
3047            @Override
3048            public MBMessage findByUserId_First(long userId,
3049                    OrderByComparator<MBMessage> orderByComparator)
3050                    throws NoSuchMessageException {
3051                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3052    
3053                    if (mbMessage != null) {
3054                            return mbMessage;
3055                    }
3056    
3057                    StringBundler msg = new StringBundler(4);
3058    
3059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3060    
3061                    msg.append("userId=");
3062                    msg.append(userId);
3063    
3064                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3065    
3066                    throw new NoSuchMessageException(msg.toString());
3067            }
3068    
3069            /**
3070             * Returns the first message-boards message in the ordered set where userId = &#63;.
3071             *
3072             * @param userId the user ID
3073             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3074             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3075             */
3076            @Override
3077            public MBMessage fetchByUserId_First(long userId,
3078                    OrderByComparator<MBMessage> orderByComparator) {
3079                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3080    
3081                    if (!list.isEmpty()) {
3082                            return list.get(0);
3083                    }
3084    
3085                    return null;
3086            }
3087    
3088            /**
3089             * Returns the last message-boards message in the ordered set where userId = &#63;.
3090             *
3091             * @param userId the user ID
3092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3093             * @return the last matching message-boards message
3094             * @throws NoSuchMessageException if a matching message-boards message could not be found
3095             */
3096            @Override
3097            public MBMessage findByUserId_Last(long userId,
3098                    OrderByComparator<MBMessage> orderByComparator)
3099                    throws NoSuchMessageException {
3100                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3101    
3102                    if (mbMessage != null) {
3103                            return mbMessage;
3104                    }
3105    
3106                    StringBundler msg = new StringBundler(4);
3107    
3108                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3109    
3110                    msg.append("userId=");
3111                    msg.append(userId);
3112    
3113                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3114    
3115                    throw new NoSuchMessageException(msg.toString());
3116            }
3117    
3118            /**
3119             * Returns the last message-boards message in the ordered set where userId = &#63;.
3120             *
3121             * @param userId the user ID
3122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3123             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3124             */
3125            @Override
3126            public MBMessage fetchByUserId_Last(long userId,
3127                    OrderByComparator<MBMessage> orderByComparator) {
3128                    int count = countByUserId(userId);
3129    
3130                    if (count == 0) {
3131                            return null;
3132                    }
3133    
3134                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3135                                    orderByComparator);
3136    
3137                    if (!list.isEmpty()) {
3138                            return list.get(0);
3139                    }
3140    
3141                    return null;
3142            }
3143    
3144            /**
3145             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3146             *
3147             * @param messageId the primary key of the current message-boards message
3148             * @param userId the user ID
3149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3150             * @return the previous, current, and next message-boards message
3151             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3152             */
3153            @Override
3154            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3155                    OrderByComparator<MBMessage> orderByComparator)
3156                    throws NoSuchMessageException {
3157                    MBMessage mbMessage = findByPrimaryKey(messageId);
3158    
3159                    Session session = null;
3160    
3161                    try {
3162                            session = openSession();
3163    
3164                            MBMessage[] array = new MBMessageImpl[3];
3165    
3166                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3167                                            orderByComparator, true);
3168    
3169                            array[1] = mbMessage;
3170    
3171                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3172                                            orderByComparator, false);
3173    
3174                            return array;
3175                    }
3176                    catch (Exception e) {
3177                            throw processException(e);
3178                    }
3179                    finally {
3180                            closeSession(session);
3181                    }
3182            }
3183    
3184            protected MBMessage getByUserId_PrevAndNext(Session session,
3185                    MBMessage mbMessage, long userId,
3186                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3187                    StringBundler query = null;
3188    
3189                    if (orderByComparator != null) {
3190                            query = new StringBundler(4 +
3191                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3192                                            (orderByComparator.getOrderByFields().length * 3));
3193                    }
3194                    else {
3195                            query = new StringBundler(3);
3196                    }
3197    
3198                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3199    
3200                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3201    
3202                    if (orderByComparator != null) {
3203                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3204    
3205                            if (orderByConditionFields.length > 0) {
3206                                    query.append(WHERE_AND);
3207                            }
3208    
3209                            for (int i = 0; i < orderByConditionFields.length; i++) {
3210                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3211                                    query.append(orderByConditionFields[i]);
3212    
3213                                    if ((i + 1) < orderByConditionFields.length) {
3214                                            if (orderByComparator.isAscending() ^ previous) {
3215                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3216                                            }
3217                                            else {
3218                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3219                                            }
3220                                    }
3221                                    else {
3222                                            if (orderByComparator.isAscending() ^ previous) {
3223                                                    query.append(WHERE_GREATER_THAN);
3224                                            }
3225                                            else {
3226                                                    query.append(WHERE_LESSER_THAN);
3227                                            }
3228                                    }
3229                            }
3230    
3231                            query.append(ORDER_BY_CLAUSE);
3232    
3233                            String[] orderByFields = orderByComparator.getOrderByFields();
3234    
3235                            for (int i = 0; i < orderByFields.length; i++) {
3236                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3237                                    query.append(orderByFields[i]);
3238    
3239                                    if ((i + 1) < orderByFields.length) {
3240                                            if (orderByComparator.isAscending() ^ previous) {
3241                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3242                                            }
3243                                            else {
3244                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3245                                            }
3246                                    }
3247                                    else {
3248                                            if (orderByComparator.isAscending() ^ previous) {
3249                                                    query.append(ORDER_BY_ASC);
3250                                            }
3251                                            else {
3252                                                    query.append(ORDER_BY_DESC);
3253                                            }
3254                                    }
3255                            }
3256                    }
3257                    else {
3258                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3259                    }
3260    
3261                    String sql = query.toString();
3262    
3263                    Query q = session.createQuery(sql);
3264    
3265                    q.setFirstResult(0);
3266                    q.setMaxResults(2);
3267    
3268                    QueryPos qPos = QueryPos.getInstance(q);
3269    
3270                    qPos.add(userId);
3271    
3272                    if (orderByComparator != null) {
3273                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3274    
3275                            for (Object value : values) {
3276                                    qPos.add(value);
3277                            }
3278                    }
3279    
3280                    List<MBMessage> list = q.list();
3281    
3282                    if (list.size() == 2) {
3283                            return list.get(1);
3284                    }
3285                    else {
3286                            return null;
3287                    }
3288            }
3289    
3290            /**
3291             * Removes all the message-boards messages where userId = &#63; from the database.
3292             *
3293             * @param userId the user ID
3294             */
3295            @Override
3296            public void removeByUserId(long userId) {
3297                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3298                                    QueryUtil.ALL_POS, null)) {
3299                            remove(mbMessage);
3300                    }
3301            }
3302    
3303            /**
3304             * Returns the number of message-boards messages where userId = &#63;.
3305             *
3306             * @param userId the user ID
3307             * @return the number of matching message-boards messages
3308             */
3309            @Override
3310            public int countByUserId(long userId) {
3311                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3312    
3313                    Object[] finderArgs = new Object[] { userId };
3314    
3315                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3316    
3317                    if (count == null) {
3318                            StringBundler query = new StringBundler(2);
3319    
3320                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3321    
3322                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3323    
3324                            String sql = query.toString();
3325    
3326                            Session session = null;
3327    
3328                            try {
3329                                    session = openSession();
3330    
3331                                    Query q = session.createQuery(sql);
3332    
3333                                    QueryPos qPos = QueryPos.getInstance(q);
3334    
3335                                    qPos.add(userId);
3336    
3337                                    count = (Long)q.uniqueResult();
3338    
3339                                    finderCache.putResult(finderPath, finderArgs, count);
3340                            }
3341                            catch (Exception e) {
3342                                    finderCache.removeResult(finderPath, finderArgs);
3343    
3344                                    throw processException(e);
3345                            }
3346                            finally {
3347                                    closeSession(session);
3348                            }
3349                    }
3350    
3351                    return count.intValue();
3352            }
3353    
3354            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3355            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3356                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3357                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3358                            new String[] {
3359                                    Long.class.getName(),
3360                                    
3361                            Integer.class.getName(), Integer.class.getName(),
3362                                    OrderByComparator.class.getName()
3363                            });
3364            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3365                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3366                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3367                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3368                            new String[] { Long.class.getName() },
3369                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3370                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3371            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3372                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3373                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3374                            new String[] { Long.class.getName() });
3375    
3376            /**
3377             * Returns all the message-boards messages where threadId = &#63;.
3378             *
3379             * @param threadId the thread ID
3380             * @return the matching message-boards messages
3381             */
3382            @Override
3383            public List<MBMessage> findByThreadId(long threadId) {
3384                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3385                            null);
3386            }
3387    
3388            /**
3389             * Returns a range of all the message-boards messages where threadId = &#63;.
3390             *
3391             * <p>
3392             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3393             * </p>
3394             *
3395             * @param threadId the thread ID
3396             * @param start the lower bound of the range of message-boards messages
3397             * @param end the upper bound of the range of message-boards messages (not inclusive)
3398             * @return the range of matching message-boards messages
3399             */
3400            @Override
3401            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3402                    return findByThreadId(threadId, start, end, null);
3403            }
3404    
3405            /**
3406             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3407             *
3408             * <p>
3409             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3410             * </p>
3411             *
3412             * @param threadId the thread ID
3413             * @param start the lower bound of the range of message-boards messages
3414             * @param end the upper bound of the range of message-boards messages (not inclusive)
3415             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3416             * @return the ordered range of matching message-boards messages
3417             */
3418            @Override
3419            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3420                    OrderByComparator<MBMessage> orderByComparator) {
3421                    return findByThreadId(threadId, start, end, orderByComparator, true);
3422            }
3423    
3424            /**
3425             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3426             *
3427             * <p>
3428             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3429             * </p>
3430             *
3431             * @param threadId the thread ID
3432             * @param start the lower bound of the range of message-boards messages
3433             * @param end the upper bound of the range of message-boards messages (not inclusive)
3434             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3435             * @param retrieveFromCache whether to retrieve from the finder cache
3436             * @return the ordered range of matching message-boards messages
3437             */
3438            @Override
3439            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3440                    OrderByComparator<MBMessage> orderByComparator,
3441                    boolean retrieveFromCache) {
3442                    boolean pagination = true;
3443                    FinderPath finderPath = null;
3444                    Object[] finderArgs = null;
3445    
3446                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3447                                    (orderByComparator == null)) {
3448                            pagination = false;
3449                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3450                            finderArgs = new Object[] { threadId };
3451                    }
3452                    else {
3453                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3454                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3455                    }
3456    
3457                    List<MBMessage> list = null;
3458    
3459                    if (retrieveFromCache) {
3460                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3461                                            finderArgs, this);
3462    
3463                            if ((list != null) && !list.isEmpty()) {
3464                                    for (MBMessage mbMessage : list) {
3465                                            if ((threadId != mbMessage.getThreadId())) {
3466                                                    list = null;
3467    
3468                                                    break;
3469                                            }
3470                                    }
3471                            }
3472                    }
3473    
3474                    if (list == null) {
3475                            StringBundler query = null;
3476    
3477                            if (orderByComparator != null) {
3478                                    query = new StringBundler(3 +
3479                                                    (orderByComparator.getOrderByFields().length * 2));
3480                            }
3481                            else {
3482                                    query = new StringBundler(3);
3483                            }
3484    
3485                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3486    
3487                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3488    
3489                            if (orderByComparator != null) {
3490                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3491                                            orderByComparator);
3492                            }
3493                            else
3494                             if (pagination) {
3495                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3496                            }
3497    
3498                            String sql = query.toString();
3499    
3500                            Session session = null;
3501    
3502                            try {
3503                                    session = openSession();
3504    
3505                                    Query q = session.createQuery(sql);
3506    
3507                                    QueryPos qPos = QueryPos.getInstance(q);
3508    
3509                                    qPos.add(threadId);
3510    
3511                                    if (!pagination) {
3512                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3513                                                            start, end, false);
3514    
3515                                            Collections.sort(list);
3516    
3517                                            list = Collections.unmodifiableList(list);
3518                                    }
3519                                    else {
3520                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3521                                                            start, end);
3522                                    }
3523    
3524                                    cacheResult(list);
3525    
3526                                    finderCache.putResult(finderPath, finderArgs, list);
3527                            }
3528                            catch (Exception e) {
3529                                    finderCache.removeResult(finderPath, finderArgs);
3530    
3531                                    throw processException(e);
3532                            }
3533                            finally {
3534                                    closeSession(session);
3535                            }
3536                    }
3537    
3538                    return list;
3539            }
3540    
3541            /**
3542             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3543             *
3544             * @param threadId the thread ID
3545             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3546             * @return the first matching message-boards message
3547             * @throws NoSuchMessageException if a matching message-boards message could not be found
3548             */
3549            @Override
3550            public MBMessage findByThreadId_First(long threadId,
3551                    OrderByComparator<MBMessage> orderByComparator)
3552                    throws NoSuchMessageException {
3553                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3554    
3555                    if (mbMessage != null) {
3556                            return mbMessage;
3557                    }
3558    
3559                    StringBundler msg = new StringBundler(4);
3560    
3561                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3562    
3563                    msg.append("threadId=");
3564                    msg.append(threadId);
3565    
3566                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3567    
3568                    throw new NoSuchMessageException(msg.toString());
3569            }
3570    
3571            /**
3572             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3573             *
3574             * @param threadId the thread ID
3575             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3576             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3577             */
3578            @Override
3579            public MBMessage fetchByThreadId_First(long threadId,
3580                    OrderByComparator<MBMessage> orderByComparator) {
3581                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3582    
3583                    if (!list.isEmpty()) {
3584                            return list.get(0);
3585                    }
3586    
3587                    return null;
3588            }
3589    
3590            /**
3591             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3592             *
3593             * @param threadId the thread ID
3594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3595             * @return the last matching message-boards message
3596             * @throws NoSuchMessageException if a matching message-boards message could not be found
3597             */
3598            @Override
3599            public MBMessage findByThreadId_Last(long threadId,
3600                    OrderByComparator<MBMessage> orderByComparator)
3601                    throws NoSuchMessageException {
3602                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3603    
3604                    if (mbMessage != null) {
3605                            return mbMessage;
3606                    }
3607    
3608                    StringBundler msg = new StringBundler(4);
3609    
3610                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3611    
3612                    msg.append("threadId=");
3613                    msg.append(threadId);
3614    
3615                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3616    
3617                    throw new NoSuchMessageException(msg.toString());
3618            }
3619    
3620            /**
3621             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3622             *
3623             * @param threadId the thread ID
3624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3625             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3626             */
3627            @Override
3628            public MBMessage fetchByThreadId_Last(long threadId,
3629                    OrderByComparator<MBMessage> orderByComparator) {
3630                    int count = countByThreadId(threadId);
3631    
3632                    if (count == 0) {
3633                            return null;
3634                    }
3635    
3636                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3637                                    orderByComparator);
3638    
3639                    if (!list.isEmpty()) {
3640                            return list.get(0);
3641                    }
3642    
3643                    return null;
3644            }
3645    
3646            /**
3647             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3648             *
3649             * @param messageId the primary key of the current message-boards message
3650             * @param threadId the thread ID
3651             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3652             * @return the previous, current, and next message-boards message
3653             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3654             */
3655            @Override
3656            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3657                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3658                    throws NoSuchMessageException {
3659                    MBMessage mbMessage = findByPrimaryKey(messageId);
3660    
3661                    Session session = null;
3662    
3663                    try {
3664                            session = openSession();
3665    
3666                            MBMessage[] array = new MBMessageImpl[3];
3667    
3668                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3669                                            orderByComparator, true);
3670    
3671                            array[1] = mbMessage;
3672    
3673                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3674                                            orderByComparator, false);
3675    
3676                            return array;
3677                    }
3678                    catch (Exception e) {
3679                            throw processException(e);
3680                    }
3681                    finally {
3682                            closeSession(session);
3683                    }
3684            }
3685    
3686            protected MBMessage getByThreadId_PrevAndNext(Session session,
3687                    MBMessage mbMessage, long threadId,
3688                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3689                    StringBundler query = null;
3690    
3691                    if (orderByComparator != null) {
3692                            query = new StringBundler(4 +
3693                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3694                                            (orderByComparator.getOrderByFields().length * 3));
3695                    }
3696                    else {
3697                            query = new StringBundler(3);
3698                    }
3699    
3700                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3701    
3702                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3703    
3704                    if (orderByComparator != null) {
3705                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3706    
3707                            if (orderByConditionFields.length > 0) {
3708                                    query.append(WHERE_AND);
3709                            }
3710    
3711                            for (int i = 0; i < orderByConditionFields.length; i++) {
3712                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3713                                    query.append(orderByConditionFields[i]);
3714    
3715                                    if ((i + 1) < orderByConditionFields.length) {
3716                                            if (orderByComparator.isAscending() ^ previous) {
3717                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3718                                            }
3719                                            else {
3720                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3721                                            }
3722                                    }
3723                                    else {
3724                                            if (orderByComparator.isAscending() ^ previous) {
3725                                                    query.append(WHERE_GREATER_THAN);
3726                                            }
3727                                            else {
3728                                                    query.append(WHERE_LESSER_THAN);
3729                                            }
3730                                    }
3731                            }
3732    
3733                            query.append(ORDER_BY_CLAUSE);
3734    
3735                            String[] orderByFields = orderByComparator.getOrderByFields();
3736    
3737                            for (int i = 0; i < orderByFields.length; i++) {
3738                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3739                                    query.append(orderByFields[i]);
3740    
3741                                    if ((i + 1) < orderByFields.length) {
3742                                            if (orderByComparator.isAscending() ^ previous) {
3743                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3744                                            }
3745                                            else {
3746                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3747                                            }
3748                                    }
3749                                    else {
3750                                            if (orderByComparator.isAscending() ^ previous) {
3751                                                    query.append(ORDER_BY_ASC);
3752                                            }
3753                                            else {
3754                                                    query.append(ORDER_BY_DESC);
3755                                            }
3756                                    }
3757                            }
3758                    }
3759                    else {
3760                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3761                    }
3762    
3763                    String sql = query.toString();
3764    
3765                    Query q = session.createQuery(sql);
3766    
3767                    q.setFirstResult(0);
3768                    q.setMaxResults(2);
3769    
3770                    QueryPos qPos = QueryPos.getInstance(q);
3771    
3772                    qPos.add(threadId);
3773    
3774                    if (orderByComparator != null) {
3775                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3776    
3777                            for (Object value : values) {
3778                                    qPos.add(value);
3779                            }
3780                    }
3781    
3782                    List<MBMessage> list = q.list();
3783    
3784                    if (list.size() == 2) {
3785                            return list.get(1);
3786                    }
3787                    else {
3788                            return null;
3789                    }
3790            }
3791    
3792            /**
3793             * Removes all the message-boards messages where threadId = &#63; from the database.
3794             *
3795             * @param threadId the thread ID
3796             */
3797            @Override
3798            public void removeByThreadId(long threadId) {
3799                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3800                                    QueryUtil.ALL_POS, null)) {
3801                            remove(mbMessage);
3802                    }
3803            }
3804    
3805            /**
3806             * Returns the number of message-boards messages where threadId = &#63;.
3807             *
3808             * @param threadId the thread ID
3809             * @return the number of matching message-boards messages
3810             */
3811            @Override
3812            public int countByThreadId(long threadId) {
3813                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3814    
3815                    Object[] finderArgs = new Object[] { threadId };
3816    
3817                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3818    
3819                    if (count == null) {
3820                            StringBundler query = new StringBundler(2);
3821    
3822                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3823    
3824                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3825    
3826                            String sql = query.toString();
3827    
3828                            Session session = null;
3829    
3830                            try {
3831                                    session = openSession();
3832    
3833                                    Query q = session.createQuery(sql);
3834    
3835                                    QueryPos qPos = QueryPos.getInstance(q);
3836    
3837                                    qPos.add(threadId);
3838    
3839                                    count = (Long)q.uniqueResult();
3840    
3841                                    finderCache.putResult(finderPath, finderArgs, count);
3842                            }
3843                            catch (Exception e) {
3844                                    finderCache.removeResult(finderPath, finderArgs);
3845    
3846                                    throw processException(e);
3847                            }
3848                            finally {
3849                                    closeSession(session);
3850                            }
3851                    }
3852    
3853                    return count.intValue();
3854            }
3855    
3856            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3857            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3858                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3859                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3860                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3861                            new String[] {
3862                                    Long.class.getName(),
3863                                    
3864                            Integer.class.getName(), Integer.class.getName(),
3865                                    OrderByComparator.class.getName()
3866                            });
3867            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3868                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3869                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3870                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3871                            new String[] { Long.class.getName() },
3872                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3873                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3874            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3875                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3876                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3877                            new String[] { Long.class.getName() });
3878    
3879            /**
3880             * Returns all the message-boards messages where threadId = &#63;.
3881             *
3882             * @param threadId the thread ID
3883             * @return the matching message-boards messages
3884             */
3885            @Override
3886            public List<MBMessage> findByThreadReplies(long threadId) {
3887                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3888                            QueryUtil.ALL_POS, null);
3889            }
3890    
3891            /**
3892             * Returns a range of all the message-boards messages where threadId = &#63;.
3893             *
3894             * <p>
3895             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3896             * </p>
3897             *
3898             * @param threadId the thread ID
3899             * @param start the lower bound of the range of message-boards messages
3900             * @param end the upper bound of the range of message-boards messages (not inclusive)
3901             * @return the range of matching message-boards messages
3902             */
3903            @Override
3904            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3905                    return findByThreadReplies(threadId, start, end, null);
3906            }
3907    
3908            /**
3909             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3910             *
3911             * <p>
3912             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3913             * </p>
3914             *
3915             * @param threadId the thread ID
3916             * @param start the lower bound of the range of message-boards messages
3917             * @param end the upper bound of the range of message-boards messages (not inclusive)
3918             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3919             * @return the ordered range of matching message-boards messages
3920             */
3921            @Override
3922            public List<MBMessage> findByThreadReplies(long threadId, int start,
3923                    int end, OrderByComparator<MBMessage> orderByComparator) {
3924                    return findByThreadReplies(threadId, start, end, orderByComparator, true);
3925            }
3926    
3927            /**
3928             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3929             *
3930             * <p>
3931             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3932             * </p>
3933             *
3934             * @param threadId the thread ID
3935             * @param start the lower bound of the range of message-boards messages
3936             * @param end the upper bound of the range of message-boards messages (not inclusive)
3937             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3938             * @param retrieveFromCache whether to retrieve from the finder cache
3939             * @return the ordered range of matching message-boards messages
3940             */
3941            @Override
3942            public List<MBMessage> findByThreadReplies(long threadId, int start,
3943                    int end, OrderByComparator<MBMessage> orderByComparator,
3944                    boolean retrieveFromCache) {
3945                    boolean pagination = true;
3946                    FinderPath finderPath = null;
3947                    Object[] finderArgs = null;
3948    
3949                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3950                                    (orderByComparator == null)) {
3951                            pagination = false;
3952                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3953                            finderArgs = new Object[] { threadId };
3954                    }
3955                    else {
3956                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3957                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3958                    }
3959    
3960                    List<MBMessage> list = null;
3961    
3962                    if (retrieveFromCache) {
3963                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3964                                            finderArgs, this);
3965    
3966                            if ((list != null) && !list.isEmpty()) {
3967                                    for (MBMessage mbMessage : list) {
3968                                            if ((threadId != mbMessage.getThreadId())) {
3969                                                    list = null;
3970    
3971                                                    break;
3972                                            }
3973                                    }
3974                            }
3975                    }
3976    
3977                    if (list == null) {
3978                            StringBundler query = null;
3979    
3980                            if (orderByComparator != null) {
3981                                    query = new StringBundler(3 +
3982                                                    (orderByComparator.getOrderByFields().length * 2));
3983                            }
3984                            else {
3985                                    query = new StringBundler(3);
3986                            }
3987    
3988                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3989    
3990                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3991    
3992                            if (orderByComparator != null) {
3993                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3994                                            orderByComparator);
3995                            }
3996                            else
3997                             if (pagination) {
3998                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3999                            }
4000    
4001                            String sql = query.toString();
4002    
4003                            Session session = null;
4004    
4005                            try {
4006                                    session = openSession();
4007    
4008                                    Query q = session.createQuery(sql);
4009    
4010                                    QueryPos qPos = QueryPos.getInstance(q);
4011    
4012                                    qPos.add(threadId);
4013    
4014                                    if (!pagination) {
4015                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4016                                                            start, end, false);
4017    
4018                                            Collections.sort(list);
4019    
4020                                            list = Collections.unmodifiableList(list);
4021                                    }
4022                                    else {
4023                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4024                                                            start, end);
4025                                    }
4026    
4027                                    cacheResult(list);
4028    
4029                                    finderCache.putResult(finderPath, finderArgs, list);
4030                            }
4031                            catch (Exception e) {
4032                                    finderCache.removeResult(finderPath, finderArgs);
4033    
4034                                    throw processException(e);
4035                            }
4036                            finally {
4037                                    closeSession(session);
4038                            }
4039                    }
4040    
4041                    return list;
4042            }
4043    
4044            /**
4045             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4046             *
4047             * @param threadId the thread ID
4048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4049             * @return the first matching message-boards message
4050             * @throws NoSuchMessageException if a matching message-boards message could not be found
4051             */
4052            @Override
4053            public MBMessage findByThreadReplies_First(long threadId,
4054                    OrderByComparator<MBMessage> orderByComparator)
4055                    throws NoSuchMessageException {
4056                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4057                                    orderByComparator);
4058    
4059                    if (mbMessage != null) {
4060                            return mbMessage;
4061                    }
4062    
4063                    StringBundler msg = new StringBundler(4);
4064    
4065                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4066    
4067                    msg.append("threadId=");
4068                    msg.append(threadId);
4069    
4070                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4071    
4072                    throw new NoSuchMessageException(msg.toString());
4073            }
4074    
4075            /**
4076             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4077             *
4078             * @param threadId the thread ID
4079             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4080             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4081             */
4082            @Override
4083            public MBMessage fetchByThreadReplies_First(long threadId,
4084                    OrderByComparator<MBMessage> orderByComparator) {
4085                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4086                                    orderByComparator);
4087    
4088                    if (!list.isEmpty()) {
4089                            return list.get(0);
4090                    }
4091    
4092                    return null;
4093            }
4094    
4095            /**
4096             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4097             *
4098             * @param threadId the thread ID
4099             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4100             * @return the last matching message-boards message
4101             * @throws NoSuchMessageException if a matching message-boards message could not be found
4102             */
4103            @Override
4104            public MBMessage findByThreadReplies_Last(long threadId,
4105                    OrderByComparator<MBMessage> orderByComparator)
4106                    throws NoSuchMessageException {
4107                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4108                                    orderByComparator);
4109    
4110                    if (mbMessage != null) {
4111                            return mbMessage;
4112                    }
4113    
4114                    StringBundler msg = new StringBundler(4);
4115    
4116                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4117    
4118                    msg.append("threadId=");
4119                    msg.append(threadId);
4120    
4121                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4122    
4123                    throw new NoSuchMessageException(msg.toString());
4124            }
4125    
4126            /**
4127             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4128             *
4129             * @param threadId the thread ID
4130             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4131             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4132             */
4133            @Override
4134            public MBMessage fetchByThreadReplies_Last(long threadId,
4135                    OrderByComparator<MBMessage> orderByComparator) {
4136                    int count = countByThreadReplies(threadId);
4137    
4138                    if (count == 0) {
4139                            return null;
4140                    }
4141    
4142                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4143                                    orderByComparator);
4144    
4145                    if (!list.isEmpty()) {
4146                            return list.get(0);
4147                    }
4148    
4149                    return null;
4150            }
4151    
4152            /**
4153             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4154             *
4155             * @param messageId the primary key of the current message-boards message
4156             * @param threadId the thread ID
4157             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4158             * @return the previous, current, and next message-boards message
4159             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4160             */
4161            @Override
4162            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4163                    long threadId, OrderByComparator<MBMessage> orderByComparator)
4164                    throws NoSuchMessageException {
4165                    MBMessage mbMessage = findByPrimaryKey(messageId);
4166    
4167                    Session session = null;
4168    
4169                    try {
4170                            session = openSession();
4171    
4172                            MBMessage[] array = new MBMessageImpl[3];
4173    
4174                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4175                                            threadId, orderByComparator, true);
4176    
4177                            array[1] = mbMessage;
4178    
4179                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4180                                            threadId, orderByComparator, false);
4181    
4182                            return array;
4183                    }
4184                    catch (Exception e) {
4185                            throw processException(e);
4186                    }
4187                    finally {
4188                            closeSession(session);
4189                    }
4190            }
4191    
4192            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4193                    MBMessage mbMessage, long threadId,
4194                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4195                    StringBundler query = null;
4196    
4197                    if (orderByComparator != null) {
4198                            query = new StringBundler(4 +
4199                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4200                                            (orderByComparator.getOrderByFields().length * 3));
4201                    }
4202                    else {
4203                            query = new StringBundler(3);
4204                    }
4205    
4206                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4207    
4208                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4209    
4210                    if (orderByComparator != null) {
4211                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4212    
4213                            if (orderByConditionFields.length > 0) {
4214                                    query.append(WHERE_AND);
4215                            }
4216    
4217                            for (int i = 0; i < orderByConditionFields.length; i++) {
4218                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4219                                    query.append(orderByConditionFields[i]);
4220    
4221                                    if ((i + 1) < orderByConditionFields.length) {
4222                                            if (orderByComparator.isAscending() ^ previous) {
4223                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4224                                            }
4225                                            else {
4226                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4227                                            }
4228                                    }
4229                                    else {
4230                                            if (orderByComparator.isAscending() ^ previous) {
4231                                                    query.append(WHERE_GREATER_THAN);
4232                                            }
4233                                            else {
4234                                                    query.append(WHERE_LESSER_THAN);
4235                                            }
4236                                    }
4237                            }
4238    
4239                            query.append(ORDER_BY_CLAUSE);
4240    
4241                            String[] orderByFields = orderByComparator.getOrderByFields();
4242    
4243                            for (int i = 0; i < orderByFields.length; i++) {
4244                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4245                                    query.append(orderByFields[i]);
4246    
4247                                    if ((i + 1) < orderByFields.length) {
4248                                            if (orderByComparator.isAscending() ^ previous) {
4249                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4250                                            }
4251                                            else {
4252                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4253                                            }
4254                                    }
4255                                    else {
4256                                            if (orderByComparator.isAscending() ^ previous) {
4257                                                    query.append(ORDER_BY_ASC);
4258                                            }
4259                                            else {
4260                                                    query.append(ORDER_BY_DESC);
4261                                            }
4262                                    }
4263                            }
4264                    }
4265                    else {
4266                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4267                    }
4268    
4269                    String sql = query.toString();
4270    
4271                    Query q = session.createQuery(sql);
4272    
4273                    q.setFirstResult(0);
4274                    q.setMaxResults(2);
4275    
4276                    QueryPos qPos = QueryPos.getInstance(q);
4277    
4278                    qPos.add(threadId);
4279    
4280                    if (orderByComparator != null) {
4281                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4282    
4283                            for (Object value : values) {
4284                                    qPos.add(value);
4285                            }
4286                    }
4287    
4288                    List<MBMessage> list = q.list();
4289    
4290                    if (list.size() == 2) {
4291                            return list.get(1);
4292                    }
4293                    else {
4294                            return null;
4295                    }
4296            }
4297    
4298            /**
4299             * Removes all the message-boards messages where threadId = &#63; from the database.
4300             *
4301             * @param threadId the thread ID
4302             */
4303            @Override
4304            public void removeByThreadReplies(long threadId) {
4305                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4306                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4307                            remove(mbMessage);
4308                    }
4309            }
4310    
4311            /**
4312             * Returns the number of message-boards messages where threadId = &#63;.
4313             *
4314             * @param threadId the thread ID
4315             * @return the number of matching message-boards messages
4316             */
4317            @Override
4318            public int countByThreadReplies(long threadId) {
4319                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4320    
4321                    Object[] finderArgs = new Object[] { threadId };
4322    
4323                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4324    
4325                    if (count == null) {
4326                            StringBundler query = new StringBundler(2);
4327    
4328                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4329    
4330                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4331    
4332                            String sql = query.toString();
4333    
4334                            Session session = null;
4335    
4336                            try {
4337                                    session = openSession();
4338    
4339                                    Query q = session.createQuery(sql);
4340    
4341                                    QueryPos qPos = QueryPos.getInstance(q);
4342    
4343                                    qPos.add(threadId);
4344    
4345                                    count = (Long)q.uniqueResult();
4346    
4347                                    finderCache.putResult(finderPath, finderArgs, count);
4348                            }
4349                            catch (Exception e) {
4350                                    finderCache.removeResult(finderPath, finderArgs);
4351    
4352                                    throw processException(e);
4353                            }
4354                            finally {
4355                                    closeSession(session);
4356                            }
4357                    }
4358    
4359                    return count.intValue();
4360            }
4361    
4362            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4363            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4364                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4365                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4366                            new String[] {
4367                                    Long.class.getName(), Long.class.getName(),
4368                                    
4369                            Integer.class.getName(), Integer.class.getName(),
4370                                    OrderByComparator.class.getName()
4371                            });
4372            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4373                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4374                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4375                            new String[] { Long.class.getName(), Long.class.getName() },
4376                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4377                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4378                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4379            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4380                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4381                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4382                            new String[] { Long.class.getName(), Long.class.getName() });
4383    
4384            /**
4385             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4386             *
4387             * @param groupId the group ID
4388             * @param userId the user ID
4389             * @return the matching message-boards messages
4390             */
4391            @Override
4392            public List<MBMessage> findByG_U(long groupId, long userId) {
4393                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4394                            null);
4395            }
4396    
4397            /**
4398             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4399             *
4400             * <p>
4401             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4402             * </p>
4403             *
4404             * @param groupId the group ID
4405             * @param userId the user ID
4406             * @param start the lower bound of the range of message-boards messages
4407             * @param end the upper bound of the range of message-boards messages (not inclusive)
4408             * @return the range of matching message-boards messages
4409             */
4410            @Override
4411            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4412                    int end) {
4413                    return findByG_U(groupId, userId, start, end, null);
4414            }
4415    
4416            /**
4417             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4418             *
4419             * <p>
4420             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4421             * </p>
4422             *
4423             * @param groupId the group ID
4424             * @param userId the user ID
4425             * @param start the lower bound of the range of message-boards messages
4426             * @param end the upper bound of the range of message-boards messages (not inclusive)
4427             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4428             * @return the ordered range of matching message-boards messages
4429             */
4430            @Override
4431            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4432                    int end, OrderByComparator<MBMessage> orderByComparator) {
4433                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
4434            }
4435    
4436            /**
4437             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4438             *
4439             * <p>
4440             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4441             * </p>
4442             *
4443             * @param groupId the group ID
4444             * @param userId the user ID
4445             * @param start the lower bound of the range of message-boards messages
4446             * @param end the upper bound of the range of message-boards messages (not inclusive)
4447             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4448             * @param retrieveFromCache whether to retrieve from the finder cache
4449             * @return the ordered range of matching message-boards messages
4450             */
4451            @Override
4452            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4453                    int end, OrderByComparator<MBMessage> orderByComparator,
4454                    boolean retrieveFromCache) {
4455                    boolean pagination = true;
4456                    FinderPath finderPath = null;
4457                    Object[] finderArgs = null;
4458    
4459                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4460                                    (orderByComparator == null)) {
4461                            pagination = false;
4462                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4463                            finderArgs = new Object[] { groupId, userId };
4464                    }
4465                    else {
4466                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4467                            finderArgs = new Object[] {
4468                                            groupId, userId,
4469                                            
4470                                            start, end, orderByComparator
4471                                    };
4472                    }
4473    
4474                    List<MBMessage> list = null;
4475    
4476                    if (retrieveFromCache) {
4477                            list = (List<MBMessage>)finderCache.getResult(finderPath,
4478                                            finderArgs, this);
4479    
4480                            if ((list != null) && !list.isEmpty()) {
4481                                    for (MBMessage mbMessage : list) {
4482                                            if ((groupId != mbMessage.getGroupId()) ||
4483                                                            (userId != mbMessage.getUserId())) {
4484                                                    list = null;
4485    
4486                                                    break;
4487                                            }
4488                                    }
4489                            }
4490                    }
4491    
4492                    if (list == null) {
4493                            StringBundler query = null;
4494    
4495                            if (orderByComparator != null) {
4496                                    query = new StringBundler(4 +
4497                                                    (orderByComparator.getOrderByFields().length * 2));
4498                            }
4499                            else {
4500                                    query = new StringBundler(4);
4501                            }
4502    
4503                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4504    
4505                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4506    
4507                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4508    
4509                            if (orderByComparator != null) {
4510                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4511                                            orderByComparator);
4512                            }
4513                            else
4514                             if (pagination) {
4515                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4516                            }
4517    
4518                            String sql = query.toString();
4519    
4520                            Session session = null;
4521    
4522                            try {
4523                                    session = openSession();
4524    
4525                                    Query q = session.createQuery(sql);
4526    
4527                                    QueryPos qPos = QueryPos.getInstance(q);
4528    
4529                                    qPos.add(groupId);
4530    
4531                                    qPos.add(userId);
4532    
4533                                    if (!pagination) {
4534                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4535                                                            start, end, false);
4536    
4537                                            Collections.sort(list);
4538    
4539                                            list = Collections.unmodifiableList(list);
4540                                    }
4541                                    else {
4542                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4543                                                            start, end);
4544                                    }
4545    
4546                                    cacheResult(list);
4547    
4548                                    finderCache.putResult(finderPath, finderArgs, list);
4549                            }
4550                            catch (Exception e) {
4551                                    finderCache.removeResult(finderPath, finderArgs);
4552    
4553                                    throw processException(e);
4554                            }
4555                            finally {
4556                                    closeSession(session);
4557                            }
4558                    }
4559    
4560                    return list;
4561            }
4562    
4563            /**
4564             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4565             *
4566             * @param groupId the group ID
4567             * @param userId the user ID
4568             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4569             * @return the first matching message-boards message
4570             * @throws NoSuchMessageException if a matching message-boards message could not be found
4571             */
4572            @Override
4573            public MBMessage findByG_U_First(long groupId, long userId,
4574                    OrderByComparator<MBMessage> orderByComparator)
4575                    throws NoSuchMessageException {
4576                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4577                                    orderByComparator);
4578    
4579                    if (mbMessage != null) {
4580                            return mbMessage;
4581                    }
4582    
4583                    StringBundler msg = new StringBundler(6);
4584    
4585                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4586    
4587                    msg.append("groupId=");
4588                    msg.append(groupId);
4589    
4590                    msg.append(", userId=");
4591                    msg.append(userId);
4592    
4593                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4594    
4595                    throw new NoSuchMessageException(msg.toString());
4596            }
4597    
4598            /**
4599             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4600             *
4601             * @param groupId the group ID
4602             * @param userId the user ID
4603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4604             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4605             */
4606            @Override
4607            public MBMessage fetchByG_U_First(long groupId, long userId,
4608                    OrderByComparator<MBMessage> orderByComparator) {
4609                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4610                                    orderByComparator);
4611    
4612                    if (!list.isEmpty()) {
4613                            return list.get(0);
4614                    }
4615    
4616                    return null;
4617            }
4618    
4619            /**
4620             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4621             *
4622             * @param groupId the group ID
4623             * @param userId the user ID
4624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4625             * @return the last matching message-boards message
4626             * @throws NoSuchMessageException if a matching message-boards message could not be found
4627             */
4628            @Override
4629            public MBMessage findByG_U_Last(long groupId, long userId,
4630                    OrderByComparator<MBMessage> orderByComparator)
4631                    throws NoSuchMessageException {
4632                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4633    
4634                    if (mbMessage != null) {
4635                            return mbMessage;
4636                    }
4637    
4638                    StringBundler msg = new StringBundler(6);
4639    
4640                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4641    
4642                    msg.append("groupId=");
4643                    msg.append(groupId);
4644    
4645                    msg.append(", userId=");
4646                    msg.append(userId);
4647    
4648                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4649    
4650                    throw new NoSuchMessageException(msg.toString());
4651            }
4652    
4653            /**
4654             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4655             *
4656             * @param groupId the group ID
4657             * @param userId the user ID
4658             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4659             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4660             */
4661            @Override
4662            public MBMessage fetchByG_U_Last(long groupId, long userId,
4663                    OrderByComparator<MBMessage> orderByComparator) {
4664                    int count = countByG_U(groupId, userId);
4665    
4666                    if (count == 0) {
4667                            return null;
4668                    }
4669    
4670                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4671                                    orderByComparator);
4672    
4673                    if (!list.isEmpty()) {
4674                            return list.get(0);
4675                    }
4676    
4677                    return null;
4678            }
4679    
4680            /**
4681             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4682             *
4683             * @param messageId the primary key of the current message-boards message
4684             * @param groupId the group ID
4685             * @param userId the user ID
4686             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4687             * @return the previous, current, and next message-boards message
4688             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4689             */
4690            @Override
4691            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4692                    long userId, OrderByComparator<MBMessage> orderByComparator)
4693                    throws NoSuchMessageException {
4694                    MBMessage mbMessage = findByPrimaryKey(messageId);
4695    
4696                    Session session = null;
4697    
4698                    try {
4699                            session = openSession();
4700    
4701                            MBMessage[] array = new MBMessageImpl[3];
4702    
4703                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4704                                            userId, orderByComparator, true);
4705    
4706                            array[1] = mbMessage;
4707    
4708                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4709                                            userId, orderByComparator, false);
4710    
4711                            return array;
4712                    }
4713                    catch (Exception e) {
4714                            throw processException(e);
4715                    }
4716                    finally {
4717                            closeSession(session);
4718                    }
4719            }
4720    
4721            protected MBMessage getByG_U_PrevAndNext(Session session,
4722                    MBMessage mbMessage, long groupId, long userId,
4723                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4724                    StringBundler query = null;
4725    
4726                    if (orderByComparator != null) {
4727                            query = new StringBundler(5 +
4728                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4729                                            (orderByComparator.getOrderByFields().length * 3));
4730                    }
4731                    else {
4732                            query = new StringBundler(4);
4733                    }
4734    
4735                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4736    
4737                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4738    
4739                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4740    
4741                    if (orderByComparator != null) {
4742                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4743    
4744                            if (orderByConditionFields.length > 0) {
4745                                    query.append(WHERE_AND);
4746                            }
4747    
4748                            for (int i = 0; i < orderByConditionFields.length; i++) {
4749                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4750                                    query.append(orderByConditionFields[i]);
4751    
4752                                    if ((i + 1) < orderByConditionFields.length) {
4753                                            if (orderByComparator.isAscending() ^ previous) {
4754                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4755                                            }
4756                                            else {
4757                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4758                                            }
4759                                    }
4760                                    else {
4761                                            if (orderByComparator.isAscending() ^ previous) {
4762                                                    query.append(WHERE_GREATER_THAN);
4763                                            }
4764                                            else {
4765                                                    query.append(WHERE_LESSER_THAN);
4766                                            }
4767                                    }
4768                            }
4769    
4770                            query.append(ORDER_BY_CLAUSE);
4771    
4772                            String[] orderByFields = orderByComparator.getOrderByFields();
4773    
4774                            for (int i = 0; i < orderByFields.length; i++) {
4775                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4776                                    query.append(orderByFields[i]);
4777    
4778                                    if ((i + 1) < orderByFields.length) {
4779                                            if (orderByComparator.isAscending() ^ previous) {
4780                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4781                                            }
4782                                            else {
4783                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4784                                            }
4785                                    }
4786                                    else {
4787                                            if (orderByComparator.isAscending() ^ previous) {
4788                                                    query.append(ORDER_BY_ASC);
4789                                            }
4790                                            else {
4791                                                    query.append(ORDER_BY_DESC);
4792                                            }
4793                                    }
4794                            }
4795                    }
4796                    else {
4797                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4798                    }
4799    
4800                    String sql = query.toString();
4801    
4802                    Query q = session.createQuery(sql);
4803    
4804                    q.setFirstResult(0);
4805                    q.setMaxResults(2);
4806    
4807                    QueryPos qPos = QueryPos.getInstance(q);
4808    
4809                    qPos.add(groupId);
4810    
4811                    qPos.add(userId);
4812    
4813                    if (orderByComparator != null) {
4814                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4815    
4816                            for (Object value : values) {
4817                                    qPos.add(value);
4818                            }
4819                    }
4820    
4821                    List<MBMessage> list = q.list();
4822    
4823                    if (list.size() == 2) {
4824                            return list.get(1);
4825                    }
4826                    else {
4827                            return null;
4828                    }
4829            }
4830    
4831            /**
4832             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4833             *
4834             * @param groupId the group ID
4835             * @param userId the user ID
4836             * @return the matching message-boards messages that the user has permission to view
4837             */
4838            @Override
4839            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4840                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4841                            QueryUtil.ALL_POS, null);
4842            }
4843    
4844            /**
4845             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4846             *
4847             * <p>
4848             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4849             * </p>
4850             *
4851             * @param groupId the group ID
4852             * @param userId the user ID
4853             * @param start the lower bound of the range of message-boards messages
4854             * @param end the upper bound of the range of message-boards messages (not inclusive)
4855             * @return the range of matching message-boards messages that the user has permission to view
4856             */
4857            @Override
4858            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4859                    int start, int end) {
4860                    return filterFindByG_U(groupId, userId, start, end, null);
4861            }
4862    
4863            /**
4864             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4865             *
4866             * <p>
4867             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4868             * </p>
4869             *
4870             * @param groupId the group ID
4871             * @param userId the user ID
4872             * @param start the lower bound of the range of message-boards messages
4873             * @param end the upper bound of the range of message-boards messages (not inclusive)
4874             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4875             * @return the ordered range of matching message-boards messages that the user has permission to view
4876             */
4877            @Override
4878            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4879                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4880                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4881                            return findByG_U(groupId, userId, start, end, orderByComparator);
4882                    }
4883    
4884                    StringBundler query = null;
4885    
4886                    if (orderByComparator != null) {
4887                            query = new StringBundler(4 +
4888                                            (orderByComparator.getOrderByFields().length * 2));
4889                    }
4890                    else {
4891                            query = new StringBundler(5);
4892                    }
4893    
4894                    if (getDB().isSupportsInlineDistinct()) {
4895                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4896                    }
4897                    else {
4898                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4899                    }
4900    
4901                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4902    
4903                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4904    
4905                    if (!getDB().isSupportsInlineDistinct()) {
4906                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4907                    }
4908    
4909                    if (orderByComparator != null) {
4910                            if (getDB().isSupportsInlineDistinct()) {
4911                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4912                                            orderByComparator, true);
4913                            }
4914                            else {
4915                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4916                                            orderByComparator, true);
4917                            }
4918                    }
4919                    else {
4920                            if (getDB().isSupportsInlineDistinct()) {
4921                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4922                            }
4923                            else {
4924                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4925                            }
4926                    }
4927    
4928                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4929                                    MBMessage.class.getName(),
4930                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4931    
4932                    Session session = null;
4933    
4934                    try {
4935                            session = openSession();
4936    
4937                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4938    
4939                            if (getDB().isSupportsInlineDistinct()) {
4940                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4941                            }
4942                            else {
4943                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4944                            }
4945    
4946                            QueryPos qPos = QueryPos.getInstance(q);
4947    
4948                            qPos.add(groupId);
4949    
4950                            qPos.add(userId);
4951    
4952                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4953                    }
4954                    catch (Exception e) {
4955                            throw processException(e);
4956                    }
4957                    finally {
4958                            closeSession(session);
4959                    }
4960            }
4961    
4962            /**
4963             * 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;.
4964             *
4965             * @param messageId the primary key of the current message-boards message
4966             * @param groupId the group ID
4967             * @param userId the user ID
4968             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4969             * @return the previous, current, and next message-boards message
4970             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4971             */
4972            @Override
4973            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4974                    long groupId, long userId,
4975                    OrderByComparator<MBMessage> orderByComparator)
4976                    throws NoSuchMessageException {
4977                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4978                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4979                                    orderByComparator);
4980                    }
4981    
4982                    MBMessage mbMessage = findByPrimaryKey(messageId);
4983    
4984                    Session session = null;
4985    
4986                    try {
4987                            session = openSession();
4988    
4989                            MBMessage[] array = new MBMessageImpl[3];
4990    
4991                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4992                                            userId, orderByComparator, true);
4993    
4994                            array[1] = mbMessage;
4995    
4996                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4997                                            userId, orderByComparator, false);
4998    
4999                            return array;
5000                    }
5001                    catch (Exception e) {
5002                            throw processException(e);
5003                    }
5004                    finally {
5005                            closeSession(session);
5006                    }
5007            }
5008    
5009            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5010                    MBMessage mbMessage, long groupId, long userId,
5011                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5012                    StringBundler query = null;
5013    
5014                    if (orderByComparator != null) {
5015                            query = new StringBundler(6 +
5016                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5017                                            (orderByComparator.getOrderByFields().length * 3));
5018                    }
5019                    else {
5020                            query = new StringBundler(5);
5021                    }
5022    
5023                    if (getDB().isSupportsInlineDistinct()) {
5024                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5025                    }
5026                    else {
5027                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5028                    }
5029    
5030                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5031    
5032                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5033    
5034                    if (!getDB().isSupportsInlineDistinct()) {
5035                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5036                    }
5037    
5038                    if (orderByComparator != null) {
5039                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5040    
5041                            if (orderByConditionFields.length > 0) {
5042                                    query.append(WHERE_AND);
5043                            }
5044    
5045                            for (int i = 0; i < orderByConditionFields.length; i++) {
5046                                    if (getDB().isSupportsInlineDistinct()) {
5047                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5048                                    }
5049                                    else {
5050                                            query.append(_ORDER_BY_ENTITY_TABLE);
5051                                    }
5052    
5053                                    query.append(orderByConditionFields[i]);
5054    
5055                                    if ((i + 1) < orderByConditionFields.length) {
5056                                            if (orderByComparator.isAscending() ^ previous) {
5057                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5058                                            }
5059                                            else {
5060                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5061                                            }
5062                                    }
5063                                    else {
5064                                            if (orderByComparator.isAscending() ^ previous) {
5065                                                    query.append(WHERE_GREATER_THAN);
5066                                            }
5067                                            else {
5068                                                    query.append(WHERE_LESSER_THAN);
5069                                            }
5070                                    }
5071                            }
5072    
5073                            query.append(ORDER_BY_CLAUSE);
5074    
5075                            String[] orderByFields = orderByComparator.getOrderByFields();
5076    
5077                            for (int i = 0; i < orderByFields.length; i++) {
5078                                    if (getDB().isSupportsInlineDistinct()) {
5079                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5080                                    }
5081                                    else {
5082                                            query.append(_ORDER_BY_ENTITY_TABLE);
5083                                    }
5084    
5085                                    query.append(orderByFields[i]);
5086    
5087                                    if ((i + 1) < orderByFields.length) {
5088                                            if (orderByComparator.isAscending() ^ previous) {
5089                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5090                                            }
5091                                            else {
5092                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5093                                            }
5094                                    }
5095                                    else {
5096                                            if (orderByComparator.isAscending() ^ previous) {
5097                                                    query.append(ORDER_BY_ASC);
5098                                            }
5099                                            else {
5100                                                    query.append(ORDER_BY_DESC);
5101                                            }
5102                                    }
5103                            }
5104                    }
5105                    else {
5106                            if (getDB().isSupportsInlineDistinct()) {
5107                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5108                            }
5109                            else {
5110                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5111                            }
5112                    }
5113    
5114                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5115                                    MBMessage.class.getName(),
5116                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5117    
5118                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5119    
5120                    q.setFirstResult(0);
5121                    q.setMaxResults(2);
5122    
5123                    if (getDB().isSupportsInlineDistinct()) {
5124                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5125                    }
5126                    else {
5127                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5128                    }
5129    
5130                    QueryPos qPos = QueryPos.getInstance(q);
5131    
5132                    qPos.add(groupId);
5133    
5134                    qPos.add(userId);
5135    
5136                    if (orderByComparator != null) {
5137                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5138    
5139                            for (Object value : values) {
5140                                    qPos.add(value);
5141                            }
5142                    }
5143    
5144                    List<MBMessage> list = q.list();
5145    
5146                    if (list.size() == 2) {
5147                            return list.get(1);
5148                    }
5149                    else {
5150                            return null;
5151                    }
5152            }
5153    
5154            /**
5155             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5156             *
5157             * @param groupId the group ID
5158             * @param userId the user ID
5159             */
5160            @Override
5161            public void removeByG_U(long groupId, long userId) {
5162                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5163                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5164                            remove(mbMessage);
5165                    }
5166            }
5167    
5168            /**
5169             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5170             *
5171             * @param groupId the group ID
5172             * @param userId the user ID
5173             * @return the number of matching message-boards messages
5174             */
5175            @Override
5176            public int countByG_U(long groupId, long userId) {
5177                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5178    
5179                    Object[] finderArgs = new Object[] { groupId, userId };
5180    
5181                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5182    
5183                    if (count == null) {
5184                            StringBundler query = new StringBundler(3);
5185    
5186                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5187    
5188                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5189    
5190                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5191    
5192                            String sql = query.toString();
5193    
5194                            Session session = null;
5195    
5196                            try {
5197                                    session = openSession();
5198    
5199                                    Query q = session.createQuery(sql);
5200    
5201                                    QueryPos qPos = QueryPos.getInstance(q);
5202    
5203                                    qPos.add(groupId);
5204    
5205                                    qPos.add(userId);
5206    
5207                                    count = (Long)q.uniqueResult();
5208    
5209                                    finderCache.putResult(finderPath, finderArgs, count);
5210                            }
5211                            catch (Exception e) {
5212                                    finderCache.removeResult(finderPath, finderArgs);
5213    
5214                                    throw processException(e);
5215                            }
5216                            finally {
5217                                    closeSession(session);
5218                            }
5219                    }
5220    
5221                    return count.intValue();
5222            }
5223    
5224            /**
5225             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5226             *
5227             * @param groupId the group ID
5228             * @param userId the user ID
5229             * @return the number of matching message-boards messages that the user has permission to view
5230             */
5231            @Override
5232            public int filterCountByG_U(long groupId, long userId) {
5233                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5234                            return countByG_U(groupId, userId);
5235                    }
5236    
5237                    StringBundler query = new StringBundler(3);
5238    
5239                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5240    
5241                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5242    
5243                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5244    
5245                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5246                                    MBMessage.class.getName(),
5247                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5248    
5249                    Session session = null;
5250    
5251                    try {
5252                            session = openSession();
5253    
5254                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5255    
5256                            q.addScalar(COUNT_COLUMN_NAME,
5257                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5258    
5259                            QueryPos qPos = QueryPos.getInstance(q);
5260    
5261                            qPos.add(groupId);
5262    
5263                            qPos.add(userId);
5264    
5265                            Long count = (Long)q.uniqueResult();
5266    
5267                            return count.intValue();
5268                    }
5269                    catch (Exception e) {
5270                            throw processException(e);
5271                    }
5272                    finally {
5273                            closeSession(session);
5274                    }
5275            }
5276    
5277            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5278            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5279            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5280                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5281                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5282                            new String[] {
5283                                    Long.class.getName(), Long.class.getName(),
5284                                    
5285                            Integer.class.getName(), Integer.class.getName(),
5286                                    OrderByComparator.class.getName()
5287                            });
5288            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5289                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5290                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5291                            new String[] { Long.class.getName(), Long.class.getName() },
5292                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5293                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5294                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5295            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5296                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5297                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5298                            new String[] { Long.class.getName(), Long.class.getName() });
5299    
5300            /**
5301             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5302             *
5303             * @param groupId the group ID
5304             * @param categoryId the category ID
5305             * @return the matching message-boards messages
5306             */
5307            @Override
5308            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5309                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5310                            QueryUtil.ALL_POS, null);
5311            }
5312    
5313            /**
5314             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5315             *
5316             * <p>
5317             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5318             * </p>
5319             *
5320             * @param groupId the group ID
5321             * @param categoryId the category ID
5322             * @param start the lower bound of the range of message-boards messages
5323             * @param end the upper bound of the range of message-boards messages (not inclusive)
5324             * @return the range of matching message-boards messages
5325             */
5326            @Override
5327            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5328                    int end) {
5329                    return findByG_C(groupId, categoryId, start, end, null);
5330            }
5331    
5332            /**
5333             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5334             *
5335             * <p>
5336             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5337             * </p>
5338             *
5339             * @param groupId the group ID
5340             * @param categoryId the category ID
5341             * @param start the lower bound of the range of message-boards messages
5342             * @param end the upper bound of the range of message-boards messages (not inclusive)
5343             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5344             * @return the ordered range of matching message-boards messages
5345             */
5346            @Override
5347            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5348                    int end, OrderByComparator<MBMessage> orderByComparator) {
5349                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
5350                            true);
5351            }
5352    
5353            /**
5354             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5355             *
5356             * <p>
5357             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5358             * </p>
5359             *
5360             * @param groupId the group ID
5361             * @param categoryId the category ID
5362             * @param start the lower bound of the range of message-boards messages
5363             * @param end the upper bound of the range of message-boards messages (not inclusive)
5364             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5365             * @param retrieveFromCache whether to retrieve from the finder cache
5366             * @return the ordered range of matching message-boards messages
5367             */
5368            @Override
5369            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5370                    int end, OrderByComparator<MBMessage> orderByComparator,
5371                    boolean retrieveFromCache) {
5372                    boolean pagination = true;
5373                    FinderPath finderPath = null;
5374                    Object[] finderArgs = null;
5375    
5376                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5377                                    (orderByComparator == null)) {
5378                            pagination = false;
5379                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5380                            finderArgs = new Object[] { groupId, categoryId };
5381                    }
5382                    else {
5383                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5384                            finderArgs = new Object[] {
5385                                            groupId, categoryId,
5386                                            
5387                                            start, end, orderByComparator
5388                                    };
5389                    }
5390    
5391                    List<MBMessage> list = null;
5392    
5393                    if (retrieveFromCache) {
5394                            list = (List<MBMessage>)finderCache.getResult(finderPath,
5395                                            finderArgs, this);
5396    
5397                            if ((list != null) && !list.isEmpty()) {
5398                                    for (MBMessage mbMessage : list) {
5399                                            if ((groupId != mbMessage.getGroupId()) ||
5400                                                            (categoryId != mbMessage.getCategoryId())) {
5401                                                    list = null;
5402    
5403                                                    break;
5404                                            }
5405                                    }
5406                            }
5407                    }
5408    
5409                    if (list == null) {
5410                            StringBundler query = null;
5411    
5412                            if (orderByComparator != null) {
5413                                    query = new StringBundler(4 +
5414                                                    (orderByComparator.getOrderByFields().length * 2));
5415                            }
5416                            else {
5417                                    query = new StringBundler(4);
5418                            }
5419    
5420                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5421    
5422                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5423    
5424                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5425    
5426                            if (orderByComparator != null) {
5427                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5428                                            orderByComparator);
5429                            }
5430                            else
5431                             if (pagination) {
5432                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5433                            }
5434    
5435                            String sql = query.toString();
5436    
5437                            Session session = null;
5438    
5439                            try {
5440                                    session = openSession();
5441    
5442                                    Query q = session.createQuery(sql);
5443    
5444                                    QueryPos qPos = QueryPos.getInstance(q);
5445    
5446                                    qPos.add(groupId);
5447    
5448                                    qPos.add(categoryId);
5449    
5450                                    if (!pagination) {
5451                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5452                                                            start, end, false);
5453    
5454                                            Collections.sort(list);
5455    
5456                                            list = Collections.unmodifiableList(list);
5457                                    }
5458                                    else {
5459                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5460                                                            start, end);
5461                                    }
5462    
5463                                    cacheResult(list);
5464    
5465                                    finderCache.putResult(finderPath, finderArgs, list);
5466                            }
5467                            catch (Exception e) {
5468                                    finderCache.removeResult(finderPath, finderArgs);
5469    
5470                                    throw processException(e);
5471                            }
5472                            finally {
5473                                    closeSession(session);
5474                            }
5475                    }
5476    
5477                    return list;
5478            }
5479    
5480            /**
5481             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5482             *
5483             * @param groupId the group ID
5484             * @param categoryId the category ID
5485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5486             * @return the first matching message-boards message
5487             * @throws NoSuchMessageException if a matching message-boards message could not be found
5488             */
5489            @Override
5490            public MBMessage findByG_C_First(long groupId, long categoryId,
5491                    OrderByComparator<MBMessage> orderByComparator)
5492                    throws NoSuchMessageException {
5493                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5494                                    orderByComparator);
5495    
5496                    if (mbMessage != null) {
5497                            return mbMessage;
5498                    }
5499    
5500                    StringBundler msg = new StringBundler(6);
5501    
5502                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5503    
5504                    msg.append("groupId=");
5505                    msg.append(groupId);
5506    
5507                    msg.append(", categoryId=");
5508                    msg.append(categoryId);
5509    
5510                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5511    
5512                    throw new NoSuchMessageException(msg.toString());
5513            }
5514    
5515            /**
5516             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5517             *
5518             * @param groupId the group ID
5519             * @param categoryId the category ID
5520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5521             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5522             */
5523            @Override
5524            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5525                    OrderByComparator<MBMessage> orderByComparator) {
5526                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5527                                    orderByComparator);
5528    
5529                    if (!list.isEmpty()) {
5530                            return list.get(0);
5531                    }
5532    
5533                    return null;
5534            }
5535    
5536            /**
5537             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5538             *
5539             * @param groupId the group ID
5540             * @param categoryId the category ID
5541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5542             * @return the last matching message-boards message
5543             * @throws NoSuchMessageException if a matching message-boards message could not be found
5544             */
5545            @Override
5546            public MBMessage findByG_C_Last(long groupId, long categoryId,
5547                    OrderByComparator<MBMessage> orderByComparator)
5548                    throws NoSuchMessageException {
5549                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5550                                    orderByComparator);
5551    
5552                    if (mbMessage != null) {
5553                            return mbMessage;
5554                    }
5555    
5556                    StringBundler msg = new StringBundler(6);
5557    
5558                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5559    
5560                    msg.append("groupId=");
5561                    msg.append(groupId);
5562    
5563                    msg.append(", categoryId=");
5564                    msg.append(categoryId);
5565    
5566                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5567    
5568                    throw new NoSuchMessageException(msg.toString());
5569            }
5570    
5571            /**
5572             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5573             *
5574             * @param groupId the group ID
5575             * @param categoryId the category ID
5576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5577             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5578             */
5579            @Override
5580            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5581                    OrderByComparator<MBMessage> orderByComparator) {
5582                    int count = countByG_C(groupId, categoryId);
5583    
5584                    if (count == 0) {
5585                            return null;
5586                    }
5587    
5588                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5589                                    orderByComparator);
5590    
5591                    if (!list.isEmpty()) {
5592                            return list.get(0);
5593                    }
5594    
5595                    return null;
5596            }
5597    
5598            /**
5599             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5600             *
5601             * @param messageId the primary key of the current message-boards message
5602             * @param groupId the group ID
5603             * @param categoryId the category ID
5604             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5605             * @return the previous, current, and next message-boards message
5606             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5607             */
5608            @Override
5609            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5610                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5611                    throws NoSuchMessageException {
5612                    MBMessage mbMessage = findByPrimaryKey(messageId);
5613    
5614                    Session session = null;
5615    
5616                    try {
5617                            session = openSession();
5618    
5619                            MBMessage[] array = new MBMessageImpl[3];
5620    
5621                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5622                                            categoryId, orderByComparator, true);
5623    
5624                            array[1] = mbMessage;
5625    
5626                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5627                                            categoryId, orderByComparator, false);
5628    
5629                            return array;
5630                    }
5631                    catch (Exception e) {
5632                            throw processException(e);
5633                    }
5634                    finally {
5635                            closeSession(session);
5636                    }
5637            }
5638    
5639            protected MBMessage getByG_C_PrevAndNext(Session session,
5640                    MBMessage mbMessage, long groupId, long categoryId,
5641                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5642                    StringBundler query = null;
5643    
5644                    if (orderByComparator != null) {
5645                            query = new StringBundler(5 +
5646                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5647                                            (orderByComparator.getOrderByFields().length * 3));
5648                    }
5649                    else {
5650                            query = new StringBundler(4);
5651                    }
5652    
5653                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5654    
5655                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5656    
5657                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5658    
5659                    if (orderByComparator != null) {
5660                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5661    
5662                            if (orderByConditionFields.length > 0) {
5663                                    query.append(WHERE_AND);
5664                            }
5665    
5666                            for (int i = 0; i < orderByConditionFields.length; i++) {
5667                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5668                                    query.append(orderByConditionFields[i]);
5669    
5670                                    if ((i + 1) < orderByConditionFields.length) {
5671                                            if (orderByComparator.isAscending() ^ previous) {
5672                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5673                                            }
5674                                            else {
5675                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5676                                            }
5677                                    }
5678                                    else {
5679                                            if (orderByComparator.isAscending() ^ previous) {
5680                                                    query.append(WHERE_GREATER_THAN);
5681                                            }
5682                                            else {
5683                                                    query.append(WHERE_LESSER_THAN);
5684                                            }
5685                                    }
5686                            }
5687    
5688                            query.append(ORDER_BY_CLAUSE);
5689    
5690                            String[] orderByFields = orderByComparator.getOrderByFields();
5691    
5692                            for (int i = 0; i < orderByFields.length; i++) {
5693                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5694                                    query.append(orderByFields[i]);
5695    
5696                                    if ((i + 1) < orderByFields.length) {
5697                                            if (orderByComparator.isAscending() ^ previous) {
5698                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5699                                            }
5700                                            else {
5701                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5702                                            }
5703                                    }
5704                                    else {
5705                                            if (orderByComparator.isAscending() ^ previous) {
5706                                                    query.append(ORDER_BY_ASC);
5707                                            }
5708                                            else {
5709                                                    query.append(ORDER_BY_DESC);
5710                                            }
5711                                    }
5712                            }
5713                    }
5714                    else {
5715                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5716                    }
5717    
5718                    String sql = query.toString();
5719    
5720                    Query q = session.createQuery(sql);
5721    
5722                    q.setFirstResult(0);
5723                    q.setMaxResults(2);
5724    
5725                    QueryPos qPos = QueryPos.getInstance(q);
5726    
5727                    qPos.add(groupId);
5728    
5729                    qPos.add(categoryId);
5730    
5731                    if (orderByComparator != null) {
5732                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5733    
5734                            for (Object value : values) {
5735                                    qPos.add(value);
5736                            }
5737                    }
5738    
5739                    List<MBMessage> list = q.list();
5740    
5741                    if (list.size() == 2) {
5742                            return list.get(1);
5743                    }
5744                    else {
5745                            return null;
5746                    }
5747            }
5748    
5749            /**
5750             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5751             *
5752             * @param groupId the group ID
5753             * @param categoryId the category ID
5754             * @return the matching message-boards messages that the user has permission to view
5755             */
5756            @Override
5757            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5758                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5759                            QueryUtil.ALL_POS, null);
5760            }
5761    
5762            /**
5763             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5764             *
5765             * <p>
5766             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5767             * </p>
5768             *
5769             * @param groupId the group ID
5770             * @param categoryId the category ID
5771             * @param start the lower bound of the range of message-boards messages
5772             * @param end the upper bound of the range of message-boards messages (not inclusive)
5773             * @return the range of matching message-boards messages that the user has permission to view
5774             */
5775            @Override
5776            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5777                    int start, int end) {
5778                    return filterFindByG_C(groupId, categoryId, start, end, null);
5779            }
5780    
5781            /**
5782             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5783             *
5784             * <p>
5785             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5786             * </p>
5787             *
5788             * @param groupId the group ID
5789             * @param categoryId the category ID
5790             * @param start the lower bound of the range of message-boards messages
5791             * @param end the upper bound of the range of message-boards messages (not inclusive)
5792             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5793             * @return the ordered range of matching message-boards messages that the user has permission to view
5794             */
5795            @Override
5796            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5797                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5798                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5799                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5800                    }
5801    
5802                    StringBundler query = null;
5803    
5804                    if (orderByComparator != null) {
5805                            query = new StringBundler(4 +
5806                                            (orderByComparator.getOrderByFields().length * 2));
5807                    }
5808                    else {
5809                            query = new StringBundler(5);
5810                    }
5811    
5812                    if (getDB().isSupportsInlineDistinct()) {
5813                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5814                    }
5815                    else {
5816                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5817                    }
5818    
5819                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5820    
5821                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5822    
5823                    if (!getDB().isSupportsInlineDistinct()) {
5824                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5825                    }
5826    
5827                    if (orderByComparator != null) {
5828                            if (getDB().isSupportsInlineDistinct()) {
5829                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5830                                            orderByComparator, true);
5831                            }
5832                            else {
5833                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5834                                            orderByComparator, true);
5835                            }
5836                    }
5837                    else {
5838                            if (getDB().isSupportsInlineDistinct()) {
5839                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5840                            }
5841                            else {
5842                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5843                            }
5844                    }
5845    
5846                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5847                                    MBMessage.class.getName(),
5848                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5849    
5850                    Session session = null;
5851    
5852                    try {
5853                            session = openSession();
5854    
5855                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5856    
5857                            if (getDB().isSupportsInlineDistinct()) {
5858                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5859                            }
5860                            else {
5861                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5862                            }
5863    
5864                            QueryPos qPos = QueryPos.getInstance(q);
5865    
5866                            qPos.add(groupId);
5867    
5868                            qPos.add(categoryId);
5869    
5870                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5871                    }
5872                    catch (Exception e) {
5873                            throw processException(e);
5874                    }
5875                    finally {
5876                            closeSession(session);
5877                    }
5878            }
5879    
5880            /**
5881             * 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;.
5882             *
5883             * @param messageId the primary key of the current message-boards message
5884             * @param groupId the group ID
5885             * @param categoryId the category ID
5886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5887             * @return the previous, current, and next message-boards message
5888             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5889             */
5890            @Override
5891            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5892                    long groupId, long categoryId,
5893                    OrderByComparator<MBMessage> orderByComparator)
5894                    throws NoSuchMessageException {
5895                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5896                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5897                                    orderByComparator);
5898                    }
5899    
5900                    MBMessage mbMessage = findByPrimaryKey(messageId);
5901    
5902                    Session session = null;
5903    
5904                    try {
5905                            session = openSession();
5906    
5907                            MBMessage[] array = new MBMessageImpl[3];
5908    
5909                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5910                                            categoryId, orderByComparator, true);
5911    
5912                            array[1] = mbMessage;
5913    
5914                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5915                                            categoryId, orderByComparator, false);
5916    
5917                            return array;
5918                    }
5919                    catch (Exception e) {
5920                            throw processException(e);
5921                    }
5922                    finally {
5923                            closeSession(session);
5924                    }
5925            }
5926    
5927            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5928                    MBMessage mbMessage, long groupId, long categoryId,
5929                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5930                    StringBundler query = null;
5931    
5932                    if (orderByComparator != null) {
5933                            query = new StringBundler(6 +
5934                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5935                                            (orderByComparator.getOrderByFields().length * 3));
5936                    }
5937                    else {
5938                            query = new StringBundler(5);
5939                    }
5940    
5941                    if (getDB().isSupportsInlineDistinct()) {
5942                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5943                    }
5944                    else {
5945                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5946                    }
5947    
5948                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5949    
5950                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5951    
5952                    if (!getDB().isSupportsInlineDistinct()) {
5953                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5954                    }
5955    
5956                    if (orderByComparator != null) {
5957                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5958    
5959                            if (orderByConditionFields.length > 0) {
5960                                    query.append(WHERE_AND);
5961                            }
5962    
5963                            for (int i = 0; i < orderByConditionFields.length; i++) {
5964                                    if (getDB().isSupportsInlineDistinct()) {
5965                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5966                                    }
5967                                    else {
5968                                            query.append(_ORDER_BY_ENTITY_TABLE);
5969                                    }
5970    
5971                                    query.append(orderByConditionFields[i]);
5972    
5973                                    if ((i + 1) < orderByConditionFields.length) {
5974                                            if (orderByComparator.isAscending() ^ previous) {
5975                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5976                                            }
5977                                            else {
5978                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5979                                            }
5980                                    }
5981                                    else {
5982                                            if (orderByComparator.isAscending() ^ previous) {
5983                                                    query.append(WHERE_GREATER_THAN);
5984                                            }
5985                                            else {
5986                                                    query.append(WHERE_LESSER_THAN);
5987                                            }
5988                                    }
5989                            }
5990    
5991                            query.append(ORDER_BY_CLAUSE);
5992    
5993                            String[] orderByFields = orderByComparator.getOrderByFields();
5994    
5995                            for (int i = 0; i < orderByFields.length; i++) {
5996                                    if (getDB().isSupportsInlineDistinct()) {
5997                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5998                                    }
5999                                    else {
6000                                            query.append(_ORDER_BY_ENTITY_TABLE);
6001                                    }
6002    
6003                                    query.append(orderByFields[i]);
6004    
6005                                    if ((i + 1) < orderByFields.length) {
6006                                            if (orderByComparator.isAscending() ^ previous) {
6007                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6008                                            }
6009                                            else {
6010                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6011                                            }
6012                                    }
6013                                    else {
6014                                            if (orderByComparator.isAscending() ^ previous) {
6015                                                    query.append(ORDER_BY_ASC);
6016                                            }
6017                                            else {
6018                                                    query.append(ORDER_BY_DESC);
6019                                            }
6020                                    }
6021                            }
6022                    }
6023                    else {
6024                            if (getDB().isSupportsInlineDistinct()) {
6025                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6026                            }
6027                            else {
6028                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6029                            }
6030                    }
6031    
6032                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6033                                    MBMessage.class.getName(),
6034                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6035    
6036                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6037    
6038                    q.setFirstResult(0);
6039                    q.setMaxResults(2);
6040    
6041                    if (getDB().isSupportsInlineDistinct()) {
6042                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6043                    }
6044                    else {
6045                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6046                    }
6047    
6048                    QueryPos qPos = QueryPos.getInstance(q);
6049    
6050                    qPos.add(groupId);
6051    
6052                    qPos.add(categoryId);
6053    
6054                    if (orderByComparator != null) {
6055                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6056    
6057                            for (Object value : values) {
6058                                    qPos.add(value);
6059                            }
6060                    }
6061    
6062                    List<MBMessage> list = q.list();
6063    
6064                    if (list.size() == 2) {
6065                            return list.get(1);
6066                    }
6067                    else {
6068                            return null;
6069                    }
6070            }
6071    
6072            /**
6073             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
6074             *
6075             * @param groupId the group ID
6076             * @param categoryId the category ID
6077             */
6078            @Override
6079            public void removeByG_C(long groupId, long categoryId) {
6080                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
6081                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6082                            remove(mbMessage);
6083                    }
6084            }
6085    
6086            /**
6087             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
6088             *
6089             * @param groupId the group ID
6090             * @param categoryId the category ID
6091             * @return the number of matching message-boards messages
6092             */
6093            @Override
6094            public int countByG_C(long groupId, long categoryId) {
6095                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6096    
6097                    Object[] finderArgs = new Object[] { groupId, categoryId };
6098    
6099                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6100    
6101                    if (count == null) {
6102                            StringBundler query = new StringBundler(3);
6103    
6104                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6105    
6106                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6107    
6108                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6109    
6110                            String sql = query.toString();
6111    
6112                            Session session = null;
6113    
6114                            try {
6115                                    session = openSession();
6116    
6117                                    Query q = session.createQuery(sql);
6118    
6119                                    QueryPos qPos = QueryPos.getInstance(q);
6120    
6121                                    qPos.add(groupId);
6122    
6123                                    qPos.add(categoryId);
6124    
6125                                    count = (Long)q.uniqueResult();
6126    
6127                                    finderCache.putResult(finderPath, finderArgs, count);
6128                            }
6129                            catch (Exception e) {
6130                                    finderCache.removeResult(finderPath, finderArgs);
6131    
6132                                    throw processException(e);
6133                            }
6134                            finally {
6135                                    closeSession(session);
6136                            }
6137                    }
6138    
6139                    return count.intValue();
6140            }
6141    
6142            /**
6143             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6144             *
6145             * @param groupId the group ID
6146             * @param categoryId the category ID
6147             * @return the number of matching message-boards messages that the user has permission to view
6148             */
6149            @Override
6150            public int filterCountByG_C(long groupId, long categoryId) {
6151                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6152                            return countByG_C(groupId, categoryId);
6153                    }
6154    
6155                    StringBundler query = new StringBundler(3);
6156    
6157                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6158    
6159                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6160    
6161                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6162    
6163                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6164                                    MBMessage.class.getName(),
6165                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6166    
6167                    Session session = null;
6168    
6169                    try {
6170                            session = openSession();
6171    
6172                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6173    
6174                            q.addScalar(COUNT_COLUMN_NAME,
6175                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6176    
6177                            QueryPos qPos = QueryPos.getInstance(q);
6178    
6179                            qPos.add(groupId);
6180    
6181                            qPos.add(categoryId);
6182    
6183                            Long count = (Long)q.uniqueResult();
6184    
6185                            return count.intValue();
6186                    }
6187                    catch (Exception e) {
6188                            throw processException(e);
6189                    }
6190                    finally {
6191                            closeSession(session);
6192                    }
6193            }
6194    
6195            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6196            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6197            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6199                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6200                            new String[] {
6201                                    Long.class.getName(), Integer.class.getName(),
6202                                    
6203                            Integer.class.getName(), Integer.class.getName(),
6204                                    OrderByComparator.class.getName()
6205                            });
6206            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6207                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6208                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6209                            new String[] { Long.class.getName(), Integer.class.getName() },
6210                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6211                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6212                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6213            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6214                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6215                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6216                            new String[] { Long.class.getName(), Integer.class.getName() });
6217    
6218            /**
6219             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6220             *
6221             * @param groupId the group ID
6222             * @param status the status
6223             * @return the matching message-boards messages
6224             */
6225            @Override
6226            public List<MBMessage> findByG_S(long groupId, int status) {
6227                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6228                            null);
6229            }
6230    
6231            /**
6232             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6233             *
6234             * <p>
6235             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6236             * </p>
6237             *
6238             * @param groupId the group ID
6239             * @param status the status
6240             * @param start the lower bound of the range of message-boards messages
6241             * @param end the upper bound of the range of message-boards messages (not inclusive)
6242             * @return the range of matching message-boards messages
6243             */
6244            @Override
6245            public List<MBMessage> findByG_S(long groupId, int status, int start,
6246                    int end) {
6247                    return findByG_S(groupId, status, start, end, null);
6248            }
6249    
6250            /**
6251             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6252             *
6253             * <p>
6254             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6255             * </p>
6256             *
6257             * @param groupId the group ID
6258             * @param status the status
6259             * @param start the lower bound of the range of message-boards messages
6260             * @param end the upper bound of the range of message-boards messages (not inclusive)
6261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6262             * @return the ordered range of matching message-boards messages
6263             */
6264            @Override
6265            public List<MBMessage> findByG_S(long groupId, int status, int start,
6266                    int end, OrderByComparator<MBMessage> orderByComparator) {
6267                    return findByG_S(groupId, status, start, end, orderByComparator, true);
6268            }
6269    
6270            /**
6271             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6272             *
6273             * <p>
6274             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6275             * </p>
6276             *
6277             * @param groupId the group ID
6278             * @param status the status
6279             * @param start the lower bound of the range of message-boards messages
6280             * @param end the upper bound of the range of message-boards messages (not inclusive)
6281             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6282             * @param retrieveFromCache whether to retrieve from the finder cache
6283             * @return the ordered range of matching message-boards messages
6284             */
6285            @Override
6286            public List<MBMessage> findByG_S(long groupId, int status, int start,
6287                    int end, OrderByComparator<MBMessage> orderByComparator,
6288                    boolean retrieveFromCache) {
6289                    boolean pagination = true;
6290                    FinderPath finderPath = null;
6291                    Object[] finderArgs = null;
6292    
6293                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6294                                    (orderByComparator == null)) {
6295                            pagination = false;
6296                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6297                            finderArgs = new Object[] { groupId, status };
6298                    }
6299                    else {
6300                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6301                            finderArgs = new Object[] {
6302                                            groupId, status,
6303                                            
6304                                            start, end, orderByComparator
6305                                    };
6306                    }
6307    
6308                    List<MBMessage> list = null;
6309    
6310                    if (retrieveFromCache) {
6311                            list = (List<MBMessage>)finderCache.getResult(finderPath,
6312                                            finderArgs, this);
6313    
6314                            if ((list != null) && !list.isEmpty()) {
6315                                    for (MBMessage mbMessage : list) {
6316                                            if ((groupId != mbMessage.getGroupId()) ||
6317                                                            (status != mbMessage.getStatus())) {
6318                                                    list = null;
6319    
6320                                                    break;
6321                                            }
6322                                    }
6323                            }
6324                    }
6325    
6326                    if (list == null) {
6327                            StringBundler query = null;
6328    
6329                            if (orderByComparator != null) {
6330                                    query = new StringBundler(4 +
6331                                                    (orderByComparator.getOrderByFields().length * 2));
6332                            }
6333                            else {
6334                                    query = new StringBundler(4);
6335                            }
6336    
6337                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6338    
6339                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6340    
6341                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6342    
6343                            if (orderByComparator != null) {
6344                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6345                                            orderByComparator);
6346                            }
6347                            else
6348                             if (pagination) {
6349                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6350                            }
6351    
6352                            String sql = query.toString();
6353    
6354                            Session session = null;
6355    
6356                            try {
6357                                    session = openSession();
6358    
6359                                    Query q = session.createQuery(sql);
6360    
6361                                    QueryPos qPos = QueryPos.getInstance(q);
6362    
6363                                    qPos.add(groupId);
6364    
6365                                    qPos.add(status);
6366    
6367                                    if (!pagination) {
6368                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6369                                                            start, end, false);
6370    
6371                                            Collections.sort(list);
6372    
6373                                            list = Collections.unmodifiableList(list);
6374                                    }
6375                                    else {
6376                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6377                                                            start, end);
6378                                    }
6379    
6380                                    cacheResult(list);
6381    
6382                                    finderCache.putResult(finderPath, finderArgs, list);
6383                            }
6384                            catch (Exception e) {
6385                                    finderCache.removeResult(finderPath, finderArgs);
6386    
6387                                    throw processException(e);
6388                            }
6389                            finally {
6390                                    closeSession(session);
6391                            }
6392                    }
6393    
6394                    return list;
6395            }
6396    
6397            /**
6398             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6399             *
6400             * @param groupId the group ID
6401             * @param status the status
6402             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6403             * @return the first matching message-boards message
6404             * @throws NoSuchMessageException if a matching message-boards message could not be found
6405             */
6406            @Override
6407            public MBMessage findByG_S_First(long groupId, int status,
6408                    OrderByComparator<MBMessage> orderByComparator)
6409                    throws NoSuchMessageException {
6410                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6411                                    orderByComparator);
6412    
6413                    if (mbMessage != null) {
6414                            return mbMessage;
6415                    }
6416    
6417                    StringBundler msg = new StringBundler(6);
6418    
6419                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6420    
6421                    msg.append("groupId=");
6422                    msg.append(groupId);
6423    
6424                    msg.append(", status=");
6425                    msg.append(status);
6426    
6427                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6428    
6429                    throw new NoSuchMessageException(msg.toString());
6430            }
6431    
6432            /**
6433             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6434             *
6435             * @param groupId the group ID
6436             * @param status the status
6437             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6438             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6439             */
6440            @Override
6441            public MBMessage fetchByG_S_First(long groupId, int status,
6442                    OrderByComparator<MBMessage> orderByComparator) {
6443                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6444                                    orderByComparator);
6445    
6446                    if (!list.isEmpty()) {
6447                            return list.get(0);
6448                    }
6449    
6450                    return null;
6451            }
6452    
6453            /**
6454             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6455             *
6456             * @param groupId the group ID
6457             * @param status the status
6458             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6459             * @return the last matching message-boards message
6460             * @throws NoSuchMessageException if a matching message-boards message could not be found
6461             */
6462            @Override
6463            public MBMessage findByG_S_Last(long groupId, int status,
6464                    OrderByComparator<MBMessage> orderByComparator)
6465                    throws NoSuchMessageException {
6466                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6467    
6468                    if (mbMessage != null) {
6469                            return mbMessage;
6470                    }
6471    
6472                    StringBundler msg = new StringBundler(6);
6473    
6474                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6475    
6476                    msg.append("groupId=");
6477                    msg.append(groupId);
6478    
6479                    msg.append(", status=");
6480                    msg.append(status);
6481    
6482                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6483    
6484                    throw new NoSuchMessageException(msg.toString());
6485            }
6486    
6487            /**
6488             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6489             *
6490             * @param groupId the group ID
6491             * @param status the status
6492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6493             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6494             */
6495            @Override
6496            public MBMessage fetchByG_S_Last(long groupId, int status,
6497                    OrderByComparator<MBMessage> orderByComparator) {
6498                    int count = countByG_S(groupId, status);
6499    
6500                    if (count == 0) {
6501                            return null;
6502                    }
6503    
6504                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6505                                    orderByComparator);
6506    
6507                    if (!list.isEmpty()) {
6508                            return list.get(0);
6509                    }
6510    
6511                    return null;
6512            }
6513    
6514            /**
6515             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6516             *
6517             * @param messageId the primary key of the current message-boards message
6518             * @param groupId the group ID
6519             * @param status the status
6520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6521             * @return the previous, current, and next message-boards message
6522             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6523             */
6524            @Override
6525            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6526                    int status, OrderByComparator<MBMessage> orderByComparator)
6527                    throws NoSuchMessageException {
6528                    MBMessage mbMessage = findByPrimaryKey(messageId);
6529    
6530                    Session session = null;
6531    
6532                    try {
6533                            session = openSession();
6534    
6535                            MBMessage[] array = new MBMessageImpl[3];
6536    
6537                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6538                                            status, orderByComparator, true);
6539    
6540                            array[1] = mbMessage;
6541    
6542                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6543                                            status, orderByComparator, false);
6544    
6545                            return array;
6546                    }
6547                    catch (Exception e) {
6548                            throw processException(e);
6549                    }
6550                    finally {
6551                            closeSession(session);
6552                    }
6553            }
6554    
6555            protected MBMessage getByG_S_PrevAndNext(Session session,
6556                    MBMessage mbMessage, long groupId, int status,
6557                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6558                    StringBundler query = null;
6559    
6560                    if (orderByComparator != null) {
6561                            query = new StringBundler(5 +
6562                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6563                                            (orderByComparator.getOrderByFields().length * 3));
6564                    }
6565                    else {
6566                            query = new StringBundler(4);
6567                    }
6568    
6569                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6570    
6571                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6572    
6573                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6574    
6575                    if (orderByComparator != null) {
6576                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6577    
6578                            if (orderByConditionFields.length > 0) {
6579                                    query.append(WHERE_AND);
6580                            }
6581    
6582                            for (int i = 0; i < orderByConditionFields.length; i++) {
6583                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6584                                    query.append(orderByConditionFields[i]);
6585    
6586                                    if ((i + 1) < orderByConditionFields.length) {
6587                                            if (orderByComparator.isAscending() ^ previous) {
6588                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6589                                            }
6590                                            else {
6591                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6592                                            }
6593                                    }
6594                                    else {
6595                                            if (orderByComparator.isAscending() ^ previous) {
6596                                                    query.append(WHERE_GREATER_THAN);
6597                                            }
6598                                            else {
6599                                                    query.append(WHERE_LESSER_THAN);
6600                                            }
6601                                    }
6602                            }
6603    
6604                            query.append(ORDER_BY_CLAUSE);
6605    
6606                            String[] orderByFields = orderByComparator.getOrderByFields();
6607    
6608                            for (int i = 0; i < orderByFields.length; i++) {
6609                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6610                                    query.append(orderByFields[i]);
6611    
6612                                    if ((i + 1) < orderByFields.length) {
6613                                            if (orderByComparator.isAscending() ^ previous) {
6614                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6615                                            }
6616                                            else {
6617                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6618                                            }
6619                                    }
6620                                    else {
6621                                            if (orderByComparator.isAscending() ^ previous) {
6622                                                    query.append(ORDER_BY_ASC);
6623                                            }
6624                                            else {
6625                                                    query.append(ORDER_BY_DESC);
6626                                            }
6627                                    }
6628                            }
6629                    }
6630                    else {
6631                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6632                    }
6633    
6634                    String sql = query.toString();
6635    
6636                    Query q = session.createQuery(sql);
6637    
6638                    q.setFirstResult(0);
6639                    q.setMaxResults(2);
6640    
6641                    QueryPos qPos = QueryPos.getInstance(q);
6642    
6643                    qPos.add(groupId);
6644    
6645                    qPos.add(status);
6646    
6647                    if (orderByComparator != null) {
6648                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6649    
6650                            for (Object value : values) {
6651                                    qPos.add(value);
6652                            }
6653                    }
6654    
6655                    List<MBMessage> list = q.list();
6656    
6657                    if (list.size() == 2) {
6658                            return list.get(1);
6659                    }
6660                    else {
6661                            return null;
6662                    }
6663            }
6664    
6665            /**
6666             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6667             *
6668             * @param groupId the group ID
6669             * @param status the status
6670             * @return the matching message-boards messages that the user has permission to view
6671             */
6672            @Override
6673            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6674                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6675                            QueryUtil.ALL_POS, null);
6676            }
6677    
6678            /**
6679             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6680             *
6681             * <p>
6682             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6683             * </p>
6684             *
6685             * @param groupId the group ID
6686             * @param status the status
6687             * @param start the lower bound of the range of message-boards messages
6688             * @param end the upper bound of the range of message-boards messages (not inclusive)
6689             * @return the range of matching message-boards messages that the user has permission to view
6690             */
6691            @Override
6692            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6693                    int end) {
6694                    return filterFindByG_S(groupId, status, start, end, null);
6695            }
6696    
6697            /**
6698             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6699             *
6700             * <p>
6701             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6702             * </p>
6703             *
6704             * @param groupId the group ID
6705             * @param status the status
6706             * @param start the lower bound of the range of message-boards messages
6707             * @param end the upper bound of the range of message-boards messages (not inclusive)
6708             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6709             * @return the ordered range of matching message-boards messages that the user has permission to view
6710             */
6711            @Override
6712            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6713                    int end, OrderByComparator<MBMessage> orderByComparator) {
6714                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6715                            return findByG_S(groupId, status, start, end, orderByComparator);
6716                    }
6717    
6718                    StringBundler query = null;
6719    
6720                    if (orderByComparator != null) {
6721                            query = new StringBundler(4 +
6722                                            (orderByComparator.getOrderByFields().length * 2));
6723                    }
6724                    else {
6725                            query = new StringBundler(5);
6726                    }
6727    
6728                    if (getDB().isSupportsInlineDistinct()) {
6729                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6730                    }
6731                    else {
6732                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6733                    }
6734    
6735                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6736    
6737                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6738    
6739                    if (!getDB().isSupportsInlineDistinct()) {
6740                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6741                    }
6742    
6743                    if (orderByComparator != null) {
6744                            if (getDB().isSupportsInlineDistinct()) {
6745                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6746                                            orderByComparator, true);
6747                            }
6748                            else {
6749                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6750                                            orderByComparator, true);
6751                            }
6752                    }
6753                    else {
6754                            if (getDB().isSupportsInlineDistinct()) {
6755                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6756                            }
6757                            else {
6758                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6759                            }
6760                    }
6761    
6762                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6763                                    MBMessage.class.getName(),
6764                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6765    
6766                    Session session = null;
6767    
6768                    try {
6769                            session = openSession();
6770    
6771                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6772    
6773                            if (getDB().isSupportsInlineDistinct()) {
6774                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6775                            }
6776                            else {
6777                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6778                            }
6779    
6780                            QueryPos qPos = QueryPos.getInstance(q);
6781    
6782                            qPos.add(groupId);
6783    
6784                            qPos.add(status);
6785    
6786                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6787                    }
6788                    catch (Exception e) {
6789                            throw processException(e);
6790                    }
6791                    finally {
6792                            closeSession(session);
6793                    }
6794            }
6795    
6796            /**
6797             * 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;.
6798             *
6799             * @param messageId the primary key of the current message-boards message
6800             * @param groupId the group ID
6801             * @param status the status
6802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6803             * @return the previous, current, and next message-boards message
6804             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6805             */
6806            @Override
6807            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6808                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6809                    throws NoSuchMessageException {
6810                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6811                            return findByG_S_PrevAndNext(messageId, groupId, status,
6812                                    orderByComparator);
6813                    }
6814    
6815                    MBMessage mbMessage = findByPrimaryKey(messageId);
6816    
6817                    Session session = null;
6818    
6819                    try {
6820                            session = openSession();
6821    
6822                            MBMessage[] array = new MBMessageImpl[3];
6823    
6824                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6825                                            status, orderByComparator, true);
6826    
6827                            array[1] = mbMessage;
6828    
6829                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6830                                            status, orderByComparator, false);
6831    
6832                            return array;
6833                    }
6834                    catch (Exception e) {
6835                            throw processException(e);
6836                    }
6837                    finally {
6838                            closeSession(session);
6839                    }
6840            }
6841    
6842            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6843                    MBMessage mbMessage, long groupId, int status,
6844                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6845                    StringBundler query = null;
6846    
6847                    if (orderByComparator != null) {
6848                            query = new StringBundler(6 +
6849                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6850                                            (orderByComparator.getOrderByFields().length * 3));
6851                    }
6852                    else {
6853                            query = new StringBundler(5);
6854                    }
6855    
6856                    if (getDB().isSupportsInlineDistinct()) {
6857                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6858                    }
6859                    else {
6860                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6861                    }
6862    
6863                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6864    
6865                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6866    
6867                    if (!getDB().isSupportsInlineDistinct()) {
6868                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6869                    }
6870    
6871                    if (orderByComparator != null) {
6872                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6873    
6874                            if (orderByConditionFields.length > 0) {
6875                                    query.append(WHERE_AND);
6876                            }
6877    
6878                            for (int i = 0; i < orderByConditionFields.length; i++) {
6879                                    if (getDB().isSupportsInlineDistinct()) {
6880                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6881                                    }
6882                                    else {
6883                                            query.append(_ORDER_BY_ENTITY_TABLE);
6884                                    }
6885    
6886                                    query.append(orderByConditionFields[i]);
6887    
6888                                    if ((i + 1) < orderByConditionFields.length) {
6889                                            if (orderByComparator.isAscending() ^ previous) {
6890                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6891                                            }
6892                                            else {
6893                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6894                                            }
6895                                    }
6896                                    else {
6897                                            if (orderByComparator.isAscending() ^ previous) {
6898                                                    query.append(WHERE_GREATER_THAN);
6899                                            }
6900                                            else {
6901                                                    query.append(WHERE_LESSER_THAN);
6902                                            }
6903                                    }
6904                            }
6905    
6906                            query.append(ORDER_BY_CLAUSE);
6907    
6908                            String[] orderByFields = orderByComparator.getOrderByFields();
6909    
6910                            for (int i = 0; i < orderByFields.length; i++) {
6911                                    if (getDB().isSupportsInlineDistinct()) {
6912                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6913                                    }
6914                                    else {
6915                                            query.append(_ORDER_BY_ENTITY_TABLE);
6916                                    }
6917    
6918                                    query.append(orderByFields[i]);
6919    
6920                                    if ((i + 1) < orderByFields.length) {
6921                                            if (orderByComparator.isAscending() ^ previous) {
6922                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6923                                            }
6924                                            else {
6925                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6926                                            }
6927                                    }
6928                                    else {
6929                                            if (orderByComparator.isAscending() ^ previous) {
6930                                                    query.append(ORDER_BY_ASC);
6931                                            }
6932                                            else {
6933                                                    query.append(ORDER_BY_DESC);
6934                                            }
6935                                    }
6936                            }
6937                    }
6938                    else {
6939                            if (getDB().isSupportsInlineDistinct()) {
6940                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6941                            }
6942                            else {
6943                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6944                            }
6945                    }
6946    
6947                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6948                                    MBMessage.class.getName(),
6949                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6950    
6951                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6952    
6953                    q.setFirstResult(0);
6954                    q.setMaxResults(2);
6955    
6956                    if (getDB().isSupportsInlineDistinct()) {
6957                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6958                    }
6959                    else {
6960                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6961                    }
6962    
6963                    QueryPos qPos = QueryPos.getInstance(q);
6964    
6965                    qPos.add(groupId);
6966    
6967                    qPos.add(status);
6968    
6969                    if (orderByComparator != null) {
6970                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6971    
6972                            for (Object value : values) {
6973                                    qPos.add(value);
6974                            }
6975                    }
6976    
6977                    List<MBMessage> list = q.list();
6978    
6979                    if (list.size() == 2) {
6980                            return list.get(1);
6981                    }
6982                    else {
6983                            return null;
6984                    }
6985            }
6986    
6987            /**
6988             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6989             *
6990             * @param groupId the group ID
6991             * @param status the status
6992             */
6993            @Override
6994            public void removeByG_S(long groupId, int status) {
6995                    for (MBMessage mbMessage : findByG_S(groupId, status,
6996                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6997                            remove(mbMessage);
6998                    }
6999            }
7000    
7001            /**
7002             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
7003             *
7004             * @param groupId the group ID
7005             * @param status the status
7006             * @return the number of matching message-boards messages
7007             */
7008            @Override
7009            public int countByG_S(long groupId, int status) {
7010                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
7011    
7012                    Object[] finderArgs = new Object[] { groupId, status };
7013    
7014                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7015    
7016                    if (count == null) {
7017                            StringBundler query = new StringBundler(3);
7018    
7019                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7020    
7021                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7022    
7023                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
7024    
7025                            String sql = query.toString();
7026    
7027                            Session session = null;
7028    
7029                            try {
7030                                    session = openSession();
7031    
7032                                    Query q = session.createQuery(sql);
7033    
7034                                    QueryPos qPos = QueryPos.getInstance(q);
7035    
7036                                    qPos.add(groupId);
7037    
7038                                    qPos.add(status);
7039    
7040                                    count = (Long)q.uniqueResult();
7041    
7042                                    finderCache.putResult(finderPath, finderArgs, count);
7043                            }
7044                            catch (Exception e) {
7045                                    finderCache.removeResult(finderPath, finderArgs);
7046    
7047                                    throw processException(e);
7048                            }
7049                            finally {
7050                                    closeSession(session);
7051                            }
7052                    }
7053    
7054                    return count.intValue();
7055            }
7056    
7057            /**
7058             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
7059             *
7060             * @param groupId the group ID
7061             * @param status the status
7062             * @return the number of matching message-boards messages that the user has permission to view
7063             */
7064            @Override
7065            public int filterCountByG_S(long groupId, int status) {
7066                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7067                            return countByG_S(groupId, status);
7068                    }
7069    
7070                    StringBundler query = new StringBundler(3);
7071    
7072                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
7073    
7074                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7075    
7076                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
7077    
7078                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7079                                    MBMessage.class.getName(),
7080                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7081    
7082                    Session session = null;
7083    
7084                    try {
7085                            session = openSession();
7086    
7087                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7088    
7089                            q.addScalar(COUNT_COLUMN_NAME,
7090                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7091    
7092                            QueryPos qPos = QueryPos.getInstance(q);
7093    
7094                            qPos.add(groupId);
7095    
7096                            qPos.add(status);
7097    
7098                            Long count = (Long)q.uniqueResult();
7099    
7100                            return count.intValue();
7101                    }
7102                    catch (Exception e) {
7103                            throw processException(e);
7104                    }
7105                    finally {
7106                            closeSession(session);
7107                    }
7108            }
7109    
7110            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
7111            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7113                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7114                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7115                            new String[] {
7116                                    Long.class.getName(), Integer.class.getName(),
7117                                    
7118                            Integer.class.getName(), Integer.class.getName(),
7119                                    OrderByComparator.class.getName()
7120                            });
7121            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7122                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7123                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7124                            new String[] { Long.class.getName(), Integer.class.getName() },
7125                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7126                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7127                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7128            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7129                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7131                            new String[] { Long.class.getName(), Integer.class.getName() });
7132    
7133            /**
7134             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7135             *
7136             * @param companyId the company ID
7137             * @param status the status
7138             * @return the matching message-boards messages
7139             */
7140            @Override
7141            public List<MBMessage> findByC_S(long companyId, int status) {
7142                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7143                            QueryUtil.ALL_POS, null);
7144            }
7145    
7146            /**
7147             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7148             *
7149             * <p>
7150             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7151             * </p>
7152             *
7153             * @param companyId the company ID
7154             * @param status the status
7155             * @param start the lower bound of the range of message-boards messages
7156             * @param end the upper bound of the range of message-boards messages (not inclusive)
7157             * @return the range of matching message-boards messages
7158             */
7159            @Override
7160            public List<MBMessage> findByC_S(long companyId, int status, int start,
7161                    int end) {
7162                    return findByC_S(companyId, status, start, end, null);
7163            }
7164    
7165            /**
7166             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7167             *
7168             * <p>
7169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7170             * </p>
7171             *
7172             * @param companyId the company ID
7173             * @param status the status
7174             * @param start the lower bound of the range of message-boards messages
7175             * @param end the upper bound of the range of message-boards messages (not inclusive)
7176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7177             * @return the ordered range of matching message-boards messages
7178             */
7179            @Override
7180            public List<MBMessage> findByC_S(long companyId, int status, int start,
7181                    int end, OrderByComparator<MBMessage> orderByComparator) {
7182                    return findByC_S(companyId, status, start, end, orderByComparator, true);
7183            }
7184    
7185            /**
7186             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7187             *
7188             * <p>
7189             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7190             * </p>
7191             *
7192             * @param companyId the company ID
7193             * @param status the status
7194             * @param start the lower bound of the range of message-boards messages
7195             * @param end the upper bound of the range of message-boards messages (not inclusive)
7196             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7197             * @param retrieveFromCache whether to retrieve from the finder cache
7198             * @return the ordered range of matching message-boards messages
7199             */
7200            @Override
7201            public List<MBMessage> findByC_S(long companyId, int status, int start,
7202                    int end, OrderByComparator<MBMessage> orderByComparator,
7203                    boolean retrieveFromCache) {
7204                    boolean pagination = true;
7205                    FinderPath finderPath = null;
7206                    Object[] finderArgs = null;
7207    
7208                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7209                                    (orderByComparator == null)) {
7210                            pagination = false;
7211                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7212                            finderArgs = new Object[] { companyId, status };
7213                    }
7214                    else {
7215                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7216                            finderArgs = new Object[] {
7217                                            companyId, status,
7218                                            
7219                                            start, end, orderByComparator
7220                                    };
7221                    }
7222    
7223                    List<MBMessage> list = null;
7224    
7225                    if (retrieveFromCache) {
7226                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7227                                            finderArgs, this);
7228    
7229                            if ((list != null) && !list.isEmpty()) {
7230                                    for (MBMessage mbMessage : list) {
7231                                            if ((companyId != mbMessage.getCompanyId()) ||
7232                                                            (status != mbMessage.getStatus())) {
7233                                                    list = null;
7234    
7235                                                    break;
7236                                            }
7237                                    }
7238                            }
7239                    }
7240    
7241                    if (list == null) {
7242                            StringBundler query = null;
7243    
7244                            if (orderByComparator != null) {
7245                                    query = new StringBundler(4 +
7246                                                    (orderByComparator.getOrderByFields().length * 2));
7247                            }
7248                            else {
7249                                    query = new StringBundler(4);
7250                            }
7251    
7252                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7253    
7254                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7255    
7256                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7257    
7258                            if (orderByComparator != null) {
7259                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7260                                            orderByComparator);
7261                            }
7262                            else
7263                             if (pagination) {
7264                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7265                            }
7266    
7267                            String sql = query.toString();
7268    
7269                            Session session = null;
7270    
7271                            try {
7272                                    session = openSession();
7273    
7274                                    Query q = session.createQuery(sql);
7275    
7276                                    QueryPos qPos = QueryPos.getInstance(q);
7277    
7278                                    qPos.add(companyId);
7279    
7280                                    qPos.add(status);
7281    
7282                                    if (!pagination) {
7283                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7284                                                            start, end, false);
7285    
7286                                            Collections.sort(list);
7287    
7288                                            list = Collections.unmodifiableList(list);
7289                                    }
7290                                    else {
7291                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7292                                                            start, end);
7293                                    }
7294    
7295                                    cacheResult(list);
7296    
7297                                    finderCache.putResult(finderPath, finderArgs, list);
7298                            }
7299                            catch (Exception e) {
7300                                    finderCache.removeResult(finderPath, finderArgs);
7301    
7302                                    throw processException(e);
7303                            }
7304                            finally {
7305                                    closeSession(session);
7306                            }
7307                    }
7308    
7309                    return list;
7310            }
7311    
7312            /**
7313             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7314             *
7315             * @param companyId the company ID
7316             * @param status the status
7317             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7318             * @return the first matching message-boards message
7319             * @throws NoSuchMessageException if a matching message-boards message could not be found
7320             */
7321            @Override
7322            public MBMessage findByC_S_First(long companyId, int status,
7323                    OrderByComparator<MBMessage> orderByComparator)
7324                    throws NoSuchMessageException {
7325                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7326                                    orderByComparator);
7327    
7328                    if (mbMessage != null) {
7329                            return mbMessage;
7330                    }
7331    
7332                    StringBundler msg = new StringBundler(6);
7333    
7334                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7335    
7336                    msg.append("companyId=");
7337                    msg.append(companyId);
7338    
7339                    msg.append(", status=");
7340                    msg.append(status);
7341    
7342                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7343    
7344                    throw new NoSuchMessageException(msg.toString());
7345            }
7346    
7347            /**
7348             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7349             *
7350             * @param companyId the company ID
7351             * @param status the status
7352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7353             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7354             */
7355            @Override
7356            public MBMessage fetchByC_S_First(long companyId, int status,
7357                    OrderByComparator<MBMessage> orderByComparator) {
7358                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7359                                    orderByComparator);
7360    
7361                    if (!list.isEmpty()) {
7362                            return list.get(0);
7363                    }
7364    
7365                    return null;
7366            }
7367    
7368            /**
7369             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7370             *
7371             * @param companyId the company ID
7372             * @param status the status
7373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7374             * @return the last matching message-boards message
7375             * @throws NoSuchMessageException if a matching message-boards message could not be found
7376             */
7377            @Override
7378            public MBMessage findByC_S_Last(long companyId, int status,
7379                    OrderByComparator<MBMessage> orderByComparator)
7380                    throws NoSuchMessageException {
7381                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7382                                    orderByComparator);
7383    
7384                    if (mbMessage != null) {
7385                            return mbMessage;
7386                    }
7387    
7388                    StringBundler msg = new StringBundler(6);
7389    
7390                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7391    
7392                    msg.append("companyId=");
7393                    msg.append(companyId);
7394    
7395                    msg.append(", status=");
7396                    msg.append(status);
7397    
7398                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7399    
7400                    throw new NoSuchMessageException(msg.toString());
7401            }
7402    
7403            /**
7404             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7405             *
7406             * @param companyId the company ID
7407             * @param status the status
7408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7409             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7410             */
7411            @Override
7412            public MBMessage fetchByC_S_Last(long companyId, int status,
7413                    OrderByComparator<MBMessage> orderByComparator) {
7414                    int count = countByC_S(companyId, status);
7415    
7416                    if (count == 0) {
7417                            return null;
7418                    }
7419    
7420                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7421                                    orderByComparator);
7422    
7423                    if (!list.isEmpty()) {
7424                            return list.get(0);
7425                    }
7426    
7427                    return null;
7428            }
7429    
7430            /**
7431             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7432             *
7433             * @param messageId the primary key of the current message-boards message
7434             * @param companyId the company ID
7435             * @param status the status
7436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7437             * @return the previous, current, and next message-boards message
7438             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7439             */
7440            @Override
7441            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7442                    int status, OrderByComparator<MBMessage> orderByComparator)
7443                    throws NoSuchMessageException {
7444                    MBMessage mbMessage = findByPrimaryKey(messageId);
7445    
7446                    Session session = null;
7447    
7448                    try {
7449                            session = openSession();
7450    
7451                            MBMessage[] array = new MBMessageImpl[3];
7452    
7453                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7454                                            status, orderByComparator, true);
7455    
7456                            array[1] = mbMessage;
7457    
7458                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7459                                            status, orderByComparator, false);
7460    
7461                            return array;
7462                    }
7463                    catch (Exception e) {
7464                            throw processException(e);
7465                    }
7466                    finally {
7467                            closeSession(session);
7468                    }
7469            }
7470    
7471            protected MBMessage getByC_S_PrevAndNext(Session session,
7472                    MBMessage mbMessage, long companyId, int status,
7473                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7474                    StringBundler query = null;
7475    
7476                    if (orderByComparator != null) {
7477                            query = new StringBundler(5 +
7478                                            (orderByComparator.getOrderByConditionFields().length * 3) +
7479                                            (orderByComparator.getOrderByFields().length * 3));
7480                    }
7481                    else {
7482                            query = new StringBundler(4);
7483                    }
7484    
7485                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7486    
7487                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7488    
7489                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7490    
7491                    if (orderByComparator != null) {
7492                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7493    
7494                            if (orderByConditionFields.length > 0) {
7495                                    query.append(WHERE_AND);
7496                            }
7497    
7498                            for (int i = 0; i < orderByConditionFields.length; i++) {
7499                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7500                                    query.append(orderByConditionFields[i]);
7501    
7502                                    if ((i + 1) < orderByConditionFields.length) {
7503                                            if (orderByComparator.isAscending() ^ previous) {
7504                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7505                                            }
7506                                            else {
7507                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7508                                            }
7509                                    }
7510                                    else {
7511                                            if (orderByComparator.isAscending() ^ previous) {
7512                                                    query.append(WHERE_GREATER_THAN);
7513                                            }
7514                                            else {
7515                                                    query.append(WHERE_LESSER_THAN);
7516                                            }
7517                                    }
7518                            }
7519    
7520                            query.append(ORDER_BY_CLAUSE);
7521    
7522                            String[] orderByFields = orderByComparator.getOrderByFields();
7523    
7524                            for (int i = 0; i < orderByFields.length; i++) {
7525                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7526                                    query.append(orderByFields[i]);
7527    
7528                                    if ((i + 1) < orderByFields.length) {
7529                                            if (orderByComparator.isAscending() ^ previous) {
7530                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7531                                            }
7532                                            else {
7533                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7534                                            }
7535                                    }
7536                                    else {
7537                                            if (orderByComparator.isAscending() ^ previous) {
7538                                                    query.append(ORDER_BY_ASC);
7539                                            }
7540                                            else {
7541                                                    query.append(ORDER_BY_DESC);
7542                                            }
7543                                    }
7544                            }
7545                    }
7546                    else {
7547                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7548                    }
7549    
7550                    String sql = query.toString();
7551    
7552                    Query q = session.createQuery(sql);
7553    
7554                    q.setFirstResult(0);
7555                    q.setMaxResults(2);
7556    
7557                    QueryPos qPos = QueryPos.getInstance(q);
7558    
7559                    qPos.add(companyId);
7560    
7561                    qPos.add(status);
7562    
7563                    if (orderByComparator != null) {
7564                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7565    
7566                            for (Object value : values) {
7567                                    qPos.add(value);
7568                            }
7569                    }
7570    
7571                    List<MBMessage> list = q.list();
7572    
7573                    if (list.size() == 2) {
7574                            return list.get(1);
7575                    }
7576                    else {
7577                            return null;
7578                    }
7579            }
7580    
7581            /**
7582             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7583             *
7584             * @param companyId the company ID
7585             * @param status the status
7586             */
7587            @Override
7588            public void removeByC_S(long companyId, int status) {
7589                    for (MBMessage mbMessage : findByC_S(companyId, status,
7590                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7591                            remove(mbMessage);
7592                    }
7593            }
7594    
7595            /**
7596             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7597             *
7598             * @param companyId the company ID
7599             * @param status the status
7600             * @return the number of matching message-boards messages
7601             */
7602            @Override
7603            public int countByC_S(long companyId, int status) {
7604                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7605    
7606                    Object[] finderArgs = new Object[] { companyId, status };
7607    
7608                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7609    
7610                    if (count == null) {
7611                            StringBundler query = new StringBundler(3);
7612    
7613                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7614    
7615                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7616    
7617                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7618    
7619                            String sql = query.toString();
7620    
7621                            Session session = null;
7622    
7623                            try {
7624                                    session = openSession();
7625    
7626                                    Query q = session.createQuery(sql);
7627    
7628                                    QueryPos qPos = QueryPos.getInstance(q);
7629    
7630                                    qPos.add(companyId);
7631    
7632                                    qPos.add(status);
7633    
7634                                    count = (Long)q.uniqueResult();
7635    
7636                                    finderCache.putResult(finderPath, finderArgs, count);
7637                            }
7638                            catch (Exception e) {
7639                                    finderCache.removeResult(finderPath, finderArgs);
7640    
7641                                    throw processException(e);
7642                            }
7643                            finally {
7644                                    closeSession(session);
7645                            }
7646                    }
7647    
7648                    return count.intValue();
7649            }
7650    
7651            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7652            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7653            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7655                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7656                            new String[] {
7657                                    Long.class.getName(), Long.class.getName(),
7658                                    
7659                            Integer.class.getName(), Integer.class.getName(),
7660                                    OrderByComparator.class.getName()
7661                            });
7662            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7663                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7664                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7665                            new String[] { Long.class.getName(), Long.class.getName() },
7666                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7667                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7668                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7669            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7670                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7671                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7672                            new String[] { Long.class.getName(), Long.class.getName() });
7673            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7674                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7675                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7676                            new String[] { Long.class.getName(), Long.class.getName() });
7677    
7678            /**
7679             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7680             *
7681             * @param userId the user ID
7682             * @param classNameId the class name ID
7683             * @return the matching message-boards messages
7684             */
7685            @Override
7686            public List<MBMessage> findByU_C(long userId, long classNameId) {
7687                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7688                            QueryUtil.ALL_POS, null);
7689            }
7690    
7691            /**
7692             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7693             *
7694             * <p>
7695             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7696             * </p>
7697             *
7698             * @param userId the user ID
7699             * @param classNameId the class name ID
7700             * @param start the lower bound of the range of message-boards messages
7701             * @param end the upper bound of the range of message-boards messages (not inclusive)
7702             * @return the range of matching message-boards messages
7703             */
7704            @Override
7705            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7706                    int end) {
7707                    return findByU_C(userId, classNameId, start, end, null);
7708            }
7709    
7710            /**
7711             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7712             *
7713             * <p>
7714             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7715             * </p>
7716             *
7717             * @param userId the user ID
7718             * @param classNameId the class name ID
7719             * @param start the lower bound of the range of message-boards messages
7720             * @param end the upper bound of the range of message-boards messages (not inclusive)
7721             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7722             * @return the ordered range of matching message-boards messages
7723             */
7724            @Override
7725            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7726                    int end, OrderByComparator<MBMessage> orderByComparator) {
7727                    return findByU_C(userId, classNameId, start, end, orderByComparator,
7728                            true);
7729            }
7730    
7731            /**
7732             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7733             *
7734             * <p>
7735             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7736             * </p>
7737             *
7738             * @param userId the user ID
7739             * @param classNameId the class name ID
7740             * @param start the lower bound of the range of message-boards messages
7741             * @param end the upper bound of the range of message-boards messages (not inclusive)
7742             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7743             * @param retrieveFromCache whether to retrieve from the finder cache
7744             * @return the ordered range of matching message-boards messages
7745             */
7746            @Override
7747            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7748                    int end, OrderByComparator<MBMessage> orderByComparator,
7749                    boolean retrieveFromCache) {
7750                    boolean pagination = true;
7751                    FinderPath finderPath = null;
7752                    Object[] finderArgs = null;
7753    
7754                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7755                                    (orderByComparator == null)) {
7756                            pagination = false;
7757                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7758                            finderArgs = new Object[] { userId, classNameId };
7759                    }
7760                    else {
7761                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7762                            finderArgs = new Object[] {
7763                                            userId, classNameId,
7764                                            
7765                                            start, end, orderByComparator
7766                                    };
7767                    }
7768    
7769                    List<MBMessage> list = null;
7770    
7771                    if (retrieveFromCache) {
7772                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7773                                            finderArgs, this);
7774    
7775                            if ((list != null) && !list.isEmpty()) {
7776                                    for (MBMessage mbMessage : list) {
7777                                            if ((userId != mbMessage.getUserId()) ||
7778                                                            (classNameId != mbMessage.getClassNameId())) {
7779                                                    list = null;
7780    
7781                                                    break;
7782                                            }
7783                                    }
7784                            }
7785                    }
7786    
7787                    if (list == null) {
7788                            StringBundler query = null;
7789    
7790                            if (orderByComparator != null) {
7791                                    query = new StringBundler(4 +
7792                                                    (orderByComparator.getOrderByFields().length * 2));
7793                            }
7794                            else {
7795                                    query = new StringBundler(4);
7796                            }
7797    
7798                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7799    
7800                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7801    
7802                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7803    
7804                            if (orderByComparator != null) {
7805                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7806                                            orderByComparator);
7807                            }
7808                            else
7809                             if (pagination) {
7810                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7811                            }
7812    
7813                            String sql = query.toString();
7814    
7815                            Session session = null;
7816    
7817                            try {
7818                                    session = openSession();
7819    
7820                                    Query q = session.createQuery(sql);
7821    
7822                                    QueryPos qPos = QueryPos.getInstance(q);
7823    
7824                                    qPos.add(userId);
7825    
7826                                    qPos.add(classNameId);
7827    
7828                                    if (!pagination) {
7829                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7830                                                            start, end, false);
7831    
7832                                            Collections.sort(list);
7833    
7834                                            list = Collections.unmodifiableList(list);
7835                                    }
7836                                    else {
7837                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7838                                                            start, end);
7839                                    }
7840    
7841                                    cacheResult(list);
7842    
7843                                    finderCache.putResult(finderPath, finderArgs, list);
7844                            }
7845                            catch (Exception e) {
7846                                    finderCache.removeResult(finderPath, finderArgs);
7847    
7848                                    throw processException(e);
7849                            }
7850                            finally {
7851                                    closeSession(session);
7852                            }
7853                    }
7854    
7855                    return list;
7856            }
7857    
7858            /**
7859             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7860             *
7861             * @param userId the user ID
7862             * @param classNameId the class name ID
7863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7864             * @return the first matching message-boards message
7865             * @throws NoSuchMessageException if a matching message-boards message could not be found
7866             */
7867            @Override
7868            public MBMessage findByU_C_First(long userId, long classNameId,
7869                    OrderByComparator<MBMessage> orderByComparator)
7870                    throws NoSuchMessageException {
7871                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7872                                    orderByComparator);
7873    
7874                    if (mbMessage != null) {
7875                            return mbMessage;
7876                    }
7877    
7878                    StringBundler msg = new StringBundler(6);
7879    
7880                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7881    
7882                    msg.append("userId=");
7883                    msg.append(userId);
7884    
7885                    msg.append(", classNameId=");
7886                    msg.append(classNameId);
7887    
7888                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7889    
7890                    throw new NoSuchMessageException(msg.toString());
7891            }
7892    
7893            /**
7894             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7895             *
7896             * @param userId the user ID
7897             * @param classNameId the class name ID
7898             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7899             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7900             */
7901            @Override
7902            public MBMessage fetchByU_C_First(long userId, long classNameId,
7903                    OrderByComparator<MBMessage> orderByComparator) {
7904                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7905                                    orderByComparator);
7906    
7907                    if (!list.isEmpty()) {
7908                            return list.get(0);
7909                    }
7910    
7911                    return null;
7912            }
7913    
7914            /**
7915             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7916             *
7917             * @param userId the user ID
7918             * @param classNameId the class name ID
7919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7920             * @return the last matching message-boards message
7921             * @throws NoSuchMessageException if a matching message-boards message could not be found
7922             */
7923            @Override
7924            public MBMessage findByU_C_Last(long userId, long classNameId,
7925                    OrderByComparator<MBMessage> orderByComparator)
7926                    throws NoSuchMessageException {
7927                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7928                                    orderByComparator);
7929    
7930                    if (mbMessage != null) {
7931                            return mbMessage;
7932                    }
7933    
7934                    StringBundler msg = new StringBundler(6);
7935    
7936                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7937    
7938                    msg.append("userId=");
7939                    msg.append(userId);
7940    
7941                    msg.append(", classNameId=");
7942                    msg.append(classNameId);
7943    
7944                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7945    
7946                    throw new NoSuchMessageException(msg.toString());
7947            }
7948    
7949            /**
7950             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7951             *
7952             * @param userId the user ID
7953             * @param classNameId the class name ID
7954             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7955             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7956             */
7957            @Override
7958            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7959                    OrderByComparator<MBMessage> orderByComparator) {
7960                    int count = countByU_C(userId, classNameId);
7961    
7962                    if (count == 0) {
7963                            return null;
7964                    }
7965    
7966                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7967                                    orderByComparator);
7968    
7969                    if (!list.isEmpty()) {
7970                            return list.get(0);
7971                    }
7972    
7973                    return null;
7974            }
7975    
7976            /**
7977             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7978             *
7979             * @param messageId the primary key of the current message-boards message
7980             * @param userId the user ID
7981             * @param classNameId the class name ID
7982             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7983             * @return the previous, current, and next message-boards message
7984             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7985             */
7986            @Override
7987            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7988                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7989                    throws NoSuchMessageException {
7990                    MBMessage mbMessage = findByPrimaryKey(messageId);
7991    
7992                    Session session = null;
7993    
7994                    try {
7995                            session = openSession();
7996    
7997                            MBMessage[] array = new MBMessageImpl[3];
7998    
7999                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
8000                                            classNameId, orderByComparator, true);
8001    
8002                            array[1] = mbMessage;
8003    
8004                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
8005                                            classNameId, orderByComparator, false);
8006    
8007                            return array;
8008                    }
8009                    catch (Exception e) {
8010                            throw processException(e);
8011                    }
8012                    finally {
8013                            closeSession(session);
8014                    }
8015            }
8016    
8017            protected MBMessage getByU_C_PrevAndNext(Session session,
8018                    MBMessage mbMessage, long userId, long classNameId,
8019                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8020                    StringBundler query = null;
8021    
8022                    if (orderByComparator != null) {
8023                            query = new StringBundler(5 +
8024                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8025                                            (orderByComparator.getOrderByFields().length * 3));
8026                    }
8027                    else {
8028                            query = new StringBundler(4);
8029                    }
8030    
8031                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8032    
8033                    query.append(_FINDER_COLUMN_U_C_USERID_2);
8034    
8035                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8036    
8037                    if (orderByComparator != null) {
8038                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8039    
8040                            if (orderByConditionFields.length > 0) {
8041                                    query.append(WHERE_AND);
8042                            }
8043    
8044                            for (int i = 0; i < orderByConditionFields.length; i++) {
8045                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8046                                    query.append(orderByConditionFields[i]);
8047    
8048                                    if ((i + 1) < orderByConditionFields.length) {
8049                                            if (orderByComparator.isAscending() ^ previous) {
8050                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8051                                            }
8052                                            else {
8053                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8054                                            }
8055                                    }
8056                                    else {
8057                                            if (orderByComparator.isAscending() ^ previous) {
8058                                                    query.append(WHERE_GREATER_THAN);
8059                                            }
8060                                            else {
8061                                                    query.append(WHERE_LESSER_THAN);
8062                                            }
8063                                    }
8064                            }
8065    
8066                            query.append(ORDER_BY_CLAUSE);
8067    
8068                            String[] orderByFields = orderByComparator.getOrderByFields();
8069    
8070                            for (int i = 0; i < orderByFields.length; i++) {
8071                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8072                                    query.append(orderByFields[i]);
8073    
8074                                    if ((i + 1) < orderByFields.length) {
8075                                            if (orderByComparator.isAscending() ^ previous) {
8076                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8077                                            }
8078                                            else {
8079                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8080                                            }
8081                                    }
8082                                    else {
8083                                            if (orderByComparator.isAscending() ^ previous) {
8084                                                    query.append(ORDER_BY_ASC);
8085                                            }
8086                                            else {
8087                                                    query.append(ORDER_BY_DESC);
8088                                            }
8089                                    }
8090                            }
8091                    }
8092                    else {
8093                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8094                    }
8095    
8096                    String sql = query.toString();
8097    
8098                    Query q = session.createQuery(sql);
8099    
8100                    q.setFirstResult(0);
8101                    q.setMaxResults(2);
8102    
8103                    QueryPos qPos = QueryPos.getInstance(q);
8104    
8105                    qPos.add(userId);
8106    
8107                    qPos.add(classNameId);
8108    
8109                    if (orderByComparator != null) {
8110                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8111    
8112                            for (Object value : values) {
8113                                    qPos.add(value);
8114                            }
8115                    }
8116    
8117                    List<MBMessage> list = q.list();
8118    
8119                    if (list.size() == 2) {
8120                            return list.get(1);
8121                    }
8122                    else {
8123                            return null;
8124                    }
8125            }
8126    
8127            /**
8128             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8129             *
8130             * <p>
8131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8132             * </p>
8133             *
8134             * @param userId the user ID
8135             * @param classNameIds the class name IDs
8136             * @return the matching message-boards messages
8137             */
8138            @Override
8139            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
8140                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
8141                            QueryUtil.ALL_POS, null);
8142            }
8143    
8144            /**
8145             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8146             *
8147             * <p>
8148             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8149             * </p>
8150             *
8151             * @param userId the user ID
8152             * @param classNameIds the class name IDs
8153             * @param start the lower bound of the range of message-boards messages
8154             * @param end the upper bound of the range of message-boards messages (not inclusive)
8155             * @return the range of matching message-boards messages
8156             */
8157            @Override
8158            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8159                    int start, int end) {
8160                    return findByU_C(userId, classNameIds, start, end, null);
8161            }
8162    
8163            /**
8164             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8165             *
8166             * <p>
8167             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8168             * </p>
8169             *
8170             * @param userId the user ID
8171             * @param classNameIds the class name IDs
8172             * @param start the lower bound of the range of message-boards messages
8173             * @param end the upper bound of the range of message-boards messages (not inclusive)
8174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8175             * @return the ordered range of matching message-boards messages
8176             */
8177            @Override
8178            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8179                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8180                    return findByU_C(userId, classNameIds, start, end, orderByComparator,
8181                            true);
8182            }
8183    
8184            /**
8185             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;, optionally using the finder cache.
8186             *
8187             * <p>
8188             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8189             * </p>
8190             *
8191             * @param userId the user ID
8192             * @param classNameId the class name ID
8193             * @param start the lower bound of the range of message-boards messages
8194             * @param end the upper bound of the range of message-boards messages (not inclusive)
8195             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8196             * @param retrieveFromCache whether to retrieve from the finder cache
8197             * @return the ordered range of matching message-boards messages
8198             */
8199            @Override
8200            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8201                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
8202                    boolean retrieveFromCache) {
8203                    if (classNameIds == null) {
8204                            classNameIds = new long[0];
8205                    }
8206                    else if (classNameIds.length > 1) {
8207                            classNameIds = ArrayUtil.unique(classNameIds);
8208    
8209                            Arrays.sort(classNameIds);
8210                    }
8211    
8212                    if (classNameIds.length == 1) {
8213                            return findByU_C(userId, classNameIds[0], start, end,
8214                                    orderByComparator);
8215                    }
8216    
8217                    boolean pagination = true;
8218                    Object[] finderArgs = null;
8219    
8220                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8221                                    (orderByComparator == null)) {
8222                            pagination = false;
8223                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8224                    }
8225                    else {
8226                            finderArgs = new Object[] {
8227                                            userId, StringUtil.merge(classNameIds),
8228                                            
8229                                            start, end, orderByComparator
8230                                    };
8231                    }
8232    
8233                    List<MBMessage> list = null;
8234    
8235                    if (retrieveFromCache) {
8236                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8237                                            finderArgs, this);
8238    
8239                            if ((list != null) && !list.isEmpty()) {
8240                                    for (MBMessage mbMessage : list) {
8241                                            if ((userId != mbMessage.getUserId()) ||
8242                                                            !ArrayUtil.contains(classNameIds,
8243                                                                    mbMessage.getClassNameId())) {
8244                                                    list = null;
8245    
8246                                                    break;
8247                                            }
8248                                    }
8249                            }
8250                    }
8251    
8252                    if (list == null) {
8253                            StringBundler query = new StringBundler();
8254    
8255                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8256    
8257                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8258    
8259                            if (classNameIds.length > 0) {
8260                                    query.append(StringPool.OPEN_PARENTHESIS);
8261    
8262                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8263    
8264                                    query.append(StringUtil.merge(classNameIds));
8265    
8266                                    query.append(StringPool.CLOSE_PARENTHESIS);
8267    
8268                                    query.append(StringPool.CLOSE_PARENTHESIS);
8269                            }
8270    
8271                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8272                                                    1)), query.index() - 1);
8273    
8274                            if (orderByComparator != null) {
8275                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8276                                            orderByComparator);
8277                            }
8278                            else
8279                             if (pagination) {
8280                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8281                            }
8282    
8283                            String sql = query.toString();
8284    
8285                            Session session = null;
8286    
8287                            try {
8288                                    session = openSession();
8289    
8290                                    Query q = session.createQuery(sql);
8291    
8292                                    QueryPos qPos = QueryPos.getInstance(q);
8293    
8294                                    qPos.add(userId);
8295    
8296                                    if (!pagination) {
8297                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8298                                                            start, end, false);
8299    
8300                                            Collections.sort(list);
8301    
8302                                            list = Collections.unmodifiableList(list);
8303                                    }
8304                                    else {
8305                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8306                                                            start, end);
8307                                    }
8308    
8309                                    cacheResult(list);
8310    
8311                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8312                                            finderArgs, list);
8313                            }
8314                            catch (Exception e) {
8315                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8316                                            finderArgs);
8317    
8318                                    throw processException(e);
8319                            }
8320                            finally {
8321                                    closeSession(session);
8322                            }
8323                    }
8324    
8325                    return list;
8326            }
8327    
8328            /**
8329             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8330             *
8331             * @param userId the user ID
8332             * @param classNameId the class name ID
8333             */
8334            @Override
8335            public void removeByU_C(long userId, long classNameId) {
8336                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8337                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8338                            remove(mbMessage);
8339                    }
8340            }
8341    
8342            /**
8343             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8344             *
8345             * @param userId the user ID
8346             * @param classNameId the class name ID
8347             * @return the number of matching message-boards messages
8348             */
8349            @Override
8350            public int countByU_C(long userId, long classNameId) {
8351                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8352    
8353                    Object[] finderArgs = new Object[] { userId, classNameId };
8354    
8355                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8356    
8357                    if (count == null) {
8358                            StringBundler query = new StringBundler(3);
8359    
8360                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8361    
8362                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8363    
8364                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8365    
8366                            String sql = query.toString();
8367    
8368                            Session session = null;
8369    
8370                            try {
8371                                    session = openSession();
8372    
8373                                    Query q = session.createQuery(sql);
8374    
8375                                    QueryPos qPos = QueryPos.getInstance(q);
8376    
8377                                    qPos.add(userId);
8378    
8379                                    qPos.add(classNameId);
8380    
8381                                    count = (Long)q.uniqueResult();
8382    
8383                                    finderCache.putResult(finderPath, finderArgs, count);
8384                            }
8385                            catch (Exception e) {
8386                                    finderCache.removeResult(finderPath, finderArgs);
8387    
8388                                    throw processException(e);
8389                            }
8390                            finally {
8391                                    closeSession(session);
8392                            }
8393                    }
8394    
8395                    return count.intValue();
8396            }
8397    
8398            /**
8399             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8400             *
8401             * @param userId the user ID
8402             * @param classNameIds the class name IDs
8403             * @return the number of matching message-boards messages
8404             */
8405            @Override
8406            public int countByU_C(long userId, long[] classNameIds) {
8407                    if (classNameIds == null) {
8408                            classNameIds = new long[0];
8409                    }
8410                    else if (classNameIds.length > 1) {
8411                            classNameIds = ArrayUtil.unique(classNameIds);
8412    
8413                            Arrays.sort(classNameIds);
8414                    }
8415    
8416                    Object[] finderArgs = new Object[] {
8417                                    userId, StringUtil.merge(classNameIds)
8418                            };
8419    
8420                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8421                                    finderArgs, this);
8422    
8423                    if (count == null) {
8424                            StringBundler query = new StringBundler();
8425    
8426                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8427    
8428                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8429    
8430                            if (classNameIds.length > 0) {
8431                                    query.append(StringPool.OPEN_PARENTHESIS);
8432    
8433                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8434    
8435                                    query.append(StringUtil.merge(classNameIds));
8436    
8437                                    query.append(StringPool.CLOSE_PARENTHESIS);
8438    
8439                                    query.append(StringPool.CLOSE_PARENTHESIS);
8440                            }
8441    
8442                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8443                                                    1)), query.index() - 1);
8444    
8445                            String sql = query.toString();
8446    
8447                            Session session = null;
8448    
8449                            try {
8450                                    session = openSession();
8451    
8452                                    Query q = session.createQuery(sql);
8453    
8454                                    QueryPos qPos = QueryPos.getInstance(q);
8455    
8456                                    qPos.add(userId);
8457    
8458                                    count = (Long)q.uniqueResult();
8459    
8460                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8461                                            finderArgs, count);
8462                            }
8463                            catch (Exception e) {
8464                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8465                                            finderArgs);
8466    
8467                                    throw processException(e);
8468                            }
8469                            finally {
8470                                    closeSession(session);
8471                            }
8472                    }
8473    
8474                    return count.intValue();
8475            }
8476    
8477            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8478            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8479            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8480            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8481                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8482                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8483                            new String[] {
8484                                    Long.class.getName(), Long.class.getName(),
8485                                    
8486                            Integer.class.getName(), Integer.class.getName(),
8487                                    OrderByComparator.class.getName()
8488                            });
8489            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8490                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8491                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8492                            new String[] { Long.class.getName(), Long.class.getName() },
8493                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8494                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8495                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8496            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8497                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8498                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8499                            new String[] { Long.class.getName(), Long.class.getName() });
8500    
8501            /**
8502             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8503             *
8504             * @param classNameId the class name ID
8505             * @param classPK the class p k
8506             * @return the matching message-boards messages
8507             */
8508            @Override
8509            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8510                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8511                            QueryUtil.ALL_POS, null);
8512            }
8513    
8514            /**
8515             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8516             *
8517             * <p>
8518             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8519             * </p>
8520             *
8521             * @param classNameId the class name ID
8522             * @param classPK the class p k
8523             * @param start the lower bound of the range of message-boards messages
8524             * @param end the upper bound of the range of message-boards messages (not inclusive)
8525             * @return the range of matching message-boards messages
8526             */
8527            @Override
8528            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8529                    int end) {
8530                    return findByC_C(classNameId, classPK, start, end, null);
8531            }
8532    
8533            /**
8534             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8535             *
8536             * <p>
8537             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8538             * </p>
8539             *
8540             * @param classNameId the class name ID
8541             * @param classPK the class p k
8542             * @param start the lower bound of the range of message-boards messages
8543             * @param end the upper bound of the range of message-boards messages (not inclusive)
8544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8545             * @return the ordered range of matching message-boards messages
8546             */
8547            @Override
8548            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8549                    int end, OrderByComparator<MBMessage> orderByComparator) {
8550                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
8551                            true);
8552            }
8553    
8554            /**
8555             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8556             *
8557             * <p>
8558             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8559             * </p>
8560             *
8561             * @param classNameId the class name ID
8562             * @param classPK the class p k
8563             * @param start the lower bound of the range of message-boards messages
8564             * @param end the upper bound of the range of message-boards messages (not inclusive)
8565             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8566             * @param retrieveFromCache whether to retrieve from the finder cache
8567             * @return the ordered range of matching message-boards messages
8568             */
8569            @Override
8570            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8571                    int end, OrderByComparator<MBMessage> orderByComparator,
8572                    boolean retrieveFromCache) {
8573                    boolean pagination = true;
8574                    FinderPath finderPath = null;
8575                    Object[] finderArgs = null;
8576    
8577                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8578                                    (orderByComparator == null)) {
8579                            pagination = false;
8580                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8581                            finderArgs = new Object[] { classNameId, classPK };
8582                    }
8583                    else {
8584                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8585                            finderArgs = new Object[] {
8586                                            classNameId, classPK,
8587                                            
8588                                            start, end, orderByComparator
8589                                    };
8590                    }
8591    
8592                    List<MBMessage> list = null;
8593    
8594                    if (retrieveFromCache) {
8595                            list = (List<MBMessage>)finderCache.getResult(finderPath,
8596                                            finderArgs, this);
8597    
8598                            if ((list != null) && !list.isEmpty()) {
8599                                    for (MBMessage mbMessage : list) {
8600                                            if ((classNameId != mbMessage.getClassNameId()) ||
8601                                                            (classPK != mbMessage.getClassPK())) {
8602                                                    list = null;
8603    
8604                                                    break;
8605                                            }
8606                                    }
8607                            }
8608                    }
8609    
8610                    if (list == null) {
8611                            StringBundler query = null;
8612    
8613                            if (orderByComparator != null) {
8614                                    query = new StringBundler(4 +
8615                                                    (orderByComparator.getOrderByFields().length * 2));
8616                            }
8617                            else {
8618                                    query = new StringBundler(4);
8619                            }
8620    
8621                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8622    
8623                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8624    
8625                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8626    
8627                            if (orderByComparator != null) {
8628                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8629                                            orderByComparator);
8630                            }
8631                            else
8632                             if (pagination) {
8633                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8634                            }
8635    
8636                            String sql = query.toString();
8637    
8638                            Session session = null;
8639    
8640                            try {
8641                                    session = openSession();
8642    
8643                                    Query q = session.createQuery(sql);
8644    
8645                                    QueryPos qPos = QueryPos.getInstance(q);
8646    
8647                                    qPos.add(classNameId);
8648    
8649                                    qPos.add(classPK);
8650    
8651                                    if (!pagination) {
8652                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8653                                                            start, end, false);
8654    
8655                                            Collections.sort(list);
8656    
8657                                            list = Collections.unmodifiableList(list);
8658                                    }
8659                                    else {
8660                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8661                                                            start, end);
8662                                    }
8663    
8664                                    cacheResult(list);
8665    
8666                                    finderCache.putResult(finderPath, finderArgs, list);
8667                            }
8668                            catch (Exception e) {
8669                                    finderCache.removeResult(finderPath, finderArgs);
8670    
8671                                    throw processException(e);
8672                            }
8673                            finally {
8674                                    closeSession(session);
8675                            }
8676                    }
8677    
8678                    return list;
8679            }
8680    
8681            /**
8682             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8683             *
8684             * @param classNameId the class name ID
8685             * @param classPK the class p k
8686             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8687             * @return the first matching message-boards message
8688             * @throws NoSuchMessageException if a matching message-boards message could not be found
8689             */
8690            @Override
8691            public MBMessage findByC_C_First(long classNameId, long classPK,
8692                    OrderByComparator<MBMessage> orderByComparator)
8693                    throws NoSuchMessageException {
8694                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8695                                    orderByComparator);
8696    
8697                    if (mbMessage != null) {
8698                            return mbMessage;
8699                    }
8700    
8701                    StringBundler msg = new StringBundler(6);
8702    
8703                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8704    
8705                    msg.append("classNameId=");
8706                    msg.append(classNameId);
8707    
8708                    msg.append(", classPK=");
8709                    msg.append(classPK);
8710    
8711                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8712    
8713                    throw new NoSuchMessageException(msg.toString());
8714            }
8715    
8716            /**
8717             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8718             *
8719             * @param classNameId the class name ID
8720             * @param classPK the class p k
8721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8722             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8723             */
8724            @Override
8725            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8726                    OrderByComparator<MBMessage> orderByComparator) {
8727                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8728                                    orderByComparator);
8729    
8730                    if (!list.isEmpty()) {
8731                            return list.get(0);
8732                    }
8733    
8734                    return null;
8735            }
8736    
8737            /**
8738             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8739             *
8740             * @param classNameId the class name ID
8741             * @param classPK the class p k
8742             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8743             * @return the last matching message-boards message
8744             * @throws NoSuchMessageException if a matching message-boards message could not be found
8745             */
8746            @Override
8747            public MBMessage findByC_C_Last(long classNameId, long classPK,
8748                    OrderByComparator<MBMessage> orderByComparator)
8749                    throws NoSuchMessageException {
8750                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8751                                    orderByComparator);
8752    
8753                    if (mbMessage != null) {
8754                            return mbMessage;
8755                    }
8756    
8757                    StringBundler msg = new StringBundler(6);
8758    
8759                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8760    
8761                    msg.append("classNameId=");
8762                    msg.append(classNameId);
8763    
8764                    msg.append(", classPK=");
8765                    msg.append(classPK);
8766    
8767                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8768    
8769                    throw new NoSuchMessageException(msg.toString());
8770            }
8771    
8772            /**
8773             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8774             *
8775             * @param classNameId the class name ID
8776             * @param classPK the class p k
8777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8778             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8779             */
8780            @Override
8781            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8782                    OrderByComparator<MBMessage> orderByComparator) {
8783                    int count = countByC_C(classNameId, classPK);
8784    
8785                    if (count == 0) {
8786                            return null;
8787                    }
8788    
8789                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8790                                    count, orderByComparator);
8791    
8792                    if (!list.isEmpty()) {
8793                            return list.get(0);
8794                    }
8795    
8796                    return null;
8797            }
8798    
8799            /**
8800             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8801             *
8802             * @param messageId the primary key of the current message-boards message
8803             * @param classNameId the class name ID
8804             * @param classPK the class p k
8805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8806             * @return the previous, current, and next message-boards message
8807             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8808             */
8809            @Override
8810            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8811                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8812                    throws NoSuchMessageException {
8813                    MBMessage mbMessage = findByPrimaryKey(messageId);
8814    
8815                    Session session = null;
8816    
8817                    try {
8818                            session = openSession();
8819    
8820                            MBMessage[] array = new MBMessageImpl[3];
8821    
8822                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8823                                            classPK, orderByComparator, true);
8824    
8825                            array[1] = mbMessage;
8826    
8827                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8828                                            classPK, orderByComparator, false);
8829    
8830                            return array;
8831                    }
8832                    catch (Exception e) {
8833                            throw processException(e);
8834                    }
8835                    finally {
8836                            closeSession(session);
8837                    }
8838            }
8839    
8840            protected MBMessage getByC_C_PrevAndNext(Session session,
8841                    MBMessage mbMessage, long classNameId, long classPK,
8842                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8843                    StringBundler query = null;
8844    
8845                    if (orderByComparator != null) {
8846                            query = new StringBundler(5 +
8847                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8848                                            (orderByComparator.getOrderByFields().length * 3));
8849                    }
8850                    else {
8851                            query = new StringBundler(4);
8852                    }
8853    
8854                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8855    
8856                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8857    
8858                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8859    
8860                    if (orderByComparator != null) {
8861                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8862    
8863                            if (orderByConditionFields.length > 0) {
8864                                    query.append(WHERE_AND);
8865                            }
8866    
8867                            for (int i = 0; i < orderByConditionFields.length; i++) {
8868                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8869                                    query.append(orderByConditionFields[i]);
8870    
8871                                    if ((i + 1) < orderByConditionFields.length) {
8872                                            if (orderByComparator.isAscending() ^ previous) {
8873                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8874                                            }
8875                                            else {
8876                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8877                                            }
8878                                    }
8879                                    else {
8880                                            if (orderByComparator.isAscending() ^ previous) {
8881                                                    query.append(WHERE_GREATER_THAN);
8882                                            }
8883                                            else {
8884                                                    query.append(WHERE_LESSER_THAN);
8885                                            }
8886                                    }
8887                            }
8888    
8889                            query.append(ORDER_BY_CLAUSE);
8890    
8891                            String[] orderByFields = orderByComparator.getOrderByFields();
8892    
8893                            for (int i = 0; i < orderByFields.length; i++) {
8894                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8895                                    query.append(orderByFields[i]);
8896    
8897                                    if ((i + 1) < orderByFields.length) {
8898                                            if (orderByComparator.isAscending() ^ previous) {
8899                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8900                                            }
8901                                            else {
8902                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8903                                            }
8904                                    }
8905                                    else {
8906                                            if (orderByComparator.isAscending() ^ previous) {
8907                                                    query.append(ORDER_BY_ASC);
8908                                            }
8909                                            else {
8910                                                    query.append(ORDER_BY_DESC);
8911                                            }
8912                                    }
8913                            }
8914                    }
8915                    else {
8916                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8917                    }
8918    
8919                    String sql = query.toString();
8920    
8921                    Query q = session.createQuery(sql);
8922    
8923                    q.setFirstResult(0);
8924                    q.setMaxResults(2);
8925    
8926                    QueryPos qPos = QueryPos.getInstance(q);
8927    
8928                    qPos.add(classNameId);
8929    
8930                    qPos.add(classPK);
8931    
8932                    if (orderByComparator != null) {
8933                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8934    
8935                            for (Object value : values) {
8936                                    qPos.add(value);
8937                            }
8938                    }
8939    
8940                    List<MBMessage> list = q.list();
8941    
8942                    if (list.size() == 2) {
8943                            return list.get(1);
8944                    }
8945                    else {
8946                            return null;
8947                    }
8948            }
8949    
8950            /**
8951             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8952             *
8953             * @param classNameId the class name ID
8954             * @param classPK the class p k
8955             */
8956            @Override
8957            public void removeByC_C(long classNameId, long classPK) {
8958                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8959                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8960                            remove(mbMessage);
8961                    }
8962            }
8963    
8964            /**
8965             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8966             *
8967             * @param classNameId the class name ID
8968             * @param classPK the class p k
8969             * @return the number of matching message-boards messages
8970             */
8971            @Override
8972            public int countByC_C(long classNameId, long classPK) {
8973                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8974    
8975                    Object[] finderArgs = new Object[] { classNameId, classPK };
8976    
8977                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8978    
8979                    if (count == null) {
8980                            StringBundler query = new StringBundler(3);
8981    
8982                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8983    
8984                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8985    
8986                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8987    
8988                            String sql = query.toString();
8989    
8990                            Session session = null;
8991    
8992                            try {
8993                                    session = openSession();
8994    
8995                                    Query q = session.createQuery(sql);
8996    
8997                                    QueryPos qPos = QueryPos.getInstance(q);
8998    
8999                                    qPos.add(classNameId);
9000    
9001                                    qPos.add(classPK);
9002    
9003                                    count = (Long)q.uniqueResult();
9004    
9005                                    finderCache.putResult(finderPath, finderArgs, count);
9006                            }
9007                            catch (Exception e) {
9008                                    finderCache.removeResult(finderPath, finderArgs);
9009    
9010                                    throw processException(e);
9011                            }
9012                            finally {
9013                                    closeSession(session);
9014                            }
9015                    }
9016    
9017                    return count.intValue();
9018            }
9019    
9020            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
9021            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
9022            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9023                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9024                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
9025                            new String[] {
9026                                    Long.class.getName(), Long.class.getName(),
9027                                    
9028                            Integer.class.getName(), Integer.class.getName(),
9029                                    OrderByComparator.class.getName()
9030                            });
9031            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9032                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9033                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
9034                            new String[] { Long.class.getName(), Long.class.getName() },
9035                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9036                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
9037                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9038            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9039                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9040                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
9041                            new String[] { Long.class.getName(), Long.class.getName() });
9042    
9043            /**
9044             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9045             *
9046             * @param threadId the thread ID
9047             * @param parentMessageId the parent message ID
9048             * @return the matching message-boards messages
9049             */
9050            @Override
9051            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
9052                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
9053                            QueryUtil.ALL_POS, null);
9054            }
9055    
9056            /**
9057             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9058             *
9059             * <p>
9060             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9061             * </p>
9062             *
9063             * @param threadId the thread ID
9064             * @param parentMessageId the parent message ID
9065             * @param start the lower bound of the range of message-boards messages
9066             * @param end the upper bound of the range of message-boards messages (not inclusive)
9067             * @return the range of matching message-boards messages
9068             */
9069            @Override
9070            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9071                    int start, int end) {
9072                    return findByT_P(threadId, parentMessageId, start, end, null);
9073            }
9074    
9075            /**
9076             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9077             *
9078             * <p>
9079             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9080             * </p>
9081             *
9082             * @param threadId the thread ID
9083             * @param parentMessageId the parent message ID
9084             * @param start the lower bound of the range of message-boards messages
9085             * @param end the upper bound of the range of message-boards messages (not inclusive)
9086             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9087             * @return the ordered range of matching message-boards messages
9088             */
9089            @Override
9090            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9091                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
9092                    return findByT_P(threadId, parentMessageId, start, end,
9093                            orderByComparator, true);
9094            }
9095    
9096            /**
9097             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9098             *
9099             * <p>
9100             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9101             * </p>
9102             *
9103             * @param threadId the thread ID
9104             * @param parentMessageId the parent message ID
9105             * @param start the lower bound of the range of message-boards messages
9106             * @param end the upper bound of the range of message-boards messages (not inclusive)
9107             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9108             * @param retrieveFromCache whether to retrieve from the finder cache
9109             * @return the ordered range of matching message-boards messages
9110             */
9111            @Override
9112            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9113                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
9114                    boolean retrieveFromCache) {
9115                    boolean pagination = true;
9116                    FinderPath finderPath = null;
9117                    Object[] finderArgs = null;
9118    
9119                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9120                                    (orderByComparator == null)) {
9121                            pagination = false;
9122                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
9123                            finderArgs = new Object[] { threadId, parentMessageId };
9124                    }
9125                    else {
9126                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
9127                            finderArgs = new Object[] {
9128                                            threadId, parentMessageId,
9129                                            
9130                                            start, end, orderByComparator
9131                                    };
9132                    }
9133    
9134                    List<MBMessage> list = null;
9135    
9136                    if (retrieveFromCache) {
9137                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9138                                            finderArgs, this);
9139    
9140                            if ((list != null) && !list.isEmpty()) {
9141                                    for (MBMessage mbMessage : list) {
9142                                            if ((threadId != mbMessage.getThreadId()) ||
9143                                                            (parentMessageId != mbMessage.getParentMessageId())) {
9144                                                    list = null;
9145    
9146                                                    break;
9147                                            }
9148                                    }
9149                            }
9150                    }
9151    
9152                    if (list == null) {
9153                            StringBundler query = null;
9154    
9155                            if (orderByComparator != null) {
9156                                    query = new StringBundler(4 +
9157                                                    (orderByComparator.getOrderByFields().length * 2));
9158                            }
9159                            else {
9160                                    query = new StringBundler(4);
9161                            }
9162    
9163                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9164    
9165                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9166    
9167                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9168    
9169                            if (orderByComparator != null) {
9170                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9171                                            orderByComparator);
9172                            }
9173                            else
9174                             if (pagination) {
9175                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9176                            }
9177    
9178                            String sql = query.toString();
9179    
9180                            Session session = null;
9181    
9182                            try {
9183                                    session = openSession();
9184    
9185                                    Query q = session.createQuery(sql);
9186    
9187                                    QueryPos qPos = QueryPos.getInstance(q);
9188    
9189                                    qPos.add(threadId);
9190    
9191                                    qPos.add(parentMessageId);
9192    
9193                                    if (!pagination) {
9194                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9195                                                            start, end, false);
9196    
9197                                            Collections.sort(list);
9198    
9199                                            list = Collections.unmodifiableList(list);
9200                                    }
9201                                    else {
9202                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9203                                                            start, end);
9204                                    }
9205    
9206                                    cacheResult(list);
9207    
9208                                    finderCache.putResult(finderPath, finderArgs, list);
9209                            }
9210                            catch (Exception e) {
9211                                    finderCache.removeResult(finderPath, finderArgs);
9212    
9213                                    throw processException(e);
9214                            }
9215                            finally {
9216                                    closeSession(session);
9217                            }
9218                    }
9219    
9220                    return list;
9221            }
9222    
9223            /**
9224             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9225             *
9226             * @param threadId the thread ID
9227             * @param parentMessageId the parent message ID
9228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9229             * @return the first matching message-boards message
9230             * @throws NoSuchMessageException if a matching message-boards message could not be found
9231             */
9232            @Override
9233            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9234                    OrderByComparator<MBMessage> orderByComparator)
9235                    throws NoSuchMessageException {
9236                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9237                                    orderByComparator);
9238    
9239                    if (mbMessage != null) {
9240                            return mbMessage;
9241                    }
9242    
9243                    StringBundler msg = new StringBundler(6);
9244    
9245                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9246    
9247                    msg.append("threadId=");
9248                    msg.append(threadId);
9249    
9250                    msg.append(", parentMessageId=");
9251                    msg.append(parentMessageId);
9252    
9253                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9254    
9255                    throw new NoSuchMessageException(msg.toString());
9256            }
9257    
9258            /**
9259             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9260             *
9261             * @param threadId the thread ID
9262             * @param parentMessageId the parent message ID
9263             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9264             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9265             */
9266            @Override
9267            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9268                    OrderByComparator<MBMessage> orderByComparator) {
9269                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9270                                    orderByComparator);
9271    
9272                    if (!list.isEmpty()) {
9273                            return list.get(0);
9274                    }
9275    
9276                    return null;
9277            }
9278    
9279            /**
9280             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9281             *
9282             * @param threadId the thread ID
9283             * @param parentMessageId the parent message ID
9284             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9285             * @return the last matching message-boards message
9286             * @throws NoSuchMessageException if a matching message-boards message could not be found
9287             */
9288            @Override
9289            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9290                    OrderByComparator<MBMessage> orderByComparator)
9291                    throws NoSuchMessageException {
9292                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9293                                    orderByComparator);
9294    
9295                    if (mbMessage != null) {
9296                            return mbMessage;
9297                    }
9298    
9299                    StringBundler msg = new StringBundler(6);
9300    
9301                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9302    
9303                    msg.append("threadId=");
9304                    msg.append(threadId);
9305    
9306                    msg.append(", parentMessageId=");
9307                    msg.append(parentMessageId);
9308    
9309                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9310    
9311                    throw new NoSuchMessageException(msg.toString());
9312            }
9313    
9314            /**
9315             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9316             *
9317             * @param threadId the thread ID
9318             * @param parentMessageId the parent message ID
9319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9320             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9321             */
9322            @Override
9323            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9324                    OrderByComparator<MBMessage> orderByComparator) {
9325                    int count = countByT_P(threadId, parentMessageId);
9326    
9327                    if (count == 0) {
9328                            return null;
9329                    }
9330    
9331                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9332                                    count, orderByComparator);
9333    
9334                    if (!list.isEmpty()) {
9335                            return list.get(0);
9336                    }
9337    
9338                    return null;
9339            }
9340    
9341            /**
9342             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9343             *
9344             * @param messageId the primary key of the current message-boards message
9345             * @param threadId the thread ID
9346             * @param parentMessageId the parent message ID
9347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9348             * @return the previous, current, and next message-boards message
9349             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9350             */
9351            @Override
9352            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9353                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
9354                    throws NoSuchMessageException {
9355                    MBMessage mbMessage = findByPrimaryKey(messageId);
9356    
9357                    Session session = null;
9358    
9359                    try {
9360                            session = openSession();
9361    
9362                            MBMessage[] array = new MBMessageImpl[3];
9363    
9364                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9365                                            parentMessageId, orderByComparator, true);
9366    
9367                            array[1] = mbMessage;
9368    
9369                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9370                                            parentMessageId, orderByComparator, false);
9371    
9372                            return array;
9373                    }
9374                    catch (Exception e) {
9375                            throw processException(e);
9376                    }
9377                    finally {
9378                            closeSession(session);
9379                    }
9380            }
9381    
9382            protected MBMessage getByT_P_PrevAndNext(Session session,
9383                    MBMessage mbMessage, long threadId, long parentMessageId,
9384                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9385                    StringBundler query = null;
9386    
9387                    if (orderByComparator != null) {
9388                            query = new StringBundler(5 +
9389                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9390                                            (orderByComparator.getOrderByFields().length * 3));
9391                    }
9392                    else {
9393                            query = new StringBundler(4);
9394                    }
9395    
9396                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9397    
9398                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9399    
9400                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9401    
9402                    if (orderByComparator != null) {
9403                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9404    
9405                            if (orderByConditionFields.length > 0) {
9406                                    query.append(WHERE_AND);
9407                            }
9408    
9409                            for (int i = 0; i < orderByConditionFields.length; i++) {
9410                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9411                                    query.append(orderByConditionFields[i]);
9412    
9413                                    if ((i + 1) < orderByConditionFields.length) {
9414                                            if (orderByComparator.isAscending() ^ previous) {
9415                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9416                                            }
9417                                            else {
9418                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9419                                            }
9420                                    }
9421                                    else {
9422                                            if (orderByComparator.isAscending() ^ previous) {
9423                                                    query.append(WHERE_GREATER_THAN);
9424                                            }
9425                                            else {
9426                                                    query.append(WHERE_LESSER_THAN);
9427                                            }
9428                                    }
9429                            }
9430    
9431                            query.append(ORDER_BY_CLAUSE);
9432    
9433                            String[] orderByFields = orderByComparator.getOrderByFields();
9434    
9435                            for (int i = 0; i < orderByFields.length; i++) {
9436                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9437                                    query.append(orderByFields[i]);
9438    
9439                                    if ((i + 1) < orderByFields.length) {
9440                                            if (orderByComparator.isAscending() ^ previous) {
9441                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9442                                            }
9443                                            else {
9444                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9445                                            }
9446                                    }
9447                                    else {
9448                                            if (orderByComparator.isAscending() ^ previous) {
9449                                                    query.append(ORDER_BY_ASC);
9450                                            }
9451                                            else {
9452                                                    query.append(ORDER_BY_DESC);
9453                                            }
9454                                    }
9455                            }
9456                    }
9457                    else {
9458                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9459                    }
9460    
9461                    String sql = query.toString();
9462    
9463                    Query q = session.createQuery(sql);
9464    
9465                    q.setFirstResult(0);
9466                    q.setMaxResults(2);
9467    
9468                    QueryPos qPos = QueryPos.getInstance(q);
9469    
9470                    qPos.add(threadId);
9471    
9472                    qPos.add(parentMessageId);
9473    
9474                    if (orderByComparator != null) {
9475                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9476    
9477                            for (Object value : values) {
9478                                    qPos.add(value);
9479                            }
9480                    }
9481    
9482                    List<MBMessage> list = q.list();
9483    
9484                    if (list.size() == 2) {
9485                            return list.get(1);
9486                    }
9487                    else {
9488                            return null;
9489                    }
9490            }
9491    
9492            /**
9493             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9494             *
9495             * @param threadId the thread ID
9496             * @param parentMessageId the parent message ID
9497             */
9498            @Override
9499            public void removeByT_P(long threadId, long parentMessageId) {
9500                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9501                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9502                            remove(mbMessage);
9503                    }
9504            }
9505    
9506            /**
9507             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9508             *
9509             * @param threadId the thread ID
9510             * @param parentMessageId the parent message ID
9511             * @return the number of matching message-boards messages
9512             */
9513            @Override
9514            public int countByT_P(long threadId, long parentMessageId) {
9515                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9516    
9517                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9518    
9519                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9520    
9521                    if (count == null) {
9522                            StringBundler query = new StringBundler(3);
9523    
9524                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9525    
9526                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9527    
9528                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9529    
9530                            String sql = query.toString();
9531    
9532                            Session session = null;
9533    
9534                            try {
9535                                    session = openSession();
9536    
9537                                    Query q = session.createQuery(sql);
9538    
9539                                    QueryPos qPos = QueryPos.getInstance(q);
9540    
9541                                    qPos.add(threadId);
9542    
9543                                    qPos.add(parentMessageId);
9544    
9545                                    count = (Long)q.uniqueResult();
9546    
9547                                    finderCache.putResult(finderPath, finderArgs, count);
9548                            }
9549                            catch (Exception e) {
9550                                    finderCache.removeResult(finderPath, finderArgs);
9551    
9552                                    throw processException(e);
9553                            }
9554                            finally {
9555                                    closeSession(session);
9556                            }
9557                    }
9558    
9559                    return count.intValue();
9560            }
9561    
9562            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9563            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9564            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9565                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9566                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9567                            new String[] {
9568                                    Long.class.getName(), Boolean.class.getName(),
9569                                    
9570                            Integer.class.getName(), Integer.class.getName(),
9571                                    OrderByComparator.class.getName()
9572                            });
9573            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9574                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9575                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9576                            new String[] { Long.class.getName(), Boolean.class.getName() },
9577                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9578                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9579                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9580            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9581                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9582                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9583                            new String[] { Long.class.getName(), Boolean.class.getName() });
9584    
9585            /**
9586             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9587             *
9588             * @param threadId the thread ID
9589             * @param answer the answer
9590             * @return the matching message-boards messages
9591             */
9592            @Override
9593            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9594                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9595                            QueryUtil.ALL_POS, null);
9596            }
9597    
9598            /**
9599             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9600             *
9601             * <p>
9602             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9603             * </p>
9604             *
9605             * @param threadId the thread ID
9606             * @param answer the answer
9607             * @param start the lower bound of the range of message-boards messages
9608             * @param end the upper bound of the range of message-boards messages (not inclusive)
9609             * @return the range of matching message-boards messages
9610             */
9611            @Override
9612            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9613                    int end) {
9614                    return findByT_A(threadId, answer, start, end, null);
9615            }
9616    
9617            /**
9618             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9619             *
9620             * <p>
9621             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9622             * </p>
9623             *
9624             * @param threadId the thread ID
9625             * @param answer the answer
9626             * @param start the lower bound of the range of message-boards messages
9627             * @param end the upper bound of the range of message-boards messages (not inclusive)
9628             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9629             * @return the ordered range of matching message-boards messages
9630             */
9631            @Override
9632            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9633                    int end, OrderByComparator<MBMessage> orderByComparator) {
9634                    return findByT_A(threadId, answer, start, end, orderByComparator, true);
9635            }
9636    
9637            /**
9638             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9639             *
9640             * <p>
9641             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9642             * </p>
9643             *
9644             * @param threadId the thread ID
9645             * @param answer the answer
9646             * @param start the lower bound of the range of message-boards messages
9647             * @param end the upper bound of the range of message-boards messages (not inclusive)
9648             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9649             * @param retrieveFromCache whether to retrieve from the finder cache
9650             * @return the ordered range of matching message-boards messages
9651             */
9652            @Override
9653            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9654                    int end, OrderByComparator<MBMessage> orderByComparator,
9655                    boolean retrieveFromCache) {
9656                    boolean pagination = true;
9657                    FinderPath finderPath = null;
9658                    Object[] finderArgs = null;
9659    
9660                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9661                                    (orderByComparator == null)) {
9662                            pagination = false;
9663                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9664                            finderArgs = new Object[] { threadId, answer };
9665                    }
9666                    else {
9667                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9668                            finderArgs = new Object[] {
9669                                            threadId, answer,
9670                                            
9671                                            start, end, orderByComparator
9672                                    };
9673                    }
9674    
9675                    List<MBMessage> list = null;
9676    
9677                    if (retrieveFromCache) {
9678                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9679                                            finderArgs, this);
9680    
9681                            if ((list != null) && !list.isEmpty()) {
9682                                    for (MBMessage mbMessage : list) {
9683                                            if ((threadId != mbMessage.getThreadId()) ||
9684                                                            (answer != mbMessage.getAnswer())) {
9685                                                    list = null;
9686    
9687                                                    break;
9688                                            }
9689                                    }
9690                            }
9691                    }
9692    
9693                    if (list == null) {
9694                            StringBundler query = null;
9695    
9696                            if (orderByComparator != null) {
9697                                    query = new StringBundler(4 +
9698                                                    (orderByComparator.getOrderByFields().length * 2));
9699                            }
9700                            else {
9701                                    query = new StringBundler(4);
9702                            }
9703    
9704                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9705    
9706                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9707    
9708                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9709    
9710                            if (orderByComparator != null) {
9711                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9712                                            orderByComparator);
9713                            }
9714                            else
9715                             if (pagination) {
9716                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9717                            }
9718    
9719                            String sql = query.toString();
9720    
9721                            Session session = null;
9722    
9723                            try {
9724                                    session = openSession();
9725    
9726                                    Query q = session.createQuery(sql);
9727    
9728                                    QueryPos qPos = QueryPos.getInstance(q);
9729    
9730                                    qPos.add(threadId);
9731    
9732                                    qPos.add(answer);
9733    
9734                                    if (!pagination) {
9735                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9736                                                            start, end, false);
9737    
9738                                            Collections.sort(list);
9739    
9740                                            list = Collections.unmodifiableList(list);
9741                                    }
9742                                    else {
9743                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9744                                                            start, end);
9745                                    }
9746    
9747                                    cacheResult(list);
9748    
9749                                    finderCache.putResult(finderPath, finderArgs, list);
9750                            }
9751                            catch (Exception e) {
9752                                    finderCache.removeResult(finderPath, finderArgs);
9753    
9754                                    throw processException(e);
9755                            }
9756                            finally {
9757                                    closeSession(session);
9758                            }
9759                    }
9760    
9761                    return list;
9762            }
9763    
9764            /**
9765             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9766             *
9767             * @param threadId the thread ID
9768             * @param answer the answer
9769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9770             * @return the first matching message-boards message
9771             * @throws NoSuchMessageException if a matching message-boards message could not be found
9772             */
9773            @Override
9774            public MBMessage findByT_A_First(long threadId, boolean answer,
9775                    OrderByComparator<MBMessage> orderByComparator)
9776                    throws NoSuchMessageException {
9777                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9778                                    orderByComparator);
9779    
9780                    if (mbMessage != null) {
9781                            return mbMessage;
9782                    }
9783    
9784                    StringBundler msg = new StringBundler(6);
9785    
9786                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9787    
9788                    msg.append("threadId=");
9789                    msg.append(threadId);
9790    
9791                    msg.append(", answer=");
9792                    msg.append(answer);
9793    
9794                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9795    
9796                    throw new NoSuchMessageException(msg.toString());
9797            }
9798    
9799            /**
9800             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9801             *
9802             * @param threadId the thread ID
9803             * @param answer the answer
9804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9805             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9806             */
9807            @Override
9808            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9809                    OrderByComparator<MBMessage> orderByComparator) {
9810                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9811                                    orderByComparator);
9812    
9813                    if (!list.isEmpty()) {
9814                            return list.get(0);
9815                    }
9816    
9817                    return null;
9818            }
9819    
9820            /**
9821             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9822             *
9823             * @param threadId the thread ID
9824             * @param answer the answer
9825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9826             * @return the last matching message-boards message
9827             * @throws NoSuchMessageException if a matching message-boards message could not be found
9828             */
9829            @Override
9830            public MBMessage findByT_A_Last(long threadId, boolean answer,
9831                    OrderByComparator<MBMessage> orderByComparator)
9832                    throws NoSuchMessageException {
9833                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9834                                    orderByComparator);
9835    
9836                    if (mbMessage != null) {
9837                            return mbMessage;
9838                    }
9839    
9840                    StringBundler msg = new StringBundler(6);
9841    
9842                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9843    
9844                    msg.append("threadId=");
9845                    msg.append(threadId);
9846    
9847                    msg.append(", answer=");
9848                    msg.append(answer);
9849    
9850                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9851    
9852                    throw new NoSuchMessageException(msg.toString());
9853            }
9854    
9855            /**
9856             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9857             *
9858             * @param threadId the thread ID
9859             * @param answer the answer
9860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9861             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9862             */
9863            @Override
9864            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9865                    OrderByComparator<MBMessage> orderByComparator) {
9866                    int count = countByT_A(threadId, answer);
9867    
9868                    if (count == 0) {
9869                            return null;
9870                    }
9871    
9872                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9873                                    orderByComparator);
9874    
9875                    if (!list.isEmpty()) {
9876                            return list.get(0);
9877                    }
9878    
9879                    return null;
9880            }
9881    
9882            /**
9883             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9884             *
9885             * @param messageId the primary key of the current message-boards message
9886             * @param threadId the thread ID
9887             * @param answer the answer
9888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9889             * @return the previous, current, and next message-boards message
9890             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9891             */
9892            @Override
9893            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9894                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9895                    throws NoSuchMessageException {
9896                    MBMessage mbMessage = findByPrimaryKey(messageId);
9897    
9898                    Session session = null;
9899    
9900                    try {
9901                            session = openSession();
9902    
9903                            MBMessage[] array = new MBMessageImpl[3];
9904    
9905                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9906                                            answer, orderByComparator, true);
9907    
9908                            array[1] = mbMessage;
9909    
9910                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9911                                            answer, orderByComparator, false);
9912    
9913                            return array;
9914                    }
9915                    catch (Exception e) {
9916                            throw processException(e);
9917                    }
9918                    finally {
9919                            closeSession(session);
9920                    }
9921            }
9922    
9923            protected MBMessage getByT_A_PrevAndNext(Session session,
9924                    MBMessage mbMessage, long threadId, boolean answer,
9925                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9926                    StringBundler query = null;
9927    
9928                    if (orderByComparator != null) {
9929                            query = new StringBundler(5 +
9930                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9931                                            (orderByComparator.getOrderByFields().length * 3));
9932                    }
9933                    else {
9934                            query = new StringBundler(4);
9935                    }
9936    
9937                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9938    
9939                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9940    
9941                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9942    
9943                    if (orderByComparator != null) {
9944                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9945    
9946                            if (orderByConditionFields.length > 0) {
9947                                    query.append(WHERE_AND);
9948                            }
9949    
9950                            for (int i = 0; i < orderByConditionFields.length; i++) {
9951                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9952                                    query.append(orderByConditionFields[i]);
9953    
9954                                    if ((i + 1) < orderByConditionFields.length) {
9955                                            if (orderByComparator.isAscending() ^ previous) {
9956                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9957                                            }
9958                                            else {
9959                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9960                                            }
9961                                    }
9962                                    else {
9963                                            if (orderByComparator.isAscending() ^ previous) {
9964                                                    query.append(WHERE_GREATER_THAN);
9965                                            }
9966                                            else {
9967                                                    query.append(WHERE_LESSER_THAN);
9968                                            }
9969                                    }
9970                            }
9971    
9972                            query.append(ORDER_BY_CLAUSE);
9973    
9974                            String[] orderByFields = orderByComparator.getOrderByFields();
9975    
9976                            for (int i = 0; i < orderByFields.length; i++) {
9977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9978                                    query.append(orderByFields[i]);
9979    
9980                                    if ((i + 1) < orderByFields.length) {
9981                                            if (orderByComparator.isAscending() ^ previous) {
9982                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9983                                            }
9984                                            else {
9985                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9986                                            }
9987                                    }
9988                                    else {
9989                                            if (orderByComparator.isAscending() ^ previous) {
9990                                                    query.append(ORDER_BY_ASC);
9991                                            }
9992                                            else {
9993                                                    query.append(ORDER_BY_DESC);
9994                                            }
9995                                    }
9996                            }
9997                    }
9998                    else {
9999                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10000                    }
10001    
10002                    String sql = query.toString();
10003    
10004                    Query q = session.createQuery(sql);
10005    
10006                    q.setFirstResult(0);
10007                    q.setMaxResults(2);
10008    
10009                    QueryPos qPos = QueryPos.getInstance(q);
10010    
10011                    qPos.add(threadId);
10012    
10013                    qPos.add(answer);
10014    
10015                    if (orderByComparator != null) {
10016                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10017    
10018                            for (Object value : values) {
10019                                    qPos.add(value);
10020                            }
10021                    }
10022    
10023                    List<MBMessage> list = q.list();
10024    
10025                    if (list.size() == 2) {
10026                            return list.get(1);
10027                    }
10028                    else {
10029                            return null;
10030                    }
10031            }
10032    
10033            /**
10034             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
10035             *
10036             * @param threadId the thread ID
10037             * @param answer the answer
10038             */
10039            @Override
10040            public void removeByT_A(long threadId, boolean answer) {
10041                    for (MBMessage mbMessage : findByT_A(threadId, answer,
10042                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10043                            remove(mbMessage);
10044                    }
10045            }
10046    
10047            /**
10048             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
10049             *
10050             * @param threadId the thread ID
10051             * @param answer the answer
10052             * @return the number of matching message-boards messages
10053             */
10054            @Override
10055            public int countByT_A(long threadId, boolean answer) {
10056                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
10057    
10058                    Object[] finderArgs = new Object[] { threadId, answer };
10059    
10060                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10061    
10062                    if (count == null) {
10063                            StringBundler query = new StringBundler(3);
10064    
10065                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10066    
10067                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
10068    
10069                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
10070    
10071                            String sql = query.toString();
10072    
10073                            Session session = null;
10074    
10075                            try {
10076                                    session = openSession();
10077    
10078                                    Query q = session.createQuery(sql);
10079    
10080                                    QueryPos qPos = QueryPos.getInstance(q);
10081    
10082                                    qPos.add(threadId);
10083    
10084                                    qPos.add(answer);
10085    
10086                                    count = (Long)q.uniqueResult();
10087    
10088                                    finderCache.putResult(finderPath, finderArgs, count);
10089                            }
10090                            catch (Exception e) {
10091                                    finderCache.removeResult(finderPath, finderArgs);
10092    
10093                                    throw processException(e);
10094                            }
10095                            finally {
10096                                    closeSession(session);
10097                            }
10098                    }
10099    
10100                    return count.intValue();
10101            }
10102    
10103            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
10104            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
10105            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10106                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10107                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
10108                            new String[] {
10109                                    Long.class.getName(), Integer.class.getName(),
10110                                    
10111                            Integer.class.getName(), Integer.class.getName(),
10112                                    OrderByComparator.class.getName()
10113                            });
10114            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
10117                            new String[] { Long.class.getName(), Integer.class.getName() },
10118                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10119                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10120                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10121            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10122                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10123                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
10124                            new String[] { Long.class.getName(), Integer.class.getName() });
10125    
10126            /**
10127             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10128             *
10129             * @param threadId the thread ID
10130             * @param status the status
10131             * @return the matching message-boards messages
10132             */
10133            @Override
10134            public List<MBMessage> findByT_S(long threadId, int status) {
10135                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
10136                            QueryUtil.ALL_POS, null);
10137            }
10138    
10139            /**
10140             * Returns a 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             * @return the range of matching message-boards messages
10151             */
10152            @Override
10153            public List<MBMessage> findByT_S(long threadId, int status, int start,
10154                    int end) {
10155                    return findByT_S(threadId, status, start, end, null);
10156            }
10157    
10158            /**
10159             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10160             *
10161             * <p>
10162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10163             * </p>
10164             *
10165             * @param threadId the thread ID
10166             * @param status the status
10167             * @param start the lower bound of the range of message-boards messages
10168             * @param end the upper bound of the range of message-boards messages (not inclusive)
10169             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10170             * @return the ordered range of matching message-boards messages
10171             */
10172            @Override
10173            public List<MBMessage> findByT_S(long threadId, int status, int start,
10174                    int end, OrderByComparator<MBMessage> orderByComparator) {
10175                    return findByT_S(threadId, status, start, end, orderByComparator, true);
10176            }
10177    
10178            /**
10179             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10180             *
10181             * <p>
10182             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10183             * </p>
10184             *
10185             * @param threadId the thread ID
10186             * @param status the status
10187             * @param start the lower bound of the range of message-boards messages
10188             * @param end the upper bound of the range of message-boards messages (not inclusive)
10189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10190             * @param retrieveFromCache whether to retrieve from the finder cache
10191             * @return the ordered range of matching message-boards messages
10192             */
10193            @Override
10194            public List<MBMessage> findByT_S(long threadId, int status, int start,
10195                    int end, OrderByComparator<MBMessage> orderByComparator,
10196                    boolean retrieveFromCache) {
10197                    boolean pagination = true;
10198                    FinderPath finderPath = null;
10199                    Object[] finderArgs = null;
10200    
10201                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10202                                    (orderByComparator == null)) {
10203                            pagination = false;
10204                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10205                            finderArgs = new Object[] { threadId, status };
10206                    }
10207                    else {
10208                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10209                            finderArgs = new Object[] {
10210                                            threadId, status,
10211                                            
10212                                            start, end, orderByComparator
10213                                    };
10214                    }
10215    
10216                    List<MBMessage> list = null;
10217    
10218                    if (retrieveFromCache) {
10219                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10220                                            finderArgs, this);
10221    
10222                            if ((list != null) && !list.isEmpty()) {
10223                                    for (MBMessage mbMessage : list) {
10224                                            if ((threadId != mbMessage.getThreadId()) ||
10225                                                            (status != mbMessage.getStatus())) {
10226                                                    list = null;
10227    
10228                                                    break;
10229                                            }
10230                                    }
10231                            }
10232                    }
10233    
10234                    if (list == null) {
10235                            StringBundler query = null;
10236    
10237                            if (orderByComparator != null) {
10238                                    query = new StringBundler(4 +
10239                                                    (orderByComparator.getOrderByFields().length * 2));
10240                            }
10241                            else {
10242                                    query = new StringBundler(4);
10243                            }
10244    
10245                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10246    
10247                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10248    
10249                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10250    
10251                            if (orderByComparator != null) {
10252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10253                                            orderByComparator);
10254                            }
10255                            else
10256                             if (pagination) {
10257                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10258                            }
10259    
10260                            String sql = query.toString();
10261    
10262                            Session session = null;
10263    
10264                            try {
10265                                    session = openSession();
10266    
10267                                    Query q = session.createQuery(sql);
10268    
10269                                    QueryPos qPos = QueryPos.getInstance(q);
10270    
10271                                    qPos.add(threadId);
10272    
10273                                    qPos.add(status);
10274    
10275                                    if (!pagination) {
10276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10277                                                            start, end, false);
10278    
10279                                            Collections.sort(list);
10280    
10281                                            list = Collections.unmodifiableList(list);
10282                                    }
10283                                    else {
10284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10285                                                            start, end);
10286                                    }
10287    
10288                                    cacheResult(list);
10289    
10290                                    finderCache.putResult(finderPath, finderArgs, list);
10291                            }
10292                            catch (Exception e) {
10293                                    finderCache.removeResult(finderPath, finderArgs);
10294    
10295                                    throw processException(e);
10296                            }
10297                            finally {
10298                                    closeSession(session);
10299                            }
10300                    }
10301    
10302                    return list;
10303            }
10304    
10305            /**
10306             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10307             *
10308             * @param threadId the thread ID
10309             * @param status the status
10310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10311             * @return the first matching message-boards message
10312             * @throws NoSuchMessageException if a matching message-boards message could not be found
10313             */
10314            @Override
10315            public MBMessage findByT_S_First(long threadId, int status,
10316                    OrderByComparator<MBMessage> orderByComparator)
10317                    throws NoSuchMessageException {
10318                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10319                                    orderByComparator);
10320    
10321                    if (mbMessage != null) {
10322                            return mbMessage;
10323                    }
10324    
10325                    StringBundler msg = new StringBundler(6);
10326    
10327                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10328    
10329                    msg.append("threadId=");
10330                    msg.append(threadId);
10331    
10332                    msg.append(", status=");
10333                    msg.append(status);
10334    
10335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10336    
10337                    throw new NoSuchMessageException(msg.toString());
10338            }
10339    
10340            /**
10341             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10342             *
10343             * @param threadId the thread ID
10344             * @param status the status
10345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10346             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10347             */
10348            @Override
10349            public MBMessage fetchByT_S_First(long threadId, int status,
10350                    OrderByComparator<MBMessage> orderByComparator) {
10351                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10352                                    orderByComparator);
10353    
10354                    if (!list.isEmpty()) {
10355                            return list.get(0);
10356                    }
10357    
10358                    return null;
10359            }
10360    
10361            /**
10362             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10363             *
10364             * @param threadId the thread ID
10365             * @param status the status
10366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10367             * @return the last matching message-boards message
10368             * @throws NoSuchMessageException if a matching message-boards message could not be found
10369             */
10370            @Override
10371            public MBMessage findByT_S_Last(long threadId, int status,
10372                    OrderByComparator<MBMessage> orderByComparator)
10373                    throws NoSuchMessageException {
10374                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10375                                    orderByComparator);
10376    
10377                    if (mbMessage != null) {
10378                            return mbMessage;
10379                    }
10380    
10381                    StringBundler msg = new StringBundler(6);
10382    
10383                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10384    
10385                    msg.append("threadId=");
10386                    msg.append(threadId);
10387    
10388                    msg.append(", status=");
10389                    msg.append(status);
10390    
10391                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10392    
10393                    throw new NoSuchMessageException(msg.toString());
10394            }
10395    
10396            /**
10397             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10398             *
10399             * @param threadId the thread ID
10400             * @param status the status
10401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10402             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10403             */
10404            @Override
10405            public MBMessage fetchByT_S_Last(long threadId, int status,
10406                    OrderByComparator<MBMessage> orderByComparator) {
10407                    int count = countByT_S(threadId, status);
10408    
10409                    if (count == 0) {
10410                            return null;
10411                    }
10412    
10413                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10414                                    orderByComparator);
10415    
10416                    if (!list.isEmpty()) {
10417                            return list.get(0);
10418                    }
10419    
10420                    return null;
10421            }
10422    
10423            /**
10424             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10425             *
10426             * @param messageId the primary key of the current message-boards message
10427             * @param threadId the thread ID
10428             * @param status the status
10429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10430             * @return the previous, current, and next message-boards message
10431             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10432             */
10433            @Override
10434            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10435                    int status, OrderByComparator<MBMessage> orderByComparator)
10436                    throws NoSuchMessageException {
10437                    MBMessage mbMessage = findByPrimaryKey(messageId);
10438    
10439                    Session session = null;
10440    
10441                    try {
10442                            session = openSession();
10443    
10444                            MBMessage[] array = new MBMessageImpl[3];
10445    
10446                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10447                                            status, orderByComparator, true);
10448    
10449                            array[1] = mbMessage;
10450    
10451                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10452                                            status, orderByComparator, false);
10453    
10454                            return array;
10455                    }
10456                    catch (Exception e) {
10457                            throw processException(e);
10458                    }
10459                    finally {
10460                            closeSession(session);
10461                    }
10462            }
10463    
10464            protected MBMessage getByT_S_PrevAndNext(Session session,
10465                    MBMessage mbMessage, long threadId, int status,
10466                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10467                    StringBundler query = null;
10468    
10469                    if (orderByComparator != null) {
10470                            query = new StringBundler(5 +
10471                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10472                                            (orderByComparator.getOrderByFields().length * 3));
10473                    }
10474                    else {
10475                            query = new StringBundler(4);
10476                    }
10477    
10478                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10479    
10480                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10481    
10482                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10483    
10484                    if (orderByComparator != null) {
10485                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10486    
10487                            if (orderByConditionFields.length > 0) {
10488                                    query.append(WHERE_AND);
10489                            }
10490    
10491                            for (int i = 0; i < orderByConditionFields.length; i++) {
10492                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10493                                    query.append(orderByConditionFields[i]);
10494    
10495                                    if ((i + 1) < orderByConditionFields.length) {
10496                                            if (orderByComparator.isAscending() ^ previous) {
10497                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10498                                            }
10499                                            else {
10500                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10501                                            }
10502                                    }
10503                                    else {
10504                                            if (orderByComparator.isAscending() ^ previous) {
10505                                                    query.append(WHERE_GREATER_THAN);
10506                                            }
10507                                            else {
10508                                                    query.append(WHERE_LESSER_THAN);
10509                                            }
10510                                    }
10511                            }
10512    
10513                            query.append(ORDER_BY_CLAUSE);
10514    
10515                            String[] orderByFields = orderByComparator.getOrderByFields();
10516    
10517                            for (int i = 0; i < orderByFields.length; i++) {
10518                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10519                                    query.append(orderByFields[i]);
10520    
10521                                    if ((i + 1) < orderByFields.length) {
10522                                            if (orderByComparator.isAscending() ^ previous) {
10523                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10524                                            }
10525                                            else {
10526                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10527                                            }
10528                                    }
10529                                    else {
10530                                            if (orderByComparator.isAscending() ^ previous) {
10531                                                    query.append(ORDER_BY_ASC);
10532                                            }
10533                                            else {
10534                                                    query.append(ORDER_BY_DESC);
10535                                            }
10536                                    }
10537                            }
10538                    }
10539                    else {
10540                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10541                    }
10542    
10543                    String sql = query.toString();
10544    
10545                    Query q = session.createQuery(sql);
10546    
10547                    q.setFirstResult(0);
10548                    q.setMaxResults(2);
10549    
10550                    QueryPos qPos = QueryPos.getInstance(q);
10551    
10552                    qPos.add(threadId);
10553    
10554                    qPos.add(status);
10555    
10556                    if (orderByComparator != null) {
10557                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10558    
10559                            for (Object value : values) {
10560                                    qPos.add(value);
10561                            }
10562                    }
10563    
10564                    List<MBMessage> list = q.list();
10565    
10566                    if (list.size() == 2) {
10567                            return list.get(1);
10568                    }
10569                    else {
10570                            return null;
10571                    }
10572            }
10573    
10574            /**
10575             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10576             *
10577             * @param threadId the thread ID
10578             * @param status the status
10579             */
10580            @Override
10581            public void removeByT_S(long threadId, int status) {
10582                    for (MBMessage mbMessage : findByT_S(threadId, status,
10583                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10584                            remove(mbMessage);
10585                    }
10586            }
10587    
10588            /**
10589             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10590             *
10591             * @param threadId the thread ID
10592             * @param status the status
10593             * @return the number of matching message-boards messages
10594             */
10595            @Override
10596            public int countByT_S(long threadId, int status) {
10597                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10598    
10599                    Object[] finderArgs = new Object[] { threadId, status };
10600    
10601                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10602    
10603                    if (count == null) {
10604                            StringBundler query = new StringBundler(3);
10605    
10606                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10607    
10608                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10609    
10610                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10611    
10612                            String sql = query.toString();
10613    
10614                            Session session = null;
10615    
10616                            try {
10617                                    session = openSession();
10618    
10619                                    Query q = session.createQuery(sql);
10620    
10621                                    QueryPos qPos = QueryPos.getInstance(q);
10622    
10623                                    qPos.add(threadId);
10624    
10625                                    qPos.add(status);
10626    
10627                                    count = (Long)q.uniqueResult();
10628    
10629                                    finderCache.putResult(finderPath, finderArgs, count);
10630                            }
10631                            catch (Exception e) {
10632                                    finderCache.removeResult(finderPath, finderArgs);
10633    
10634                                    throw processException(e);
10635                            }
10636                            finally {
10637                                    closeSession(session);
10638                            }
10639                    }
10640    
10641                    return count.intValue();
10642            }
10643    
10644            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10645            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10646            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10647                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10648                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10649                            new String[] {
10650                                    Long.class.getName(), Integer.class.getName(),
10651                                    
10652                            Integer.class.getName(), Integer.class.getName(),
10653                                    OrderByComparator.class.getName()
10654                            });
10655            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10656                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10657                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10658                            new String[] { Long.class.getName(), Integer.class.getName() },
10659                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10660                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10661                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10662            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10663                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10664                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10665                            new String[] { Long.class.getName(), Integer.class.getName() });
10666    
10667            /**
10668             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10669             *
10670             * @param threadId the thread ID
10671             * @param status the status
10672             * @return the matching message-boards messages
10673             */
10674            @Override
10675            public List<MBMessage> findByTR_S(long threadId, int status) {
10676                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10677                            QueryUtil.ALL_POS, null);
10678            }
10679    
10680            /**
10681             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10682             *
10683             * <p>
10684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10685             * </p>
10686             *
10687             * @param threadId the thread ID
10688             * @param status the status
10689             * @param start the lower bound of the range of message-boards messages
10690             * @param end the upper bound of the range of message-boards messages (not inclusive)
10691             * @return the range of matching message-boards messages
10692             */
10693            @Override
10694            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10695                    int end) {
10696                    return findByTR_S(threadId, status, start, end, null);
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             * @return the ordered range of matching message-boards messages
10712             */
10713            @Override
10714            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10715                    int end, OrderByComparator<MBMessage> orderByComparator) {
10716                    return findByTR_S(threadId, status, start, end, orderByComparator, true);
10717            }
10718    
10719            /**
10720             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10721             *
10722             * <p>
10723             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10724             * </p>
10725             *
10726             * @param threadId the thread ID
10727             * @param status the status
10728             * @param start the lower bound of the range of message-boards messages
10729             * @param end the upper bound of the range of message-boards messages (not inclusive)
10730             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10731             * @param retrieveFromCache whether to retrieve from the finder cache
10732             * @return the ordered range of matching message-boards messages
10733             */
10734            @Override
10735            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10736                    int end, OrderByComparator<MBMessage> orderByComparator,
10737                    boolean retrieveFromCache) {
10738                    boolean pagination = true;
10739                    FinderPath finderPath = null;
10740                    Object[] finderArgs = null;
10741    
10742                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10743                                    (orderByComparator == null)) {
10744                            pagination = false;
10745                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10746                            finderArgs = new Object[] { threadId, status };
10747                    }
10748                    else {
10749                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10750                            finderArgs = new Object[] {
10751                                            threadId, status,
10752                                            
10753                                            start, end, orderByComparator
10754                                    };
10755                    }
10756    
10757                    List<MBMessage> list = null;
10758    
10759                    if (retrieveFromCache) {
10760                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10761                                            finderArgs, this);
10762    
10763                            if ((list != null) && !list.isEmpty()) {
10764                                    for (MBMessage mbMessage : list) {
10765                                            if ((threadId != mbMessage.getThreadId()) ||
10766                                                            (status != mbMessage.getStatus())) {
10767                                                    list = null;
10768    
10769                                                    break;
10770                                            }
10771                                    }
10772                            }
10773                    }
10774    
10775                    if (list == null) {
10776                            StringBundler query = null;
10777    
10778                            if (orderByComparator != null) {
10779                                    query = new StringBundler(4 +
10780                                                    (orderByComparator.getOrderByFields().length * 2));
10781                            }
10782                            else {
10783                                    query = new StringBundler(4);
10784                            }
10785    
10786                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10787    
10788                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10789    
10790                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10791    
10792                            if (orderByComparator != null) {
10793                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10794                                            orderByComparator);
10795                            }
10796                            else
10797                             if (pagination) {
10798                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10799                            }
10800    
10801                            String sql = query.toString();
10802    
10803                            Session session = null;
10804    
10805                            try {
10806                                    session = openSession();
10807    
10808                                    Query q = session.createQuery(sql);
10809    
10810                                    QueryPos qPos = QueryPos.getInstance(q);
10811    
10812                                    qPos.add(threadId);
10813    
10814                                    qPos.add(status);
10815    
10816                                    if (!pagination) {
10817                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10818                                                            start, end, false);
10819    
10820                                            Collections.sort(list);
10821    
10822                                            list = Collections.unmodifiableList(list);
10823                                    }
10824                                    else {
10825                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10826                                                            start, end);
10827                                    }
10828    
10829                                    cacheResult(list);
10830    
10831                                    finderCache.putResult(finderPath, finderArgs, list);
10832                            }
10833                            catch (Exception e) {
10834                                    finderCache.removeResult(finderPath, finderArgs);
10835    
10836                                    throw processException(e);
10837                            }
10838                            finally {
10839                                    closeSession(session);
10840                            }
10841                    }
10842    
10843                    return list;
10844            }
10845    
10846            /**
10847             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10848             *
10849             * @param threadId the thread ID
10850             * @param status the status
10851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10852             * @return the first matching message-boards message
10853             * @throws NoSuchMessageException if a matching message-boards message could not be found
10854             */
10855            @Override
10856            public MBMessage findByTR_S_First(long threadId, int status,
10857                    OrderByComparator<MBMessage> orderByComparator)
10858                    throws NoSuchMessageException {
10859                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10860                                    orderByComparator);
10861    
10862                    if (mbMessage != null) {
10863                            return mbMessage;
10864                    }
10865    
10866                    StringBundler msg = new StringBundler(6);
10867    
10868                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10869    
10870                    msg.append("threadId=");
10871                    msg.append(threadId);
10872    
10873                    msg.append(", status=");
10874                    msg.append(status);
10875    
10876                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10877    
10878                    throw new NoSuchMessageException(msg.toString());
10879            }
10880    
10881            /**
10882             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10883             *
10884             * @param threadId the thread ID
10885             * @param status the status
10886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10887             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10888             */
10889            @Override
10890            public MBMessage fetchByTR_S_First(long threadId, int status,
10891                    OrderByComparator<MBMessage> orderByComparator) {
10892                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10893                                    orderByComparator);
10894    
10895                    if (!list.isEmpty()) {
10896                            return list.get(0);
10897                    }
10898    
10899                    return null;
10900            }
10901    
10902            /**
10903             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10904             *
10905             * @param threadId the thread ID
10906             * @param status the status
10907             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10908             * @return the last matching message-boards message
10909             * @throws NoSuchMessageException if a matching message-boards message could not be found
10910             */
10911            @Override
10912            public MBMessage findByTR_S_Last(long threadId, int status,
10913                    OrderByComparator<MBMessage> orderByComparator)
10914                    throws NoSuchMessageException {
10915                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10916                                    orderByComparator);
10917    
10918                    if (mbMessage != null) {
10919                            return mbMessage;
10920                    }
10921    
10922                    StringBundler msg = new StringBundler(6);
10923    
10924                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10925    
10926                    msg.append("threadId=");
10927                    msg.append(threadId);
10928    
10929                    msg.append(", status=");
10930                    msg.append(status);
10931    
10932                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10933    
10934                    throw new NoSuchMessageException(msg.toString());
10935            }
10936    
10937            /**
10938             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10939             *
10940             * @param threadId the thread ID
10941             * @param status the status
10942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10943             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10944             */
10945            @Override
10946            public MBMessage fetchByTR_S_Last(long threadId, int status,
10947                    OrderByComparator<MBMessage> orderByComparator) {
10948                    int count = countByTR_S(threadId, status);
10949    
10950                    if (count == 0) {
10951                            return null;
10952                    }
10953    
10954                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10955                                    orderByComparator);
10956    
10957                    if (!list.isEmpty()) {
10958                            return list.get(0);
10959                    }
10960    
10961                    return null;
10962            }
10963    
10964            /**
10965             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10966             *
10967             * @param messageId the primary key of the current message-boards message
10968             * @param threadId the thread ID
10969             * @param status the status
10970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10971             * @return the previous, current, and next message-boards message
10972             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10973             */
10974            @Override
10975            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10976                    int status, OrderByComparator<MBMessage> orderByComparator)
10977                    throws NoSuchMessageException {
10978                    MBMessage mbMessage = findByPrimaryKey(messageId);
10979    
10980                    Session session = null;
10981    
10982                    try {
10983                            session = openSession();
10984    
10985                            MBMessage[] array = new MBMessageImpl[3];
10986    
10987                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10988                                            status, orderByComparator, true);
10989    
10990                            array[1] = mbMessage;
10991    
10992                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10993                                            status, orderByComparator, false);
10994    
10995                            return array;
10996                    }
10997                    catch (Exception e) {
10998                            throw processException(e);
10999                    }
11000                    finally {
11001                            closeSession(session);
11002                    }
11003            }
11004    
11005            protected MBMessage getByTR_S_PrevAndNext(Session session,
11006                    MBMessage mbMessage, long threadId, int status,
11007                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11008                    StringBundler query = null;
11009    
11010                    if (orderByComparator != null) {
11011                            query = new StringBundler(5 +
11012                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11013                                            (orderByComparator.getOrderByFields().length * 3));
11014                    }
11015                    else {
11016                            query = new StringBundler(4);
11017                    }
11018    
11019                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11020    
11021                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11022    
11023                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11024    
11025                    if (orderByComparator != null) {
11026                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11027    
11028                            if (orderByConditionFields.length > 0) {
11029                                    query.append(WHERE_AND);
11030                            }
11031    
11032                            for (int i = 0; i < orderByConditionFields.length; i++) {
11033                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11034                                    query.append(orderByConditionFields[i]);
11035    
11036                                    if ((i + 1) < orderByConditionFields.length) {
11037                                            if (orderByComparator.isAscending() ^ previous) {
11038                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11039                                            }
11040                                            else {
11041                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11042                                            }
11043                                    }
11044                                    else {
11045                                            if (orderByComparator.isAscending() ^ previous) {
11046                                                    query.append(WHERE_GREATER_THAN);
11047                                            }
11048                                            else {
11049                                                    query.append(WHERE_LESSER_THAN);
11050                                            }
11051                                    }
11052                            }
11053    
11054                            query.append(ORDER_BY_CLAUSE);
11055    
11056                            String[] orderByFields = orderByComparator.getOrderByFields();
11057    
11058                            for (int i = 0; i < orderByFields.length; i++) {
11059                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11060                                    query.append(orderByFields[i]);
11061    
11062                                    if ((i + 1) < orderByFields.length) {
11063                                            if (orderByComparator.isAscending() ^ previous) {
11064                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11065                                            }
11066                                            else {
11067                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11068                                            }
11069                                    }
11070                                    else {
11071                                            if (orderByComparator.isAscending() ^ previous) {
11072                                                    query.append(ORDER_BY_ASC);
11073                                            }
11074                                            else {
11075                                                    query.append(ORDER_BY_DESC);
11076                                            }
11077                                    }
11078                            }
11079                    }
11080                    else {
11081                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11082                    }
11083    
11084                    String sql = query.toString();
11085    
11086                    Query q = session.createQuery(sql);
11087    
11088                    q.setFirstResult(0);
11089                    q.setMaxResults(2);
11090    
11091                    QueryPos qPos = QueryPos.getInstance(q);
11092    
11093                    qPos.add(threadId);
11094    
11095                    qPos.add(status);
11096    
11097                    if (orderByComparator != null) {
11098                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11099    
11100                            for (Object value : values) {
11101                                    qPos.add(value);
11102                            }
11103                    }
11104    
11105                    List<MBMessage> list = q.list();
11106    
11107                    if (list.size() == 2) {
11108                            return list.get(1);
11109                    }
11110                    else {
11111                            return null;
11112                    }
11113            }
11114    
11115            /**
11116             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
11117             *
11118             * @param threadId the thread ID
11119             * @param status the status
11120             */
11121            @Override
11122            public void removeByTR_S(long threadId, int status) {
11123                    for (MBMessage mbMessage : findByTR_S(threadId, status,
11124                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11125                            remove(mbMessage);
11126                    }
11127            }
11128    
11129            /**
11130             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
11131             *
11132             * @param threadId the thread ID
11133             * @param status the status
11134             * @return the number of matching message-boards messages
11135             */
11136            @Override
11137            public int countByTR_S(long threadId, int status) {
11138                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
11139    
11140                    Object[] finderArgs = new Object[] { threadId, status };
11141    
11142                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
11143    
11144                    if (count == null) {
11145                            StringBundler query = new StringBundler(3);
11146    
11147                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11148    
11149                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11150    
11151                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11152    
11153                            String sql = query.toString();
11154    
11155                            Session session = null;
11156    
11157                            try {
11158                                    session = openSession();
11159    
11160                                    Query q = session.createQuery(sql);
11161    
11162                                    QueryPos qPos = QueryPos.getInstance(q);
11163    
11164                                    qPos.add(threadId);
11165    
11166                                    qPos.add(status);
11167    
11168                                    count = (Long)q.uniqueResult();
11169    
11170                                    finderCache.putResult(finderPath, finderArgs, count);
11171                            }
11172                            catch (Exception e) {
11173                                    finderCache.removeResult(finderPath, finderArgs);
11174    
11175                                    throw processException(e);
11176                            }
11177                            finally {
11178                                    closeSession(session);
11179                            }
11180                    }
11181    
11182                    return count.intValue();
11183            }
11184    
11185            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11186            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11187            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11188                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11189                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
11190                            new String[] {
11191                                    Long.class.getName(), Long.class.getName(),
11192                                    Integer.class.getName(),
11193                                    
11194                            Integer.class.getName(), Integer.class.getName(),
11195                                    OrderByComparator.class.getName()
11196                            });
11197            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11199                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
11200                            new String[] {
11201                                    Long.class.getName(), Long.class.getName(),
11202                                    Integer.class.getName()
11203                            },
11204                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11205                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
11206                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
11207                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11208            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11209                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11210                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
11211                            new String[] {
11212                                    Long.class.getName(), Long.class.getName(),
11213                                    Integer.class.getName()
11214                            });
11215    
11216            /**
11217             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11218             *
11219             * @param groupId the group ID
11220             * @param userId the user ID
11221             * @param status the status
11222             * @return the matching message-boards messages
11223             */
11224            @Override
11225            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
11226                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11227                            QueryUtil.ALL_POS, null);
11228            }
11229    
11230            /**
11231             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11232             *
11233             * <p>
11234             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11235             * </p>
11236             *
11237             * @param groupId the group ID
11238             * @param userId the user ID
11239             * @param status the status
11240             * @param start the lower bound of the range of message-boards messages
11241             * @param end the upper bound of the range of message-boards messages (not inclusive)
11242             * @return the 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) {
11247                    return findByG_U_S(groupId, userId, status, start, end, null);
11248            }
11249    
11250            /**
11251             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11252             *
11253             * <p>
11254             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11255             * </p>
11256             *
11257             * @param groupId the group ID
11258             * @param userId the user ID
11259             * @param status the status
11260             * @param start the lower bound of the range of message-boards messages
11261             * @param end the upper bound of the range of message-boards messages (not inclusive)
11262             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11263             * @return the ordered range of matching message-boards messages
11264             */
11265            @Override
11266            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11267                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
11268                    return findByG_U_S(groupId, userId, status, start, end,
11269                            orderByComparator, true);
11270            }
11271    
11272            /**
11273             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11274             *
11275             * <p>
11276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11277             * </p>
11278             *
11279             * @param groupId the group ID
11280             * @param userId the user ID
11281             * @param status the status
11282             * @param start the lower bound of the range of message-boards messages
11283             * @param end the upper bound of the range of message-boards messages (not inclusive)
11284             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11285             * @param retrieveFromCache whether to retrieve from the finder cache
11286             * @return the ordered range of matching message-boards messages
11287             */
11288            @Override
11289            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11290                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
11291                    boolean retrieveFromCache) {
11292                    boolean pagination = true;
11293                    FinderPath finderPath = null;
11294                    Object[] finderArgs = null;
11295    
11296                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11297                                    (orderByComparator == null)) {
11298                            pagination = false;
11299                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11300                            finderArgs = new Object[] { groupId, userId, status };
11301                    }
11302                    else {
11303                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11304                            finderArgs = new Object[] {
11305                                            groupId, userId, status,
11306                                            
11307                                            start, end, orderByComparator
11308                                    };
11309                    }
11310    
11311                    List<MBMessage> list = null;
11312    
11313                    if (retrieveFromCache) {
11314                            list = (List<MBMessage>)finderCache.getResult(finderPath,
11315                                            finderArgs, this);
11316    
11317                            if ((list != null) && !list.isEmpty()) {
11318                                    for (MBMessage mbMessage : list) {
11319                                            if ((groupId != mbMessage.getGroupId()) ||
11320                                                            (userId != mbMessage.getUserId()) ||
11321                                                            (status != mbMessage.getStatus())) {
11322                                                    list = null;
11323    
11324                                                    break;
11325                                            }
11326                                    }
11327                            }
11328                    }
11329    
11330                    if (list == null) {
11331                            StringBundler query = null;
11332    
11333                            if (orderByComparator != null) {
11334                                    query = new StringBundler(5 +
11335                                                    (orderByComparator.getOrderByFields().length * 2));
11336                            }
11337                            else {
11338                                    query = new StringBundler(5);
11339                            }
11340    
11341                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11342    
11343                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11344    
11345                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11346    
11347                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11348    
11349                            if (orderByComparator != null) {
11350                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11351                                            orderByComparator);
11352                            }
11353                            else
11354                             if (pagination) {
11355                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11356                            }
11357    
11358                            String sql = query.toString();
11359    
11360                            Session session = null;
11361    
11362                            try {
11363                                    session = openSession();
11364    
11365                                    Query q = session.createQuery(sql);
11366    
11367                                    QueryPos qPos = QueryPos.getInstance(q);
11368    
11369                                    qPos.add(groupId);
11370    
11371                                    qPos.add(userId);
11372    
11373                                    qPos.add(status);
11374    
11375                                    if (!pagination) {
11376                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11377                                                            start, end, false);
11378    
11379                                            Collections.sort(list);
11380    
11381                                            list = Collections.unmodifiableList(list);
11382                                    }
11383                                    else {
11384                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11385                                                            start, end);
11386                                    }
11387    
11388                                    cacheResult(list);
11389    
11390                                    finderCache.putResult(finderPath, finderArgs, list);
11391                            }
11392                            catch (Exception e) {
11393                                    finderCache.removeResult(finderPath, finderArgs);
11394    
11395                                    throw processException(e);
11396                            }
11397                            finally {
11398                                    closeSession(session);
11399                            }
11400                    }
11401    
11402                    return list;
11403            }
11404    
11405            /**
11406             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11407             *
11408             * @param groupId the group ID
11409             * @param userId the user ID
11410             * @param status the status
11411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11412             * @return the first matching message-boards message
11413             * @throws NoSuchMessageException if a matching message-boards message could not be found
11414             */
11415            @Override
11416            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11417                    OrderByComparator<MBMessage> orderByComparator)
11418                    throws NoSuchMessageException {
11419                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11420                                    orderByComparator);
11421    
11422                    if (mbMessage != null) {
11423                            return mbMessage;
11424                    }
11425    
11426                    StringBundler msg = new StringBundler(8);
11427    
11428                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11429    
11430                    msg.append("groupId=");
11431                    msg.append(groupId);
11432    
11433                    msg.append(", userId=");
11434                    msg.append(userId);
11435    
11436                    msg.append(", status=");
11437                    msg.append(status);
11438    
11439                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11440    
11441                    throw new NoSuchMessageException(msg.toString());
11442            }
11443    
11444            /**
11445             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11446             *
11447             * @param groupId the group ID
11448             * @param userId the user ID
11449             * @param status the status
11450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11451             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11452             */
11453            @Override
11454            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11455                    OrderByComparator<MBMessage> orderByComparator) {
11456                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11457                                    orderByComparator);
11458    
11459                    if (!list.isEmpty()) {
11460                            return list.get(0);
11461                    }
11462    
11463                    return null;
11464            }
11465    
11466            /**
11467             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11468             *
11469             * @param groupId the group ID
11470             * @param userId the user ID
11471             * @param status the status
11472             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11473             * @return the last matching message-boards message
11474             * @throws NoSuchMessageException if a matching message-boards message could not be found
11475             */
11476            @Override
11477            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11478                    OrderByComparator<MBMessage> orderByComparator)
11479                    throws NoSuchMessageException {
11480                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11481                                    orderByComparator);
11482    
11483                    if (mbMessage != null) {
11484                            return mbMessage;
11485                    }
11486    
11487                    StringBundler msg = new StringBundler(8);
11488    
11489                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11490    
11491                    msg.append("groupId=");
11492                    msg.append(groupId);
11493    
11494                    msg.append(", userId=");
11495                    msg.append(userId);
11496    
11497                    msg.append(", status=");
11498                    msg.append(status);
11499    
11500                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11501    
11502                    throw new NoSuchMessageException(msg.toString());
11503            }
11504    
11505            /**
11506             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11507             *
11508             * @param groupId the group ID
11509             * @param userId the user ID
11510             * @param status the status
11511             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11512             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11513             */
11514            @Override
11515            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11516                    OrderByComparator<MBMessage> orderByComparator) {
11517                    int count = countByG_U_S(groupId, userId, status);
11518    
11519                    if (count == 0) {
11520                            return null;
11521                    }
11522    
11523                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11524                                    count, orderByComparator);
11525    
11526                    if (!list.isEmpty()) {
11527                            return list.get(0);
11528                    }
11529    
11530                    return null;
11531            }
11532    
11533            /**
11534             * 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;.
11535             *
11536             * @param messageId the primary key of the current message-boards message
11537             * @param groupId the group ID
11538             * @param userId the user ID
11539             * @param status the status
11540             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11541             * @return the previous, current, and next message-boards message
11542             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11543             */
11544            @Override
11545            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11546                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11547                    throws NoSuchMessageException {
11548                    MBMessage mbMessage = findByPrimaryKey(messageId);
11549    
11550                    Session session = null;
11551    
11552                    try {
11553                            session = openSession();
11554    
11555                            MBMessage[] array = new MBMessageImpl[3];
11556    
11557                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11558                                            userId, status, orderByComparator, true);
11559    
11560                            array[1] = mbMessage;
11561    
11562                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11563                                            userId, status, orderByComparator, false);
11564    
11565                            return array;
11566                    }
11567                    catch (Exception e) {
11568                            throw processException(e);
11569                    }
11570                    finally {
11571                            closeSession(session);
11572                    }
11573            }
11574    
11575            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11576                    MBMessage mbMessage, long groupId, long userId, int status,
11577                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11578                    StringBundler query = null;
11579    
11580                    if (orderByComparator != null) {
11581                            query = new StringBundler(6 +
11582                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11583                                            (orderByComparator.getOrderByFields().length * 3));
11584                    }
11585                    else {
11586                            query = new StringBundler(5);
11587                    }
11588    
11589                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11590    
11591                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11592    
11593                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11594    
11595                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11596    
11597                    if (orderByComparator != null) {
11598                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11599    
11600                            if (orderByConditionFields.length > 0) {
11601                                    query.append(WHERE_AND);
11602                            }
11603    
11604                            for (int i = 0; i < orderByConditionFields.length; i++) {
11605                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11606                                    query.append(orderByConditionFields[i]);
11607    
11608                                    if ((i + 1) < orderByConditionFields.length) {
11609                                            if (orderByComparator.isAscending() ^ previous) {
11610                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11611                                            }
11612                                            else {
11613                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11614                                            }
11615                                    }
11616                                    else {
11617                                            if (orderByComparator.isAscending() ^ previous) {
11618                                                    query.append(WHERE_GREATER_THAN);
11619                                            }
11620                                            else {
11621                                                    query.append(WHERE_LESSER_THAN);
11622                                            }
11623                                    }
11624                            }
11625    
11626                            query.append(ORDER_BY_CLAUSE);
11627    
11628                            String[] orderByFields = orderByComparator.getOrderByFields();
11629    
11630                            for (int i = 0; i < orderByFields.length; i++) {
11631                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11632                                    query.append(orderByFields[i]);
11633    
11634                                    if ((i + 1) < orderByFields.length) {
11635                                            if (orderByComparator.isAscending() ^ previous) {
11636                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11637                                            }
11638                                            else {
11639                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11640                                            }
11641                                    }
11642                                    else {
11643                                            if (orderByComparator.isAscending() ^ previous) {
11644                                                    query.append(ORDER_BY_ASC);
11645                                            }
11646                                            else {
11647                                                    query.append(ORDER_BY_DESC);
11648                                            }
11649                                    }
11650                            }
11651                    }
11652                    else {
11653                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11654                    }
11655    
11656                    String sql = query.toString();
11657    
11658                    Query q = session.createQuery(sql);
11659    
11660                    q.setFirstResult(0);
11661                    q.setMaxResults(2);
11662    
11663                    QueryPos qPos = QueryPos.getInstance(q);
11664    
11665                    qPos.add(groupId);
11666    
11667                    qPos.add(userId);
11668    
11669                    qPos.add(status);
11670    
11671                    if (orderByComparator != null) {
11672                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11673    
11674                            for (Object value : values) {
11675                                    qPos.add(value);
11676                            }
11677                    }
11678    
11679                    List<MBMessage> list = q.list();
11680    
11681                    if (list.size() == 2) {
11682                            return list.get(1);
11683                    }
11684                    else {
11685                            return null;
11686                    }
11687            }
11688    
11689            /**
11690             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11691             *
11692             * @param groupId the group ID
11693             * @param userId the user ID
11694             * @param status the status
11695             * @return the matching message-boards messages that the user has permission to view
11696             */
11697            @Override
11698            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11699                    int status) {
11700                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11701                            QueryUtil.ALL_POS, null);
11702            }
11703    
11704            /**
11705             * 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;.
11706             *
11707             * <p>
11708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11709             * </p>
11710             *
11711             * @param groupId the group ID
11712             * @param userId the user ID
11713             * @param status the status
11714             * @param start the lower bound of the range of message-boards messages
11715             * @param end the upper bound of the range of message-boards messages (not inclusive)
11716             * @return the range of matching message-boards messages that the user has permission to view
11717             */
11718            @Override
11719            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11720                    int status, int start, int end) {
11721                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11722            }
11723    
11724            /**
11725             * 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;.
11726             *
11727             * <p>
11728             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11729             * </p>
11730             *
11731             * @param groupId the group ID
11732             * @param userId the user ID
11733             * @param status the status
11734             * @param start the lower bound of the range of message-boards messages
11735             * @param end the upper bound of the range of message-boards messages (not inclusive)
11736             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11737             * @return the ordered range of matching message-boards messages that the user has permission to view
11738             */
11739            @Override
11740            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11741                    int status, int start, int end,
11742                    OrderByComparator<MBMessage> orderByComparator) {
11743                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11744                            return findByG_U_S(groupId, userId, status, start, end,
11745                                    orderByComparator);
11746                    }
11747    
11748                    StringBundler query = null;
11749    
11750                    if (orderByComparator != null) {
11751                            query = new StringBundler(5 +
11752                                            (orderByComparator.getOrderByFields().length * 2));
11753                    }
11754                    else {
11755                            query = new StringBundler(6);
11756                    }
11757    
11758                    if (getDB().isSupportsInlineDistinct()) {
11759                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11760                    }
11761                    else {
11762                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11763                    }
11764    
11765                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11766    
11767                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11768    
11769                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11770    
11771                    if (!getDB().isSupportsInlineDistinct()) {
11772                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11773                    }
11774    
11775                    if (orderByComparator != null) {
11776                            if (getDB().isSupportsInlineDistinct()) {
11777                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11778                                            orderByComparator, true);
11779                            }
11780                            else {
11781                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11782                                            orderByComparator, true);
11783                            }
11784                    }
11785                    else {
11786                            if (getDB().isSupportsInlineDistinct()) {
11787                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11788                            }
11789                            else {
11790                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11791                            }
11792                    }
11793    
11794                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11795                                    MBMessage.class.getName(),
11796                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11797    
11798                    Session session = null;
11799    
11800                    try {
11801                            session = openSession();
11802    
11803                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11804    
11805                            if (getDB().isSupportsInlineDistinct()) {
11806                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11807                            }
11808                            else {
11809                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11810                            }
11811    
11812                            QueryPos qPos = QueryPos.getInstance(q);
11813    
11814                            qPos.add(groupId);
11815    
11816                            qPos.add(userId);
11817    
11818                            qPos.add(status);
11819    
11820                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11821                    }
11822                    catch (Exception e) {
11823                            throw processException(e);
11824                    }
11825                    finally {
11826                            closeSession(session);
11827                    }
11828            }
11829    
11830            /**
11831             * 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;.
11832             *
11833             * @param messageId the primary key of the current message-boards message
11834             * @param groupId the group ID
11835             * @param userId the user ID
11836             * @param status the status
11837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11838             * @return the previous, current, and next message-boards message
11839             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11840             */
11841            @Override
11842            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11843                    long groupId, long userId, int status,
11844                    OrderByComparator<MBMessage> orderByComparator)
11845                    throws NoSuchMessageException {
11846                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11847                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11848                                    orderByComparator);
11849                    }
11850    
11851                    MBMessage mbMessage = findByPrimaryKey(messageId);
11852    
11853                    Session session = null;
11854    
11855                    try {
11856                            session = openSession();
11857    
11858                            MBMessage[] array = new MBMessageImpl[3];
11859    
11860                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11861                                            groupId, userId, status, orderByComparator, true);
11862    
11863                            array[1] = mbMessage;
11864    
11865                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11866                                            groupId, userId, status, orderByComparator, false);
11867    
11868                            return array;
11869                    }
11870                    catch (Exception e) {
11871                            throw processException(e);
11872                    }
11873                    finally {
11874                            closeSession(session);
11875                    }
11876            }
11877    
11878            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11879                    MBMessage mbMessage, long groupId, long userId, int status,
11880                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11881                    StringBundler query = null;
11882    
11883                    if (orderByComparator != null) {
11884                            query = new StringBundler(7 +
11885                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11886                                            (orderByComparator.getOrderByFields().length * 3));
11887                    }
11888                    else {
11889                            query = new StringBundler(6);
11890                    }
11891    
11892                    if (getDB().isSupportsInlineDistinct()) {
11893                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11894                    }
11895                    else {
11896                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11897                    }
11898    
11899                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11900    
11901                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11902    
11903                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11904    
11905                    if (!getDB().isSupportsInlineDistinct()) {
11906                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11907                    }
11908    
11909                    if (orderByComparator != null) {
11910                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11911    
11912                            if (orderByConditionFields.length > 0) {
11913                                    query.append(WHERE_AND);
11914                            }
11915    
11916                            for (int i = 0; i < orderByConditionFields.length; i++) {
11917                                    if (getDB().isSupportsInlineDistinct()) {
11918                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11919                                    }
11920                                    else {
11921                                            query.append(_ORDER_BY_ENTITY_TABLE);
11922                                    }
11923    
11924                                    query.append(orderByConditionFields[i]);
11925    
11926                                    if ((i + 1) < orderByConditionFields.length) {
11927                                            if (orderByComparator.isAscending() ^ previous) {
11928                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11929                                            }
11930                                            else {
11931                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11932                                            }
11933                                    }
11934                                    else {
11935                                            if (orderByComparator.isAscending() ^ previous) {
11936                                                    query.append(WHERE_GREATER_THAN);
11937                                            }
11938                                            else {
11939                                                    query.append(WHERE_LESSER_THAN);
11940                                            }
11941                                    }
11942                            }
11943    
11944                            query.append(ORDER_BY_CLAUSE);
11945    
11946                            String[] orderByFields = orderByComparator.getOrderByFields();
11947    
11948                            for (int i = 0; i < orderByFields.length; i++) {
11949                                    if (getDB().isSupportsInlineDistinct()) {
11950                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11951                                    }
11952                                    else {
11953                                            query.append(_ORDER_BY_ENTITY_TABLE);
11954                                    }
11955    
11956                                    query.append(orderByFields[i]);
11957    
11958                                    if ((i + 1) < orderByFields.length) {
11959                                            if (orderByComparator.isAscending() ^ previous) {
11960                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11961                                            }
11962                                            else {
11963                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11964                                            }
11965                                    }
11966                                    else {
11967                                            if (orderByComparator.isAscending() ^ previous) {
11968                                                    query.append(ORDER_BY_ASC);
11969                                            }
11970                                            else {
11971                                                    query.append(ORDER_BY_DESC);
11972                                            }
11973                                    }
11974                            }
11975                    }
11976                    else {
11977                            if (getDB().isSupportsInlineDistinct()) {
11978                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11979                            }
11980                            else {
11981                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11982                            }
11983                    }
11984    
11985                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11986                                    MBMessage.class.getName(),
11987                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11988    
11989                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11990    
11991                    q.setFirstResult(0);
11992                    q.setMaxResults(2);
11993    
11994                    if (getDB().isSupportsInlineDistinct()) {
11995                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11996                    }
11997                    else {
11998                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11999                    }
12000    
12001                    QueryPos qPos = QueryPos.getInstance(q);
12002    
12003                    qPos.add(groupId);
12004    
12005                    qPos.add(userId);
12006    
12007                    qPos.add(status);
12008    
12009                    if (orderByComparator != null) {
12010                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12011    
12012                            for (Object value : values) {
12013                                    qPos.add(value);
12014                            }
12015                    }
12016    
12017                    List<MBMessage> list = q.list();
12018    
12019                    if (list.size() == 2) {
12020                            return list.get(1);
12021                    }
12022                    else {
12023                            return null;
12024                    }
12025            }
12026    
12027            /**
12028             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
12029             *
12030             * @param groupId the group ID
12031             * @param userId the user ID
12032             * @param status the status
12033             */
12034            @Override
12035            public void removeByG_U_S(long groupId, long userId, int status) {
12036                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
12037                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12038                            remove(mbMessage);
12039                    }
12040            }
12041    
12042            /**
12043             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
12044             *
12045             * @param groupId the group ID
12046             * @param userId the user ID
12047             * @param status the status
12048             * @return the number of matching message-boards messages
12049             */
12050            @Override
12051            public int countByG_U_S(long groupId, long userId, int status) {
12052                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
12053    
12054                    Object[] finderArgs = new Object[] { groupId, userId, status };
12055    
12056                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12057    
12058                    if (count == null) {
12059                            StringBundler query = new StringBundler(4);
12060    
12061                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12062    
12063                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12064    
12065                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12066    
12067                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12068    
12069                            String sql = query.toString();
12070    
12071                            Session session = null;
12072    
12073                            try {
12074                                    session = openSession();
12075    
12076                                    Query q = session.createQuery(sql);
12077    
12078                                    QueryPos qPos = QueryPos.getInstance(q);
12079    
12080                                    qPos.add(groupId);
12081    
12082                                    qPos.add(userId);
12083    
12084                                    qPos.add(status);
12085    
12086                                    count = (Long)q.uniqueResult();
12087    
12088                                    finderCache.putResult(finderPath, finderArgs, count);
12089                            }
12090                            catch (Exception e) {
12091                                    finderCache.removeResult(finderPath, finderArgs);
12092    
12093                                    throw processException(e);
12094                            }
12095                            finally {
12096                                    closeSession(session);
12097                            }
12098                    }
12099    
12100                    return count.intValue();
12101            }
12102    
12103            /**
12104             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
12105             *
12106             * @param groupId the group ID
12107             * @param userId the user ID
12108             * @param status the status
12109             * @return the number of matching message-boards messages that the user has permission to view
12110             */
12111            @Override
12112            public int filterCountByG_U_S(long groupId, long userId, int status) {
12113                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12114                            return countByG_U_S(groupId, userId, status);
12115                    }
12116    
12117                    StringBundler query = new StringBundler(4);
12118    
12119                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12120    
12121                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12122    
12123                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12124    
12125                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12126    
12127                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12128                                    MBMessage.class.getName(),
12129                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12130    
12131                    Session session = null;
12132    
12133                    try {
12134                            session = openSession();
12135    
12136                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12137    
12138                            q.addScalar(COUNT_COLUMN_NAME,
12139                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12140    
12141                            QueryPos qPos = QueryPos.getInstance(q);
12142    
12143                            qPos.add(groupId);
12144    
12145                            qPos.add(userId);
12146    
12147                            qPos.add(status);
12148    
12149                            Long count = (Long)q.uniqueResult();
12150    
12151                            return count.intValue();
12152                    }
12153                    catch (Exception e) {
12154                            throw processException(e);
12155                    }
12156                    finally {
12157                            closeSession(session);
12158                    }
12159            }
12160    
12161            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
12162            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
12163            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
12164            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12165                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12166                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
12167                            new String[] {
12168                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12169                                    
12170                            Integer.class.getName(), Integer.class.getName(),
12171                                    OrderByComparator.class.getName()
12172                            });
12173            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12174                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12175                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
12176                            new String[] {
12177                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12178                            },
12179                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12180                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12181                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
12182                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12183            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12184                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12185                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
12186                            new String[] {
12187                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12188                            });
12189    
12190            /**
12191             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12192             *
12193             * @param groupId the group ID
12194             * @param categoryId the category ID
12195             * @param threadId the thread ID
12196             * @return the matching message-boards messages
12197             */
12198            @Override
12199            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12200                    long threadId) {
12201                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
12202                            QueryUtil.ALL_POS, null);
12203            }
12204    
12205            /**
12206             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12207             *
12208             * <p>
12209             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12210             * </p>
12211             *
12212             * @param groupId the group ID
12213             * @param categoryId the category ID
12214             * @param threadId the thread ID
12215             * @param start the lower bound of the range of message-boards messages
12216             * @param end the upper bound of the range of message-boards messages (not inclusive)
12217             * @return the range of matching message-boards messages
12218             */
12219            @Override
12220            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12221                    long threadId, int start, int end) {
12222                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
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             * @return the ordered range of matching message-boards messages
12239             */
12240            @Override
12241            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12242                    long threadId, int start, int end,
12243                    OrderByComparator<MBMessage> orderByComparator) {
12244                    return findByG_C_T(groupId, categoryId, threadId, start, end,
12245                            orderByComparator, true);
12246            }
12247    
12248            /**
12249             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12250             *
12251             * <p>
12252             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12253             * </p>
12254             *
12255             * @param groupId the group ID
12256             * @param categoryId the category ID
12257             * @param threadId the thread ID
12258             * @param start the lower bound of the range of message-boards messages
12259             * @param end the upper bound of the range of message-boards messages (not inclusive)
12260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12261             * @param retrieveFromCache whether to retrieve from the finder cache
12262             * @return the ordered range of matching message-boards messages
12263             */
12264            @Override
12265            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12266                    long threadId, int start, int end,
12267                    OrderByComparator<MBMessage> orderByComparator,
12268                    boolean retrieveFromCache) {
12269                    boolean pagination = true;
12270                    FinderPath finderPath = null;
12271                    Object[] finderArgs = null;
12272    
12273                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12274                                    (orderByComparator == null)) {
12275                            pagination = false;
12276                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12277                            finderArgs = new Object[] { groupId, categoryId, threadId };
12278                    }
12279                    else {
12280                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12281                            finderArgs = new Object[] {
12282                                            groupId, categoryId, threadId,
12283                                            
12284                                            start, end, orderByComparator
12285                                    };
12286                    }
12287    
12288                    List<MBMessage> list = null;
12289    
12290                    if (retrieveFromCache) {
12291                            list = (List<MBMessage>)finderCache.getResult(finderPath,
12292                                            finderArgs, this);
12293    
12294                            if ((list != null) && !list.isEmpty()) {
12295                                    for (MBMessage mbMessage : list) {
12296                                            if ((groupId != mbMessage.getGroupId()) ||
12297                                                            (categoryId != mbMessage.getCategoryId()) ||
12298                                                            (threadId != mbMessage.getThreadId())) {
12299                                                    list = null;
12300    
12301                                                    break;
12302                                            }
12303                                    }
12304                            }
12305                    }
12306    
12307                    if (list == null) {
12308                            StringBundler query = null;
12309    
12310                            if (orderByComparator != null) {
12311                                    query = new StringBundler(5 +
12312                                                    (orderByComparator.getOrderByFields().length * 2));
12313                            }
12314                            else {
12315                                    query = new StringBundler(5);
12316                            }
12317    
12318                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12319    
12320                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12321    
12322                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12323    
12324                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12325    
12326                            if (orderByComparator != null) {
12327                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12328                                            orderByComparator);
12329                            }
12330                            else
12331                             if (pagination) {
12332                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12333                            }
12334    
12335                            String sql = query.toString();
12336    
12337                            Session session = null;
12338    
12339                            try {
12340                                    session = openSession();
12341    
12342                                    Query q = session.createQuery(sql);
12343    
12344                                    QueryPos qPos = QueryPos.getInstance(q);
12345    
12346                                    qPos.add(groupId);
12347    
12348                                    qPos.add(categoryId);
12349    
12350                                    qPos.add(threadId);
12351    
12352                                    if (!pagination) {
12353                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12354                                                            start, end, false);
12355    
12356                                            Collections.sort(list);
12357    
12358                                            list = Collections.unmodifiableList(list);
12359                                    }
12360                                    else {
12361                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12362                                                            start, end);
12363                                    }
12364    
12365                                    cacheResult(list);
12366    
12367                                    finderCache.putResult(finderPath, finderArgs, list);
12368                            }
12369                            catch (Exception e) {
12370                                    finderCache.removeResult(finderPath, finderArgs);
12371    
12372                                    throw processException(e);
12373                            }
12374                            finally {
12375                                    closeSession(session);
12376                            }
12377                    }
12378    
12379                    return list;
12380            }
12381    
12382            /**
12383             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12384             *
12385             * @param groupId the group ID
12386             * @param categoryId the category ID
12387             * @param threadId the thread ID
12388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12389             * @return the first matching message-boards message
12390             * @throws NoSuchMessageException if a matching message-boards message could not be found
12391             */
12392            @Override
12393            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12394                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12395                    throws NoSuchMessageException {
12396                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12397                                    orderByComparator);
12398    
12399                    if (mbMessage != null) {
12400                            return mbMessage;
12401                    }
12402    
12403                    StringBundler msg = new StringBundler(8);
12404    
12405                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12406    
12407                    msg.append("groupId=");
12408                    msg.append(groupId);
12409    
12410                    msg.append(", categoryId=");
12411                    msg.append(categoryId);
12412    
12413                    msg.append(", threadId=");
12414                    msg.append(threadId);
12415    
12416                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12417    
12418                    throw new NoSuchMessageException(msg.toString());
12419            }
12420    
12421            /**
12422             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12423             *
12424             * @param groupId the group ID
12425             * @param categoryId the category ID
12426             * @param threadId the thread ID
12427             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12428             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12429             */
12430            @Override
12431            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12432                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12433                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12434                                    orderByComparator);
12435    
12436                    if (!list.isEmpty()) {
12437                            return list.get(0);
12438                    }
12439    
12440                    return null;
12441            }
12442    
12443            /**
12444             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12445             *
12446             * @param groupId the group ID
12447             * @param categoryId the category ID
12448             * @param threadId the thread ID
12449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12450             * @return the last matching message-boards message
12451             * @throws NoSuchMessageException if a matching message-boards message could not be found
12452             */
12453            @Override
12454            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12455                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12456                    throws NoSuchMessageException {
12457                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12458                                    orderByComparator);
12459    
12460                    if (mbMessage != null) {
12461                            return mbMessage;
12462                    }
12463    
12464                    StringBundler msg = new StringBundler(8);
12465    
12466                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12467    
12468                    msg.append("groupId=");
12469                    msg.append(groupId);
12470    
12471                    msg.append(", categoryId=");
12472                    msg.append(categoryId);
12473    
12474                    msg.append(", threadId=");
12475                    msg.append(threadId);
12476    
12477                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12478    
12479                    throw new NoSuchMessageException(msg.toString());
12480            }
12481    
12482            /**
12483             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12484             *
12485             * @param groupId the group ID
12486             * @param categoryId the category ID
12487             * @param threadId the thread ID
12488             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12489             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12490             */
12491            @Override
12492            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12493                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12494                    int count = countByG_C_T(groupId, categoryId, threadId);
12495    
12496                    if (count == 0) {
12497                            return null;
12498                    }
12499    
12500                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12501                                    count - 1, count, orderByComparator);
12502    
12503                    if (!list.isEmpty()) {
12504                            return list.get(0);
12505                    }
12506    
12507                    return null;
12508            }
12509    
12510            /**
12511             * 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;.
12512             *
12513             * @param messageId the primary key of the current message-boards message
12514             * @param groupId the group ID
12515             * @param categoryId the category ID
12516             * @param threadId the thread ID
12517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12518             * @return the previous, current, and next message-boards message
12519             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12520             */
12521            @Override
12522            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12523                    long categoryId, long threadId,
12524                    OrderByComparator<MBMessage> orderByComparator)
12525                    throws NoSuchMessageException {
12526                    MBMessage mbMessage = findByPrimaryKey(messageId);
12527    
12528                    Session session = null;
12529    
12530                    try {
12531                            session = openSession();
12532    
12533                            MBMessage[] array = new MBMessageImpl[3];
12534    
12535                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12536                                            categoryId, threadId, orderByComparator, true);
12537    
12538                            array[1] = mbMessage;
12539    
12540                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12541                                            categoryId, threadId, orderByComparator, false);
12542    
12543                            return array;
12544                    }
12545                    catch (Exception e) {
12546                            throw processException(e);
12547                    }
12548                    finally {
12549                            closeSession(session);
12550                    }
12551            }
12552    
12553            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12554                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12555                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12556                    StringBundler query = null;
12557    
12558                    if (orderByComparator != null) {
12559                            query = new StringBundler(6 +
12560                                            (orderByComparator.getOrderByConditionFields().length * 3) +
12561                                            (orderByComparator.getOrderByFields().length * 3));
12562                    }
12563                    else {
12564                            query = new StringBundler(5);
12565                    }
12566    
12567                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12568    
12569                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12570    
12571                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12572    
12573                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12574    
12575                    if (orderByComparator != null) {
12576                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12577    
12578                            if (orderByConditionFields.length > 0) {
12579                                    query.append(WHERE_AND);
12580                            }
12581    
12582                            for (int i = 0; i < orderByConditionFields.length; i++) {
12583                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12584                                    query.append(orderByConditionFields[i]);
12585    
12586                                    if ((i + 1) < orderByConditionFields.length) {
12587                                            if (orderByComparator.isAscending() ^ previous) {
12588                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12589                                            }
12590                                            else {
12591                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12592                                            }
12593                                    }
12594                                    else {
12595                                            if (orderByComparator.isAscending() ^ previous) {
12596                                                    query.append(WHERE_GREATER_THAN);
12597                                            }
12598                                            else {
12599                                                    query.append(WHERE_LESSER_THAN);
12600                                            }
12601                                    }
12602                            }
12603    
12604                            query.append(ORDER_BY_CLAUSE);
12605    
12606                            String[] orderByFields = orderByComparator.getOrderByFields();
12607    
12608                            for (int i = 0; i < orderByFields.length; i++) {
12609                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12610                                    query.append(orderByFields[i]);
12611    
12612                                    if ((i + 1) < orderByFields.length) {
12613                                            if (orderByComparator.isAscending() ^ previous) {
12614                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12615                                            }
12616                                            else {
12617                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12618                                            }
12619                                    }
12620                                    else {
12621                                            if (orderByComparator.isAscending() ^ previous) {
12622                                                    query.append(ORDER_BY_ASC);
12623                                            }
12624                                            else {
12625                                                    query.append(ORDER_BY_DESC);
12626                                            }
12627                                    }
12628                            }
12629                    }
12630                    else {
12631                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12632                    }
12633    
12634                    String sql = query.toString();
12635    
12636                    Query q = session.createQuery(sql);
12637    
12638                    q.setFirstResult(0);
12639                    q.setMaxResults(2);
12640    
12641                    QueryPos qPos = QueryPos.getInstance(q);
12642    
12643                    qPos.add(groupId);
12644    
12645                    qPos.add(categoryId);
12646    
12647                    qPos.add(threadId);
12648    
12649                    if (orderByComparator != null) {
12650                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12651    
12652                            for (Object value : values) {
12653                                    qPos.add(value);
12654                            }
12655                    }
12656    
12657                    List<MBMessage> list = q.list();
12658    
12659                    if (list.size() == 2) {
12660                            return list.get(1);
12661                    }
12662                    else {
12663                            return null;
12664                    }
12665            }
12666    
12667            /**
12668             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12669             *
12670             * @param groupId the group ID
12671             * @param categoryId the category ID
12672             * @param threadId the thread ID
12673             * @return the matching message-boards messages that the user has permission to view
12674             */
12675            @Override
12676            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12677                    long threadId) {
12678                    return filterFindByG_C_T(groupId, categoryId, threadId,
12679                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12680            }
12681    
12682            /**
12683             * 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;.
12684             *
12685             * <p>
12686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12687             * </p>
12688             *
12689             * @param groupId the group ID
12690             * @param categoryId the category ID
12691             * @param threadId the thread ID
12692             * @param start the lower bound of the range of message-boards messages
12693             * @param end the upper bound of the range of message-boards messages (not inclusive)
12694             * @return the range of matching message-boards messages that the user has permission to view
12695             */
12696            @Override
12697            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12698                    long threadId, int start, int end) {
12699                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12700            }
12701    
12702            /**
12703             * 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;.
12704             *
12705             * <p>
12706             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12707             * </p>
12708             *
12709             * @param groupId the group ID
12710             * @param categoryId the category ID
12711             * @param threadId the thread ID
12712             * @param start the lower bound of the range of message-boards messages
12713             * @param end the upper bound of the range of message-boards messages (not inclusive)
12714             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12715             * @return the ordered range of matching message-boards messages that the user has permission to view
12716             */
12717            @Override
12718            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12719                    long threadId, int start, int end,
12720                    OrderByComparator<MBMessage> orderByComparator) {
12721                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12722                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12723                                    orderByComparator);
12724                    }
12725    
12726                    StringBundler query = null;
12727    
12728                    if (orderByComparator != null) {
12729                            query = new StringBundler(5 +
12730                                            (orderByComparator.getOrderByFields().length * 2));
12731                    }
12732                    else {
12733                            query = new StringBundler(6);
12734                    }
12735    
12736                    if (getDB().isSupportsInlineDistinct()) {
12737                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12738                    }
12739                    else {
12740                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12741                    }
12742    
12743                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12744    
12745                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12746    
12747                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12748    
12749                    if (!getDB().isSupportsInlineDistinct()) {
12750                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12751                    }
12752    
12753                    if (orderByComparator != null) {
12754                            if (getDB().isSupportsInlineDistinct()) {
12755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12756                                            orderByComparator, true);
12757                            }
12758                            else {
12759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12760                                            orderByComparator, true);
12761                            }
12762                    }
12763                    else {
12764                            if (getDB().isSupportsInlineDistinct()) {
12765                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12766                            }
12767                            else {
12768                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12769                            }
12770                    }
12771    
12772                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12773                                    MBMessage.class.getName(),
12774                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12775    
12776                    Session session = null;
12777    
12778                    try {
12779                            session = openSession();
12780    
12781                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12782    
12783                            if (getDB().isSupportsInlineDistinct()) {
12784                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12785                            }
12786                            else {
12787                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12788                            }
12789    
12790                            QueryPos qPos = QueryPos.getInstance(q);
12791    
12792                            qPos.add(groupId);
12793    
12794                            qPos.add(categoryId);
12795    
12796                            qPos.add(threadId);
12797    
12798                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12799                    }
12800                    catch (Exception e) {
12801                            throw processException(e);
12802                    }
12803                    finally {
12804                            closeSession(session);
12805                    }
12806            }
12807    
12808            /**
12809             * 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;.
12810             *
12811             * @param messageId the primary key of the current message-boards message
12812             * @param groupId the group ID
12813             * @param categoryId the category ID
12814             * @param threadId the thread ID
12815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12816             * @return the previous, current, and next message-boards message
12817             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12818             */
12819            @Override
12820            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12821                    long groupId, long categoryId, long threadId,
12822                    OrderByComparator<MBMessage> orderByComparator)
12823                    throws NoSuchMessageException {
12824                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12825                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12826                                    threadId, orderByComparator);
12827                    }
12828    
12829                    MBMessage mbMessage = findByPrimaryKey(messageId);
12830    
12831                    Session session = null;
12832    
12833                    try {
12834                            session = openSession();
12835    
12836                            MBMessage[] array = new MBMessageImpl[3];
12837    
12838                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12839                                            groupId, categoryId, threadId, orderByComparator, true);
12840    
12841                            array[1] = mbMessage;
12842    
12843                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12844                                            groupId, categoryId, threadId, orderByComparator, false);
12845    
12846                            return array;
12847                    }
12848                    catch (Exception e) {
12849                            throw processException(e);
12850                    }
12851                    finally {
12852                            closeSession(session);
12853                    }
12854            }
12855    
12856            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12857                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12858                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12859                    StringBundler query = null;
12860    
12861                    if (orderByComparator != null) {
12862                            query = new StringBundler(7 +
12863                                            (orderByComparator.getOrderByConditionFields().length * 3) +
12864                                            (orderByComparator.getOrderByFields().length * 3));
12865                    }
12866                    else {
12867                            query = new StringBundler(6);
12868                    }
12869    
12870                    if (getDB().isSupportsInlineDistinct()) {
12871                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12872                    }
12873                    else {
12874                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12875                    }
12876    
12877                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12878    
12879                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12880    
12881                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12882    
12883                    if (!getDB().isSupportsInlineDistinct()) {
12884                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12885                    }
12886    
12887                    if (orderByComparator != null) {
12888                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12889    
12890                            if (orderByConditionFields.length > 0) {
12891                                    query.append(WHERE_AND);
12892                            }
12893    
12894                            for (int i = 0; i < orderByConditionFields.length; i++) {
12895                                    if (getDB().isSupportsInlineDistinct()) {
12896                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12897                                    }
12898                                    else {
12899                                            query.append(_ORDER_BY_ENTITY_TABLE);
12900                                    }
12901    
12902                                    query.append(orderByConditionFields[i]);
12903    
12904                                    if ((i + 1) < orderByConditionFields.length) {
12905                                            if (orderByComparator.isAscending() ^ previous) {
12906                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12907                                            }
12908                                            else {
12909                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12910                                            }
12911                                    }
12912                                    else {
12913                                            if (orderByComparator.isAscending() ^ previous) {
12914                                                    query.append(WHERE_GREATER_THAN);
12915                                            }
12916                                            else {
12917                                                    query.append(WHERE_LESSER_THAN);
12918                                            }
12919                                    }
12920                            }
12921    
12922                            query.append(ORDER_BY_CLAUSE);
12923    
12924                            String[] orderByFields = orderByComparator.getOrderByFields();
12925    
12926                            for (int i = 0; i < orderByFields.length; i++) {
12927                                    if (getDB().isSupportsInlineDistinct()) {
12928                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12929                                    }
12930                                    else {
12931                                            query.append(_ORDER_BY_ENTITY_TABLE);
12932                                    }
12933    
12934                                    query.append(orderByFields[i]);
12935    
12936                                    if ((i + 1) < orderByFields.length) {
12937                                            if (orderByComparator.isAscending() ^ previous) {
12938                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12939                                            }
12940                                            else {
12941                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12942                                            }
12943                                    }
12944                                    else {
12945                                            if (orderByComparator.isAscending() ^ previous) {
12946                                                    query.append(ORDER_BY_ASC);
12947                                            }
12948                                            else {
12949                                                    query.append(ORDER_BY_DESC);
12950                                            }
12951                                    }
12952                            }
12953                    }
12954                    else {
12955                            if (getDB().isSupportsInlineDistinct()) {
12956                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12957                            }
12958                            else {
12959                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12960                            }
12961                    }
12962    
12963                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12964                                    MBMessage.class.getName(),
12965                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12966    
12967                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12968    
12969                    q.setFirstResult(0);
12970                    q.setMaxResults(2);
12971    
12972                    if (getDB().isSupportsInlineDistinct()) {
12973                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12974                    }
12975                    else {
12976                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12977                    }
12978    
12979                    QueryPos qPos = QueryPos.getInstance(q);
12980    
12981                    qPos.add(groupId);
12982    
12983                    qPos.add(categoryId);
12984    
12985                    qPos.add(threadId);
12986    
12987                    if (orderByComparator != null) {
12988                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12989    
12990                            for (Object value : values) {
12991                                    qPos.add(value);
12992                            }
12993                    }
12994    
12995                    List<MBMessage> list = q.list();
12996    
12997                    if (list.size() == 2) {
12998                            return list.get(1);
12999                    }
13000                    else {
13001                            return null;
13002                    }
13003            }
13004    
13005            /**
13006             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
13007             *
13008             * @param groupId the group ID
13009             * @param categoryId the category ID
13010             * @param threadId the thread ID
13011             */
13012            @Override
13013            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
13014                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
13015                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13016                            remove(mbMessage);
13017                    }
13018            }
13019    
13020            /**
13021             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13022             *
13023             * @param groupId the group ID
13024             * @param categoryId the category ID
13025             * @param threadId the thread ID
13026             * @return the number of matching message-boards messages
13027             */
13028            @Override
13029            public int countByG_C_T(long groupId, long categoryId, long threadId) {
13030                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
13031    
13032                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
13033    
13034                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13035    
13036                    if (count == null) {
13037                            StringBundler query = new StringBundler(4);
13038    
13039                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13040    
13041                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13042    
13043                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13044    
13045                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13046    
13047                            String sql = query.toString();
13048    
13049                            Session session = null;
13050    
13051                            try {
13052                                    session = openSession();
13053    
13054                                    Query q = session.createQuery(sql);
13055    
13056                                    QueryPos qPos = QueryPos.getInstance(q);
13057    
13058                                    qPos.add(groupId);
13059    
13060                                    qPos.add(categoryId);
13061    
13062                                    qPos.add(threadId);
13063    
13064                                    count = (Long)q.uniqueResult();
13065    
13066                                    finderCache.putResult(finderPath, finderArgs, count);
13067                            }
13068                            catch (Exception e) {
13069                                    finderCache.removeResult(finderPath, finderArgs);
13070    
13071                                    throw processException(e);
13072                            }
13073                            finally {
13074                                    closeSession(session);
13075                            }
13076                    }
13077    
13078                    return count.intValue();
13079            }
13080    
13081            /**
13082             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13083             *
13084             * @param groupId the group ID
13085             * @param categoryId the category ID
13086             * @param threadId the thread ID
13087             * @return the number of matching message-boards messages that the user has permission to view
13088             */
13089            @Override
13090            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
13091                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13092                            return countByG_C_T(groupId, categoryId, threadId);
13093                    }
13094    
13095                    StringBundler query = new StringBundler(4);
13096    
13097                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13098    
13099                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13100    
13101                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13102    
13103                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13104    
13105                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13106                                    MBMessage.class.getName(),
13107                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13108    
13109                    Session session = null;
13110    
13111                    try {
13112                            session = openSession();
13113    
13114                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13115    
13116                            q.addScalar(COUNT_COLUMN_NAME,
13117                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13118    
13119                            QueryPos qPos = QueryPos.getInstance(q);
13120    
13121                            qPos.add(groupId);
13122    
13123                            qPos.add(categoryId);
13124    
13125                            qPos.add(threadId);
13126    
13127                            Long count = (Long)q.uniqueResult();
13128    
13129                            return count.intValue();
13130                    }
13131                    catch (Exception e) {
13132                            throw processException(e);
13133                    }
13134                    finally {
13135                            closeSession(session);
13136                    }
13137            }
13138    
13139            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
13140            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13141            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
13142            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13143                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13144                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
13145                            new String[] {
13146                                    Long.class.getName(), Long.class.getName(),
13147                                    Integer.class.getName(),
13148                                    
13149                            Integer.class.getName(), Integer.class.getName(),
13150                                    OrderByComparator.class.getName()
13151                            });
13152            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13153                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13154                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
13155                            new String[] {
13156                                    Long.class.getName(), Long.class.getName(),
13157                                    Integer.class.getName()
13158                            },
13159                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
13160                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
13161                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
13162                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13163            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13164                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
13166                            new String[] {
13167                                    Long.class.getName(), Long.class.getName(),
13168                                    Integer.class.getName()
13169                            });
13170    
13171            /**
13172             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13173             *
13174             * @param groupId the group ID
13175             * @param categoryId the category ID
13176             * @param status the status
13177             * @return the matching message-boards messages
13178             */
13179            @Override
13180            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
13181                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
13182                            QueryUtil.ALL_POS, null);
13183            }
13184    
13185            /**
13186             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13187             *
13188             * <p>
13189             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13190             * </p>
13191             *
13192             * @param groupId the group ID
13193             * @param categoryId the category ID
13194             * @param status the status
13195             * @param start the lower bound of the range of message-boards messages
13196             * @param end the upper bound of the range of message-boards messages (not inclusive)
13197             * @return the range of matching message-boards messages
13198             */
13199            @Override
13200            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13201                    int status, int start, int end) {
13202                    return findByG_C_S(groupId, categoryId, status, start, end, null);
13203            }
13204    
13205            /**
13206             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13207             *
13208             * <p>
13209             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13210             * </p>
13211             *
13212             * @param groupId the group ID
13213             * @param categoryId the category ID
13214             * @param status the status
13215             * @param start the lower bound of the range of message-boards messages
13216             * @param end the upper bound of the range of message-boards messages (not inclusive)
13217             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13218             * @return the ordered range of matching message-boards messages
13219             */
13220            @Override
13221            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13222                    int status, int start, int end,
13223                    OrderByComparator<MBMessage> orderByComparator) {
13224                    return findByG_C_S(groupId, categoryId, status, start, end,
13225                            orderByComparator, true);
13226            }
13227    
13228            /**
13229             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13230             *
13231             * <p>
13232             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13233             * </p>
13234             *
13235             * @param groupId the group ID
13236             * @param categoryId the category ID
13237             * @param status the status
13238             * @param start the lower bound of the range of message-boards messages
13239             * @param end the upper bound of the range of message-boards messages (not inclusive)
13240             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13241             * @param retrieveFromCache whether to retrieve from the finder cache
13242             * @return the ordered range of matching message-boards messages
13243             */
13244            @Override
13245            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13246                    int status, int start, int end,
13247                    OrderByComparator<MBMessage> orderByComparator,
13248                    boolean retrieveFromCache) {
13249                    boolean pagination = true;
13250                    FinderPath finderPath = null;
13251                    Object[] finderArgs = null;
13252    
13253                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13254                                    (orderByComparator == null)) {
13255                            pagination = false;
13256                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13257                            finderArgs = new Object[] { groupId, categoryId, status };
13258                    }
13259                    else {
13260                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13261                            finderArgs = new Object[] {
13262                                            groupId, categoryId, status,
13263                                            
13264                                            start, end, orderByComparator
13265                                    };
13266                    }
13267    
13268                    List<MBMessage> list = null;
13269    
13270                    if (retrieveFromCache) {
13271                            list = (List<MBMessage>)finderCache.getResult(finderPath,
13272                                            finderArgs, this);
13273    
13274                            if ((list != null) && !list.isEmpty()) {
13275                                    for (MBMessage mbMessage : list) {
13276                                            if ((groupId != mbMessage.getGroupId()) ||
13277                                                            (categoryId != mbMessage.getCategoryId()) ||
13278                                                            (status != mbMessage.getStatus())) {
13279                                                    list = null;
13280    
13281                                                    break;
13282                                            }
13283                                    }
13284                            }
13285                    }
13286    
13287                    if (list == null) {
13288                            StringBundler query = null;
13289    
13290                            if (orderByComparator != null) {
13291                                    query = new StringBundler(5 +
13292                                                    (orderByComparator.getOrderByFields().length * 2));
13293                            }
13294                            else {
13295                                    query = new StringBundler(5);
13296                            }
13297    
13298                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13299    
13300                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13301    
13302                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13303    
13304                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13305    
13306                            if (orderByComparator != null) {
13307                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13308                                            orderByComparator);
13309                            }
13310                            else
13311                             if (pagination) {
13312                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13313                            }
13314    
13315                            String sql = query.toString();
13316    
13317                            Session session = null;
13318    
13319                            try {
13320                                    session = openSession();
13321    
13322                                    Query q = session.createQuery(sql);
13323    
13324                                    QueryPos qPos = QueryPos.getInstance(q);
13325    
13326                                    qPos.add(groupId);
13327    
13328                                    qPos.add(categoryId);
13329    
13330                                    qPos.add(status);
13331    
13332                                    if (!pagination) {
13333                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13334                                                            start, end, false);
13335    
13336                                            Collections.sort(list);
13337    
13338                                            list = Collections.unmodifiableList(list);
13339                                    }
13340                                    else {
13341                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13342                                                            start, end);
13343                                    }
13344    
13345                                    cacheResult(list);
13346    
13347                                    finderCache.putResult(finderPath, finderArgs, list);
13348                            }
13349                            catch (Exception e) {
13350                                    finderCache.removeResult(finderPath, finderArgs);
13351    
13352                                    throw processException(e);
13353                            }
13354                            finally {
13355                                    closeSession(session);
13356                            }
13357                    }
13358    
13359                    return list;
13360            }
13361    
13362            /**
13363             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13364             *
13365             * @param groupId the group ID
13366             * @param categoryId the category ID
13367             * @param status the status
13368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13369             * @return the first matching message-boards message
13370             * @throws NoSuchMessageException if a matching message-boards message could not be found
13371             */
13372            @Override
13373            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13374                    int status, OrderByComparator<MBMessage> orderByComparator)
13375                    throws NoSuchMessageException {
13376                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13377                                    orderByComparator);
13378    
13379                    if (mbMessage != null) {
13380                            return mbMessage;
13381                    }
13382    
13383                    StringBundler msg = new StringBundler(8);
13384    
13385                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13386    
13387                    msg.append("groupId=");
13388                    msg.append(groupId);
13389    
13390                    msg.append(", categoryId=");
13391                    msg.append(categoryId);
13392    
13393                    msg.append(", status=");
13394                    msg.append(status);
13395    
13396                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13397    
13398                    throw new NoSuchMessageException(msg.toString());
13399            }
13400    
13401            /**
13402             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13403             *
13404             * @param groupId the group ID
13405             * @param categoryId the category ID
13406             * @param status the status
13407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13408             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13409             */
13410            @Override
13411            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13412                    int status, OrderByComparator<MBMessage> orderByComparator) {
13413                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13414                                    orderByComparator);
13415    
13416                    if (!list.isEmpty()) {
13417                            return list.get(0);
13418                    }
13419    
13420                    return null;
13421            }
13422    
13423            /**
13424             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13425             *
13426             * @param groupId the group ID
13427             * @param categoryId the category ID
13428             * @param status the status
13429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13430             * @return the last matching message-boards message
13431             * @throws NoSuchMessageException if a matching message-boards message could not be found
13432             */
13433            @Override
13434            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13435                    int status, OrderByComparator<MBMessage> orderByComparator)
13436                    throws NoSuchMessageException {
13437                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13438                                    orderByComparator);
13439    
13440                    if (mbMessage != null) {
13441                            return mbMessage;
13442                    }
13443    
13444                    StringBundler msg = new StringBundler(8);
13445    
13446                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13447    
13448                    msg.append("groupId=");
13449                    msg.append(groupId);
13450    
13451                    msg.append(", categoryId=");
13452                    msg.append(categoryId);
13453    
13454                    msg.append(", status=");
13455                    msg.append(status);
13456    
13457                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13458    
13459                    throw new NoSuchMessageException(msg.toString());
13460            }
13461    
13462            /**
13463             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13464             *
13465             * @param groupId the group ID
13466             * @param categoryId the category ID
13467             * @param status the status
13468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13469             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13470             */
13471            @Override
13472            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13473                    int status, OrderByComparator<MBMessage> orderByComparator) {
13474                    int count = countByG_C_S(groupId, categoryId, status);
13475    
13476                    if (count == 0) {
13477                            return null;
13478                    }
13479    
13480                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13481                                    count - 1, count, orderByComparator);
13482    
13483                    if (!list.isEmpty()) {
13484                            return list.get(0);
13485                    }
13486    
13487                    return null;
13488            }
13489    
13490            /**
13491             * 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;.
13492             *
13493             * @param messageId the primary key of the current message-boards message
13494             * @param groupId the group ID
13495             * @param categoryId the category ID
13496             * @param status the status
13497             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13498             * @return the previous, current, and next message-boards message
13499             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13500             */
13501            @Override
13502            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13503                    long categoryId, int status,
13504                    OrderByComparator<MBMessage> orderByComparator)
13505                    throws NoSuchMessageException {
13506                    MBMessage mbMessage = findByPrimaryKey(messageId);
13507    
13508                    Session session = null;
13509    
13510                    try {
13511                            session = openSession();
13512    
13513                            MBMessage[] array = new MBMessageImpl[3];
13514    
13515                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13516                                            categoryId, status, orderByComparator, true);
13517    
13518                            array[1] = mbMessage;
13519    
13520                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13521                                            categoryId, status, orderByComparator, false);
13522    
13523                            return array;
13524                    }
13525                    catch (Exception e) {
13526                            throw processException(e);
13527                    }
13528                    finally {
13529                            closeSession(session);
13530                    }
13531            }
13532    
13533            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13534                    MBMessage mbMessage, long groupId, long categoryId, int status,
13535                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13536                    StringBundler query = null;
13537    
13538                    if (orderByComparator != null) {
13539                            query = new StringBundler(6 +
13540                                            (orderByComparator.getOrderByConditionFields().length * 3) +
13541                                            (orderByComparator.getOrderByFields().length * 3));
13542                    }
13543                    else {
13544                            query = new StringBundler(5);
13545                    }
13546    
13547                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13548    
13549                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13550    
13551                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13552    
13553                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13554    
13555                    if (orderByComparator != null) {
13556                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13557    
13558                            if (orderByConditionFields.length > 0) {
13559                                    query.append(WHERE_AND);
13560                            }
13561    
13562                            for (int i = 0; i < orderByConditionFields.length; i++) {
13563                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13564                                    query.append(orderByConditionFields[i]);
13565    
13566                                    if ((i + 1) < orderByConditionFields.length) {
13567                                            if (orderByComparator.isAscending() ^ previous) {
13568                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13569                                            }
13570                                            else {
13571                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13572                                            }
13573                                    }
13574                                    else {
13575                                            if (orderByComparator.isAscending() ^ previous) {
13576                                                    query.append(WHERE_GREATER_THAN);
13577                                            }
13578                                            else {
13579                                                    query.append(WHERE_LESSER_THAN);
13580                                            }
13581                                    }
13582                            }
13583    
13584                            query.append(ORDER_BY_CLAUSE);
13585    
13586                            String[] orderByFields = orderByComparator.getOrderByFields();
13587    
13588                            for (int i = 0; i < orderByFields.length; i++) {
13589                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13590                                    query.append(orderByFields[i]);
13591    
13592                                    if ((i + 1) < orderByFields.length) {
13593                                            if (orderByComparator.isAscending() ^ previous) {
13594                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13595                                            }
13596                                            else {
13597                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13598                                            }
13599                                    }
13600                                    else {
13601                                            if (orderByComparator.isAscending() ^ previous) {
13602                                                    query.append(ORDER_BY_ASC);
13603                                            }
13604                                            else {
13605                                                    query.append(ORDER_BY_DESC);
13606                                            }
13607                                    }
13608                            }
13609                    }
13610                    else {
13611                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13612                    }
13613    
13614                    String sql = query.toString();
13615    
13616                    Query q = session.createQuery(sql);
13617    
13618                    q.setFirstResult(0);
13619                    q.setMaxResults(2);
13620    
13621                    QueryPos qPos = QueryPos.getInstance(q);
13622    
13623                    qPos.add(groupId);
13624    
13625                    qPos.add(categoryId);
13626    
13627                    qPos.add(status);
13628    
13629                    if (orderByComparator != null) {
13630                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13631    
13632                            for (Object value : values) {
13633                                    qPos.add(value);
13634                            }
13635                    }
13636    
13637                    List<MBMessage> list = q.list();
13638    
13639                    if (list.size() == 2) {
13640                            return list.get(1);
13641                    }
13642                    else {
13643                            return null;
13644                    }
13645            }
13646    
13647            /**
13648             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13649             *
13650             * @param groupId the group ID
13651             * @param categoryId the category ID
13652             * @param status the status
13653             * @return the matching message-boards messages that the user has permission to view
13654             */
13655            @Override
13656            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13657                    int status) {
13658                    return filterFindByG_C_S(groupId, categoryId, status,
13659                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13660            }
13661    
13662            /**
13663             * 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;.
13664             *
13665             * <p>
13666             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13667             * </p>
13668             *
13669             * @param groupId the group ID
13670             * @param categoryId the category ID
13671             * @param status the status
13672             * @param start the lower bound of the range of message-boards messages
13673             * @param end the upper bound of the range of message-boards messages (not inclusive)
13674             * @return the range of matching message-boards messages that the user has permission to view
13675             */
13676            @Override
13677            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13678                    int status, int start, int end) {
13679                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13680            }
13681    
13682            /**
13683             * 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;.
13684             *
13685             * <p>
13686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13687             * </p>
13688             *
13689             * @param groupId the group ID
13690             * @param categoryId the category ID
13691             * @param status the status
13692             * @param start the lower bound of the range of message-boards messages
13693             * @param end the upper bound of the range of message-boards messages (not inclusive)
13694             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13695             * @return the ordered range of matching message-boards messages that the user has permission to view
13696             */
13697            @Override
13698            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13699                    int status, int start, int end,
13700                    OrderByComparator<MBMessage> orderByComparator) {
13701                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13702                            return findByG_C_S(groupId, categoryId, status, start, end,
13703                                    orderByComparator);
13704                    }
13705    
13706                    StringBundler query = null;
13707    
13708                    if (orderByComparator != null) {
13709                            query = new StringBundler(5 +
13710                                            (orderByComparator.getOrderByFields().length * 2));
13711                    }
13712                    else {
13713                            query = new StringBundler(6);
13714                    }
13715    
13716                    if (getDB().isSupportsInlineDistinct()) {
13717                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13718                    }
13719                    else {
13720                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13721                    }
13722    
13723                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13724    
13725                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13726    
13727                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13728    
13729                    if (!getDB().isSupportsInlineDistinct()) {
13730                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13731                    }
13732    
13733                    if (orderByComparator != null) {
13734                            if (getDB().isSupportsInlineDistinct()) {
13735                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13736                                            orderByComparator, true);
13737                            }
13738                            else {
13739                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13740                                            orderByComparator, true);
13741                            }
13742                    }
13743                    else {
13744                            if (getDB().isSupportsInlineDistinct()) {
13745                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13746                            }
13747                            else {
13748                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13749                            }
13750                    }
13751    
13752                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13753                                    MBMessage.class.getName(),
13754                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13755    
13756                    Session session = null;
13757    
13758                    try {
13759                            session = openSession();
13760    
13761                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13762    
13763                            if (getDB().isSupportsInlineDistinct()) {
13764                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13765                            }
13766                            else {
13767                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13768                            }
13769    
13770                            QueryPos qPos = QueryPos.getInstance(q);
13771    
13772                            qPos.add(groupId);
13773    
13774                            qPos.add(categoryId);
13775    
13776                            qPos.add(status);
13777    
13778                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13779                    }
13780                    catch (Exception e) {
13781                            throw processException(e);
13782                    }
13783                    finally {
13784                            closeSession(session);
13785                    }
13786            }
13787    
13788            /**
13789             * 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;.
13790             *
13791             * @param messageId the primary key of the current message-boards message
13792             * @param groupId the group ID
13793             * @param categoryId the category ID
13794             * @param status the status
13795             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13796             * @return the previous, current, and next message-boards message
13797             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13798             */
13799            @Override
13800            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13801                    long groupId, long categoryId, int status,
13802                    OrderByComparator<MBMessage> orderByComparator)
13803                    throws NoSuchMessageException {
13804                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13805                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13806                                    status, orderByComparator);
13807                    }
13808    
13809                    MBMessage mbMessage = findByPrimaryKey(messageId);
13810    
13811                    Session session = null;
13812    
13813                    try {
13814                            session = openSession();
13815    
13816                            MBMessage[] array = new MBMessageImpl[3];
13817    
13818                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13819                                            groupId, categoryId, status, orderByComparator, true);
13820    
13821                            array[1] = mbMessage;
13822    
13823                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13824                                            groupId, categoryId, status, orderByComparator, false);
13825    
13826                            return array;
13827                    }
13828                    catch (Exception e) {
13829                            throw processException(e);
13830                    }
13831                    finally {
13832                            closeSession(session);
13833                    }
13834            }
13835    
13836            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13837                    MBMessage mbMessage, long groupId, long categoryId, int status,
13838                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13839                    StringBundler query = null;
13840    
13841                    if (orderByComparator != null) {
13842                            query = new StringBundler(7 +
13843                                            (orderByComparator.getOrderByConditionFields().length * 3) +
13844                                            (orderByComparator.getOrderByFields().length * 3));
13845                    }
13846                    else {
13847                            query = new StringBundler(6);
13848                    }
13849    
13850                    if (getDB().isSupportsInlineDistinct()) {
13851                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13852                    }
13853                    else {
13854                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13855                    }
13856    
13857                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13858    
13859                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13860    
13861                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13862    
13863                    if (!getDB().isSupportsInlineDistinct()) {
13864                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13865                    }
13866    
13867                    if (orderByComparator != null) {
13868                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13869    
13870                            if (orderByConditionFields.length > 0) {
13871                                    query.append(WHERE_AND);
13872                            }
13873    
13874                            for (int i = 0; i < orderByConditionFields.length; i++) {
13875                                    if (getDB().isSupportsInlineDistinct()) {
13876                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13877                                    }
13878                                    else {
13879                                            query.append(_ORDER_BY_ENTITY_TABLE);
13880                                    }
13881    
13882                                    query.append(orderByConditionFields[i]);
13883    
13884                                    if ((i + 1) < orderByConditionFields.length) {
13885                                            if (orderByComparator.isAscending() ^ previous) {
13886                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13887                                            }
13888                                            else {
13889                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13890                                            }
13891                                    }
13892                                    else {
13893                                            if (orderByComparator.isAscending() ^ previous) {
13894                                                    query.append(WHERE_GREATER_THAN);
13895                                            }
13896                                            else {
13897                                                    query.append(WHERE_LESSER_THAN);
13898                                            }
13899                                    }
13900                            }
13901    
13902                            query.append(ORDER_BY_CLAUSE);
13903    
13904                            String[] orderByFields = orderByComparator.getOrderByFields();
13905    
13906                            for (int i = 0; i < orderByFields.length; i++) {
13907                                    if (getDB().isSupportsInlineDistinct()) {
13908                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13909                                    }
13910                                    else {
13911                                            query.append(_ORDER_BY_ENTITY_TABLE);
13912                                    }
13913    
13914                                    query.append(orderByFields[i]);
13915    
13916                                    if ((i + 1) < orderByFields.length) {
13917                                            if (orderByComparator.isAscending() ^ previous) {
13918                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13919                                            }
13920                                            else {
13921                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13922                                            }
13923                                    }
13924                                    else {
13925                                            if (orderByComparator.isAscending() ^ previous) {
13926                                                    query.append(ORDER_BY_ASC);
13927                                            }
13928                                            else {
13929                                                    query.append(ORDER_BY_DESC);
13930                                            }
13931                                    }
13932                            }
13933                    }
13934                    else {
13935                            if (getDB().isSupportsInlineDistinct()) {
13936                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13937                            }
13938                            else {
13939                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13940                            }
13941                    }
13942    
13943                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13944                                    MBMessage.class.getName(),
13945                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13946    
13947                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13948    
13949                    q.setFirstResult(0);
13950                    q.setMaxResults(2);
13951    
13952                    if (getDB().isSupportsInlineDistinct()) {
13953                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13954                    }
13955                    else {
13956                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13957                    }
13958    
13959                    QueryPos qPos = QueryPos.getInstance(q);
13960    
13961                    qPos.add(groupId);
13962    
13963                    qPos.add(categoryId);
13964    
13965                    qPos.add(status);
13966    
13967                    if (orderByComparator != null) {
13968                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13969    
13970                            for (Object value : values) {
13971                                    qPos.add(value);
13972                            }
13973                    }
13974    
13975                    List<MBMessage> list = q.list();
13976    
13977                    if (list.size() == 2) {
13978                            return list.get(1);
13979                    }
13980                    else {
13981                            return null;
13982                    }
13983            }
13984    
13985            /**
13986             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13987             *
13988             * @param groupId the group ID
13989             * @param categoryId the category ID
13990             * @param status the status
13991             */
13992            @Override
13993            public void removeByG_C_S(long groupId, long categoryId, int status) {
13994                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13995                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13996                            remove(mbMessage);
13997                    }
13998            }
13999    
14000            /**
14001             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
14002             *
14003             * @param groupId the group ID
14004             * @param categoryId the category ID
14005             * @param status the status
14006             * @return the number of matching message-boards messages
14007             */
14008            @Override
14009            public int countByG_C_S(long groupId, long categoryId, int status) {
14010                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
14011    
14012                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
14013    
14014                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14015    
14016                    if (count == null) {
14017                            StringBundler query = new StringBundler(4);
14018    
14019                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14020    
14021                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14022    
14023                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14024    
14025                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14026    
14027                            String sql = query.toString();
14028    
14029                            Session session = null;
14030    
14031                            try {
14032                                    session = openSession();
14033    
14034                                    Query q = session.createQuery(sql);
14035    
14036                                    QueryPos qPos = QueryPos.getInstance(q);
14037    
14038                                    qPos.add(groupId);
14039    
14040                                    qPos.add(categoryId);
14041    
14042                                    qPos.add(status);
14043    
14044                                    count = (Long)q.uniqueResult();
14045    
14046                                    finderCache.putResult(finderPath, finderArgs, count);
14047                            }
14048                            catch (Exception e) {
14049                                    finderCache.removeResult(finderPath, finderArgs);
14050    
14051                                    throw processException(e);
14052                            }
14053                            finally {
14054                                    closeSession(session);
14055                            }
14056                    }
14057    
14058                    return count.intValue();
14059            }
14060    
14061            /**
14062             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
14063             *
14064             * @param groupId the group ID
14065             * @param categoryId the category ID
14066             * @param status the status
14067             * @return the number of matching message-boards messages that the user has permission to view
14068             */
14069            @Override
14070            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
14071                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14072                            return countByG_C_S(groupId, categoryId, status);
14073                    }
14074    
14075                    StringBundler query = new StringBundler(4);
14076    
14077                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
14078    
14079                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14080    
14081                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14082    
14083                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14084    
14085                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14086                                    MBMessage.class.getName(),
14087                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14088    
14089                    Session session = null;
14090    
14091                    try {
14092                            session = openSession();
14093    
14094                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
14095    
14096                            q.addScalar(COUNT_COLUMN_NAME,
14097                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14098    
14099                            QueryPos qPos = QueryPos.getInstance(q);
14100    
14101                            qPos.add(groupId);
14102    
14103                            qPos.add(categoryId);
14104    
14105                            qPos.add(status);
14106    
14107                            Long count = (Long)q.uniqueResult();
14108    
14109                            return count.intValue();
14110                    }
14111                    catch (Exception e) {
14112                            throw processException(e);
14113                    }
14114                    finally {
14115                            closeSession(session);
14116                    }
14117            }
14118    
14119            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
14120            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
14121            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
14122            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14123                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14124                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
14125                            new String[] {
14126                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14127                                    
14128                            Integer.class.getName(), Integer.class.getName(),
14129                                    OrderByComparator.class.getName()
14130                            });
14131            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14132                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
14134                            new String[] {
14135                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14136                            },
14137                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14138                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14139                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14140                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14141            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14142                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14143                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
14144                            new String[] {
14145                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14146                            });
14147    
14148            /**
14149             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14150             *
14151             * @param userId the user ID
14152             * @param classNameId the class name ID
14153             * @param classPK the class p k
14154             * @return the matching message-boards messages
14155             */
14156            @Override
14157            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14158                    long classPK) {
14159                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
14160                            QueryUtil.ALL_POS, null);
14161            }
14162    
14163            /**
14164             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14165             *
14166             * <p>
14167             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14168             * </p>
14169             *
14170             * @param userId the user ID
14171             * @param classNameId the class name ID
14172             * @param classPK the class p k
14173             * @param start the lower bound of the range of message-boards messages
14174             * @param end the upper bound of the range of message-boards messages (not inclusive)
14175             * @return the range of matching message-boards messages
14176             */
14177            @Override
14178            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14179                    long classPK, int start, int end) {
14180                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
14181            }
14182    
14183            /**
14184             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14185             *
14186             * <p>
14187             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14188             * </p>
14189             *
14190             * @param userId the user ID
14191             * @param classNameId the class name ID
14192             * @param classPK the class p k
14193             * @param start the lower bound of the range of message-boards messages
14194             * @param end the upper bound of the range of message-boards messages (not inclusive)
14195             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14196             * @return the ordered range of matching message-boards messages
14197             */
14198            @Override
14199            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14200                    long classPK, int start, int end,
14201                    OrderByComparator<MBMessage> orderByComparator) {
14202                    return findByU_C_C(userId, classNameId, classPK, start, end,
14203                            orderByComparator, true);
14204            }
14205    
14206            /**
14207             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14208             *
14209             * <p>
14210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14211             * </p>
14212             *
14213             * @param userId the user ID
14214             * @param classNameId the class name ID
14215             * @param classPK the class p k
14216             * @param start the lower bound of the range of message-boards messages
14217             * @param end the upper bound of the range of message-boards messages (not inclusive)
14218             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14219             * @param retrieveFromCache whether to retrieve from the finder cache
14220             * @return the ordered range of matching message-boards messages
14221             */
14222            @Override
14223            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14224                    long classPK, int start, int end,
14225                    OrderByComparator<MBMessage> orderByComparator,
14226                    boolean retrieveFromCache) {
14227                    boolean pagination = true;
14228                    FinderPath finderPath = null;
14229                    Object[] finderArgs = null;
14230    
14231                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14232                                    (orderByComparator == null)) {
14233                            pagination = false;
14234                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
14235                            finderArgs = new Object[] { userId, classNameId, classPK };
14236                    }
14237                    else {
14238                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
14239                            finderArgs = new Object[] {
14240                                            userId, classNameId, classPK,
14241                                            
14242                                            start, end, orderByComparator
14243                                    };
14244                    }
14245    
14246                    List<MBMessage> list = null;
14247    
14248                    if (retrieveFromCache) {
14249                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14250                                            finderArgs, this);
14251    
14252                            if ((list != null) && !list.isEmpty()) {
14253                                    for (MBMessage mbMessage : list) {
14254                                            if ((userId != mbMessage.getUserId()) ||
14255                                                            (classNameId != mbMessage.getClassNameId()) ||
14256                                                            (classPK != mbMessage.getClassPK())) {
14257                                                    list = null;
14258    
14259                                                    break;
14260                                            }
14261                                    }
14262                            }
14263                    }
14264    
14265                    if (list == null) {
14266                            StringBundler query = null;
14267    
14268                            if (orderByComparator != null) {
14269                                    query = new StringBundler(5 +
14270                                                    (orderByComparator.getOrderByFields().length * 2));
14271                            }
14272                            else {
14273                                    query = new StringBundler(5);
14274                            }
14275    
14276                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14277    
14278                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14279    
14280                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14281    
14282                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14283    
14284                            if (orderByComparator != null) {
14285                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14286                                            orderByComparator);
14287                            }
14288                            else
14289                             if (pagination) {
14290                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14291                            }
14292    
14293                            String sql = query.toString();
14294    
14295                            Session session = null;
14296    
14297                            try {
14298                                    session = openSession();
14299    
14300                                    Query q = session.createQuery(sql);
14301    
14302                                    QueryPos qPos = QueryPos.getInstance(q);
14303    
14304                                    qPos.add(userId);
14305    
14306                                    qPos.add(classNameId);
14307    
14308                                    qPos.add(classPK);
14309    
14310                                    if (!pagination) {
14311                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14312                                                            start, end, false);
14313    
14314                                            Collections.sort(list);
14315    
14316                                            list = Collections.unmodifiableList(list);
14317                                    }
14318                                    else {
14319                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14320                                                            start, end);
14321                                    }
14322    
14323                                    cacheResult(list);
14324    
14325                                    finderCache.putResult(finderPath, finderArgs, list);
14326                            }
14327                            catch (Exception e) {
14328                                    finderCache.removeResult(finderPath, finderArgs);
14329    
14330                                    throw processException(e);
14331                            }
14332                            finally {
14333                                    closeSession(session);
14334                            }
14335                    }
14336    
14337                    return list;
14338            }
14339    
14340            /**
14341             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14342             *
14343             * @param userId the user ID
14344             * @param classNameId the class name ID
14345             * @param classPK the class p k
14346             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14347             * @return the first matching message-boards message
14348             * @throws NoSuchMessageException if a matching message-boards message could not be found
14349             */
14350            @Override
14351            public MBMessage findByU_C_C_First(long userId, long classNameId,
14352                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14353                    throws NoSuchMessageException {
14354                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14355                                    orderByComparator);
14356    
14357                    if (mbMessage != null) {
14358                            return mbMessage;
14359                    }
14360    
14361                    StringBundler msg = new StringBundler(8);
14362    
14363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14364    
14365                    msg.append("userId=");
14366                    msg.append(userId);
14367    
14368                    msg.append(", classNameId=");
14369                    msg.append(classNameId);
14370    
14371                    msg.append(", classPK=");
14372                    msg.append(classPK);
14373    
14374                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14375    
14376                    throw new NoSuchMessageException(msg.toString());
14377            }
14378    
14379            /**
14380             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14381             *
14382             * @param userId the user ID
14383             * @param classNameId the class name ID
14384             * @param classPK the class p k
14385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14386             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14387             */
14388            @Override
14389            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14390                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14391                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14392                                    orderByComparator);
14393    
14394                    if (!list.isEmpty()) {
14395                            return list.get(0);
14396                    }
14397    
14398                    return null;
14399            }
14400    
14401            /**
14402             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14403             *
14404             * @param userId the user ID
14405             * @param classNameId the class name ID
14406             * @param classPK the class p k
14407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14408             * @return the last matching message-boards message
14409             * @throws NoSuchMessageException if a matching message-boards message could not be found
14410             */
14411            @Override
14412            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14413                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14414                    throws NoSuchMessageException {
14415                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14416                                    orderByComparator);
14417    
14418                    if (mbMessage != null) {
14419                            return mbMessage;
14420                    }
14421    
14422                    StringBundler msg = new StringBundler(8);
14423    
14424                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14425    
14426                    msg.append("userId=");
14427                    msg.append(userId);
14428    
14429                    msg.append(", classNameId=");
14430                    msg.append(classNameId);
14431    
14432                    msg.append(", classPK=");
14433                    msg.append(classPK);
14434    
14435                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14436    
14437                    throw new NoSuchMessageException(msg.toString());
14438            }
14439    
14440            /**
14441             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14442             *
14443             * @param userId the user ID
14444             * @param classNameId the class name ID
14445             * @param classPK the class p k
14446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14447             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14448             */
14449            @Override
14450            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14451                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14452                    int count = countByU_C_C(userId, classNameId, classPK);
14453    
14454                    if (count == 0) {
14455                            return null;
14456                    }
14457    
14458                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14459                                    count - 1, count, orderByComparator);
14460    
14461                    if (!list.isEmpty()) {
14462                            return list.get(0);
14463                    }
14464    
14465                    return null;
14466            }
14467    
14468            /**
14469             * 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;.
14470             *
14471             * @param messageId the primary key of the current message-boards message
14472             * @param userId the user ID
14473             * @param classNameId the class name ID
14474             * @param classPK the class p k
14475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14476             * @return the previous, current, and next message-boards message
14477             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14478             */
14479            @Override
14480            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14481                    long classNameId, long classPK,
14482                    OrderByComparator<MBMessage> orderByComparator)
14483                    throws NoSuchMessageException {
14484                    MBMessage mbMessage = findByPrimaryKey(messageId);
14485    
14486                    Session session = null;
14487    
14488                    try {
14489                            session = openSession();
14490    
14491                            MBMessage[] array = new MBMessageImpl[3];
14492    
14493                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14494                                            classNameId, classPK, orderByComparator, true);
14495    
14496                            array[1] = mbMessage;
14497    
14498                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14499                                            classNameId, classPK, orderByComparator, false);
14500    
14501                            return array;
14502                    }
14503                    catch (Exception e) {
14504                            throw processException(e);
14505                    }
14506                    finally {
14507                            closeSession(session);
14508                    }
14509            }
14510    
14511            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14512                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14513                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14514                    StringBundler query = null;
14515    
14516                    if (orderByComparator != null) {
14517                            query = new StringBundler(6 +
14518                                            (orderByComparator.getOrderByConditionFields().length * 3) +
14519                                            (orderByComparator.getOrderByFields().length * 3));
14520                    }
14521                    else {
14522                            query = new StringBundler(5);
14523                    }
14524    
14525                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14526    
14527                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14528    
14529                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14530    
14531                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14532    
14533                    if (orderByComparator != null) {
14534                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14535    
14536                            if (orderByConditionFields.length > 0) {
14537                                    query.append(WHERE_AND);
14538                            }
14539    
14540                            for (int i = 0; i < orderByConditionFields.length; i++) {
14541                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14542                                    query.append(orderByConditionFields[i]);
14543    
14544                                    if ((i + 1) < orderByConditionFields.length) {
14545                                            if (orderByComparator.isAscending() ^ previous) {
14546                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14547                                            }
14548                                            else {
14549                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14550                                            }
14551                                    }
14552                                    else {
14553                                            if (orderByComparator.isAscending() ^ previous) {
14554                                                    query.append(WHERE_GREATER_THAN);
14555                                            }
14556                                            else {
14557                                                    query.append(WHERE_LESSER_THAN);
14558                                            }
14559                                    }
14560                            }
14561    
14562                            query.append(ORDER_BY_CLAUSE);
14563    
14564                            String[] orderByFields = orderByComparator.getOrderByFields();
14565    
14566                            for (int i = 0; i < orderByFields.length; i++) {
14567                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14568                                    query.append(orderByFields[i]);
14569    
14570                                    if ((i + 1) < orderByFields.length) {
14571                                            if (orderByComparator.isAscending() ^ previous) {
14572                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14573                                            }
14574                                            else {
14575                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14576                                            }
14577                                    }
14578                                    else {
14579                                            if (orderByComparator.isAscending() ^ previous) {
14580                                                    query.append(ORDER_BY_ASC);
14581                                            }
14582                                            else {
14583                                                    query.append(ORDER_BY_DESC);
14584                                            }
14585                                    }
14586                            }
14587                    }
14588                    else {
14589                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14590                    }
14591    
14592                    String sql = query.toString();
14593    
14594                    Query q = session.createQuery(sql);
14595    
14596                    q.setFirstResult(0);
14597                    q.setMaxResults(2);
14598    
14599                    QueryPos qPos = QueryPos.getInstance(q);
14600    
14601                    qPos.add(userId);
14602    
14603                    qPos.add(classNameId);
14604    
14605                    qPos.add(classPK);
14606    
14607                    if (orderByComparator != null) {
14608                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14609    
14610                            for (Object value : values) {
14611                                    qPos.add(value);
14612                            }
14613                    }
14614    
14615                    List<MBMessage> list = q.list();
14616    
14617                    if (list.size() == 2) {
14618                            return list.get(1);
14619                    }
14620                    else {
14621                            return null;
14622                    }
14623            }
14624    
14625            /**
14626             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14627             *
14628             * @param userId the user ID
14629             * @param classNameId the class name ID
14630             * @param classPK the class p k
14631             */
14632            @Override
14633            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14634                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14635                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14636                            remove(mbMessage);
14637                    }
14638            }
14639    
14640            /**
14641             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14642             *
14643             * @param userId the user ID
14644             * @param classNameId the class name ID
14645             * @param classPK the class p k
14646             * @return the number of matching message-boards messages
14647             */
14648            @Override
14649            public int countByU_C_C(long userId, long classNameId, long classPK) {
14650                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14651    
14652                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14653    
14654                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14655    
14656                    if (count == null) {
14657                            StringBundler query = new StringBundler(4);
14658    
14659                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14660    
14661                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14662    
14663                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14664    
14665                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14666    
14667                            String sql = query.toString();
14668    
14669                            Session session = null;
14670    
14671                            try {
14672                                    session = openSession();
14673    
14674                                    Query q = session.createQuery(sql);
14675    
14676                                    QueryPos qPos = QueryPos.getInstance(q);
14677    
14678                                    qPos.add(userId);
14679    
14680                                    qPos.add(classNameId);
14681    
14682                                    qPos.add(classPK);
14683    
14684                                    count = (Long)q.uniqueResult();
14685    
14686                                    finderCache.putResult(finderPath, finderArgs, count);
14687                            }
14688                            catch (Exception e) {
14689                                    finderCache.removeResult(finderPath, finderArgs);
14690    
14691                                    throw processException(e);
14692                            }
14693                            finally {
14694                                    closeSession(session);
14695                            }
14696                    }
14697    
14698                    return count.intValue();
14699            }
14700    
14701            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14702            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14703            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14704            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14705                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14706                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14707                            new String[] {
14708                                    Long.class.getName(), Long.class.getName(),
14709                                    Integer.class.getName(),
14710                                    
14711                            Integer.class.getName(), Integer.class.getName(),
14712                                    OrderByComparator.class.getName()
14713                            });
14714            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14715                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14716                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14717                            new String[] {
14718                                    Long.class.getName(), Long.class.getName(),
14719                                    Integer.class.getName()
14720                            },
14721                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14722                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14723                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14724                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14725            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14726                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14727                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14728                            new String[] {
14729                                    Long.class.getName(), Long.class.getName(),
14730                                    Integer.class.getName()
14731                            });
14732            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14733                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14734                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14735                            new String[] {
14736                                    Long.class.getName(), Long.class.getName(),
14737                                    Integer.class.getName()
14738                            });
14739    
14740            /**
14741             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14742             *
14743             * @param userId the user ID
14744             * @param classNameId the class name ID
14745             * @param status the status
14746             * @return the matching message-boards messages
14747             */
14748            @Override
14749            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14750                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14751                            QueryUtil.ALL_POS, null);
14752            }
14753    
14754            /**
14755             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14756             *
14757             * <p>
14758             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14759             * </p>
14760             *
14761             * @param userId the user ID
14762             * @param classNameId the class name ID
14763             * @param status the status
14764             * @param start the lower bound of the range of message-boards messages
14765             * @param end the upper bound of the range of message-boards messages (not inclusive)
14766             * @return the range of matching message-boards messages
14767             */
14768            @Override
14769            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14770                    int status, int start, int end) {
14771                    return findByU_C_S(userId, classNameId, status, start, end, null);
14772            }
14773    
14774            /**
14775             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14776             *
14777             * <p>
14778             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14779             * </p>
14780             *
14781             * @param userId the user ID
14782             * @param classNameId the class name ID
14783             * @param status the status
14784             * @param start the lower bound of the range of message-boards messages
14785             * @param end the upper bound of the range of message-boards messages (not inclusive)
14786             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14787             * @return the ordered range of matching message-boards messages
14788             */
14789            @Override
14790            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14791                    int status, int start, int end,
14792                    OrderByComparator<MBMessage> orderByComparator) {
14793                    return findByU_C_S(userId, classNameId, status, start, end,
14794                            orderByComparator, true);
14795            }
14796    
14797            /**
14798             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14799             *
14800             * <p>
14801             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14802             * </p>
14803             *
14804             * @param userId the user ID
14805             * @param classNameId the class name ID
14806             * @param status the status
14807             * @param start the lower bound of the range of message-boards messages
14808             * @param end the upper bound of the range of message-boards messages (not inclusive)
14809             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14810             * @param retrieveFromCache whether to retrieve from the finder cache
14811             * @return the ordered range of matching message-boards messages
14812             */
14813            @Override
14814            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14815                    int status, int start, int end,
14816                    OrderByComparator<MBMessage> orderByComparator,
14817                    boolean retrieveFromCache) {
14818                    boolean pagination = true;
14819                    FinderPath finderPath = null;
14820                    Object[] finderArgs = null;
14821    
14822                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14823                                    (orderByComparator == null)) {
14824                            pagination = false;
14825                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14826                            finderArgs = new Object[] { userId, classNameId, status };
14827                    }
14828                    else {
14829                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14830                            finderArgs = new Object[] {
14831                                            userId, classNameId, status,
14832                                            
14833                                            start, end, orderByComparator
14834                                    };
14835                    }
14836    
14837                    List<MBMessage> list = null;
14838    
14839                    if (retrieveFromCache) {
14840                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14841                                            finderArgs, this);
14842    
14843                            if ((list != null) && !list.isEmpty()) {
14844                                    for (MBMessage mbMessage : list) {
14845                                            if ((userId != mbMessage.getUserId()) ||
14846                                                            (classNameId != mbMessage.getClassNameId()) ||
14847                                                            (status != mbMessage.getStatus())) {
14848                                                    list = null;
14849    
14850                                                    break;
14851                                            }
14852                                    }
14853                            }
14854                    }
14855    
14856                    if (list == null) {
14857                            StringBundler query = null;
14858    
14859                            if (orderByComparator != null) {
14860                                    query = new StringBundler(5 +
14861                                                    (orderByComparator.getOrderByFields().length * 2));
14862                            }
14863                            else {
14864                                    query = new StringBundler(5);
14865                            }
14866    
14867                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14868    
14869                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14870    
14871                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14872    
14873                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14874    
14875                            if (orderByComparator != null) {
14876                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14877                                            orderByComparator);
14878                            }
14879                            else
14880                             if (pagination) {
14881                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14882                            }
14883    
14884                            String sql = query.toString();
14885    
14886                            Session session = null;
14887    
14888                            try {
14889                                    session = openSession();
14890    
14891                                    Query q = session.createQuery(sql);
14892    
14893                                    QueryPos qPos = QueryPos.getInstance(q);
14894    
14895                                    qPos.add(userId);
14896    
14897                                    qPos.add(classNameId);
14898    
14899                                    qPos.add(status);
14900    
14901                                    if (!pagination) {
14902                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14903                                                            start, end, false);
14904    
14905                                            Collections.sort(list);
14906    
14907                                            list = Collections.unmodifiableList(list);
14908                                    }
14909                                    else {
14910                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14911                                                            start, end);
14912                                    }
14913    
14914                                    cacheResult(list);
14915    
14916                                    finderCache.putResult(finderPath, finderArgs, list);
14917                            }
14918                            catch (Exception e) {
14919                                    finderCache.removeResult(finderPath, finderArgs);
14920    
14921                                    throw processException(e);
14922                            }
14923                            finally {
14924                                    closeSession(session);
14925                            }
14926                    }
14927    
14928                    return list;
14929            }
14930    
14931            /**
14932             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14933             *
14934             * @param userId the user ID
14935             * @param classNameId the class name ID
14936             * @param status the status
14937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14938             * @return the first matching message-boards message
14939             * @throws NoSuchMessageException if a matching message-boards message could not be found
14940             */
14941            @Override
14942            public MBMessage findByU_C_S_First(long userId, long classNameId,
14943                    int status, OrderByComparator<MBMessage> orderByComparator)
14944                    throws NoSuchMessageException {
14945                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14946                                    orderByComparator);
14947    
14948                    if (mbMessage != null) {
14949                            return mbMessage;
14950                    }
14951    
14952                    StringBundler msg = new StringBundler(8);
14953    
14954                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14955    
14956                    msg.append("userId=");
14957                    msg.append(userId);
14958    
14959                    msg.append(", classNameId=");
14960                    msg.append(classNameId);
14961    
14962                    msg.append(", status=");
14963                    msg.append(status);
14964    
14965                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14966    
14967                    throw new NoSuchMessageException(msg.toString());
14968            }
14969    
14970            /**
14971             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14972             *
14973             * @param userId the user ID
14974             * @param classNameId the class name ID
14975             * @param status the status
14976             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14977             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14978             */
14979            @Override
14980            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14981                    int status, OrderByComparator<MBMessage> orderByComparator) {
14982                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14983                                    orderByComparator);
14984    
14985                    if (!list.isEmpty()) {
14986                            return list.get(0);
14987                    }
14988    
14989                    return null;
14990            }
14991    
14992            /**
14993             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14994             *
14995             * @param userId the user ID
14996             * @param classNameId the class name ID
14997             * @param status the status
14998             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14999             * @return the last matching message-boards message
15000             * @throws NoSuchMessageException if a matching message-boards message could not be found
15001             */
15002            @Override
15003            public MBMessage findByU_C_S_Last(long userId, long classNameId,
15004                    int status, OrderByComparator<MBMessage> orderByComparator)
15005                    throws NoSuchMessageException {
15006                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
15007                                    orderByComparator);
15008    
15009                    if (mbMessage != null) {
15010                            return mbMessage;
15011                    }
15012    
15013                    StringBundler msg = new StringBundler(8);
15014    
15015                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15016    
15017                    msg.append("userId=");
15018                    msg.append(userId);
15019    
15020                    msg.append(", classNameId=");
15021                    msg.append(classNameId);
15022    
15023                    msg.append(", status=");
15024                    msg.append(status);
15025    
15026                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15027    
15028                    throw new NoSuchMessageException(msg.toString());
15029            }
15030    
15031            /**
15032             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
15033             *
15034             * @param userId the user ID
15035             * @param classNameId the class name ID
15036             * @param status the status
15037             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15038             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15039             */
15040            @Override
15041            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
15042                    int status, OrderByComparator<MBMessage> orderByComparator) {
15043                    int count = countByU_C_S(userId, classNameId, status);
15044    
15045                    if (count == 0) {
15046                            return null;
15047                    }
15048    
15049                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
15050                                    count - 1, count, orderByComparator);
15051    
15052                    if (!list.isEmpty()) {
15053                            return list.get(0);
15054                    }
15055    
15056                    return null;
15057            }
15058    
15059            /**
15060             * 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;.
15061             *
15062             * @param messageId the primary key of the current message-boards message
15063             * @param userId the user ID
15064             * @param classNameId the class name ID
15065             * @param status the status
15066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15067             * @return the previous, current, and next message-boards message
15068             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15069             */
15070            @Override
15071            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
15072                    long classNameId, int status,
15073                    OrderByComparator<MBMessage> orderByComparator)
15074                    throws NoSuchMessageException {
15075                    MBMessage mbMessage = findByPrimaryKey(messageId);
15076    
15077                    Session session = null;
15078    
15079                    try {
15080                            session = openSession();
15081    
15082                            MBMessage[] array = new MBMessageImpl[3];
15083    
15084                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15085                                            classNameId, status, orderByComparator, true);
15086    
15087                            array[1] = mbMessage;
15088    
15089                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15090                                            classNameId, status, orderByComparator, false);
15091    
15092                            return array;
15093                    }
15094                    catch (Exception e) {
15095                            throw processException(e);
15096                    }
15097                    finally {
15098                            closeSession(session);
15099                    }
15100            }
15101    
15102            protected MBMessage getByU_C_S_PrevAndNext(Session session,
15103                    MBMessage mbMessage, long userId, long classNameId, int status,
15104                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15105                    StringBundler query = null;
15106    
15107                    if (orderByComparator != null) {
15108                            query = new StringBundler(6 +
15109                                            (orderByComparator.getOrderByConditionFields().length * 3) +
15110                                            (orderByComparator.getOrderByFields().length * 3));
15111                    }
15112                    else {
15113                            query = new StringBundler(5);
15114                    }
15115    
15116                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15117    
15118                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15119    
15120                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15121    
15122                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15123    
15124                    if (orderByComparator != null) {
15125                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15126    
15127                            if (orderByConditionFields.length > 0) {
15128                                    query.append(WHERE_AND);
15129                            }
15130    
15131                            for (int i = 0; i < orderByConditionFields.length; i++) {
15132                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15133                                    query.append(orderByConditionFields[i]);
15134    
15135                                    if ((i + 1) < orderByConditionFields.length) {
15136                                            if (orderByComparator.isAscending() ^ previous) {
15137                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15138                                            }
15139                                            else {
15140                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15141                                            }
15142                                    }
15143                                    else {
15144                                            if (orderByComparator.isAscending() ^ previous) {
15145                                                    query.append(WHERE_GREATER_THAN);
15146                                            }
15147                                            else {
15148                                                    query.append(WHERE_LESSER_THAN);
15149                                            }
15150                                    }
15151                            }
15152    
15153                            query.append(ORDER_BY_CLAUSE);
15154    
15155                            String[] orderByFields = orderByComparator.getOrderByFields();
15156    
15157                            for (int i = 0; i < orderByFields.length; i++) {
15158                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15159                                    query.append(orderByFields[i]);
15160    
15161                                    if ((i + 1) < orderByFields.length) {
15162                                            if (orderByComparator.isAscending() ^ previous) {
15163                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15164                                            }
15165                                            else {
15166                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15167                                            }
15168                                    }
15169                                    else {
15170                                            if (orderByComparator.isAscending() ^ previous) {
15171                                                    query.append(ORDER_BY_ASC);
15172                                            }
15173                                            else {
15174                                                    query.append(ORDER_BY_DESC);
15175                                            }
15176                                    }
15177                            }
15178                    }
15179                    else {
15180                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15181                    }
15182    
15183                    String sql = query.toString();
15184    
15185                    Query q = session.createQuery(sql);
15186    
15187                    q.setFirstResult(0);
15188                    q.setMaxResults(2);
15189    
15190                    QueryPos qPos = QueryPos.getInstance(q);
15191    
15192                    qPos.add(userId);
15193    
15194                    qPos.add(classNameId);
15195    
15196                    qPos.add(status);
15197    
15198                    if (orderByComparator != null) {
15199                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15200    
15201                            for (Object value : values) {
15202                                    qPos.add(value);
15203                            }
15204                    }
15205    
15206                    List<MBMessage> list = q.list();
15207    
15208                    if (list.size() == 2) {
15209                            return list.get(1);
15210                    }
15211                    else {
15212                            return null;
15213                    }
15214            }
15215    
15216            /**
15217             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15218             *
15219             * <p>
15220             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15221             * </p>
15222             *
15223             * @param userId the user ID
15224             * @param classNameIds the class name IDs
15225             * @param status the status
15226             * @return the matching message-boards messages
15227             */
15228            @Override
15229            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15230                    int status) {
15231                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
15232                            QueryUtil.ALL_POS, null);
15233            }
15234    
15235            /**
15236             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15237             *
15238             * <p>
15239             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15240             * </p>
15241             *
15242             * @param userId the user ID
15243             * @param classNameIds the class name IDs
15244             * @param status the status
15245             * @param start the lower bound of the range of message-boards messages
15246             * @param end the upper bound of the range of message-boards messages (not inclusive)
15247             * @return the range of matching message-boards messages
15248             */
15249            @Override
15250            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15251                    int status, int start, int end) {
15252                    return findByU_C_S(userId, classNameIds, status, start, end, null);
15253            }
15254    
15255            /**
15256             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15257             *
15258             * <p>
15259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15260             * </p>
15261             *
15262             * @param userId the user ID
15263             * @param classNameIds the class name IDs
15264             * @param status the status
15265             * @param start the lower bound of the range of message-boards messages
15266             * @param end the upper bound of the range of message-boards messages (not inclusive)
15267             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15268             * @return the ordered range of matching message-boards messages
15269             */
15270            @Override
15271            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15272                    int status, int start, int end,
15273                    OrderByComparator<MBMessage> orderByComparator) {
15274                    return findByU_C_S(userId, classNameIds, status, start, end,
15275                            orderByComparator, true);
15276            }
15277    
15278            /**
15279             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;, optionally using the finder cache.
15280             *
15281             * <p>
15282             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15283             * </p>
15284             *
15285             * @param userId the user ID
15286             * @param classNameId the class name ID
15287             * @param status the status
15288             * @param start the lower bound of the range of message-boards messages
15289             * @param end the upper bound of the range of message-boards messages (not inclusive)
15290             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15291             * @param retrieveFromCache whether to retrieve from the finder cache
15292             * @return the ordered range of matching message-boards messages
15293             */
15294            @Override
15295            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15296                    int status, int start, int end,
15297                    OrderByComparator<MBMessage> orderByComparator,
15298                    boolean retrieveFromCache) {
15299                    if (classNameIds == null) {
15300                            classNameIds = new long[0];
15301                    }
15302                    else if (classNameIds.length > 1) {
15303                            classNameIds = ArrayUtil.unique(classNameIds);
15304    
15305                            Arrays.sort(classNameIds);
15306                    }
15307    
15308                    if (classNameIds.length == 1) {
15309                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15310                                    orderByComparator);
15311                    }
15312    
15313                    boolean pagination = true;
15314                    Object[] finderArgs = null;
15315    
15316                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15317                                    (orderByComparator == null)) {
15318                            pagination = false;
15319                            finderArgs = new Object[] {
15320                                            userId, StringUtil.merge(classNameIds), status
15321                                    };
15322                    }
15323                    else {
15324                            finderArgs = new Object[] {
15325                                            userId, StringUtil.merge(classNameIds), status,
15326                                            
15327                                            start, end, orderByComparator
15328                                    };
15329                    }
15330    
15331                    List<MBMessage> list = null;
15332    
15333                    if (retrieveFromCache) {
15334                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15335                                            finderArgs, this);
15336    
15337                            if ((list != null) && !list.isEmpty()) {
15338                                    for (MBMessage mbMessage : list) {
15339                                            if ((userId != mbMessage.getUserId()) ||
15340                                                            !ArrayUtil.contains(classNameIds,
15341                                                                    mbMessage.getClassNameId()) ||
15342                                                            (status != mbMessage.getStatus())) {
15343                                                    list = null;
15344    
15345                                                    break;
15346                                            }
15347                                    }
15348                            }
15349                    }
15350    
15351                    if (list == null) {
15352                            StringBundler query = new StringBundler();
15353    
15354                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15355    
15356                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15357    
15358                            if (classNameIds.length > 0) {
15359                                    query.append(StringPool.OPEN_PARENTHESIS);
15360    
15361                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15362    
15363                                    query.append(StringUtil.merge(classNameIds));
15364    
15365                                    query.append(StringPool.CLOSE_PARENTHESIS);
15366    
15367                                    query.append(StringPool.CLOSE_PARENTHESIS);
15368    
15369                                    query.append(WHERE_AND);
15370                            }
15371    
15372                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15373    
15374                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15375                                                    1)), query.index() - 1);
15376    
15377                            if (orderByComparator != null) {
15378                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15379                                            orderByComparator);
15380                            }
15381                            else
15382                             if (pagination) {
15383                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15384                            }
15385    
15386                            String sql = query.toString();
15387    
15388                            Session session = null;
15389    
15390                            try {
15391                                    session = openSession();
15392    
15393                                    Query q = session.createQuery(sql);
15394    
15395                                    QueryPos qPos = QueryPos.getInstance(q);
15396    
15397                                    qPos.add(userId);
15398    
15399                                    qPos.add(status);
15400    
15401                                    if (!pagination) {
15402                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15403                                                            start, end, false);
15404    
15405                                            Collections.sort(list);
15406    
15407                                            list = Collections.unmodifiableList(list);
15408                                    }
15409                                    else {
15410                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15411                                                            start, end);
15412                                    }
15413    
15414                                    cacheResult(list);
15415    
15416                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15417                                            finderArgs, list);
15418                            }
15419                            catch (Exception e) {
15420                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15421                                            finderArgs);
15422    
15423                                    throw processException(e);
15424                            }
15425                            finally {
15426                                    closeSession(session);
15427                            }
15428                    }
15429    
15430                    return list;
15431            }
15432    
15433            /**
15434             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15435             *
15436             * @param userId the user ID
15437             * @param classNameId the class name ID
15438             * @param status the status
15439             */
15440            @Override
15441            public void removeByU_C_S(long userId, long classNameId, int status) {
15442                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15443                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15444                            remove(mbMessage);
15445                    }
15446            }
15447    
15448            /**
15449             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15450             *
15451             * @param userId the user ID
15452             * @param classNameId the class name ID
15453             * @param status the status
15454             * @return the number of matching message-boards messages
15455             */
15456            @Override
15457            public int countByU_C_S(long userId, long classNameId, int status) {
15458                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15459    
15460                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15461    
15462                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
15463    
15464                    if (count == null) {
15465                            StringBundler query = new StringBundler(4);
15466    
15467                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15468    
15469                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15470    
15471                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15472    
15473                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15474    
15475                            String sql = query.toString();
15476    
15477                            Session session = null;
15478    
15479                            try {
15480                                    session = openSession();
15481    
15482                                    Query q = session.createQuery(sql);
15483    
15484                                    QueryPos qPos = QueryPos.getInstance(q);
15485    
15486                                    qPos.add(userId);
15487    
15488                                    qPos.add(classNameId);
15489    
15490                                    qPos.add(status);
15491    
15492                                    count = (Long)q.uniqueResult();
15493    
15494                                    finderCache.putResult(finderPath, finderArgs, count);
15495                            }
15496                            catch (Exception e) {
15497                                    finderCache.removeResult(finderPath, finderArgs);
15498    
15499                                    throw processException(e);
15500                            }
15501                            finally {
15502                                    closeSession(session);
15503                            }
15504                    }
15505    
15506                    return count.intValue();
15507            }
15508    
15509            /**
15510             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15511             *
15512             * @param userId the user ID
15513             * @param classNameIds the class name IDs
15514             * @param status the status
15515             * @return the number of matching message-boards messages
15516             */
15517            @Override
15518            public int countByU_C_S(long userId, long[] classNameIds, int status) {
15519                    if (classNameIds == null) {
15520                            classNameIds = new long[0];
15521                    }
15522                    else if (classNameIds.length > 1) {
15523                            classNameIds = ArrayUtil.unique(classNameIds);
15524    
15525                            Arrays.sort(classNameIds);
15526                    }
15527    
15528                    Object[] finderArgs = new Object[] {
15529                                    userId, StringUtil.merge(classNameIds), status
15530                            };
15531    
15532                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15533                                    finderArgs, this);
15534    
15535                    if (count == null) {
15536                            StringBundler query = new StringBundler();
15537    
15538                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15539    
15540                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15541    
15542                            if (classNameIds.length > 0) {
15543                                    query.append(StringPool.OPEN_PARENTHESIS);
15544    
15545                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15546    
15547                                    query.append(StringUtil.merge(classNameIds));
15548    
15549                                    query.append(StringPool.CLOSE_PARENTHESIS);
15550    
15551                                    query.append(StringPool.CLOSE_PARENTHESIS);
15552    
15553                                    query.append(WHERE_AND);
15554                            }
15555    
15556                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15557    
15558                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15559                                                    1)), query.index() - 1);
15560    
15561                            String sql = query.toString();
15562    
15563                            Session session = null;
15564    
15565                            try {
15566                                    session = openSession();
15567    
15568                                    Query q = session.createQuery(sql);
15569    
15570                                    QueryPos qPos = QueryPos.getInstance(q);
15571    
15572                                    qPos.add(userId);
15573    
15574                                    qPos.add(status);
15575    
15576                                    count = (Long)q.uniqueResult();
15577    
15578                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15579                                            finderArgs, count);
15580                            }
15581                            catch (Exception e) {
15582                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15583                                            finderArgs);
15584    
15585                                    throw processException(e);
15586                            }
15587                            finally {
15588                                    closeSession(session);
15589                            }
15590                    }
15591    
15592                    return count.intValue();
15593            }
15594    
15595            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15596            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15597            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
15598            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15599            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15600                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15601                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15602                            new String[] {
15603                                    Long.class.getName(), Long.class.getName(),
15604                                    Integer.class.getName(),
15605                                    
15606                            Integer.class.getName(), Integer.class.getName(),
15607                                    OrderByComparator.class.getName()
15608                            });
15609            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15610                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15612                            new String[] {
15613                                    Long.class.getName(), Long.class.getName(),
15614                                    Integer.class.getName()
15615                            },
15616                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15617                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15618                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15619                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15620            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15621                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15622                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15623                            new String[] {
15624                                    Long.class.getName(), Long.class.getName(),
15625                                    Integer.class.getName()
15626                            });
15627    
15628            /**
15629             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15630             *
15631             * @param classNameId the class name ID
15632             * @param classPK the class p k
15633             * @param status the status
15634             * @return the matching message-boards messages
15635             */
15636            @Override
15637            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15638                    int status) {
15639                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15640                            QueryUtil.ALL_POS, null);
15641            }
15642    
15643            /**
15644             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15645             *
15646             * <p>
15647             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15648             * </p>
15649             *
15650             * @param classNameId the class name ID
15651             * @param classPK the class p k
15652             * @param status the status
15653             * @param start the lower bound of the range of message-boards messages
15654             * @param end the upper bound of the range of message-boards messages (not inclusive)
15655             * @return the range of matching message-boards messages
15656             */
15657            @Override
15658            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15659                    int status, int start, int end) {
15660                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15661            }
15662    
15663            /**
15664             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15665             *
15666             * <p>
15667             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15668             * </p>
15669             *
15670             * @param classNameId the class name ID
15671             * @param classPK the class p k
15672             * @param status the status
15673             * @param start the lower bound of the range of message-boards messages
15674             * @param end the upper bound of the range of message-boards messages (not inclusive)
15675             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15676             * @return the ordered range of matching message-boards messages
15677             */
15678            @Override
15679            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15680                    int status, int start, int end,
15681                    OrderByComparator<MBMessage> orderByComparator) {
15682                    return findByC_C_S(classNameId, classPK, status, start, end,
15683                            orderByComparator, true);
15684            }
15685    
15686            /**
15687             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15688             *
15689             * <p>
15690             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15691             * </p>
15692             *
15693             * @param classNameId the class name ID
15694             * @param classPK the class p k
15695             * @param status the status
15696             * @param start the lower bound of the range of message-boards messages
15697             * @param end the upper bound of the range of message-boards messages (not inclusive)
15698             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15699             * @param retrieveFromCache whether to retrieve from the finder cache
15700             * @return the ordered range of matching message-boards messages
15701             */
15702            @Override
15703            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15704                    int status, int start, int end,
15705                    OrderByComparator<MBMessage> orderByComparator,
15706                    boolean retrieveFromCache) {
15707                    boolean pagination = true;
15708                    FinderPath finderPath = null;
15709                    Object[] finderArgs = null;
15710    
15711                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15712                                    (orderByComparator == null)) {
15713                            pagination = false;
15714                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15715                            finderArgs = new Object[] { classNameId, classPK, status };
15716                    }
15717                    else {
15718                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15719                            finderArgs = new Object[] {
15720                                            classNameId, classPK, status,
15721                                            
15722                                            start, end, orderByComparator
15723                                    };
15724                    }
15725    
15726                    List<MBMessage> list = null;
15727    
15728                    if (retrieveFromCache) {
15729                            list = (List<MBMessage>)finderCache.getResult(finderPath,
15730                                            finderArgs, this);
15731    
15732                            if ((list != null) && !list.isEmpty()) {
15733                                    for (MBMessage mbMessage : list) {
15734                                            if ((classNameId != mbMessage.getClassNameId()) ||
15735                                                            (classPK != mbMessage.getClassPK()) ||
15736                                                            (status != mbMessage.getStatus())) {
15737                                                    list = null;
15738    
15739                                                    break;
15740                                            }
15741                                    }
15742                            }
15743                    }
15744    
15745                    if (list == null) {
15746                            StringBundler query = null;
15747    
15748                            if (orderByComparator != null) {
15749                                    query = new StringBundler(5 +
15750                                                    (orderByComparator.getOrderByFields().length * 2));
15751                            }
15752                            else {
15753                                    query = new StringBundler(5);
15754                            }
15755    
15756                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15757    
15758                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15759    
15760                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15761    
15762                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15763    
15764                            if (orderByComparator != null) {
15765                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15766                                            orderByComparator);
15767                            }
15768                            else
15769                             if (pagination) {
15770                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15771                            }
15772    
15773                            String sql = query.toString();
15774    
15775                            Session session = null;
15776    
15777                            try {
15778                                    session = openSession();
15779    
15780                                    Query q = session.createQuery(sql);
15781    
15782                                    QueryPos qPos = QueryPos.getInstance(q);
15783    
15784                                    qPos.add(classNameId);
15785    
15786                                    qPos.add(classPK);
15787    
15788                                    qPos.add(status);
15789    
15790                                    if (!pagination) {
15791                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15792                                                            start, end, false);
15793    
15794                                            Collections.sort(list);
15795    
15796                                            list = Collections.unmodifiableList(list);
15797                                    }
15798                                    else {
15799                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15800                                                            start, end);
15801                                    }
15802    
15803                                    cacheResult(list);
15804    
15805                                    finderCache.putResult(finderPath, finderArgs, list);
15806                            }
15807                            catch (Exception e) {
15808                                    finderCache.removeResult(finderPath, finderArgs);
15809    
15810                                    throw processException(e);
15811                            }
15812                            finally {
15813                                    closeSession(session);
15814                            }
15815                    }
15816    
15817                    return list;
15818            }
15819    
15820            /**
15821             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15822             *
15823             * @param classNameId the class name ID
15824             * @param classPK the class p k
15825             * @param status the status
15826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15827             * @return the first matching message-boards message
15828             * @throws NoSuchMessageException if a matching message-boards message could not be found
15829             */
15830            @Override
15831            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15832                    int status, OrderByComparator<MBMessage> orderByComparator)
15833                    throws NoSuchMessageException {
15834                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15835                                    orderByComparator);
15836    
15837                    if (mbMessage != null) {
15838                            return mbMessage;
15839                    }
15840    
15841                    StringBundler msg = new StringBundler(8);
15842    
15843                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15844    
15845                    msg.append("classNameId=");
15846                    msg.append(classNameId);
15847    
15848                    msg.append(", classPK=");
15849                    msg.append(classPK);
15850    
15851                    msg.append(", status=");
15852                    msg.append(status);
15853    
15854                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15855    
15856                    throw new NoSuchMessageException(msg.toString());
15857            }
15858    
15859            /**
15860             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15861             *
15862             * @param classNameId the class name ID
15863             * @param classPK the class p k
15864             * @param status the status
15865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15866             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15867             */
15868            @Override
15869            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15870                    int status, OrderByComparator<MBMessage> orderByComparator) {
15871                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15872                                    orderByComparator);
15873    
15874                    if (!list.isEmpty()) {
15875                            return list.get(0);
15876                    }
15877    
15878                    return null;
15879            }
15880    
15881            /**
15882             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15883             *
15884             * @param classNameId the class name ID
15885             * @param classPK the class p k
15886             * @param status the status
15887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15888             * @return the last matching message-boards message
15889             * @throws NoSuchMessageException if a matching message-boards message could not be found
15890             */
15891            @Override
15892            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15893                    int status, OrderByComparator<MBMessage> orderByComparator)
15894                    throws NoSuchMessageException {
15895                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15896                                    orderByComparator);
15897    
15898                    if (mbMessage != null) {
15899                            return mbMessage;
15900                    }
15901    
15902                    StringBundler msg = new StringBundler(8);
15903    
15904                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15905    
15906                    msg.append("classNameId=");
15907                    msg.append(classNameId);
15908    
15909                    msg.append(", classPK=");
15910                    msg.append(classPK);
15911    
15912                    msg.append(", status=");
15913                    msg.append(status);
15914    
15915                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15916    
15917                    throw new NoSuchMessageException(msg.toString());
15918            }
15919    
15920            /**
15921             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15922             *
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 last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15928             */
15929            @Override
15930            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15931                    int status, OrderByComparator<MBMessage> orderByComparator) {
15932                    int count = countByC_C_S(classNameId, classPK, status);
15933    
15934                    if (count == 0) {
15935                            return null;
15936                    }
15937    
15938                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15939                                    count - 1, count, orderByComparator);
15940    
15941                    if (!list.isEmpty()) {
15942                            return list.get(0);
15943                    }
15944    
15945                    return null;
15946            }
15947    
15948            /**
15949             * 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;.
15950             *
15951             * @param messageId the primary key of the current message-boards message
15952             * @param classNameId the class name ID
15953             * @param classPK the class p k
15954             * @param status the status
15955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15956             * @return the previous, current, and next message-boards message
15957             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15958             */
15959            @Override
15960            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15961                    long classNameId, long classPK, int status,
15962                    OrderByComparator<MBMessage> orderByComparator)
15963                    throws NoSuchMessageException {
15964                    MBMessage mbMessage = findByPrimaryKey(messageId);
15965    
15966                    Session session = null;
15967    
15968                    try {
15969                            session = openSession();
15970    
15971                            MBMessage[] array = new MBMessageImpl[3];
15972    
15973                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15974                                            classPK, status, orderByComparator, true);
15975    
15976                            array[1] = mbMessage;
15977    
15978                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15979                                            classPK, status, orderByComparator, false);
15980    
15981                            return array;
15982                    }
15983                    catch (Exception e) {
15984                            throw processException(e);
15985                    }
15986                    finally {
15987                            closeSession(session);
15988                    }
15989            }
15990    
15991            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15992                    MBMessage mbMessage, long classNameId, long classPK, int status,
15993                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15994                    StringBundler query = null;
15995    
15996                    if (orderByComparator != null) {
15997                            query = new StringBundler(6 +
15998                                            (orderByComparator.getOrderByConditionFields().length * 3) +
15999                                            (orderByComparator.getOrderByFields().length * 3));
16000                    }
16001                    else {
16002                            query = new StringBundler(5);
16003                    }
16004    
16005                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16006    
16007                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16008    
16009                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16010    
16011                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16012    
16013                    if (orderByComparator != null) {
16014                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16015    
16016                            if (orderByConditionFields.length > 0) {
16017                                    query.append(WHERE_AND);
16018                            }
16019    
16020                            for (int i = 0; i < orderByConditionFields.length; i++) {
16021                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16022                                    query.append(orderByConditionFields[i]);
16023    
16024                                    if ((i + 1) < orderByConditionFields.length) {
16025                                            if (orderByComparator.isAscending() ^ previous) {
16026                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16027                                            }
16028                                            else {
16029                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16030                                            }
16031                                    }
16032                                    else {
16033                                            if (orderByComparator.isAscending() ^ previous) {
16034                                                    query.append(WHERE_GREATER_THAN);
16035                                            }
16036                                            else {
16037                                                    query.append(WHERE_LESSER_THAN);
16038                                            }
16039                                    }
16040                            }
16041    
16042                            query.append(ORDER_BY_CLAUSE);
16043    
16044                            String[] orderByFields = orderByComparator.getOrderByFields();
16045    
16046                            for (int i = 0; i < orderByFields.length; i++) {
16047                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16048                                    query.append(orderByFields[i]);
16049    
16050                                    if ((i + 1) < orderByFields.length) {
16051                                            if (orderByComparator.isAscending() ^ previous) {
16052                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16053                                            }
16054                                            else {
16055                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16056                                            }
16057                                    }
16058                                    else {
16059                                            if (orderByComparator.isAscending() ^ previous) {
16060                                                    query.append(ORDER_BY_ASC);
16061                                            }
16062                                            else {
16063                                                    query.append(ORDER_BY_DESC);
16064                                            }
16065                                    }
16066                            }
16067                    }
16068                    else {
16069                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16070                    }
16071    
16072                    String sql = query.toString();
16073    
16074                    Query q = session.createQuery(sql);
16075    
16076                    q.setFirstResult(0);
16077                    q.setMaxResults(2);
16078    
16079                    QueryPos qPos = QueryPos.getInstance(q);
16080    
16081                    qPos.add(classNameId);
16082    
16083                    qPos.add(classPK);
16084    
16085                    qPos.add(status);
16086    
16087                    if (orderByComparator != null) {
16088                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16089    
16090                            for (Object value : values) {
16091                                    qPos.add(value);
16092                            }
16093                    }
16094    
16095                    List<MBMessage> list = q.list();
16096    
16097                    if (list.size() == 2) {
16098                            return list.get(1);
16099                    }
16100                    else {
16101                            return null;
16102                    }
16103            }
16104    
16105            /**
16106             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16107             *
16108             * @param classNameId the class name ID
16109             * @param classPK the class p k
16110             * @param status the status
16111             */
16112            @Override
16113            public void removeByC_C_S(long classNameId, long classPK, int status) {
16114                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
16115                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16116                            remove(mbMessage);
16117                    }
16118            }
16119    
16120            /**
16121             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16122             *
16123             * @param classNameId the class name ID
16124             * @param classPK the class p k
16125             * @param status the status
16126             * @return the number of matching message-boards messages
16127             */
16128            @Override
16129            public int countByC_C_S(long classNameId, long classPK, int status) {
16130                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
16131    
16132                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16133    
16134                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
16135    
16136                    if (count == null) {
16137                            StringBundler query = new StringBundler(4);
16138    
16139                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16140    
16141                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16142    
16143                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16144    
16145                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16146    
16147                            String sql = query.toString();
16148    
16149                            Session session = null;
16150    
16151                            try {
16152                                    session = openSession();
16153    
16154                                    Query q = session.createQuery(sql);
16155    
16156                                    QueryPos qPos = QueryPos.getInstance(q);
16157    
16158                                    qPos.add(classNameId);
16159    
16160                                    qPos.add(classPK);
16161    
16162                                    qPos.add(status);
16163    
16164                                    count = (Long)q.uniqueResult();
16165    
16166                                    finderCache.putResult(finderPath, finderArgs, count);
16167                            }
16168                            catch (Exception e) {
16169                                    finderCache.removeResult(finderPath, finderArgs);
16170    
16171                                    throw processException(e);
16172                            }
16173                            finally {
16174                                    closeSession(session);
16175                            }
16176                    }
16177    
16178                    return count.intValue();
16179            }
16180    
16181            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
16182            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
16183            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
16184            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16186                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
16187                            new String[] {
16188                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16189                                    Boolean.class.getName(),
16190                                    
16191                            Integer.class.getName(), Integer.class.getName(),
16192                                    OrderByComparator.class.getName()
16193                            });
16194            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
16195                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16196                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16197                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
16198                            new String[] {
16199                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16200                                    Boolean.class.getName()
16201                            },
16202                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16203                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16204                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16205                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
16206                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16207            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
16210                            new String[] {
16211                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16212                                    Boolean.class.getName()
16213                            });
16214    
16215            /**
16216             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16217             *
16218             * @param groupId the group ID
16219             * @param categoryId the category ID
16220             * @param threadId the thread ID
16221             * @param answer the answer
16222             * @return the matching message-boards messages
16223             */
16224            @Override
16225            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16226                    long threadId, boolean answer) {
16227                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
16228                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16229            }
16230    
16231            /**
16232             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16233             *
16234             * <p>
16235             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16236             * </p>
16237             *
16238             * @param groupId the group ID
16239             * @param categoryId the category ID
16240             * @param threadId the thread ID
16241             * @param answer the answer
16242             * @param start the lower bound of the range of message-boards messages
16243             * @param end the upper bound of the range of message-boards messages (not inclusive)
16244             * @return the range of matching message-boards messages
16245             */
16246            @Override
16247            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16248                    long threadId, boolean answer, int start, int end) {
16249                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16250                            null);
16251            }
16252    
16253            /**
16254             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16255             *
16256             * <p>
16257             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16258             * </p>
16259             *
16260             * @param groupId the group ID
16261             * @param categoryId the category ID
16262             * @param threadId the thread ID
16263             * @param answer the answer
16264             * @param start the lower bound of the range of message-boards messages
16265             * @param end the upper bound of the range of message-boards messages (not inclusive)
16266             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16267             * @return the ordered range of matching message-boards messages
16268             */
16269            @Override
16270            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16271                    long threadId, boolean answer, int start, int end,
16272                    OrderByComparator<MBMessage> orderByComparator) {
16273                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16274                            orderByComparator, true);
16275            }
16276    
16277            /**
16278             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16279             *
16280             * <p>
16281             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16282             * </p>
16283             *
16284             * @param groupId the group ID
16285             * @param categoryId the category ID
16286             * @param threadId the thread ID
16287             * @param answer the answer
16288             * @param start the lower bound of the range of message-boards messages
16289             * @param end the upper bound of the range of message-boards messages (not inclusive)
16290             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16291             * @param retrieveFromCache whether to retrieve from the finder cache
16292             * @return the ordered range of matching message-boards messages
16293             */
16294            @Override
16295            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16296                    long threadId, boolean answer, int start, int end,
16297                    OrderByComparator<MBMessage> orderByComparator,
16298                    boolean retrieveFromCache) {
16299                    boolean pagination = true;
16300                    FinderPath finderPath = null;
16301                    Object[] finderArgs = null;
16302    
16303                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16304                                    (orderByComparator == null)) {
16305                            pagination = false;
16306                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16307                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16308                    }
16309                    else {
16310                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16311                            finderArgs = new Object[] {
16312                                            groupId, categoryId, threadId, answer,
16313                                            
16314                                            start, end, orderByComparator
16315                                    };
16316                    }
16317    
16318                    List<MBMessage> list = null;
16319    
16320                    if (retrieveFromCache) {
16321                            list = (List<MBMessage>)finderCache.getResult(finderPath,
16322                                            finderArgs, this);
16323    
16324                            if ((list != null) && !list.isEmpty()) {
16325                                    for (MBMessage mbMessage : list) {
16326                                            if ((groupId != mbMessage.getGroupId()) ||
16327                                                            (categoryId != mbMessage.getCategoryId()) ||
16328                                                            (threadId != mbMessage.getThreadId()) ||
16329                                                            (answer != mbMessage.getAnswer())) {
16330                                                    list = null;
16331    
16332                                                    break;
16333                                            }
16334                                    }
16335                            }
16336                    }
16337    
16338                    if (list == null) {
16339                            StringBundler query = null;
16340    
16341                            if (orderByComparator != null) {
16342                                    query = new StringBundler(6 +
16343                                                    (orderByComparator.getOrderByFields().length * 2));
16344                            }
16345                            else {
16346                                    query = new StringBundler(6);
16347                            }
16348    
16349                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16350    
16351                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16352    
16353                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16354    
16355                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16356    
16357                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16358    
16359                            if (orderByComparator != null) {
16360                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16361                                            orderByComparator);
16362                            }
16363                            else
16364                             if (pagination) {
16365                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16366                            }
16367    
16368                            String sql = query.toString();
16369    
16370                            Session session = null;
16371    
16372                            try {
16373                                    session = openSession();
16374    
16375                                    Query q = session.createQuery(sql);
16376    
16377                                    QueryPos qPos = QueryPos.getInstance(q);
16378    
16379                                    qPos.add(groupId);
16380    
16381                                    qPos.add(categoryId);
16382    
16383                                    qPos.add(threadId);
16384    
16385                                    qPos.add(answer);
16386    
16387                                    if (!pagination) {
16388                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16389                                                            start, end, false);
16390    
16391                                            Collections.sort(list);
16392    
16393                                            list = Collections.unmodifiableList(list);
16394                                    }
16395                                    else {
16396                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16397                                                            start, end);
16398                                    }
16399    
16400                                    cacheResult(list);
16401    
16402                                    finderCache.putResult(finderPath, finderArgs, list);
16403                            }
16404                            catch (Exception e) {
16405                                    finderCache.removeResult(finderPath, finderArgs);
16406    
16407                                    throw processException(e);
16408                            }
16409                            finally {
16410                                    closeSession(session);
16411                            }
16412                    }
16413    
16414                    return list;
16415            }
16416    
16417            /**
16418             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16419             *
16420             * @param groupId the group ID
16421             * @param categoryId the category ID
16422             * @param threadId the thread ID
16423             * @param answer the answer
16424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16425             * @return the first matching message-boards message
16426             * @throws NoSuchMessageException if a matching message-boards message could not be found
16427             */
16428            @Override
16429            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16430                    long threadId, boolean answer,
16431                    OrderByComparator<MBMessage> orderByComparator)
16432                    throws NoSuchMessageException {
16433                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16434                                    threadId, answer, orderByComparator);
16435    
16436                    if (mbMessage != null) {
16437                            return mbMessage;
16438                    }
16439    
16440                    StringBundler msg = new StringBundler(10);
16441    
16442                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16443    
16444                    msg.append("groupId=");
16445                    msg.append(groupId);
16446    
16447                    msg.append(", categoryId=");
16448                    msg.append(categoryId);
16449    
16450                    msg.append(", threadId=");
16451                    msg.append(threadId);
16452    
16453                    msg.append(", answer=");
16454                    msg.append(answer);
16455    
16456                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16457    
16458                    throw new NoSuchMessageException(msg.toString());
16459            }
16460    
16461            /**
16462             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16463             *
16464             * @param groupId the group ID
16465             * @param categoryId the category ID
16466             * @param threadId the thread ID
16467             * @param answer the answer
16468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16469             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16470             */
16471            @Override
16472            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16473                    long threadId, boolean answer,
16474                    OrderByComparator<MBMessage> orderByComparator) {
16475                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16476                                    answer, 0, 1, orderByComparator);
16477    
16478                    if (!list.isEmpty()) {
16479                            return list.get(0);
16480                    }
16481    
16482                    return null;
16483            }
16484    
16485            /**
16486             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16487             *
16488             * @param groupId the group ID
16489             * @param categoryId the category ID
16490             * @param threadId the thread ID
16491             * @param answer the answer
16492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16493             * @return the last matching message-boards message
16494             * @throws NoSuchMessageException if a matching message-boards message could not be found
16495             */
16496            @Override
16497            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16498                    long threadId, boolean answer,
16499                    OrderByComparator<MBMessage> orderByComparator)
16500                    throws NoSuchMessageException {
16501                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16502                                    threadId, answer, orderByComparator);
16503    
16504                    if (mbMessage != null) {
16505                            return mbMessage;
16506                    }
16507    
16508                    StringBundler msg = new StringBundler(10);
16509    
16510                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16511    
16512                    msg.append("groupId=");
16513                    msg.append(groupId);
16514    
16515                    msg.append(", categoryId=");
16516                    msg.append(categoryId);
16517    
16518                    msg.append(", threadId=");
16519                    msg.append(threadId);
16520    
16521                    msg.append(", answer=");
16522                    msg.append(answer);
16523    
16524                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16525    
16526                    throw new NoSuchMessageException(msg.toString());
16527            }
16528    
16529            /**
16530             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16531             *
16532             * @param groupId the group ID
16533             * @param categoryId the category ID
16534             * @param threadId the thread ID
16535             * @param answer the answer
16536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16537             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16538             */
16539            @Override
16540            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16541                    long threadId, boolean answer,
16542                    OrderByComparator<MBMessage> orderByComparator) {
16543                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16544    
16545                    if (count == 0) {
16546                            return null;
16547                    }
16548    
16549                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16550                                    answer, count - 1, count, orderByComparator);
16551    
16552                    if (!list.isEmpty()) {
16553                            return list.get(0);
16554                    }
16555    
16556                    return null;
16557            }
16558    
16559            /**
16560             * 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;.
16561             *
16562             * @param messageId the primary key of the current message-boards message
16563             * @param groupId the group ID
16564             * @param categoryId the category ID
16565             * @param threadId the thread ID
16566             * @param answer the answer
16567             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16568             * @return the previous, current, and next message-boards message
16569             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16570             */
16571            @Override
16572            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16573                    long categoryId, long threadId, boolean answer,
16574                    OrderByComparator<MBMessage> orderByComparator)
16575                    throws NoSuchMessageException {
16576                    MBMessage mbMessage = findByPrimaryKey(messageId);
16577    
16578                    Session session = null;
16579    
16580                    try {
16581                            session = openSession();
16582    
16583                            MBMessage[] array = new MBMessageImpl[3];
16584    
16585                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16586                                            categoryId, threadId, answer, orderByComparator, true);
16587    
16588                            array[1] = mbMessage;
16589    
16590                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16591                                            categoryId, threadId, answer, orderByComparator, false);
16592    
16593                            return array;
16594                    }
16595                    catch (Exception e) {
16596                            throw processException(e);
16597                    }
16598                    finally {
16599                            closeSession(session);
16600                    }
16601            }
16602    
16603            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16604                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16605                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16606                    boolean previous) {
16607                    StringBundler query = null;
16608    
16609                    if (orderByComparator != null) {
16610                            query = new StringBundler(7 +
16611                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16612                                            (orderByComparator.getOrderByFields().length * 3));
16613                    }
16614                    else {
16615                            query = new StringBundler(6);
16616                    }
16617    
16618                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16619    
16620                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16621    
16622                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16623    
16624                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16625    
16626                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16627    
16628                    if (orderByComparator != null) {
16629                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16630    
16631                            if (orderByConditionFields.length > 0) {
16632                                    query.append(WHERE_AND);
16633                            }
16634    
16635                            for (int i = 0; i < orderByConditionFields.length; i++) {
16636                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16637                                    query.append(orderByConditionFields[i]);
16638    
16639                                    if ((i + 1) < orderByConditionFields.length) {
16640                                            if (orderByComparator.isAscending() ^ previous) {
16641                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16642                                            }
16643                                            else {
16644                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16645                                            }
16646                                    }
16647                                    else {
16648                                            if (orderByComparator.isAscending() ^ previous) {
16649                                                    query.append(WHERE_GREATER_THAN);
16650                                            }
16651                                            else {
16652                                                    query.append(WHERE_LESSER_THAN);
16653                                            }
16654                                    }
16655                            }
16656    
16657                            query.append(ORDER_BY_CLAUSE);
16658    
16659                            String[] orderByFields = orderByComparator.getOrderByFields();
16660    
16661                            for (int i = 0; i < orderByFields.length; i++) {
16662                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16663                                    query.append(orderByFields[i]);
16664    
16665                                    if ((i + 1) < orderByFields.length) {
16666                                            if (orderByComparator.isAscending() ^ previous) {
16667                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16668                                            }
16669                                            else {
16670                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16671                                            }
16672                                    }
16673                                    else {
16674                                            if (orderByComparator.isAscending() ^ previous) {
16675                                                    query.append(ORDER_BY_ASC);
16676                                            }
16677                                            else {
16678                                                    query.append(ORDER_BY_DESC);
16679                                            }
16680                                    }
16681                            }
16682                    }
16683                    else {
16684                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16685                    }
16686    
16687                    String sql = query.toString();
16688    
16689                    Query q = session.createQuery(sql);
16690    
16691                    q.setFirstResult(0);
16692                    q.setMaxResults(2);
16693    
16694                    QueryPos qPos = QueryPos.getInstance(q);
16695    
16696                    qPos.add(groupId);
16697    
16698                    qPos.add(categoryId);
16699    
16700                    qPos.add(threadId);
16701    
16702                    qPos.add(answer);
16703    
16704                    if (orderByComparator != null) {
16705                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16706    
16707                            for (Object value : values) {
16708                                    qPos.add(value);
16709                            }
16710                    }
16711    
16712                    List<MBMessage> list = q.list();
16713    
16714                    if (list.size() == 2) {
16715                            return list.get(1);
16716                    }
16717                    else {
16718                            return null;
16719                    }
16720            }
16721    
16722            /**
16723             * 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;.
16724             *
16725             * @param groupId the group ID
16726             * @param categoryId the category ID
16727             * @param threadId the thread ID
16728             * @param answer the answer
16729             * @return the matching message-boards messages that the user has permission to view
16730             */
16731            @Override
16732            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16733                    long threadId, boolean answer) {
16734                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16735                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16736            }
16737    
16738            /**
16739             * 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;.
16740             *
16741             * <p>
16742             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16743             * </p>
16744             *
16745             * @param groupId the group ID
16746             * @param categoryId the category ID
16747             * @param threadId the thread ID
16748             * @param answer the answer
16749             * @param start the lower bound of the range of message-boards messages
16750             * @param end the upper bound of the range of message-boards messages (not inclusive)
16751             * @return the range of matching message-boards messages that the user has permission to view
16752             */
16753            @Override
16754            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16755                    long threadId, boolean answer, int start, int end) {
16756                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16757                            start, end, null);
16758            }
16759    
16760            /**
16761             * 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;.
16762             *
16763             * <p>
16764             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16765             * </p>
16766             *
16767             * @param groupId the group ID
16768             * @param categoryId the category ID
16769             * @param threadId the thread ID
16770             * @param answer the answer
16771             * @param start the lower bound of the range of message-boards messages
16772             * @param end the upper bound of the range of message-boards messages (not inclusive)
16773             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16774             * @return the ordered range of matching message-boards messages that the user has permission to view
16775             */
16776            @Override
16777            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16778                    long threadId, boolean answer, int start, int end,
16779                    OrderByComparator<MBMessage> orderByComparator) {
16780                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16781                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16782                                    end, orderByComparator);
16783                    }
16784    
16785                    StringBundler query = null;
16786    
16787                    if (orderByComparator != null) {
16788                            query = new StringBundler(6 +
16789                                            (orderByComparator.getOrderByFields().length * 2));
16790                    }
16791                    else {
16792                            query = new StringBundler(7);
16793                    }
16794    
16795                    if (getDB().isSupportsInlineDistinct()) {
16796                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16797                    }
16798                    else {
16799                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16800                    }
16801    
16802                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16803    
16804                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16805    
16806                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16807    
16808                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16809    
16810                    if (!getDB().isSupportsInlineDistinct()) {
16811                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16812                    }
16813    
16814                    if (orderByComparator != null) {
16815                            if (getDB().isSupportsInlineDistinct()) {
16816                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16817                                            orderByComparator, true);
16818                            }
16819                            else {
16820                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16821                                            orderByComparator, true);
16822                            }
16823                    }
16824                    else {
16825                            if (getDB().isSupportsInlineDistinct()) {
16826                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16827                            }
16828                            else {
16829                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16830                            }
16831                    }
16832    
16833                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16834                                    MBMessage.class.getName(),
16835                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16836    
16837                    Session session = null;
16838    
16839                    try {
16840                            session = openSession();
16841    
16842                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16843    
16844                            if (getDB().isSupportsInlineDistinct()) {
16845                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16846                            }
16847                            else {
16848                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16849                            }
16850    
16851                            QueryPos qPos = QueryPos.getInstance(q);
16852    
16853                            qPos.add(groupId);
16854    
16855                            qPos.add(categoryId);
16856    
16857                            qPos.add(threadId);
16858    
16859                            qPos.add(answer);
16860    
16861                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16862                    }
16863                    catch (Exception e) {
16864                            throw processException(e);
16865                    }
16866                    finally {
16867                            closeSession(session);
16868                    }
16869            }
16870    
16871            /**
16872             * 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;.
16873             *
16874             * @param messageId the primary key of the current message-boards message
16875             * @param groupId the group ID
16876             * @param categoryId the category ID
16877             * @param threadId the thread ID
16878             * @param answer the answer
16879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16880             * @return the previous, current, and next message-boards message
16881             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16882             */
16883            @Override
16884            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16885                    long groupId, long categoryId, long threadId, boolean answer,
16886                    OrderByComparator<MBMessage> orderByComparator)
16887                    throws NoSuchMessageException {
16888                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16889                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16890                                    threadId, answer, orderByComparator);
16891                    }
16892    
16893                    MBMessage mbMessage = findByPrimaryKey(messageId);
16894    
16895                    Session session = null;
16896    
16897                    try {
16898                            session = openSession();
16899    
16900                            MBMessage[] array = new MBMessageImpl[3];
16901    
16902                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16903                                            groupId, categoryId, threadId, answer, orderByComparator,
16904                                            true);
16905    
16906                            array[1] = mbMessage;
16907    
16908                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16909                                            groupId, categoryId, threadId, answer, orderByComparator,
16910                                            false);
16911    
16912                            return array;
16913                    }
16914                    catch (Exception e) {
16915                            throw processException(e);
16916                    }
16917                    finally {
16918                            closeSession(session);
16919                    }
16920            }
16921    
16922            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16923                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16924                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16925                    boolean previous) {
16926                    StringBundler query = null;
16927    
16928                    if (orderByComparator != null) {
16929                            query = new StringBundler(8 +
16930                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16931                                            (orderByComparator.getOrderByFields().length * 3));
16932                    }
16933                    else {
16934                            query = new StringBundler(7);
16935                    }
16936    
16937                    if (getDB().isSupportsInlineDistinct()) {
16938                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16939                    }
16940                    else {
16941                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16942                    }
16943    
16944                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16945    
16946                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16947    
16948                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16949    
16950                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16951    
16952                    if (!getDB().isSupportsInlineDistinct()) {
16953                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16954                    }
16955    
16956                    if (orderByComparator != null) {
16957                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16958    
16959                            if (orderByConditionFields.length > 0) {
16960                                    query.append(WHERE_AND);
16961                            }
16962    
16963                            for (int i = 0; i < orderByConditionFields.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(orderByConditionFields[i]);
16972    
16973                                    if ((i + 1) < orderByConditionFields.length) {
16974                                            if (orderByComparator.isAscending() ^ previous) {
16975                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16976                                            }
16977                                            else {
16978                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16979                                            }
16980                                    }
16981                                    else {
16982                                            if (orderByComparator.isAscending() ^ previous) {
16983                                                    query.append(WHERE_GREATER_THAN);
16984                                            }
16985                                            else {
16986                                                    query.append(WHERE_LESSER_THAN);
16987                                            }
16988                                    }
16989                            }
16990    
16991                            query.append(ORDER_BY_CLAUSE);
16992    
16993                            String[] orderByFields = orderByComparator.getOrderByFields();
16994    
16995                            for (int i = 0; i < orderByFields.length; i++) {
16996                                    if (getDB().isSupportsInlineDistinct()) {
16997                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16998                                    }
16999                                    else {
17000                                            query.append(_ORDER_BY_ENTITY_TABLE);
17001                                    }
17002    
17003                                    query.append(orderByFields[i]);
17004    
17005                                    if ((i + 1) < orderByFields.length) {
17006                                            if (orderByComparator.isAscending() ^ previous) {
17007                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17008                                            }
17009                                            else {
17010                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17011                                            }
17012                                    }
17013                                    else {
17014                                            if (orderByComparator.isAscending() ^ previous) {
17015                                                    query.append(ORDER_BY_ASC);
17016                                            }
17017                                            else {
17018                                                    query.append(ORDER_BY_DESC);
17019                                            }
17020                                    }
17021                            }
17022                    }
17023                    else {
17024                            if (getDB().isSupportsInlineDistinct()) {
17025                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17026                            }
17027                            else {
17028                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17029                            }
17030                    }
17031    
17032                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17033                                    MBMessage.class.getName(),
17034                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17035    
17036                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17037    
17038                    q.setFirstResult(0);
17039                    q.setMaxResults(2);
17040    
17041                    if (getDB().isSupportsInlineDistinct()) {
17042                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17043                    }
17044                    else {
17045                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17046                    }
17047    
17048                    QueryPos qPos = QueryPos.getInstance(q);
17049    
17050                    qPos.add(groupId);
17051    
17052                    qPos.add(categoryId);
17053    
17054                    qPos.add(threadId);
17055    
17056                    qPos.add(answer);
17057    
17058                    if (orderByComparator != null) {
17059                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17060    
17061                            for (Object value : values) {
17062                                    qPos.add(value);
17063                            }
17064                    }
17065    
17066                    List<MBMessage> list = q.list();
17067    
17068                    if (list.size() == 2) {
17069                            return list.get(1);
17070                    }
17071                    else {
17072                            return null;
17073                    }
17074            }
17075    
17076            /**
17077             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
17078             *
17079             * @param groupId the group ID
17080             * @param categoryId the category ID
17081             * @param threadId the thread ID
17082             * @param answer the answer
17083             */
17084            @Override
17085            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
17086                    boolean answer) {
17087                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
17088                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17089                            remove(mbMessage);
17090                    }
17091            }
17092    
17093            /**
17094             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17095             *
17096             * @param groupId the group ID
17097             * @param categoryId the category ID
17098             * @param threadId the thread ID
17099             * @param answer the answer
17100             * @return the number of matching message-boards messages
17101             */
17102            @Override
17103            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17104                    boolean answer) {
17105                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
17106    
17107                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17108    
17109                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
17110    
17111                    if (count == null) {
17112                            StringBundler query = new StringBundler(5);
17113    
17114                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17115    
17116                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17117    
17118                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17119    
17120                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17121    
17122                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17123    
17124                            String sql = query.toString();
17125    
17126                            Session session = null;
17127    
17128                            try {
17129                                    session = openSession();
17130    
17131                                    Query q = session.createQuery(sql);
17132    
17133                                    QueryPos qPos = QueryPos.getInstance(q);
17134    
17135                                    qPos.add(groupId);
17136    
17137                                    qPos.add(categoryId);
17138    
17139                                    qPos.add(threadId);
17140    
17141                                    qPos.add(answer);
17142    
17143                                    count = (Long)q.uniqueResult();
17144    
17145                                    finderCache.putResult(finderPath, finderArgs, count);
17146                            }
17147                            catch (Exception e) {
17148                                    finderCache.removeResult(finderPath, finderArgs);
17149    
17150                                    throw processException(e);
17151                            }
17152                            finally {
17153                                    closeSession(session);
17154                            }
17155                    }
17156    
17157                    return count.intValue();
17158            }
17159    
17160            /**
17161             * 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;.
17162             *
17163             * @param groupId the group ID
17164             * @param categoryId the category ID
17165             * @param threadId the thread ID
17166             * @param answer the answer
17167             * @return the number of matching message-boards messages that the user has permission to view
17168             */
17169            @Override
17170            public int filterCountByG_C_T_A(long groupId, long categoryId,
17171                    long threadId, boolean answer) {
17172                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17173                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17174                    }
17175    
17176                    StringBundler query = new StringBundler(5);
17177    
17178                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17179    
17180                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17181    
17182                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17183    
17184                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17185    
17186                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17187    
17188                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17189                                    MBMessage.class.getName(),
17190                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17191    
17192                    Session session = null;
17193    
17194                    try {
17195                            session = openSession();
17196    
17197                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17198    
17199                            q.addScalar(COUNT_COLUMN_NAME,
17200                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17201    
17202                            QueryPos qPos = QueryPos.getInstance(q);
17203    
17204                            qPos.add(groupId);
17205    
17206                            qPos.add(categoryId);
17207    
17208                            qPos.add(threadId);
17209    
17210                            qPos.add(answer);
17211    
17212                            Long count = (Long)q.uniqueResult();
17213    
17214                            return count.intValue();
17215                    }
17216                    catch (Exception e) {
17217                            throw processException(e);
17218                    }
17219                    finally {
17220                            closeSession(session);
17221                    }
17222            }
17223    
17224            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17225            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17226            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17227            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17228            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17229                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17230                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
17231                            new String[] {
17232                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17233                                    Integer.class.getName(),
17234                                    
17235                            Integer.class.getName(), Integer.class.getName(),
17236                                    OrderByComparator.class.getName()
17237                            });
17238            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
17239                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17240                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17241                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
17242                            new String[] {
17243                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17244                                    Integer.class.getName()
17245                            },
17246                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17247                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17248                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17249                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17250                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17251            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17252                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17253                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
17254                            new String[] {
17255                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17256                                    Integer.class.getName()
17257                            });
17258    
17259            /**
17260             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17261             *
17262             * @param groupId the group ID
17263             * @param categoryId the category ID
17264             * @param threadId the thread ID
17265             * @param status the status
17266             * @return the matching message-boards messages
17267             */
17268            @Override
17269            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17270                    long threadId, int status) {
17271                    return findByG_C_T_S(groupId, categoryId, threadId, status,
17272                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17273            }
17274    
17275            /**
17276             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17277             *
17278             * <p>
17279             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17280             * </p>
17281             *
17282             * @param groupId the group ID
17283             * @param categoryId the category ID
17284             * @param threadId the thread ID
17285             * @param status the status
17286             * @param start the lower bound of the range of message-boards messages
17287             * @param end the upper bound of the range of message-boards messages (not inclusive)
17288             * @return the range of matching message-boards messages
17289             */
17290            @Override
17291            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17292                    long threadId, int status, int start, int end) {
17293                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17294                            null);
17295            }
17296    
17297            /**
17298             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17299             *
17300             * <p>
17301             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17302             * </p>
17303             *
17304             * @param groupId the group ID
17305             * @param categoryId the category ID
17306             * @param threadId the thread ID
17307             * @param status the status
17308             * @param start the lower bound of the range of message-boards messages
17309             * @param end the upper bound of the range of message-boards messages (not inclusive)
17310             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17311             * @return the ordered range of matching message-boards messages
17312             */
17313            @Override
17314            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17315                    long threadId, int status, int start, int end,
17316                    OrderByComparator<MBMessage> orderByComparator) {
17317                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17318                            orderByComparator, true);
17319            }
17320    
17321            /**
17322             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17323             *
17324             * <p>
17325             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17326             * </p>
17327             *
17328             * @param groupId the group ID
17329             * @param categoryId the category ID
17330             * @param threadId the thread ID
17331             * @param status the status
17332             * @param start the lower bound of the range of message-boards messages
17333             * @param end the upper bound of the range of message-boards messages (not inclusive)
17334             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17335             * @param retrieveFromCache whether to retrieve from the finder cache
17336             * @return the ordered range of matching message-boards messages
17337             */
17338            @Override
17339            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17340                    long threadId, int status, int start, int end,
17341                    OrderByComparator<MBMessage> orderByComparator,
17342                    boolean retrieveFromCache) {
17343                    boolean pagination = true;
17344                    FinderPath finderPath = null;
17345                    Object[] finderArgs = null;
17346    
17347                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17348                                    (orderByComparator == null)) {
17349                            pagination = false;
17350                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17351                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17352                    }
17353                    else {
17354                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17355                            finderArgs = new Object[] {
17356                                            groupId, categoryId, threadId, status,
17357                                            
17358                                            start, end, orderByComparator
17359                                    };
17360                    }
17361    
17362                    List<MBMessage> list = null;
17363    
17364                    if (retrieveFromCache) {
17365                            list = (List<MBMessage>)finderCache.getResult(finderPath,
17366                                            finderArgs, this);
17367    
17368                            if ((list != null) && !list.isEmpty()) {
17369                                    for (MBMessage mbMessage : list) {
17370                                            if ((groupId != mbMessage.getGroupId()) ||
17371                                                            (categoryId != mbMessage.getCategoryId()) ||
17372                                                            (threadId != mbMessage.getThreadId()) ||
17373                                                            (status != mbMessage.getStatus())) {
17374                                                    list = null;
17375    
17376                                                    break;
17377                                            }
17378                                    }
17379                            }
17380                    }
17381    
17382                    if (list == null) {
17383                            StringBundler query = null;
17384    
17385                            if (orderByComparator != null) {
17386                                    query = new StringBundler(6 +
17387                                                    (orderByComparator.getOrderByFields().length * 2));
17388                            }
17389                            else {
17390                                    query = new StringBundler(6);
17391                            }
17392    
17393                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17394    
17395                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17396    
17397                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17398    
17399                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17400    
17401                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17402    
17403                            if (orderByComparator != null) {
17404                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17405                                            orderByComparator);
17406                            }
17407                            else
17408                             if (pagination) {
17409                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17410                            }
17411    
17412                            String sql = query.toString();
17413    
17414                            Session session = null;
17415    
17416                            try {
17417                                    session = openSession();
17418    
17419                                    Query q = session.createQuery(sql);
17420    
17421                                    QueryPos qPos = QueryPos.getInstance(q);
17422    
17423                                    qPos.add(groupId);
17424    
17425                                    qPos.add(categoryId);
17426    
17427                                    qPos.add(threadId);
17428    
17429                                    qPos.add(status);
17430    
17431                                    if (!pagination) {
17432                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17433                                                            start, end, false);
17434    
17435                                            Collections.sort(list);
17436    
17437                                            list = Collections.unmodifiableList(list);
17438                                    }
17439                                    else {
17440                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17441                                                            start, end);
17442                                    }
17443    
17444                                    cacheResult(list);
17445    
17446                                    finderCache.putResult(finderPath, finderArgs, list);
17447                            }
17448                            catch (Exception e) {
17449                                    finderCache.removeResult(finderPath, finderArgs);
17450    
17451                                    throw processException(e);
17452                            }
17453                            finally {
17454                                    closeSession(session);
17455                            }
17456                    }
17457    
17458                    return list;
17459            }
17460    
17461            /**
17462             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17463             *
17464             * @param groupId the group ID
17465             * @param categoryId the category ID
17466             * @param threadId the thread ID
17467             * @param status the status
17468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17469             * @return the first matching message-boards message
17470             * @throws NoSuchMessageException if a matching message-boards message could not be found
17471             */
17472            @Override
17473            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17474                    long threadId, int status,
17475                    OrderByComparator<MBMessage> orderByComparator)
17476                    throws NoSuchMessageException {
17477                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17478                                    threadId, status, orderByComparator);
17479    
17480                    if (mbMessage != null) {
17481                            return mbMessage;
17482                    }
17483    
17484                    StringBundler msg = new StringBundler(10);
17485    
17486                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17487    
17488                    msg.append("groupId=");
17489                    msg.append(groupId);
17490    
17491                    msg.append(", categoryId=");
17492                    msg.append(categoryId);
17493    
17494                    msg.append(", threadId=");
17495                    msg.append(threadId);
17496    
17497                    msg.append(", status=");
17498                    msg.append(status);
17499    
17500                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17501    
17502                    throw new NoSuchMessageException(msg.toString());
17503            }
17504    
17505            /**
17506             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17507             *
17508             * @param groupId the group ID
17509             * @param categoryId the category ID
17510             * @param threadId the thread ID
17511             * @param status the status
17512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17513             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17514             */
17515            @Override
17516            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17517                    long threadId, int status,
17518                    OrderByComparator<MBMessage> orderByComparator) {
17519                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17520                                    status, 0, 1, orderByComparator);
17521    
17522                    if (!list.isEmpty()) {
17523                            return list.get(0);
17524                    }
17525    
17526                    return null;
17527            }
17528    
17529            /**
17530             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17531             *
17532             * @param groupId the group ID
17533             * @param categoryId the category ID
17534             * @param threadId the thread ID
17535             * @param status the status
17536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17537             * @return the last matching message-boards message
17538             * @throws NoSuchMessageException if a matching message-boards message could not be found
17539             */
17540            @Override
17541            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17542                    long threadId, int status,
17543                    OrderByComparator<MBMessage> orderByComparator)
17544                    throws NoSuchMessageException {
17545                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17546                                    threadId, status, orderByComparator);
17547    
17548                    if (mbMessage != null) {
17549                            return mbMessage;
17550                    }
17551    
17552                    StringBundler msg = new StringBundler(10);
17553    
17554                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17555    
17556                    msg.append("groupId=");
17557                    msg.append(groupId);
17558    
17559                    msg.append(", categoryId=");
17560                    msg.append(categoryId);
17561    
17562                    msg.append(", threadId=");
17563                    msg.append(threadId);
17564    
17565                    msg.append(", status=");
17566                    msg.append(status);
17567    
17568                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17569    
17570                    throw new NoSuchMessageException(msg.toString());
17571            }
17572    
17573            /**
17574             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17575             *
17576             * @param groupId the group ID
17577             * @param categoryId the category ID
17578             * @param threadId the thread ID
17579             * @param status the status
17580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17581             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17582             */
17583            @Override
17584            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17585                    long threadId, int status,
17586                    OrderByComparator<MBMessage> orderByComparator) {
17587                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17588    
17589                    if (count == 0) {
17590                            return null;
17591                    }
17592    
17593                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17594                                    status, count - 1, count, orderByComparator);
17595    
17596                    if (!list.isEmpty()) {
17597                            return list.get(0);
17598                    }
17599    
17600                    return null;
17601            }
17602    
17603            /**
17604             * 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;.
17605             *
17606             * @param messageId the primary key of the current message-boards message
17607             * @param groupId the group ID
17608             * @param categoryId the category ID
17609             * @param threadId the thread ID
17610             * @param status the status
17611             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17612             * @return the previous, current, and next message-boards message
17613             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17614             */
17615            @Override
17616            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17617                    long categoryId, long threadId, int status,
17618                    OrderByComparator<MBMessage> orderByComparator)
17619                    throws NoSuchMessageException {
17620                    MBMessage mbMessage = findByPrimaryKey(messageId);
17621    
17622                    Session session = null;
17623    
17624                    try {
17625                            session = openSession();
17626    
17627                            MBMessage[] array = new MBMessageImpl[3];
17628    
17629                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17630                                            categoryId, threadId, status, orderByComparator, true);
17631    
17632                            array[1] = mbMessage;
17633    
17634                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17635                                            categoryId, threadId, status, orderByComparator, false);
17636    
17637                            return array;
17638                    }
17639                    catch (Exception e) {
17640                            throw processException(e);
17641                    }
17642                    finally {
17643                            closeSession(session);
17644                    }
17645            }
17646    
17647            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17648                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17649                    int status, OrderByComparator<MBMessage> orderByComparator,
17650                    boolean previous) {
17651                    StringBundler query = null;
17652    
17653                    if (orderByComparator != null) {
17654                            query = new StringBundler(7 +
17655                                            (orderByComparator.getOrderByConditionFields().length * 3) +
17656                                            (orderByComparator.getOrderByFields().length * 3));
17657                    }
17658                    else {
17659                            query = new StringBundler(6);
17660                    }
17661    
17662                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17663    
17664                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17665    
17666                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17667    
17668                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17669    
17670                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17671    
17672                    if (orderByComparator != null) {
17673                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17674    
17675                            if (orderByConditionFields.length > 0) {
17676                                    query.append(WHERE_AND);
17677                            }
17678    
17679                            for (int i = 0; i < orderByConditionFields.length; i++) {
17680                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17681                                    query.append(orderByConditionFields[i]);
17682    
17683                                    if ((i + 1) < orderByConditionFields.length) {
17684                                            if (orderByComparator.isAscending() ^ previous) {
17685                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17686                                            }
17687                                            else {
17688                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17689                                            }
17690                                    }
17691                                    else {
17692                                            if (orderByComparator.isAscending() ^ previous) {
17693                                                    query.append(WHERE_GREATER_THAN);
17694                                            }
17695                                            else {
17696                                                    query.append(WHERE_LESSER_THAN);
17697                                            }
17698                                    }
17699                            }
17700    
17701                            query.append(ORDER_BY_CLAUSE);
17702    
17703                            String[] orderByFields = orderByComparator.getOrderByFields();
17704    
17705                            for (int i = 0; i < orderByFields.length; i++) {
17706                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17707                                    query.append(orderByFields[i]);
17708    
17709                                    if ((i + 1) < orderByFields.length) {
17710                                            if (orderByComparator.isAscending() ^ previous) {
17711                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17712                                            }
17713                                            else {
17714                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17715                                            }
17716                                    }
17717                                    else {
17718                                            if (orderByComparator.isAscending() ^ previous) {
17719                                                    query.append(ORDER_BY_ASC);
17720                                            }
17721                                            else {
17722                                                    query.append(ORDER_BY_DESC);
17723                                            }
17724                                    }
17725                            }
17726                    }
17727                    else {
17728                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17729                    }
17730    
17731                    String sql = query.toString();
17732    
17733                    Query q = session.createQuery(sql);
17734    
17735                    q.setFirstResult(0);
17736                    q.setMaxResults(2);
17737    
17738                    QueryPos qPos = QueryPos.getInstance(q);
17739    
17740                    qPos.add(groupId);
17741    
17742                    qPos.add(categoryId);
17743    
17744                    qPos.add(threadId);
17745    
17746                    qPos.add(status);
17747    
17748                    if (orderByComparator != null) {
17749                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17750    
17751                            for (Object value : values) {
17752                                    qPos.add(value);
17753                            }
17754                    }
17755    
17756                    List<MBMessage> list = q.list();
17757    
17758                    if (list.size() == 2) {
17759                            return list.get(1);
17760                    }
17761                    else {
17762                            return null;
17763                    }
17764            }
17765    
17766            /**
17767             * 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;.
17768             *
17769             * @param groupId the group ID
17770             * @param categoryId the category ID
17771             * @param threadId the thread ID
17772             * @param status the status
17773             * @return the matching message-boards messages that the user has permission to view
17774             */
17775            @Override
17776            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17777                    long threadId, int status) {
17778                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17779                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17780            }
17781    
17782            /**
17783             * 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;.
17784             *
17785             * <p>
17786             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17787             * </p>
17788             *
17789             * @param groupId the group ID
17790             * @param categoryId the category ID
17791             * @param threadId the thread ID
17792             * @param status the status
17793             * @param start the lower bound of the range of message-boards messages
17794             * @param end the upper bound of the range of message-boards messages (not inclusive)
17795             * @return the range of matching message-boards messages that the user has permission to view
17796             */
17797            @Override
17798            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17799                    long threadId, int status, int start, int end) {
17800                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17801                            start, end, null);
17802            }
17803    
17804            /**
17805             * 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;.
17806             *
17807             * <p>
17808             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17809             * </p>
17810             *
17811             * @param groupId the group ID
17812             * @param categoryId the category ID
17813             * @param threadId the thread ID
17814             * @param status the status
17815             * @param start the lower bound of the range of message-boards messages
17816             * @param end the upper bound of the range of message-boards messages (not inclusive)
17817             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17818             * @return the ordered range of matching message-boards messages that the user has permission to view
17819             */
17820            @Override
17821            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17822                    long threadId, int status, int start, int end,
17823                    OrderByComparator<MBMessage> orderByComparator) {
17824                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17825                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17826                                    end, orderByComparator);
17827                    }
17828    
17829                    StringBundler query = null;
17830    
17831                    if (orderByComparator != null) {
17832                            query = new StringBundler(6 +
17833                                            (orderByComparator.getOrderByFields().length * 2));
17834                    }
17835                    else {
17836                            query = new StringBundler(7);
17837                    }
17838    
17839                    if (getDB().isSupportsInlineDistinct()) {
17840                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17841                    }
17842                    else {
17843                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17844                    }
17845    
17846                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17847    
17848                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17849    
17850                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17851    
17852                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17853    
17854                    if (!getDB().isSupportsInlineDistinct()) {
17855                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17856                    }
17857    
17858                    if (orderByComparator != null) {
17859                            if (getDB().isSupportsInlineDistinct()) {
17860                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17861                                            orderByComparator, true);
17862                            }
17863                            else {
17864                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17865                                            orderByComparator, true);
17866                            }
17867                    }
17868                    else {
17869                            if (getDB().isSupportsInlineDistinct()) {
17870                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17871                            }
17872                            else {
17873                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17874                            }
17875                    }
17876    
17877                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17878                                    MBMessage.class.getName(),
17879                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17880    
17881                    Session session = null;
17882    
17883                    try {
17884                            session = openSession();
17885    
17886                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17887    
17888                            if (getDB().isSupportsInlineDistinct()) {
17889                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17890                            }
17891                            else {
17892                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17893                            }
17894    
17895                            QueryPos qPos = QueryPos.getInstance(q);
17896    
17897                            qPos.add(groupId);
17898    
17899                            qPos.add(categoryId);
17900    
17901                            qPos.add(threadId);
17902    
17903                            qPos.add(status);
17904    
17905                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17906                    }
17907                    catch (Exception e) {
17908                            throw processException(e);
17909                    }
17910                    finally {
17911                            closeSession(session);
17912                    }
17913            }
17914    
17915            /**
17916             * 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;.
17917             *
17918             * @param messageId the primary key of the current message-boards message
17919             * @param groupId the group ID
17920             * @param categoryId the category ID
17921             * @param threadId the thread ID
17922             * @param status the status
17923             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17924             * @return the previous, current, and next message-boards message
17925             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17926             */
17927            @Override
17928            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17929                    long groupId, long categoryId, long threadId, int status,
17930                    OrderByComparator<MBMessage> orderByComparator)
17931                    throws NoSuchMessageException {
17932                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17933                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17934                                    threadId, status, orderByComparator);
17935                    }
17936    
17937                    MBMessage mbMessage = findByPrimaryKey(messageId);
17938    
17939                    Session session = null;
17940    
17941                    try {
17942                            session = openSession();
17943    
17944                            MBMessage[] array = new MBMessageImpl[3];
17945    
17946                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17947                                            groupId, categoryId, threadId, status, orderByComparator,
17948                                            true);
17949    
17950                            array[1] = mbMessage;
17951    
17952                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17953                                            groupId, categoryId, threadId, status, orderByComparator,
17954                                            false);
17955    
17956                            return array;
17957                    }
17958                    catch (Exception e) {
17959                            throw processException(e);
17960                    }
17961                    finally {
17962                            closeSession(session);
17963                    }
17964            }
17965    
17966            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17967                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17968                    int status, OrderByComparator<MBMessage> orderByComparator,
17969                    boolean previous) {
17970                    StringBundler query = null;
17971    
17972                    if (orderByComparator != null) {
17973                            query = new StringBundler(8 +
17974                                            (orderByComparator.getOrderByConditionFields().length * 3) +
17975                                            (orderByComparator.getOrderByFields().length * 3));
17976                    }
17977                    else {
17978                            query = new StringBundler(7);
17979                    }
17980    
17981                    if (getDB().isSupportsInlineDistinct()) {
17982                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17983                    }
17984                    else {
17985                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17986                    }
17987    
17988                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17989    
17990                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17991    
17992                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17993    
17994                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17995    
17996                    if (!getDB().isSupportsInlineDistinct()) {
17997                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17998                    }
17999    
18000                    if (orderByComparator != null) {
18001                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18002    
18003                            if (orderByConditionFields.length > 0) {
18004                                    query.append(WHERE_AND);
18005                            }
18006    
18007                            for (int i = 0; i < orderByConditionFields.length; i++) {
18008                                    if (getDB().isSupportsInlineDistinct()) {
18009                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18010                                    }
18011                                    else {
18012                                            query.append(_ORDER_BY_ENTITY_TABLE);
18013                                    }
18014    
18015                                    query.append(orderByConditionFields[i]);
18016    
18017                                    if ((i + 1) < orderByConditionFields.length) {
18018                                            if (orderByComparator.isAscending() ^ previous) {
18019                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18020                                            }
18021                                            else {
18022                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18023                                            }
18024                                    }
18025                                    else {
18026                                            if (orderByComparator.isAscending() ^ previous) {
18027                                                    query.append(WHERE_GREATER_THAN);
18028                                            }
18029                                            else {
18030                                                    query.append(WHERE_LESSER_THAN);
18031                                            }
18032                                    }
18033                            }
18034    
18035                            query.append(ORDER_BY_CLAUSE);
18036    
18037                            String[] orderByFields = orderByComparator.getOrderByFields();
18038    
18039                            for (int i = 0; i < orderByFields.length; i++) {
18040                                    if (getDB().isSupportsInlineDistinct()) {
18041                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18042                                    }
18043                                    else {
18044                                            query.append(_ORDER_BY_ENTITY_TABLE);
18045                                    }
18046    
18047                                    query.append(orderByFields[i]);
18048    
18049                                    if ((i + 1) < orderByFields.length) {
18050                                            if (orderByComparator.isAscending() ^ previous) {
18051                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18052                                            }
18053                                            else {
18054                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18055                                            }
18056                                    }
18057                                    else {
18058                                            if (orderByComparator.isAscending() ^ previous) {
18059                                                    query.append(ORDER_BY_ASC);
18060                                            }
18061                                            else {
18062                                                    query.append(ORDER_BY_DESC);
18063                                            }
18064                                    }
18065                            }
18066                    }
18067                    else {
18068                            if (getDB().isSupportsInlineDistinct()) {
18069                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18070                            }
18071                            else {
18072                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18073                            }
18074                    }
18075    
18076                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18077                                    MBMessage.class.getName(),
18078                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18079    
18080                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
18081    
18082                    q.setFirstResult(0);
18083                    q.setMaxResults(2);
18084    
18085                    if (getDB().isSupportsInlineDistinct()) {
18086                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18087                    }
18088                    else {
18089                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18090                    }
18091    
18092                    QueryPos qPos = QueryPos.getInstance(q);
18093    
18094                    qPos.add(groupId);
18095    
18096                    qPos.add(categoryId);
18097    
18098                    qPos.add(threadId);
18099    
18100                    qPos.add(status);
18101    
18102                    if (orderByComparator != null) {
18103                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18104    
18105                            for (Object value : values) {
18106                                    qPos.add(value);
18107                            }
18108                    }
18109    
18110                    List<MBMessage> list = q.list();
18111    
18112                    if (list.size() == 2) {
18113                            return list.get(1);
18114                    }
18115                    else {
18116                            return null;
18117                    }
18118            }
18119    
18120            /**
18121             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
18122             *
18123             * @param groupId the group ID
18124             * @param categoryId the category ID
18125             * @param threadId the thread ID
18126             * @param status the status
18127             */
18128            @Override
18129            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
18130                    int status) {
18131                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
18132                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18133                            remove(mbMessage);
18134                    }
18135            }
18136    
18137            /**
18138             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18139             *
18140             * @param groupId the group ID
18141             * @param categoryId the category ID
18142             * @param threadId the thread ID
18143             * @param status the status
18144             * @return the number of matching message-boards messages
18145             */
18146            @Override
18147            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18148                    int status) {
18149                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
18150    
18151                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18152    
18153                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18154    
18155                    if (count == null) {
18156                            StringBundler query = new StringBundler(5);
18157    
18158                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18159    
18160                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18161    
18162                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18163    
18164                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18165    
18166                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18167    
18168                            String sql = query.toString();
18169    
18170                            Session session = null;
18171    
18172                            try {
18173                                    session = openSession();
18174    
18175                                    Query q = session.createQuery(sql);
18176    
18177                                    QueryPos qPos = QueryPos.getInstance(q);
18178    
18179                                    qPos.add(groupId);
18180    
18181                                    qPos.add(categoryId);
18182    
18183                                    qPos.add(threadId);
18184    
18185                                    qPos.add(status);
18186    
18187                                    count = (Long)q.uniqueResult();
18188    
18189                                    finderCache.putResult(finderPath, finderArgs, count);
18190                            }
18191                            catch (Exception e) {
18192                                    finderCache.removeResult(finderPath, finderArgs);
18193    
18194                                    throw processException(e);
18195                            }
18196                            finally {
18197                                    closeSession(session);
18198                            }
18199                    }
18200    
18201                    return count.intValue();
18202            }
18203    
18204            /**
18205             * 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;.
18206             *
18207             * @param groupId the group ID
18208             * @param categoryId the category ID
18209             * @param threadId the thread ID
18210             * @param status the status
18211             * @return the number of matching message-boards messages that the user has permission to view
18212             */
18213            @Override
18214            public int filterCountByG_C_T_S(long groupId, long categoryId,
18215                    long threadId, int status) {
18216                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18217                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18218                    }
18219    
18220                    StringBundler query = new StringBundler(5);
18221    
18222                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18223    
18224                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18225    
18226                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18227    
18228                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18229    
18230                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18231    
18232                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18233                                    MBMessage.class.getName(),
18234                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18235    
18236                    Session session = null;
18237    
18238                    try {
18239                            session = openSession();
18240    
18241                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
18242    
18243                            q.addScalar(COUNT_COLUMN_NAME,
18244                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18245    
18246                            QueryPos qPos = QueryPos.getInstance(q);
18247    
18248                            qPos.add(groupId);
18249    
18250                            qPos.add(categoryId);
18251    
18252                            qPos.add(threadId);
18253    
18254                            qPos.add(status);
18255    
18256                            Long count = (Long)q.uniqueResult();
18257    
18258                            return count.intValue();
18259                    }
18260                    catch (Exception e) {
18261                            throw processException(e);
18262                    }
18263                    finally {
18264                            closeSession(session);
18265                    }
18266            }
18267    
18268            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18269            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18270            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18271            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18272            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18273                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18274                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
18275                            new String[] {
18276                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18277                                    Integer.class.getName(),
18278                                    
18279                            Integer.class.getName(), Integer.class.getName(),
18280                                    OrderByComparator.class.getName()
18281                            });
18282            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
18283                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18284                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18285                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
18286                            new String[] {
18287                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18288                                    Integer.class.getName()
18289                            },
18290                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
18291                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
18292                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
18293                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18294                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18295            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18296                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18297                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
18298                            new String[] {
18299                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18300                                    Integer.class.getName()
18301                            });
18302    
18303            /**
18304             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18305             *
18306             * @param userId the user ID
18307             * @param classNameId the class name ID
18308             * @param classPK the class p k
18309             * @param status the status
18310             * @return the matching message-boards messages
18311             */
18312            @Override
18313            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18314                    long classPK, int status) {
18315                    return findByU_C_C_S(userId, classNameId, classPK, status,
18316                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18317            }
18318    
18319            /**
18320             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18321             *
18322             * <p>
18323             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18324             * </p>
18325             *
18326             * @param userId the user ID
18327             * @param classNameId the class name ID
18328             * @param classPK the class p k
18329             * @param status the status
18330             * @param start the lower bound of the range of message-boards messages
18331             * @param end the upper bound of the range of message-boards messages (not inclusive)
18332             * @return the range of matching message-boards messages
18333             */
18334            @Override
18335            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18336                    long classPK, int status, int start, int end) {
18337                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18338                            null);
18339            }
18340    
18341            /**
18342             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18343             *
18344             * <p>
18345             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18346             * </p>
18347             *
18348             * @param userId the user ID
18349             * @param classNameId the class name ID
18350             * @param classPK the class p k
18351             * @param status the status
18352             * @param start the lower bound of the range of message-boards messages
18353             * @param end the upper bound of the range of message-boards messages (not inclusive)
18354             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18355             * @return the ordered range of matching message-boards messages
18356             */
18357            @Override
18358            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18359                    long classPK, int status, int start, int end,
18360                    OrderByComparator<MBMessage> orderByComparator) {
18361                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18362                            orderByComparator, true);
18363            }
18364    
18365            /**
18366             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18367             *
18368             * <p>
18369             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18370             * </p>
18371             *
18372             * @param userId the user ID
18373             * @param classNameId the class name ID
18374             * @param classPK the class p k
18375             * @param status the status
18376             * @param start the lower bound of the range of message-boards messages
18377             * @param end the upper bound of the range of message-boards messages (not inclusive)
18378             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18379             * @param retrieveFromCache whether to retrieve from the finder cache
18380             * @return the ordered range of matching message-boards messages
18381             */
18382            @Override
18383            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18384                    long classPK, int status, int start, int end,
18385                    OrderByComparator<MBMessage> orderByComparator,
18386                    boolean retrieveFromCache) {
18387                    boolean pagination = true;
18388                    FinderPath finderPath = null;
18389                    Object[] finderArgs = null;
18390    
18391                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18392                                    (orderByComparator == null)) {
18393                            pagination = false;
18394                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18395                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18396                    }
18397                    else {
18398                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18399                            finderArgs = new Object[] {
18400                                            userId, classNameId, classPK, status,
18401                                            
18402                                            start, end, orderByComparator
18403                                    };
18404                    }
18405    
18406                    List<MBMessage> list = null;
18407    
18408                    if (retrieveFromCache) {
18409                            list = (List<MBMessage>)finderCache.getResult(finderPath,
18410                                            finderArgs, this);
18411    
18412                            if ((list != null) && !list.isEmpty()) {
18413                                    for (MBMessage mbMessage : list) {
18414                                            if ((userId != mbMessage.getUserId()) ||
18415                                                            (classNameId != mbMessage.getClassNameId()) ||
18416                                                            (classPK != mbMessage.getClassPK()) ||
18417                                                            (status != mbMessage.getStatus())) {
18418                                                    list = null;
18419    
18420                                                    break;
18421                                            }
18422                                    }
18423                            }
18424                    }
18425    
18426                    if (list == null) {
18427                            StringBundler query = null;
18428    
18429                            if (orderByComparator != null) {
18430                                    query = new StringBundler(6 +
18431                                                    (orderByComparator.getOrderByFields().length * 2));
18432                            }
18433                            else {
18434                                    query = new StringBundler(6);
18435                            }
18436    
18437                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18438    
18439                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18440    
18441                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18442    
18443                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18444    
18445                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18446    
18447                            if (orderByComparator != null) {
18448                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18449                                            orderByComparator);
18450                            }
18451                            else
18452                             if (pagination) {
18453                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18454                            }
18455    
18456                            String sql = query.toString();
18457    
18458                            Session session = null;
18459    
18460                            try {
18461                                    session = openSession();
18462    
18463                                    Query q = session.createQuery(sql);
18464    
18465                                    QueryPos qPos = QueryPos.getInstance(q);
18466    
18467                                    qPos.add(userId);
18468    
18469                                    qPos.add(classNameId);
18470    
18471                                    qPos.add(classPK);
18472    
18473                                    qPos.add(status);
18474    
18475                                    if (!pagination) {
18476                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18477                                                            start, end, false);
18478    
18479                                            Collections.sort(list);
18480    
18481                                            list = Collections.unmodifiableList(list);
18482                                    }
18483                                    else {
18484                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18485                                                            start, end);
18486                                    }
18487    
18488                                    cacheResult(list);
18489    
18490                                    finderCache.putResult(finderPath, finderArgs, list);
18491                            }
18492                            catch (Exception e) {
18493                                    finderCache.removeResult(finderPath, finderArgs);
18494    
18495                                    throw processException(e);
18496                            }
18497                            finally {
18498                                    closeSession(session);
18499                            }
18500                    }
18501    
18502                    return list;
18503            }
18504    
18505            /**
18506             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18507             *
18508             * @param userId the user ID
18509             * @param classNameId the class name ID
18510             * @param classPK the class p k
18511             * @param status the status
18512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18513             * @return the first matching message-boards message
18514             * @throws NoSuchMessageException if a matching message-boards message could not be found
18515             */
18516            @Override
18517            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18518                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18519                    throws NoSuchMessageException {
18520                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18521                                    classPK, status, orderByComparator);
18522    
18523                    if (mbMessage != null) {
18524                            return mbMessage;
18525                    }
18526    
18527                    StringBundler msg = new StringBundler(10);
18528    
18529                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18530    
18531                    msg.append("userId=");
18532                    msg.append(userId);
18533    
18534                    msg.append(", classNameId=");
18535                    msg.append(classNameId);
18536    
18537                    msg.append(", classPK=");
18538                    msg.append(classPK);
18539    
18540                    msg.append(", status=");
18541                    msg.append(status);
18542    
18543                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18544    
18545                    throw new NoSuchMessageException(msg.toString());
18546            }
18547    
18548            /**
18549             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18550             *
18551             * @param userId the user ID
18552             * @param classNameId the class name ID
18553             * @param classPK the class p k
18554             * @param status the status
18555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18556             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18557             */
18558            @Override
18559            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18560                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18561                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18562                                    status, 0, 1, orderByComparator);
18563    
18564                    if (!list.isEmpty()) {
18565                            return list.get(0);
18566                    }
18567    
18568                    return null;
18569            }
18570    
18571            /**
18572             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18573             *
18574             * @param userId the user ID
18575             * @param classNameId the class name ID
18576             * @param classPK the class p k
18577             * @param status the status
18578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18579             * @return the last matching message-boards message
18580             * @throws NoSuchMessageException if a matching message-boards message could not be found
18581             */
18582            @Override
18583            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18584                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18585                    throws NoSuchMessageException {
18586                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18587                                    status, orderByComparator);
18588    
18589                    if (mbMessage != null) {
18590                            return mbMessage;
18591                    }
18592    
18593                    StringBundler msg = new StringBundler(10);
18594    
18595                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18596    
18597                    msg.append("userId=");
18598                    msg.append(userId);
18599    
18600                    msg.append(", classNameId=");
18601                    msg.append(classNameId);
18602    
18603                    msg.append(", classPK=");
18604                    msg.append(classPK);
18605    
18606                    msg.append(", status=");
18607                    msg.append(status);
18608    
18609                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18610    
18611                    throw new NoSuchMessageException(msg.toString());
18612            }
18613    
18614            /**
18615             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18616             *
18617             * @param userId the user ID
18618             * @param classNameId the class name ID
18619             * @param classPK the class p k
18620             * @param status the status
18621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18622             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18623             */
18624            @Override
18625            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18626                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18627                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18628    
18629                    if (count == 0) {
18630                            return null;
18631                    }
18632    
18633                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18634                                    status, count - 1, count, orderByComparator);
18635    
18636                    if (!list.isEmpty()) {
18637                            return list.get(0);
18638                    }
18639    
18640                    return null;
18641            }
18642    
18643            /**
18644             * 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;.
18645             *
18646             * @param messageId the primary key of the current message-boards message
18647             * @param userId the user ID
18648             * @param classNameId the class name ID
18649             * @param classPK the class p k
18650             * @param status the status
18651             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18652             * @return the previous, current, and next message-boards message
18653             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18654             */
18655            @Override
18656            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18657                    long classNameId, long classPK, int status,
18658                    OrderByComparator<MBMessage> orderByComparator)
18659                    throws NoSuchMessageException {
18660                    MBMessage mbMessage = findByPrimaryKey(messageId);
18661    
18662                    Session session = null;
18663    
18664                    try {
18665                            session = openSession();
18666    
18667                            MBMessage[] array = new MBMessageImpl[3];
18668    
18669                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18670                                            classNameId, classPK, status, orderByComparator, true);
18671    
18672                            array[1] = mbMessage;
18673    
18674                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18675                                            classNameId, classPK, status, orderByComparator, false);
18676    
18677                            return array;
18678                    }
18679                    catch (Exception e) {
18680                            throw processException(e);
18681                    }
18682                    finally {
18683                            closeSession(session);
18684                    }
18685            }
18686    
18687            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18688                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18689                    int status, OrderByComparator<MBMessage> orderByComparator,
18690                    boolean previous) {
18691                    StringBundler query = null;
18692    
18693                    if (orderByComparator != null) {
18694                            query = new StringBundler(7 +
18695                                            (orderByComparator.getOrderByConditionFields().length * 3) +
18696                                            (orderByComparator.getOrderByFields().length * 3));
18697                    }
18698                    else {
18699                            query = new StringBundler(6);
18700                    }
18701    
18702                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18703    
18704                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18705    
18706                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18707    
18708                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18709    
18710                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18711    
18712                    if (orderByComparator != null) {
18713                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18714    
18715                            if (orderByConditionFields.length > 0) {
18716                                    query.append(WHERE_AND);
18717                            }
18718    
18719                            for (int i = 0; i < orderByConditionFields.length; i++) {
18720                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18721                                    query.append(orderByConditionFields[i]);
18722    
18723                                    if ((i + 1) < orderByConditionFields.length) {
18724                                            if (orderByComparator.isAscending() ^ previous) {
18725                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18726                                            }
18727                                            else {
18728                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18729                                            }
18730                                    }
18731                                    else {
18732                                            if (orderByComparator.isAscending() ^ previous) {
18733                                                    query.append(WHERE_GREATER_THAN);
18734                                            }
18735                                            else {
18736                                                    query.append(WHERE_LESSER_THAN);
18737                                            }
18738                                    }
18739                            }
18740    
18741                            query.append(ORDER_BY_CLAUSE);
18742    
18743                            String[] orderByFields = orderByComparator.getOrderByFields();
18744    
18745                            for (int i = 0; i < orderByFields.length; i++) {
18746                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18747                                    query.append(orderByFields[i]);
18748    
18749                                    if ((i + 1) < orderByFields.length) {
18750                                            if (orderByComparator.isAscending() ^ previous) {
18751                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18752                                            }
18753                                            else {
18754                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18755                                            }
18756                                    }
18757                                    else {
18758                                            if (orderByComparator.isAscending() ^ previous) {
18759                                                    query.append(ORDER_BY_ASC);
18760                                            }
18761                                            else {
18762                                                    query.append(ORDER_BY_DESC);
18763                                            }
18764                                    }
18765                            }
18766                    }
18767                    else {
18768                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18769                    }
18770    
18771                    String sql = query.toString();
18772    
18773                    Query q = session.createQuery(sql);
18774    
18775                    q.setFirstResult(0);
18776                    q.setMaxResults(2);
18777    
18778                    QueryPos qPos = QueryPos.getInstance(q);
18779    
18780                    qPos.add(userId);
18781    
18782                    qPos.add(classNameId);
18783    
18784                    qPos.add(classPK);
18785    
18786                    qPos.add(status);
18787    
18788                    if (orderByComparator != null) {
18789                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18790    
18791                            for (Object value : values) {
18792                                    qPos.add(value);
18793                            }
18794                    }
18795    
18796                    List<MBMessage> list = q.list();
18797    
18798                    if (list.size() == 2) {
18799                            return list.get(1);
18800                    }
18801                    else {
18802                            return null;
18803                    }
18804            }
18805    
18806            /**
18807             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18808             *
18809             * @param userId the user ID
18810             * @param classNameId the class name ID
18811             * @param classPK the class p k
18812             * @param status the status
18813             */
18814            @Override
18815            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18816                    int status) {
18817                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18818                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18819                            remove(mbMessage);
18820                    }
18821            }
18822    
18823            /**
18824             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18825             *
18826             * @param userId the user ID
18827             * @param classNameId the class name ID
18828             * @param classPK the class p k
18829             * @param status the status
18830             * @return the number of matching message-boards messages
18831             */
18832            @Override
18833            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18834                    int status) {
18835                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18836    
18837                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18838    
18839                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18840    
18841                    if (count == null) {
18842                            StringBundler query = new StringBundler(5);
18843    
18844                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18845    
18846                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18847    
18848                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18849    
18850                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18851    
18852                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18853    
18854                            String sql = query.toString();
18855    
18856                            Session session = null;
18857    
18858                            try {
18859                                    session = openSession();
18860    
18861                                    Query q = session.createQuery(sql);
18862    
18863                                    QueryPos qPos = QueryPos.getInstance(q);
18864    
18865                                    qPos.add(userId);
18866    
18867                                    qPos.add(classNameId);
18868    
18869                                    qPos.add(classPK);
18870    
18871                                    qPos.add(status);
18872    
18873                                    count = (Long)q.uniqueResult();
18874    
18875                                    finderCache.putResult(finderPath, finderArgs, count);
18876                            }
18877                            catch (Exception e) {
18878                                    finderCache.removeResult(finderPath, finderArgs);
18879    
18880                                    throw processException(e);
18881                            }
18882                            finally {
18883                                    closeSession(session);
18884                            }
18885                    }
18886    
18887                    return count.intValue();
18888            }
18889    
18890            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18891            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18892            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18893            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18894    
18895            public MBMessagePersistenceImpl() {
18896                    setModelClass(MBMessage.class);
18897            }
18898    
18899            /**
18900             * Caches the message-boards message in the entity cache if it is enabled.
18901             *
18902             * @param mbMessage the message-boards message
18903             */
18904            @Override
18905            public void cacheResult(MBMessage mbMessage) {
18906                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18907                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18908    
18909                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18910                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18911                            mbMessage);
18912    
18913                    mbMessage.resetOriginalValues();
18914            }
18915    
18916            /**
18917             * Caches the message-boards messages in the entity cache if it is enabled.
18918             *
18919             * @param mbMessages the message-boards messages
18920             */
18921            @Override
18922            public void cacheResult(List<MBMessage> mbMessages) {
18923                    for (MBMessage mbMessage : mbMessages) {
18924                            if (entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18925                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18926                                    cacheResult(mbMessage);
18927                            }
18928                            else {
18929                                    mbMessage.resetOriginalValues();
18930                            }
18931                    }
18932            }
18933    
18934            /**
18935             * Clears the cache for all message-boards messages.
18936             *
18937             * <p>
18938             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18939             * </p>
18940             */
18941            @Override
18942            public void clearCache() {
18943                    entityCache.clearCache(MBMessageImpl.class);
18944    
18945                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
18946                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18947                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18948            }
18949    
18950            /**
18951             * Clears the cache for the message-boards message.
18952             *
18953             * <p>
18954             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18955             * </p>
18956             */
18957            @Override
18958            public void clearCache(MBMessage mbMessage) {
18959                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18960                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18961    
18962                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18963                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18964    
18965                    clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18966            }
18967    
18968            @Override
18969            public void clearCache(List<MBMessage> mbMessages) {
18970                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18971                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18972    
18973                    for (MBMessage mbMessage : mbMessages) {
18974                            entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18975                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18976    
18977                            clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18978                    }
18979            }
18980    
18981            protected void cacheUniqueFindersCache(
18982                    MBMessageModelImpl mbMessageModelImpl, boolean isNew) {
18983                    if (isNew) {
18984                            Object[] args = new Object[] {
18985                                            mbMessageModelImpl.getUuid(),
18986                                            mbMessageModelImpl.getGroupId()
18987                                    };
18988    
18989                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18990                                    Long.valueOf(1));
18991                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18992                                    mbMessageModelImpl);
18993                    }
18994                    else {
18995                            if ((mbMessageModelImpl.getColumnBitmask() &
18996                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18997                                    Object[] args = new Object[] {
18998                                                    mbMessageModelImpl.getUuid(),
18999                                                    mbMessageModelImpl.getGroupId()
19000                                            };
19001    
19002                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
19003                                            Long.valueOf(1));
19004                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
19005                                            mbMessageModelImpl);
19006                            }
19007                    }
19008            }
19009    
19010            protected void clearUniqueFindersCache(
19011                    MBMessageModelImpl mbMessageModelImpl) {
19012                    Object[] args = new Object[] {
19013                                    mbMessageModelImpl.getUuid(), mbMessageModelImpl.getGroupId()
19014                            };
19015    
19016                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19017                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19018    
19019                    if ((mbMessageModelImpl.getColumnBitmask() &
19020                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
19021                            args = new Object[] {
19022                                            mbMessageModelImpl.getOriginalUuid(),
19023                                            mbMessageModelImpl.getOriginalGroupId()
19024                                    };
19025    
19026                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19027                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19028                    }
19029            }
19030    
19031            /**
19032             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
19033             *
19034             * @param messageId the primary key for the new message-boards message
19035             * @return the new message-boards message
19036             */
19037            @Override
19038            public MBMessage create(long messageId) {
19039                    MBMessage mbMessage = new MBMessageImpl();
19040    
19041                    mbMessage.setNew(true);
19042                    mbMessage.setPrimaryKey(messageId);
19043    
19044                    String uuid = PortalUUIDUtil.generate();
19045    
19046                    mbMessage.setUuid(uuid);
19047    
19048                    mbMessage.setCompanyId(companyProvider.getCompanyId());
19049    
19050                    return mbMessage;
19051            }
19052    
19053            /**
19054             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19055             *
19056             * @param messageId the primary key of the message-boards message
19057             * @return the message-boards message that was removed
19058             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19059             */
19060            @Override
19061            public MBMessage remove(long messageId) throws NoSuchMessageException {
19062                    return remove((Serializable)messageId);
19063            }
19064    
19065            /**
19066             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19067             *
19068             * @param primaryKey the primary key of the message-boards message
19069             * @return the message-boards message that was removed
19070             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19071             */
19072            @Override
19073            public MBMessage remove(Serializable primaryKey)
19074                    throws NoSuchMessageException {
19075                    Session session = null;
19076    
19077                    try {
19078                            session = openSession();
19079    
19080                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19081                                            primaryKey);
19082    
19083                            if (mbMessage == null) {
19084                                    if (_log.isWarnEnabled()) {
19085                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19086                                    }
19087    
19088                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19089                                            primaryKey);
19090                            }
19091    
19092                            return remove(mbMessage);
19093                    }
19094                    catch (NoSuchMessageException nsee) {
19095                            throw nsee;
19096                    }
19097                    catch (Exception e) {
19098                            throw processException(e);
19099                    }
19100                    finally {
19101                            closeSession(session);
19102                    }
19103            }
19104    
19105            @Override
19106            protected MBMessage removeImpl(MBMessage mbMessage) {
19107                    mbMessage = toUnwrappedModel(mbMessage);
19108    
19109                    Session session = null;
19110    
19111                    try {
19112                            session = openSession();
19113    
19114                            if (!session.contains(mbMessage)) {
19115                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19116                                                    mbMessage.getPrimaryKeyObj());
19117                            }
19118    
19119                            if (mbMessage != null) {
19120                                    session.delete(mbMessage);
19121                            }
19122                    }
19123                    catch (Exception e) {
19124                            throw processException(e);
19125                    }
19126                    finally {
19127                            closeSession(session);
19128                    }
19129    
19130                    if (mbMessage != null) {
19131                            clearCache(mbMessage);
19132                    }
19133    
19134                    return mbMessage;
19135            }
19136    
19137            @Override
19138            public MBMessage updateImpl(MBMessage mbMessage) {
19139                    mbMessage = toUnwrappedModel(mbMessage);
19140    
19141                    boolean isNew = mbMessage.isNew();
19142    
19143                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19144    
19145                    if (Validator.isNull(mbMessage.getUuid())) {
19146                            String uuid = PortalUUIDUtil.generate();
19147    
19148                            mbMessage.setUuid(uuid);
19149                    }
19150    
19151                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
19152    
19153                    Date now = new Date();
19154    
19155                    if (isNew && (mbMessage.getCreateDate() == null)) {
19156                            if (serviceContext == null) {
19157                                    mbMessage.setCreateDate(now);
19158                            }
19159                            else {
19160                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
19161                            }
19162                    }
19163    
19164                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
19165                            if (serviceContext == null) {
19166                                    mbMessage.setModifiedDate(now);
19167                            }
19168                            else {
19169                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
19170                            }
19171                    }
19172    
19173                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
19174    
19175                    if (userId > 0) {
19176                            long companyId = mbMessage.getCompanyId();
19177    
19178                            long groupId = mbMessage.getGroupId();
19179    
19180                            long messageId = 0;
19181    
19182                            if (!isNew) {
19183                                    messageId = mbMessage.getPrimaryKey();
19184                            }
19185    
19186                            try {
19187                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
19188                                                    userId,
19189                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
19190                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
19191                                                    mbMessage.getSubject(), null));
19192                            }
19193                            catch (SanitizerException se) {
19194                                    throw new SystemException(se);
19195                            }
19196                    }
19197    
19198                    Session session = null;
19199    
19200                    try {
19201                            session = openSession();
19202    
19203                            if (mbMessage.isNew()) {
19204                                    session.save(mbMessage);
19205    
19206                                    mbMessage.setNew(false);
19207                            }
19208                            else {
19209                                    mbMessage = (MBMessage)session.merge(mbMessage);
19210                            }
19211                    }
19212                    catch (Exception e) {
19213                            throw processException(e);
19214                    }
19215                    finally {
19216                            closeSession(session);
19217                    }
19218    
19219                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19220    
19221                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
19222                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19223                    }
19224    
19225                    else {
19226                            if ((mbMessageModelImpl.getColumnBitmask() &
19227                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
19228                                    Object[] args = new Object[] {
19229                                                    mbMessageModelImpl.getOriginalUuid()
19230                                            };
19231    
19232                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19233                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19234                                            args);
19235    
19236                                    args = new Object[] { mbMessageModelImpl.getUuid() };
19237    
19238                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19239                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19240                                            args);
19241                            }
19242    
19243                            if ((mbMessageModelImpl.getColumnBitmask() &
19244                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
19245                                    Object[] args = new Object[] {
19246                                                    mbMessageModelImpl.getOriginalUuid(),
19247                                                    mbMessageModelImpl.getOriginalCompanyId()
19248                                            };
19249    
19250                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19251                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19252                                            args);
19253    
19254                                    args = new Object[] {
19255                                                    mbMessageModelImpl.getUuid(),
19256                                                    mbMessageModelImpl.getCompanyId()
19257                                            };
19258    
19259                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19260                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19261                                            args);
19262                            }
19263    
19264                            if ((mbMessageModelImpl.getColumnBitmask() &
19265                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
19266                                    Object[] args = new Object[] {
19267                                                    mbMessageModelImpl.getOriginalGroupId()
19268                                            };
19269    
19270                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19271                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19272                                            args);
19273    
19274                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
19275    
19276                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19277                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19278                                            args);
19279                            }
19280    
19281                            if ((mbMessageModelImpl.getColumnBitmask() &
19282                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
19283                                    Object[] args = new Object[] {
19284                                                    mbMessageModelImpl.getOriginalCompanyId()
19285                                            };
19286    
19287                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19288                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19289                                            args);
19290    
19291                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
19292    
19293                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19294                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19295                                            args);
19296                            }
19297    
19298                            if ((mbMessageModelImpl.getColumnBitmask() &
19299                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
19300                                    Object[] args = new Object[] {
19301                                                    mbMessageModelImpl.getOriginalUserId()
19302                                            };
19303    
19304                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19305                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19306                                            args);
19307    
19308                                    args = new Object[] { mbMessageModelImpl.getUserId() };
19309    
19310                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19311                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19312                                            args);
19313                            }
19314    
19315                            if ((mbMessageModelImpl.getColumnBitmask() &
19316                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
19317                                    Object[] args = new Object[] {
19318                                                    mbMessageModelImpl.getOriginalThreadId()
19319                                            };
19320    
19321                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19322                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19323                                            args);
19324    
19325                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19326    
19327                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19328                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19329                                            args);
19330                            }
19331    
19332                            if ((mbMessageModelImpl.getColumnBitmask() &
19333                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
19334                                    Object[] args = new Object[] {
19335                                                    mbMessageModelImpl.getOriginalThreadId()
19336                                            };
19337    
19338                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19339                                            args);
19340                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19341                                            args);
19342    
19343                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19344    
19345                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19346                                            args);
19347                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19348                                            args);
19349                            }
19350    
19351                            if ((mbMessageModelImpl.getColumnBitmask() &
19352                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19353                                    Object[] args = new Object[] {
19354                                                    mbMessageModelImpl.getOriginalGroupId(),
19355                                                    mbMessageModelImpl.getOriginalUserId()
19356                                            };
19357    
19358                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19359                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19360                                            args);
19361    
19362                                    args = new Object[] {
19363                                                    mbMessageModelImpl.getGroupId(),
19364                                                    mbMessageModelImpl.getUserId()
19365                                            };
19366    
19367                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19368                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19369                                            args);
19370                            }
19371    
19372                            if ((mbMessageModelImpl.getColumnBitmask() &
19373                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19374                                    Object[] args = new Object[] {
19375                                                    mbMessageModelImpl.getOriginalGroupId(),
19376                                                    mbMessageModelImpl.getOriginalCategoryId()
19377                                            };
19378    
19379                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19380                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19381                                            args);
19382    
19383                                    args = new Object[] {
19384                                                    mbMessageModelImpl.getGroupId(),
19385                                                    mbMessageModelImpl.getCategoryId()
19386                                            };
19387    
19388                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19389                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19390                                            args);
19391                            }
19392    
19393                            if ((mbMessageModelImpl.getColumnBitmask() &
19394                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19395                                    Object[] args = new Object[] {
19396                                                    mbMessageModelImpl.getOriginalGroupId(),
19397                                                    mbMessageModelImpl.getOriginalStatus()
19398                                            };
19399    
19400                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19401                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19402                                            args);
19403    
19404                                    args = new Object[] {
19405                                                    mbMessageModelImpl.getGroupId(),
19406                                                    mbMessageModelImpl.getStatus()
19407                                            };
19408    
19409                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19410                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19411                                            args);
19412                            }
19413    
19414                            if ((mbMessageModelImpl.getColumnBitmask() &
19415                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19416                                    Object[] args = new Object[] {
19417                                                    mbMessageModelImpl.getOriginalCompanyId(),
19418                                                    mbMessageModelImpl.getOriginalStatus()
19419                                            };
19420    
19421                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19422                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19423                                            args);
19424    
19425                                    args = new Object[] {
19426                                                    mbMessageModelImpl.getCompanyId(),
19427                                                    mbMessageModelImpl.getStatus()
19428                                            };
19429    
19430                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19431                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19432                                            args);
19433                            }
19434    
19435                            if ((mbMessageModelImpl.getColumnBitmask() &
19436                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19437                                    Object[] args = new Object[] {
19438                                                    mbMessageModelImpl.getOriginalUserId(),
19439                                                    mbMessageModelImpl.getOriginalClassNameId()
19440                                            };
19441    
19442                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19443                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19444                                            args);
19445    
19446                                    args = new Object[] {
19447                                                    mbMessageModelImpl.getUserId(),
19448                                                    mbMessageModelImpl.getClassNameId()
19449                                            };
19450    
19451                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19452                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19453                                            args);
19454                            }
19455    
19456                            if ((mbMessageModelImpl.getColumnBitmask() &
19457                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19458                                    Object[] args = new Object[] {
19459                                                    mbMessageModelImpl.getOriginalClassNameId(),
19460                                                    mbMessageModelImpl.getOriginalClassPK()
19461                                            };
19462    
19463                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19464                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19465                                            args);
19466    
19467                                    args = new Object[] {
19468                                                    mbMessageModelImpl.getClassNameId(),
19469                                                    mbMessageModelImpl.getClassPK()
19470                                            };
19471    
19472                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19473                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19474                                            args);
19475                            }
19476    
19477                            if ((mbMessageModelImpl.getColumnBitmask() &
19478                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19479                                    Object[] args = new Object[] {
19480                                                    mbMessageModelImpl.getOriginalThreadId(),
19481                                                    mbMessageModelImpl.getOriginalParentMessageId()
19482                                            };
19483    
19484                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19485                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19486                                            args);
19487    
19488                                    args = new Object[] {
19489                                                    mbMessageModelImpl.getThreadId(),
19490                                                    mbMessageModelImpl.getParentMessageId()
19491                                            };
19492    
19493                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19494                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19495                                            args);
19496                            }
19497    
19498                            if ((mbMessageModelImpl.getColumnBitmask() &
19499                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19500                                    Object[] args = new Object[] {
19501                                                    mbMessageModelImpl.getOriginalThreadId(),
19502                                                    mbMessageModelImpl.getOriginalAnswer()
19503                                            };
19504    
19505                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19506                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19507                                            args);
19508    
19509                                    args = new Object[] {
19510                                                    mbMessageModelImpl.getThreadId(),
19511                                                    mbMessageModelImpl.getAnswer()
19512                                            };
19513    
19514                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19515                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19516                                            args);
19517                            }
19518    
19519                            if ((mbMessageModelImpl.getColumnBitmask() &
19520                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19521                                    Object[] args = new Object[] {
19522                                                    mbMessageModelImpl.getOriginalThreadId(),
19523                                                    mbMessageModelImpl.getOriginalStatus()
19524                                            };
19525    
19526                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19527                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19528                                            args);
19529    
19530                                    args = new Object[] {
19531                                                    mbMessageModelImpl.getThreadId(),
19532                                                    mbMessageModelImpl.getStatus()
19533                                            };
19534    
19535                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19536                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19537                                            args);
19538                            }
19539    
19540                            if ((mbMessageModelImpl.getColumnBitmask() &
19541                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19542                                    Object[] args = new Object[] {
19543                                                    mbMessageModelImpl.getOriginalThreadId(),
19544                                                    mbMessageModelImpl.getOriginalStatus()
19545                                            };
19546    
19547                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19548                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19549                                            args);
19550    
19551                                    args = new Object[] {
19552                                                    mbMessageModelImpl.getThreadId(),
19553                                                    mbMessageModelImpl.getStatus()
19554                                            };
19555    
19556                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19557                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19558                                            args);
19559                            }
19560    
19561                            if ((mbMessageModelImpl.getColumnBitmask() &
19562                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19563                                    Object[] args = new Object[] {
19564                                                    mbMessageModelImpl.getOriginalGroupId(),
19565                                                    mbMessageModelImpl.getOriginalUserId(),
19566                                                    mbMessageModelImpl.getOriginalStatus()
19567                                            };
19568    
19569                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19570                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19571                                            args);
19572    
19573                                    args = new Object[] {
19574                                                    mbMessageModelImpl.getGroupId(),
19575                                                    mbMessageModelImpl.getUserId(),
19576                                                    mbMessageModelImpl.getStatus()
19577                                            };
19578    
19579                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19580                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19581                                            args);
19582                            }
19583    
19584                            if ((mbMessageModelImpl.getColumnBitmask() &
19585                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19586                                    Object[] args = new Object[] {
19587                                                    mbMessageModelImpl.getOriginalGroupId(),
19588                                                    mbMessageModelImpl.getOriginalCategoryId(),
19589                                                    mbMessageModelImpl.getOriginalThreadId()
19590                                            };
19591    
19592                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19593                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19594                                            args);
19595    
19596                                    args = new Object[] {
19597                                                    mbMessageModelImpl.getGroupId(),
19598                                                    mbMessageModelImpl.getCategoryId(),
19599                                                    mbMessageModelImpl.getThreadId()
19600                                            };
19601    
19602                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19603                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19604                                            args);
19605                            }
19606    
19607                            if ((mbMessageModelImpl.getColumnBitmask() &
19608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19609                                    Object[] args = new Object[] {
19610                                                    mbMessageModelImpl.getOriginalGroupId(),
19611                                                    mbMessageModelImpl.getOriginalCategoryId(),
19612                                                    mbMessageModelImpl.getOriginalStatus()
19613                                            };
19614    
19615                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19616                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19617                                            args);
19618    
19619                                    args = new Object[] {
19620                                                    mbMessageModelImpl.getGroupId(),
19621                                                    mbMessageModelImpl.getCategoryId(),
19622                                                    mbMessageModelImpl.getStatus()
19623                                            };
19624    
19625                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19626                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19627                                            args);
19628                            }
19629    
19630                            if ((mbMessageModelImpl.getColumnBitmask() &
19631                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19632                                    Object[] args = new Object[] {
19633                                                    mbMessageModelImpl.getOriginalUserId(),
19634                                                    mbMessageModelImpl.getOriginalClassNameId(),
19635                                                    mbMessageModelImpl.getOriginalClassPK()
19636                                            };
19637    
19638                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19639                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19640                                            args);
19641    
19642                                    args = new Object[] {
19643                                                    mbMessageModelImpl.getUserId(),
19644                                                    mbMessageModelImpl.getClassNameId(),
19645                                                    mbMessageModelImpl.getClassPK()
19646                                            };
19647    
19648                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19649                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19650                                            args);
19651                            }
19652    
19653                            if ((mbMessageModelImpl.getColumnBitmask() &
19654                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19655                                    Object[] args = new Object[] {
19656                                                    mbMessageModelImpl.getOriginalUserId(),
19657                                                    mbMessageModelImpl.getOriginalClassNameId(),
19658                                                    mbMessageModelImpl.getOriginalStatus()
19659                                            };
19660    
19661                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19662                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19663                                            args);
19664    
19665                                    args = new Object[] {
19666                                                    mbMessageModelImpl.getUserId(),
19667                                                    mbMessageModelImpl.getClassNameId(),
19668                                                    mbMessageModelImpl.getStatus()
19669                                            };
19670    
19671                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19672                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19673                                            args);
19674                            }
19675    
19676                            if ((mbMessageModelImpl.getColumnBitmask() &
19677                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19678                                    Object[] args = new Object[] {
19679                                                    mbMessageModelImpl.getOriginalClassNameId(),
19680                                                    mbMessageModelImpl.getOriginalClassPK(),
19681                                                    mbMessageModelImpl.getOriginalStatus()
19682                                            };
19683    
19684                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19685                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19686                                            args);
19687    
19688                                    args = new Object[] {
19689                                                    mbMessageModelImpl.getClassNameId(),
19690                                                    mbMessageModelImpl.getClassPK(),
19691                                                    mbMessageModelImpl.getStatus()
19692                                            };
19693    
19694                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19695                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19696                                            args);
19697                            }
19698    
19699                            if ((mbMessageModelImpl.getColumnBitmask() &
19700                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19701                                    Object[] args = new Object[] {
19702                                                    mbMessageModelImpl.getOriginalGroupId(),
19703                                                    mbMessageModelImpl.getOriginalCategoryId(),
19704                                                    mbMessageModelImpl.getOriginalThreadId(),
19705                                                    mbMessageModelImpl.getOriginalAnswer()
19706                                            };
19707    
19708                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19709                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19710                                            args);
19711    
19712                                    args = new Object[] {
19713                                                    mbMessageModelImpl.getGroupId(),
19714                                                    mbMessageModelImpl.getCategoryId(),
19715                                                    mbMessageModelImpl.getThreadId(),
19716                                                    mbMessageModelImpl.getAnswer()
19717                                            };
19718    
19719                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19720                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19721                                            args);
19722                            }
19723    
19724                            if ((mbMessageModelImpl.getColumnBitmask() &
19725                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19726                                    Object[] args = new Object[] {
19727                                                    mbMessageModelImpl.getOriginalGroupId(),
19728                                                    mbMessageModelImpl.getOriginalCategoryId(),
19729                                                    mbMessageModelImpl.getOriginalThreadId(),
19730                                                    mbMessageModelImpl.getOriginalStatus()
19731                                            };
19732    
19733                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19734                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19735                                            args);
19736    
19737                                    args = new Object[] {
19738                                                    mbMessageModelImpl.getGroupId(),
19739                                                    mbMessageModelImpl.getCategoryId(),
19740                                                    mbMessageModelImpl.getThreadId(),
19741                                                    mbMessageModelImpl.getStatus()
19742                                            };
19743    
19744                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19745                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19746                                            args);
19747                            }
19748    
19749                            if ((mbMessageModelImpl.getColumnBitmask() &
19750                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19751                                    Object[] args = new Object[] {
19752                                                    mbMessageModelImpl.getOriginalUserId(),
19753                                                    mbMessageModelImpl.getOriginalClassNameId(),
19754                                                    mbMessageModelImpl.getOriginalClassPK(),
19755                                                    mbMessageModelImpl.getOriginalStatus()
19756                                            };
19757    
19758                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19759                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19760                                            args);
19761    
19762                                    args = new Object[] {
19763                                                    mbMessageModelImpl.getUserId(),
19764                                                    mbMessageModelImpl.getClassNameId(),
19765                                                    mbMessageModelImpl.getClassPK(),
19766                                                    mbMessageModelImpl.getStatus()
19767                                            };
19768    
19769                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19770                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19771                                            args);
19772                            }
19773                    }
19774    
19775                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19776                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
19777    
19778                    clearUniqueFindersCache(mbMessageModelImpl);
19779                    cacheUniqueFindersCache(mbMessageModelImpl, isNew);
19780    
19781                    mbMessage.resetOriginalValues();
19782    
19783                    return mbMessage;
19784            }
19785    
19786            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19787                    if (mbMessage instanceof MBMessageImpl) {
19788                            return mbMessage;
19789                    }
19790    
19791                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19792    
19793                    mbMessageImpl.setNew(mbMessage.isNew());
19794                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19795    
19796                    mbMessageImpl.setUuid(mbMessage.getUuid());
19797                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19798                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19799                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19800                    mbMessageImpl.setUserId(mbMessage.getUserId());
19801                    mbMessageImpl.setUserName(mbMessage.getUserName());
19802                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19803                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19804                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19805                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19806                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19807                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19808                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19809                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19810                    mbMessageImpl.setSubject(mbMessage.getSubject());
19811                    mbMessageImpl.setBody(mbMessage.getBody());
19812                    mbMessageImpl.setFormat(mbMessage.getFormat());
19813                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19814                    mbMessageImpl.setPriority(mbMessage.getPriority());
19815                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19816                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19817                    mbMessageImpl.setLastPublishDate(mbMessage.getLastPublishDate());
19818                    mbMessageImpl.setStatus(mbMessage.getStatus());
19819                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19820                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19821                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19822    
19823                    return mbMessageImpl;
19824            }
19825    
19826            /**
19827             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
19828             *
19829             * @param primaryKey the primary key of the message-boards message
19830             * @return the message-boards message
19831             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19832             */
19833            @Override
19834            public MBMessage findByPrimaryKey(Serializable primaryKey)
19835                    throws NoSuchMessageException {
19836                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19837    
19838                    if (mbMessage == null) {
19839                            if (_log.isWarnEnabled()) {
19840                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19841                            }
19842    
19843                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19844                                    primaryKey);
19845                    }
19846    
19847                    return mbMessage;
19848            }
19849    
19850            /**
19851             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19852             *
19853             * @param messageId the primary key of the message-boards message
19854             * @return the message-boards message
19855             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19856             */
19857            @Override
19858            public MBMessage findByPrimaryKey(long messageId)
19859                    throws NoSuchMessageException {
19860                    return findByPrimaryKey((Serializable)messageId);
19861            }
19862    
19863            /**
19864             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19865             *
19866             * @param primaryKey the primary key of the message-boards message
19867             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19868             */
19869            @Override
19870            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19871                    MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19872                                    MBMessageImpl.class, primaryKey);
19873    
19874                    if (mbMessage == _nullMBMessage) {
19875                            return null;
19876                    }
19877    
19878                    if (mbMessage == null) {
19879                            Session session = null;
19880    
19881                            try {
19882                                    session = openSession();
19883    
19884                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19885                                                    primaryKey);
19886    
19887                                    if (mbMessage != null) {
19888                                            cacheResult(mbMessage);
19889                                    }
19890                                    else {
19891                                            entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19892                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19893                                    }
19894                            }
19895                            catch (Exception e) {
19896                                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19897                                            MBMessageImpl.class, primaryKey);
19898    
19899                                    throw processException(e);
19900                            }
19901                            finally {
19902                                    closeSession(session);
19903                            }
19904                    }
19905    
19906                    return mbMessage;
19907            }
19908    
19909            /**
19910             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19911             *
19912             * @param messageId the primary key of the message-boards message
19913             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19914             */
19915            @Override
19916            public MBMessage fetchByPrimaryKey(long messageId) {
19917                    return fetchByPrimaryKey((Serializable)messageId);
19918            }
19919    
19920            @Override
19921            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19922                    Set<Serializable> primaryKeys) {
19923                    if (primaryKeys.isEmpty()) {
19924                            return Collections.emptyMap();
19925                    }
19926    
19927                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19928    
19929                    if (primaryKeys.size() == 1) {
19930                            Iterator<Serializable> iterator = primaryKeys.iterator();
19931    
19932                            Serializable primaryKey = iterator.next();
19933    
19934                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19935    
19936                            if (mbMessage != null) {
19937                                    map.put(primaryKey, mbMessage);
19938                            }
19939    
19940                            return map;
19941                    }
19942    
19943                    Set<Serializable> uncachedPrimaryKeys = null;
19944    
19945                    for (Serializable primaryKey : primaryKeys) {
19946                            MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19947                                            MBMessageImpl.class, primaryKey);
19948    
19949                            if (mbMessage == null) {
19950                                    if (uncachedPrimaryKeys == null) {
19951                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19952                                    }
19953    
19954                                    uncachedPrimaryKeys.add(primaryKey);
19955                            }
19956                            else {
19957                                    map.put(primaryKey, mbMessage);
19958                            }
19959                    }
19960    
19961                    if (uncachedPrimaryKeys == null) {
19962                            return map;
19963                    }
19964    
19965                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19966                                    1);
19967    
19968                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19969    
19970                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19971                            query.append(String.valueOf(primaryKey));
19972    
19973                            query.append(StringPool.COMMA);
19974                    }
19975    
19976                    query.setIndex(query.index() - 1);
19977    
19978                    query.append(StringPool.CLOSE_PARENTHESIS);
19979    
19980                    String sql = query.toString();
19981    
19982                    Session session = null;
19983    
19984                    try {
19985                            session = openSession();
19986    
19987                            Query q = session.createQuery(sql);
19988    
19989                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19990                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19991    
19992                                    cacheResult(mbMessage);
19993    
19994                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19995                            }
19996    
19997                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19998                                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19999                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
20000                            }
20001                    }
20002                    catch (Exception e) {
20003                            throw processException(e);
20004                    }
20005                    finally {
20006                            closeSession(session);
20007                    }
20008    
20009                    return map;
20010            }
20011    
20012            /**
20013             * Returns all the message-boards messages.
20014             *
20015             * @return the message-boards messages
20016             */
20017            @Override
20018            public List<MBMessage> findAll() {
20019                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20020            }
20021    
20022            /**
20023             * Returns a range of all the message-boards messages.
20024             *
20025             * <p>
20026             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20027             * </p>
20028             *
20029             * @param start the lower bound of the range of message-boards messages
20030             * @param end the upper bound of the range of message-boards messages (not inclusive)
20031             * @return the range of message-boards messages
20032             */
20033            @Override
20034            public List<MBMessage> findAll(int start, int end) {
20035                    return findAll(start, end, null);
20036            }
20037    
20038            /**
20039             * Returns an ordered range of all the message-boards messages.
20040             *
20041             * <p>
20042             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20043             * </p>
20044             *
20045             * @param start the lower bound of the range of message-boards messages
20046             * @param end the upper bound of the range of message-boards messages (not inclusive)
20047             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20048             * @return the ordered range of message-boards messages
20049             */
20050            @Override
20051            public List<MBMessage> findAll(int start, int end,
20052                    OrderByComparator<MBMessage> orderByComparator) {
20053                    return findAll(start, end, orderByComparator, true);
20054            }
20055    
20056            /**
20057             * Returns an ordered range of all the message-boards messages.
20058             *
20059             * <p>
20060             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20061             * </p>
20062             *
20063             * @param start the lower bound of the range of message-boards messages
20064             * @param end the upper bound of the range of message-boards messages (not inclusive)
20065             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20066             * @param retrieveFromCache whether to retrieve from the finder cache
20067             * @return the ordered range of message-boards messages
20068             */
20069            @Override
20070            public List<MBMessage> findAll(int start, int end,
20071                    OrderByComparator<MBMessage> orderByComparator,
20072                    boolean retrieveFromCache) {
20073                    boolean pagination = true;
20074                    FinderPath finderPath = null;
20075                    Object[] finderArgs = null;
20076    
20077                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20078                                    (orderByComparator == null)) {
20079                            pagination = false;
20080                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20081                            finderArgs = FINDER_ARGS_EMPTY;
20082                    }
20083                    else {
20084                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20085                            finderArgs = new Object[] { start, end, orderByComparator };
20086                    }
20087    
20088                    List<MBMessage> list = null;
20089    
20090                    if (retrieveFromCache) {
20091                            list = (List<MBMessage>)finderCache.getResult(finderPath,
20092                                            finderArgs, this);
20093                    }
20094    
20095                    if (list == null) {
20096                            StringBundler query = null;
20097                            String sql = null;
20098    
20099                            if (orderByComparator != null) {
20100                                    query = new StringBundler(2 +
20101                                                    (orderByComparator.getOrderByFields().length * 2));
20102    
20103                                    query.append(_SQL_SELECT_MBMESSAGE);
20104    
20105                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20106                                            orderByComparator);
20107    
20108                                    sql = query.toString();
20109                            }
20110                            else {
20111                                    sql = _SQL_SELECT_MBMESSAGE;
20112    
20113                                    if (pagination) {
20114                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20115                                    }
20116                            }
20117    
20118                            Session session = null;
20119    
20120                            try {
20121                                    session = openSession();
20122    
20123                                    Query q = session.createQuery(sql);
20124    
20125                                    if (!pagination) {
20126                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20127                                                            start, end, false);
20128    
20129                                            Collections.sort(list);
20130    
20131                                            list = Collections.unmodifiableList(list);
20132                                    }
20133                                    else {
20134                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20135                                                            start, end);
20136                                    }
20137    
20138                                    cacheResult(list);
20139    
20140                                    finderCache.putResult(finderPath, finderArgs, list);
20141                            }
20142                            catch (Exception e) {
20143                                    finderCache.removeResult(finderPath, finderArgs);
20144    
20145                                    throw processException(e);
20146                            }
20147                            finally {
20148                                    closeSession(session);
20149                            }
20150                    }
20151    
20152                    return list;
20153            }
20154    
20155            /**
20156             * Removes all the message-boards messages from the database.
20157             *
20158             */
20159            @Override
20160            public void removeAll() {
20161                    for (MBMessage mbMessage : findAll()) {
20162                            remove(mbMessage);
20163                    }
20164            }
20165    
20166            /**
20167             * Returns the number of message-boards messages.
20168             *
20169             * @return the number of message-boards messages
20170             */
20171            @Override
20172            public int countAll() {
20173                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
20174                                    FINDER_ARGS_EMPTY, this);
20175    
20176                    if (count == null) {
20177                            Session session = null;
20178    
20179                            try {
20180                                    session = openSession();
20181    
20182                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20183    
20184                                    count = (Long)q.uniqueResult();
20185    
20186                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
20187                                            count);
20188                            }
20189                            catch (Exception e) {
20190                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
20191                                            FINDER_ARGS_EMPTY);
20192    
20193                                    throw processException(e);
20194                            }
20195                            finally {
20196                                    closeSession(session);
20197                            }
20198                    }
20199    
20200                    return count.intValue();
20201            }
20202    
20203            @Override
20204            public Set<String> getBadColumnNames() {
20205                    return _badColumnNames;
20206            }
20207    
20208            @Override
20209            protected Map<String, Integer> getTableColumnsMap() {
20210                    return MBMessageModelImpl.TABLE_COLUMNS_MAP;
20211            }
20212    
20213            /**
20214             * Initializes the message-boards message persistence.
20215             */
20216            public void afterPropertiesSet() {
20217            }
20218    
20219            public void destroy() {
20220                    entityCache.removeCache(MBMessageImpl.class.getName());
20221                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
20222                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20223                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20224            }
20225    
20226            @BeanReference(type = CompanyProviderWrapper.class)
20227            protected CompanyProvider companyProvider;
20228            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
20229            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
20230            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
20231            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
20232            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
20233            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
20234            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
20235            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
20236            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
20237            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
20238                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
20239            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
20240                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
20241            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
20242            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
20243            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
20244            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
20245            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
20246            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
20247            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
20248            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
20249            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
20250                                    "uuid"
20251                            });
20252            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
20253                            @Override
20254                            public Object clone() {
20255                                    return this;
20256                            }
20257    
20258                            @Override
20259                            public CacheModel<MBMessage> toCacheModel() {
20260                                    return _nullMBMessageCacheModel;
20261                            }
20262                    };
20263    
20264            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
20265                            @Override
20266                            public MBMessage toEntityModel() {
20267                                    return _nullMBMessage;
20268                            }
20269                    };
20270    }