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.message.boards.kernel.exception.NoSuchMessageException;
020    import com.liferay.message.boards.kernel.model.MBMessage;
021    import com.liferay.message.boards.kernel.service.persistence.MBMessagePersistence;
022    
023    import com.liferay.portal.kernel.bean.BeanReference;
024    import com.liferay.portal.kernel.dao.orm.EntityCache;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCache;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.model.CacheModel;
038    import com.liferay.portal.kernel.sanitizer.Sanitizer;
039    import com.liferay.portal.kernel.sanitizer.SanitizerException;
040    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
041    import com.liferay.portal.kernel.security.auth.PrincipalThreadLocal;
042    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.kernel.service.ServiceContext;
044    import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
045    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
046    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
047    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
048    import com.liferay.portal.kernel.util.ArrayUtil;
049    import com.liferay.portal.kernel.util.ContentTypes;
050    import com.liferay.portal.kernel.util.GetterUtil;
051    import com.liferay.portal.kernel.util.OrderByComparator;
052    import com.liferay.portal.kernel.util.SetUtil;
053    import com.liferay.portal.kernel.util.StringBundler;
054    import com.liferay.portal.kernel.util.StringPool;
055    import com.liferay.portal.kernel.util.StringUtil;
056    import com.liferay.portal.kernel.util.Validator;
057    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
058    
059    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
060    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
061    
062    import java.io.Serializable;
063    
064    import java.util.Arrays;
065    import java.util.Collections;
066    import java.util.Date;
067    import java.util.HashMap;
068    import java.util.HashSet;
069    import java.util.Iterator;
070    import java.util.List;
071    import java.util.Map;
072    import java.util.Set;
073    
074    /**
075     * The persistence implementation for the message-boards message service.
076     *
077     * <p>
078     * Caching information and settings can be found in <code>portal.properties</code>
079     * </p>
080     *
081     * @author Brian Wing Shun Chan
082     * @see MBMessagePersistence
083     * @see com.liferay.message.boards.kernel.service.persistence.MBMessageUtil
084     * @generated
085     */
086    @ProviderType
087    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
088            implements MBMessagePersistence {
089            /*
090             * NOTE FOR DEVELOPERS:
091             *
092             * 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.
093             */
094            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
095            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
096                    ".List1";
097            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
098                    ".List2";
099            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
100                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
103                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
106                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
109                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
111                            new String[] {
112                                    String.class.getName(),
113                                    
114                            Integer.class.getName(), Integer.class.getName(),
115                                    OrderByComparator.class.getName()
116                            });
117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
118                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
120                            new String[] { String.class.getName() },
121                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
122                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
123            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
124                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
126                            new String[] { String.class.getName() });
127    
128            /**
129             * Returns all the message-boards messages where uuid = &#63;.
130             *
131             * @param uuid the uuid
132             * @return the matching message-boards messages
133             */
134            @Override
135            public List<MBMessage> findByUuid(String uuid) {
136                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
137            }
138    
139            /**
140             * Returns a range of all the message-boards messages where uuid = &#63;.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
144             * </p>
145             *
146             * @param uuid the uuid
147             * @param start the lower bound of the range of message-boards messages
148             * @param end the upper bound of the range of message-boards messages (not inclusive)
149             * @return the range of matching message-boards messages
150             */
151            @Override
152            public List<MBMessage> findByUuid(String uuid, int start, int end) {
153                    return findByUuid(uuid, start, end, null);
154            }
155    
156            /**
157             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
158             *
159             * <p>
160             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
161             * </p>
162             *
163             * @param uuid the uuid
164             * @param start the lower bound of the range of message-boards messages
165             * @param end the upper bound of the range of message-boards messages (not inclusive)
166             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
167             * @return the ordered range of matching message-boards messages
168             */
169            @Override
170            public List<MBMessage> findByUuid(String uuid, int start, int end,
171                    OrderByComparator<MBMessage> orderByComparator) {
172                    return findByUuid(uuid, start, end, orderByComparator, true);
173            }
174    
175            /**
176             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
177             *
178             * <p>
179             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
180             * </p>
181             *
182             * @param uuid the uuid
183             * @param start the lower bound of the range of message-boards messages
184             * @param end the upper bound of the range of message-boards messages (not inclusive)
185             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
186             * @param retrieveFromCache whether to retrieve from the finder cache
187             * @return the ordered range of matching message-boards messages
188             */
189            @Override
190            public List<MBMessage> findByUuid(String uuid, int start, int end,
191                    OrderByComparator<MBMessage> orderByComparator,
192                    boolean retrieveFromCache) {
193                    boolean pagination = true;
194                    FinderPath finderPath = null;
195                    Object[] finderArgs = null;
196    
197                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
198                                    (orderByComparator == null)) {
199                            pagination = false;
200                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
201                            finderArgs = new Object[] { uuid };
202                    }
203                    else {
204                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
205                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
206                    }
207    
208                    List<MBMessage> list = null;
209    
210                    if (retrieveFromCache) {
211                            list = (List<MBMessage>)finderCache.getResult(finderPath,
212                                            finderArgs, this);
213    
214                            if ((list != null) && !list.isEmpty()) {
215                                    for (MBMessage mbMessage : list) {
216                                            if (!Validator.equals(uuid, mbMessage.getUuid())) {
217                                                    list = null;
218    
219                                                    break;
220                                            }
221                                    }
222                            }
223                    }
224    
225                    if (list == null) {
226                            StringBundler query = null;
227    
228                            if (orderByComparator != null) {
229                                    query = new StringBundler(3 +
230                                                    (orderByComparator.getOrderByFields().length * 2));
231                            }
232                            else {
233                                    query = new StringBundler(3);
234                            }
235    
236                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
237    
238                            boolean bindUuid = false;
239    
240                            if (uuid == null) {
241                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
242                            }
243                            else if (uuid.equals(StringPool.BLANK)) {
244                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
245                            }
246                            else {
247                                    bindUuid = true;
248    
249                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
250                            }
251    
252                            if (orderByComparator != null) {
253                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
254                                            orderByComparator);
255                            }
256                            else
257                             if (pagination) {
258                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
259                            }
260    
261                            String sql = query.toString();
262    
263                            Session session = null;
264    
265                            try {
266                                    session = openSession();
267    
268                                    Query q = session.createQuery(sql);
269    
270                                    QueryPos qPos = QueryPos.getInstance(q);
271    
272                                    if (bindUuid) {
273                                            qPos.add(uuid);
274                                    }
275    
276                                    if (!pagination) {
277                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
278                                                            start, end, false);
279    
280                                            Collections.sort(list);
281    
282                                            list = Collections.unmodifiableList(list);
283                                    }
284                                    else {
285                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
286                                                            start, end);
287                                    }
288    
289                                    cacheResult(list);
290    
291                                    finderCache.putResult(finderPath, finderArgs, list);
292                            }
293                            catch (Exception e) {
294                                    finderCache.removeResult(finderPath, finderArgs);
295    
296                                    throw processException(e);
297                            }
298                            finally {
299                                    closeSession(session);
300                            }
301                    }
302    
303                    return list;
304            }
305    
306            /**
307             * Returns the first message-boards message in the ordered set where uuid = &#63;.
308             *
309             * @param uuid the uuid
310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
311             * @return the first matching message-boards message
312             * @throws NoSuchMessageException if a matching message-boards message could not be found
313             */
314            @Override
315            public MBMessage findByUuid_First(String uuid,
316                    OrderByComparator<MBMessage> orderByComparator)
317                    throws NoSuchMessageException {
318                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
319    
320                    if (mbMessage != null) {
321                            return mbMessage;
322                    }
323    
324                    StringBundler msg = new StringBundler(4);
325    
326                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327    
328                    msg.append("uuid=");
329                    msg.append(uuid);
330    
331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
332    
333                    throw new NoSuchMessageException(msg.toString());
334            }
335    
336            /**
337             * Returns the first message-boards message in the ordered set where uuid = &#63;.
338             *
339             * @param uuid the uuid
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
342             */
343            @Override
344            public MBMessage fetchByUuid_First(String uuid,
345                    OrderByComparator<MBMessage> orderByComparator) {
346                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
347    
348                    if (!list.isEmpty()) {
349                            return list.get(0);
350                    }
351    
352                    return null;
353            }
354    
355            /**
356             * Returns the last message-boards message in the ordered set where uuid = &#63;.
357             *
358             * @param uuid the uuid
359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
360             * @return the last matching message-boards message
361             * @throws NoSuchMessageException if a matching message-boards message could not be found
362             */
363            @Override
364            public MBMessage findByUuid_Last(String uuid,
365                    OrderByComparator<MBMessage> orderByComparator)
366                    throws NoSuchMessageException {
367                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
368    
369                    if (mbMessage != null) {
370                            return mbMessage;
371                    }
372    
373                    StringBundler msg = new StringBundler(4);
374    
375                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
376    
377                    msg.append("uuid=");
378                    msg.append(uuid);
379    
380                    msg.append(StringPool.CLOSE_CURLY_BRACE);
381    
382                    throw new NoSuchMessageException(msg.toString());
383            }
384    
385            /**
386             * Returns the last message-boards message in the ordered set where uuid = &#63;.
387             *
388             * @param uuid the uuid
389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
390             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
391             */
392            @Override
393            public MBMessage fetchByUuid_Last(String uuid,
394                    OrderByComparator<MBMessage> orderByComparator) {
395                    int count = countByUuid(uuid);
396    
397                    if (count == 0) {
398                            return null;
399                    }
400    
401                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
402                                    orderByComparator);
403    
404                    if (!list.isEmpty()) {
405                            return list.get(0);
406                    }
407    
408                    return null;
409            }
410    
411            /**
412             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
413             *
414             * @param messageId the primary key of the current message-boards message
415             * @param uuid the uuid
416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
417             * @return the previous, current, and next message-boards message
418             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
419             */
420            @Override
421            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
422                    OrderByComparator<MBMessage> orderByComparator)
423                    throws NoSuchMessageException {
424                    MBMessage mbMessage = findByPrimaryKey(messageId);
425    
426                    Session session = null;
427    
428                    try {
429                            session = openSession();
430    
431                            MBMessage[] array = new MBMessageImpl[3];
432    
433                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
434                                            orderByComparator, true);
435    
436                            array[1] = mbMessage;
437    
438                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
439                                            orderByComparator, false);
440    
441                            return array;
442                    }
443                    catch (Exception e) {
444                            throw processException(e);
445                    }
446                    finally {
447                            closeSession(session);
448                    }
449            }
450    
451            protected MBMessage getByUuid_PrevAndNext(Session session,
452                    MBMessage mbMessage, String uuid,
453                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
454                    StringBundler query = null;
455    
456                    if (orderByComparator != null) {
457                            query = new StringBundler(4 +
458                                            (orderByComparator.getOrderByConditionFields().length * 3) +
459                                            (orderByComparator.getOrderByFields().length * 3));
460                    }
461                    else {
462                            query = new StringBundler(3);
463                    }
464    
465                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
466    
467                    boolean bindUuid = false;
468    
469                    if (uuid == null) {
470                            query.append(_FINDER_COLUMN_UUID_UUID_1);
471                    }
472                    else if (uuid.equals(StringPool.BLANK)) {
473                            query.append(_FINDER_COLUMN_UUID_UUID_3);
474                    }
475                    else {
476                            bindUuid = true;
477    
478                            query.append(_FINDER_COLUMN_UUID_UUID_2);
479                    }
480    
481                    if (orderByComparator != null) {
482                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
483    
484                            if (orderByConditionFields.length > 0) {
485                                    query.append(WHERE_AND);
486                            }
487    
488                            for (int i = 0; i < orderByConditionFields.length; i++) {
489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
490                                    query.append(orderByConditionFields[i]);
491    
492                                    if ((i + 1) < orderByConditionFields.length) {
493                                            if (orderByComparator.isAscending() ^ previous) {
494                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
495                                            }
496                                            else {
497                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
498                                            }
499                                    }
500                                    else {
501                                            if (orderByComparator.isAscending() ^ previous) {
502                                                    query.append(WHERE_GREATER_THAN);
503                                            }
504                                            else {
505                                                    query.append(WHERE_LESSER_THAN);
506                                            }
507                                    }
508                            }
509    
510                            query.append(ORDER_BY_CLAUSE);
511    
512                            String[] orderByFields = orderByComparator.getOrderByFields();
513    
514                            for (int i = 0; i < orderByFields.length; i++) {
515                                    query.append(_ORDER_BY_ENTITY_ALIAS);
516                                    query.append(orderByFields[i]);
517    
518                                    if ((i + 1) < orderByFields.length) {
519                                            if (orderByComparator.isAscending() ^ previous) {
520                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
521                                            }
522                                            else {
523                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
524                                            }
525                                    }
526                                    else {
527                                            if (orderByComparator.isAscending() ^ previous) {
528                                                    query.append(ORDER_BY_ASC);
529                                            }
530                                            else {
531                                                    query.append(ORDER_BY_DESC);
532                                            }
533                                    }
534                            }
535                    }
536                    else {
537                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
538                    }
539    
540                    String sql = query.toString();
541    
542                    Query q = session.createQuery(sql);
543    
544                    q.setFirstResult(0);
545                    q.setMaxResults(2);
546    
547                    QueryPos qPos = QueryPos.getInstance(q);
548    
549                    if (bindUuid) {
550                            qPos.add(uuid);
551                    }
552    
553                    if (orderByComparator != null) {
554                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
555    
556                            for (Object value : values) {
557                                    qPos.add(value);
558                            }
559                    }
560    
561                    List<MBMessage> list = q.list();
562    
563                    if (list.size() == 2) {
564                            return list.get(1);
565                    }
566                    else {
567                            return null;
568                    }
569            }
570    
571            /**
572             * Removes all the message-boards messages where uuid = &#63; from the database.
573             *
574             * @param uuid the uuid
575             */
576            @Override
577            public void removeByUuid(String uuid) {
578                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
579                                    QueryUtil.ALL_POS, null)) {
580                            remove(mbMessage);
581                    }
582            }
583    
584            /**
585             * Returns the number of message-boards messages where uuid = &#63;.
586             *
587             * @param uuid the uuid
588             * @return the number of matching message-boards messages
589             */
590            @Override
591            public int countByUuid(String uuid) {
592                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
593    
594                    Object[] finderArgs = new Object[] { uuid };
595    
596                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
597    
598                    if (count == null) {
599                            StringBundler query = new StringBundler(2);
600    
601                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
602    
603                            boolean bindUuid = false;
604    
605                            if (uuid == null) {
606                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
607                            }
608                            else if (uuid.equals(StringPool.BLANK)) {
609                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
610                            }
611                            else {
612                                    bindUuid = true;
613    
614                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
615                            }
616    
617                            String sql = query.toString();
618    
619                            Session session = null;
620    
621                            try {
622                                    session = openSession();
623    
624                                    Query q = session.createQuery(sql);
625    
626                                    QueryPos qPos = QueryPos.getInstance(q);
627    
628                                    if (bindUuid) {
629                                            qPos.add(uuid);
630                                    }
631    
632                                    count = (Long)q.uniqueResult();
633    
634                                    finderCache.putResult(finderPath, finderArgs, count);
635                            }
636                            catch (Exception e) {
637                                    finderCache.removeResult(finderPath, finderArgs);
638    
639                                    throw processException(e);
640                            }
641                            finally {
642                                    closeSession(session);
643                            }
644                    }
645    
646                    return count.intValue();
647            }
648    
649            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
650            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
651            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
652            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
653                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
654                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
655                            new String[] { String.class.getName(), Long.class.getName() },
656                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
657                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
658            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
659                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
660                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
661                            new String[] { String.class.getName(), Long.class.getName() });
662    
663            /**
664             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchMessageException} if it could not be found.
665             *
666             * @param uuid the uuid
667             * @param groupId the group ID
668             * @return the matching message-boards message
669             * @throws NoSuchMessageException if a matching message-boards message could not be found
670             */
671            @Override
672            public MBMessage findByUUID_G(String uuid, long groupId)
673                    throws NoSuchMessageException {
674                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
675    
676                    if (mbMessage == null) {
677                            StringBundler msg = new StringBundler(6);
678    
679                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
680    
681                            msg.append("uuid=");
682                            msg.append(uuid);
683    
684                            msg.append(", groupId=");
685                            msg.append(groupId);
686    
687                            msg.append(StringPool.CLOSE_CURLY_BRACE);
688    
689                            if (_log.isWarnEnabled()) {
690                                    _log.warn(msg.toString());
691                            }
692    
693                            throw new NoSuchMessageException(msg.toString());
694                    }
695    
696                    return mbMessage;
697            }
698    
699            /**
700             * 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.
701             *
702             * @param uuid the uuid
703             * @param groupId the group ID
704             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
705             */
706            @Override
707            public MBMessage fetchByUUID_G(String uuid, long groupId) {
708                    return fetchByUUID_G(uuid, groupId, true);
709            }
710    
711            /**
712             * 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.
713             *
714             * @param uuid the uuid
715             * @param groupId the group ID
716             * @param retrieveFromCache whether to retrieve from the finder cache
717             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
718             */
719            @Override
720            public MBMessage fetchByUUID_G(String uuid, long groupId,
721                    boolean retrieveFromCache) {
722                    Object[] finderArgs = new Object[] { uuid, groupId };
723    
724                    Object result = null;
725    
726                    if (retrieveFromCache) {
727                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
728                                            finderArgs, this);
729                    }
730    
731                    if (result instanceof MBMessage) {
732                            MBMessage mbMessage = (MBMessage)result;
733    
734                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
735                                            (groupId != mbMessage.getGroupId())) {
736                                    result = null;
737                            }
738                    }
739    
740                    if (result == null) {
741                            StringBundler query = new StringBundler(4);
742    
743                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
744    
745                            boolean bindUuid = false;
746    
747                            if (uuid == null) {
748                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
749                            }
750                            else if (uuid.equals(StringPool.BLANK)) {
751                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
752                            }
753                            else {
754                                    bindUuid = true;
755    
756                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
757                            }
758    
759                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
760    
761                            String sql = query.toString();
762    
763                            Session session = null;
764    
765                            try {
766                                    session = openSession();
767    
768                                    Query q = session.createQuery(sql);
769    
770                                    QueryPos qPos = QueryPos.getInstance(q);
771    
772                                    if (bindUuid) {
773                                            qPos.add(uuid);
774                                    }
775    
776                                    qPos.add(groupId);
777    
778                                    List<MBMessage> list = q.list();
779    
780                                    if (list.isEmpty()) {
781                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
782                                                    finderArgs, list);
783                                    }
784                                    else {
785                                            MBMessage mbMessage = list.get(0);
786    
787                                            result = mbMessage;
788    
789                                            cacheResult(mbMessage);
790    
791                                            if ((mbMessage.getUuid() == null) ||
792                                                            !mbMessage.getUuid().equals(uuid) ||
793                                                            (mbMessage.getGroupId() != groupId)) {
794                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
795                                                            finderArgs, mbMessage);
796                                            }
797                                    }
798                            }
799                            catch (Exception e) {
800                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
801    
802                                    throw processException(e);
803                            }
804                            finally {
805                                    closeSession(session);
806                            }
807                    }
808    
809                    if (result instanceof List<?>) {
810                            return null;
811                    }
812                    else {
813                            return (MBMessage)result;
814                    }
815            }
816    
817            /**
818             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
819             *
820             * @param uuid the uuid
821             * @param groupId the group ID
822             * @return the message-boards message that was removed
823             */
824            @Override
825            public MBMessage removeByUUID_G(String uuid, long groupId)
826                    throws NoSuchMessageException {
827                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
828    
829                    return remove(mbMessage);
830            }
831    
832            /**
833             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
834             *
835             * @param uuid the uuid
836             * @param groupId the group ID
837             * @return the number of matching message-boards messages
838             */
839            @Override
840            public int countByUUID_G(String uuid, long groupId) {
841                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
842    
843                    Object[] finderArgs = new Object[] { uuid, groupId };
844    
845                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
846    
847                    if (count == null) {
848                            StringBundler query = new StringBundler(3);
849    
850                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
851    
852                            boolean bindUuid = false;
853    
854                            if (uuid == null) {
855                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
856                            }
857                            else if (uuid.equals(StringPool.BLANK)) {
858                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
859                            }
860                            else {
861                                    bindUuid = true;
862    
863                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
864                            }
865    
866                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
867    
868                            String sql = query.toString();
869    
870                            Session session = null;
871    
872                            try {
873                                    session = openSession();
874    
875                                    Query q = session.createQuery(sql);
876    
877                                    QueryPos qPos = QueryPos.getInstance(q);
878    
879                                    if (bindUuid) {
880                                            qPos.add(uuid);
881                                    }
882    
883                                    qPos.add(groupId);
884    
885                                    count = (Long)q.uniqueResult();
886    
887                                    finderCache.putResult(finderPath, finderArgs, count);
888                            }
889                            catch (Exception e) {
890                                    finderCache.removeResult(finderPath, finderArgs);
891    
892                                    throw processException(e);
893                            }
894                            finally {
895                                    closeSession(session);
896                            }
897                    }
898    
899                    return count.intValue();
900            }
901    
902            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
903            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
904            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
905            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
906            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
907                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
908                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
909                            new String[] {
910                                    String.class.getName(), Long.class.getName(),
911                                    
912                            Integer.class.getName(), Integer.class.getName(),
913                                    OrderByComparator.class.getName()
914                            });
915            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
916                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
917                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
918                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
919                            new String[] { String.class.getName(), Long.class.getName() },
920                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
921                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
922                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
923            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
924                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
925                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
926                            new String[] { String.class.getName(), Long.class.getName() });
927    
928            /**
929             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
930             *
931             * @param uuid the uuid
932             * @param companyId the company ID
933             * @return the matching message-boards messages
934             */
935            @Override
936            public List<MBMessage> findByUuid_C(String uuid, long companyId) {
937                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
938                            QueryUtil.ALL_POS, null);
939            }
940    
941            /**
942             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
943             *
944             * <p>
945             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
946             * </p>
947             *
948             * @param uuid the uuid
949             * @param companyId the company ID
950             * @param start the lower bound of the range of message-boards messages
951             * @param end the upper bound of the range of message-boards messages (not inclusive)
952             * @return the range of matching message-boards messages
953             */
954            @Override
955            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
956                    int end) {
957                    return findByUuid_C(uuid, companyId, start, end, null);
958            }
959    
960            /**
961             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
962             *
963             * <p>
964             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
965             * </p>
966             *
967             * @param uuid the uuid
968             * @param companyId the company ID
969             * @param start the lower bound of the range of message-boards messages
970             * @param end the upper bound of the range of message-boards messages (not inclusive)
971             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
972             * @return the ordered range of matching message-boards messages
973             */
974            @Override
975            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
976                    int end, OrderByComparator<MBMessage> orderByComparator) {
977                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
978            }
979    
980            /**
981             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
982             *
983             * <p>
984             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
985             * </p>
986             *
987             * @param uuid the uuid
988             * @param companyId the company ID
989             * @param start the lower bound of the range of message-boards messages
990             * @param end the upper bound of the range of message-boards messages (not inclusive)
991             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
992             * @param retrieveFromCache whether to retrieve from the finder cache
993             * @return the ordered range of matching message-boards messages
994             */
995            @Override
996            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
997                    int end, OrderByComparator<MBMessage> orderByComparator,
998                    boolean retrieveFromCache) {
999                    boolean pagination = true;
1000                    FinderPath finderPath = null;
1001                    Object[] finderArgs = null;
1002    
1003                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1004                                    (orderByComparator == null)) {
1005                            pagination = false;
1006                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1007                            finderArgs = new Object[] { uuid, companyId };
1008                    }
1009                    else {
1010                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1011                            finderArgs = new Object[] {
1012                                            uuid, companyId,
1013                                            
1014                                            start, end, orderByComparator
1015                                    };
1016                    }
1017    
1018                    List<MBMessage> list = null;
1019    
1020                    if (retrieveFromCache) {
1021                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1022                                            finderArgs, this);
1023    
1024                            if ((list != null) && !list.isEmpty()) {
1025                                    for (MBMessage mbMessage : list) {
1026                                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
1027                                                            (companyId != mbMessage.getCompanyId())) {
1028                                                    list = null;
1029    
1030                                                    break;
1031                                            }
1032                                    }
1033                            }
1034                    }
1035    
1036                    if (list == null) {
1037                            StringBundler query = null;
1038    
1039                            if (orderByComparator != null) {
1040                                    query = new StringBundler(4 +
1041                                                    (orderByComparator.getOrderByFields().length * 2));
1042                            }
1043                            else {
1044                                    query = new StringBundler(4);
1045                            }
1046    
1047                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1048    
1049                            boolean bindUuid = false;
1050    
1051                            if (uuid == null) {
1052                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1053                            }
1054                            else if (uuid.equals(StringPool.BLANK)) {
1055                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1056                            }
1057                            else {
1058                                    bindUuid = true;
1059    
1060                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1061                            }
1062    
1063                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1064    
1065                            if (orderByComparator != null) {
1066                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1067                                            orderByComparator);
1068                            }
1069                            else
1070                             if (pagination) {
1071                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1072                            }
1073    
1074                            String sql = query.toString();
1075    
1076                            Session session = null;
1077    
1078                            try {
1079                                    session = openSession();
1080    
1081                                    Query q = session.createQuery(sql);
1082    
1083                                    QueryPos qPos = QueryPos.getInstance(q);
1084    
1085                                    if (bindUuid) {
1086                                            qPos.add(uuid);
1087                                    }
1088    
1089                                    qPos.add(companyId);
1090    
1091                                    if (!pagination) {
1092                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1093                                                            start, end, false);
1094    
1095                                            Collections.sort(list);
1096    
1097                                            list = Collections.unmodifiableList(list);
1098                                    }
1099                                    else {
1100                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1101                                                            start, end);
1102                                    }
1103    
1104                                    cacheResult(list);
1105    
1106                                    finderCache.putResult(finderPath, finderArgs, list);
1107                            }
1108                            catch (Exception e) {
1109                                    finderCache.removeResult(finderPath, finderArgs);
1110    
1111                                    throw processException(e);
1112                            }
1113                            finally {
1114                                    closeSession(session);
1115                            }
1116                    }
1117    
1118                    return list;
1119            }
1120    
1121            /**
1122             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1123             *
1124             * @param uuid the uuid
1125             * @param companyId the company ID
1126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1127             * @return the first matching message-boards message
1128             * @throws NoSuchMessageException if a matching message-boards message could not be found
1129             */
1130            @Override
1131            public MBMessage findByUuid_C_First(String uuid, long companyId,
1132                    OrderByComparator<MBMessage> orderByComparator)
1133                    throws NoSuchMessageException {
1134                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1135                                    orderByComparator);
1136    
1137                    if (mbMessage != null) {
1138                            return mbMessage;
1139                    }
1140    
1141                    StringBundler msg = new StringBundler(6);
1142    
1143                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1144    
1145                    msg.append("uuid=");
1146                    msg.append(uuid);
1147    
1148                    msg.append(", companyId=");
1149                    msg.append(companyId);
1150    
1151                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1152    
1153                    throw new NoSuchMessageException(msg.toString());
1154            }
1155    
1156            /**
1157             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1158             *
1159             * @param uuid the uuid
1160             * @param companyId the company ID
1161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1162             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1163             */
1164            @Override
1165            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1166                    OrderByComparator<MBMessage> orderByComparator) {
1167                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1168                                    orderByComparator);
1169    
1170                    if (!list.isEmpty()) {
1171                            return list.get(0);
1172                    }
1173    
1174                    return null;
1175            }
1176    
1177            /**
1178             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1179             *
1180             * @param uuid the uuid
1181             * @param companyId the company ID
1182             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1183             * @return the last matching message-boards message
1184             * @throws NoSuchMessageException if a matching message-boards message could not be found
1185             */
1186            @Override
1187            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1188                    OrderByComparator<MBMessage> orderByComparator)
1189                    throws NoSuchMessageException {
1190                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1191                                    orderByComparator);
1192    
1193                    if (mbMessage != null) {
1194                            return mbMessage;
1195                    }
1196    
1197                    StringBundler msg = new StringBundler(6);
1198    
1199                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1200    
1201                    msg.append("uuid=");
1202                    msg.append(uuid);
1203    
1204                    msg.append(", companyId=");
1205                    msg.append(companyId);
1206    
1207                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1208    
1209                    throw new NoSuchMessageException(msg.toString());
1210            }
1211    
1212            /**
1213             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1214             *
1215             * @param uuid the uuid
1216             * @param companyId the company ID
1217             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1218             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1219             */
1220            @Override
1221            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1222                    OrderByComparator<MBMessage> orderByComparator) {
1223                    int count = countByUuid_C(uuid, companyId);
1224    
1225                    if (count == 0) {
1226                            return null;
1227                    }
1228    
1229                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1230                                    orderByComparator);
1231    
1232                    if (!list.isEmpty()) {
1233                            return list.get(0);
1234                    }
1235    
1236                    return null;
1237            }
1238    
1239            /**
1240             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1241             *
1242             * @param messageId the primary key of the current message-boards message
1243             * @param uuid the uuid
1244             * @param companyId the company ID
1245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1246             * @return the previous, current, and next message-boards message
1247             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1248             */
1249            @Override
1250            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1251                    long companyId, OrderByComparator<MBMessage> orderByComparator)
1252                    throws NoSuchMessageException {
1253                    MBMessage mbMessage = findByPrimaryKey(messageId);
1254    
1255                    Session session = null;
1256    
1257                    try {
1258                            session = openSession();
1259    
1260                            MBMessage[] array = new MBMessageImpl[3];
1261    
1262                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1263                                            companyId, orderByComparator, true);
1264    
1265                            array[1] = mbMessage;
1266    
1267                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1268                                            companyId, orderByComparator, false);
1269    
1270                            return array;
1271                    }
1272                    catch (Exception e) {
1273                            throw processException(e);
1274                    }
1275                    finally {
1276                            closeSession(session);
1277                    }
1278            }
1279    
1280            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1281                    MBMessage mbMessage, String uuid, long companyId,
1282                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1283                    StringBundler query = null;
1284    
1285                    if (orderByComparator != null) {
1286                            query = new StringBundler(5 +
1287                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1288                                            (orderByComparator.getOrderByFields().length * 3));
1289                    }
1290                    else {
1291                            query = new StringBundler(4);
1292                    }
1293    
1294                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1295    
1296                    boolean bindUuid = false;
1297    
1298                    if (uuid == null) {
1299                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1300                    }
1301                    else if (uuid.equals(StringPool.BLANK)) {
1302                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1303                    }
1304                    else {
1305                            bindUuid = true;
1306    
1307                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1308                    }
1309    
1310                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1311    
1312                    if (orderByComparator != null) {
1313                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1314    
1315                            if (orderByConditionFields.length > 0) {
1316                                    query.append(WHERE_AND);
1317                            }
1318    
1319                            for (int i = 0; i < orderByConditionFields.length; i++) {
1320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1321                                    query.append(orderByConditionFields[i]);
1322    
1323                                    if ((i + 1) < orderByConditionFields.length) {
1324                                            if (orderByComparator.isAscending() ^ previous) {
1325                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1326                                            }
1327                                            else {
1328                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1329                                            }
1330                                    }
1331                                    else {
1332                                            if (orderByComparator.isAscending() ^ previous) {
1333                                                    query.append(WHERE_GREATER_THAN);
1334                                            }
1335                                            else {
1336                                                    query.append(WHERE_LESSER_THAN);
1337                                            }
1338                                    }
1339                            }
1340    
1341                            query.append(ORDER_BY_CLAUSE);
1342    
1343                            String[] orderByFields = orderByComparator.getOrderByFields();
1344    
1345                            for (int i = 0; i < orderByFields.length; i++) {
1346                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1347                                    query.append(orderByFields[i]);
1348    
1349                                    if ((i + 1) < orderByFields.length) {
1350                                            if (orderByComparator.isAscending() ^ previous) {
1351                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1352                                            }
1353                                            else {
1354                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1355                                            }
1356                                    }
1357                                    else {
1358                                            if (orderByComparator.isAscending() ^ previous) {
1359                                                    query.append(ORDER_BY_ASC);
1360                                            }
1361                                            else {
1362                                                    query.append(ORDER_BY_DESC);
1363                                            }
1364                                    }
1365                            }
1366                    }
1367                    else {
1368                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1369                    }
1370    
1371                    String sql = query.toString();
1372    
1373                    Query q = session.createQuery(sql);
1374    
1375                    q.setFirstResult(0);
1376                    q.setMaxResults(2);
1377    
1378                    QueryPos qPos = QueryPos.getInstance(q);
1379    
1380                    if (bindUuid) {
1381                            qPos.add(uuid);
1382                    }
1383    
1384                    qPos.add(companyId);
1385    
1386                    if (orderByComparator != null) {
1387                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1388    
1389                            for (Object value : values) {
1390                                    qPos.add(value);
1391                            }
1392                    }
1393    
1394                    List<MBMessage> list = q.list();
1395    
1396                    if (list.size() == 2) {
1397                            return list.get(1);
1398                    }
1399                    else {
1400                            return null;
1401                    }
1402            }
1403    
1404            /**
1405             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1406             *
1407             * @param uuid the uuid
1408             * @param companyId the company ID
1409             */
1410            @Override
1411            public void removeByUuid_C(String uuid, long companyId) {
1412                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1413                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1414                            remove(mbMessage);
1415                    }
1416            }
1417    
1418            /**
1419             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1420             *
1421             * @param uuid the uuid
1422             * @param companyId the company ID
1423             * @return the number of matching message-boards messages
1424             */
1425            @Override
1426            public int countByUuid_C(String uuid, long companyId) {
1427                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1428    
1429                    Object[] finderArgs = new Object[] { uuid, companyId };
1430    
1431                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1432    
1433                    if (count == null) {
1434                            StringBundler query = new StringBundler(3);
1435    
1436                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1437    
1438                            boolean bindUuid = false;
1439    
1440                            if (uuid == null) {
1441                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1442                            }
1443                            else if (uuid.equals(StringPool.BLANK)) {
1444                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1445                            }
1446                            else {
1447                                    bindUuid = true;
1448    
1449                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1450                            }
1451    
1452                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1453    
1454                            String sql = query.toString();
1455    
1456                            Session session = null;
1457    
1458                            try {
1459                                    session = openSession();
1460    
1461                                    Query q = session.createQuery(sql);
1462    
1463                                    QueryPos qPos = QueryPos.getInstance(q);
1464    
1465                                    if (bindUuid) {
1466                                            qPos.add(uuid);
1467                                    }
1468    
1469                                    qPos.add(companyId);
1470    
1471                                    count = (Long)q.uniqueResult();
1472    
1473                                    finderCache.putResult(finderPath, finderArgs, count);
1474                            }
1475                            catch (Exception e) {
1476                                    finderCache.removeResult(finderPath, finderArgs);
1477    
1478                                    throw processException(e);
1479                            }
1480                            finally {
1481                                    closeSession(session);
1482                            }
1483                    }
1484    
1485                    return count.intValue();
1486            }
1487    
1488            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1489            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1490            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1491            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1492            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1493                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1494                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1495                            new String[] {
1496                                    Long.class.getName(),
1497                                    
1498                            Integer.class.getName(), Integer.class.getName(),
1499                                    OrderByComparator.class.getName()
1500                            });
1501            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1502                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1503                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1504                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1505                            new String[] { Long.class.getName() },
1506                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1507                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1508            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1509                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1510                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1511                            new String[] { Long.class.getName() });
1512    
1513            /**
1514             * Returns all the message-boards messages where groupId = &#63;.
1515             *
1516             * @param groupId the group ID
1517             * @return the matching message-boards messages
1518             */
1519            @Override
1520            public List<MBMessage> findByGroupId(long groupId) {
1521                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1522            }
1523    
1524            /**
1525             * Returns a range of all the message-boards messages where groupId = &#63;.
1526             *
1527             * <p>
1528             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1529             * </p>
1530             *
1531             * @param groupId the group ID
1532             * @param start the lower bound of the range of message-boards messages
1533             * @param end the upper bound of the range of message-boards messages (not inclusive)
1534             * @return the range of matching message-boards messages
1535             */
1536            @Override
1537            public List<MBMessage> findByGroupId(long groupId, int start, int end) {
1538                    return findByGroupId(groupId, start, end, null);
1539            }
1540    
1541            /**
1542             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1543             *
1544             * <p>
1545             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1546             * </p>
1547             *
1548             * @param groupId the group ID
1549             * @param start the lower bound of the range of message-boards messages
1550             * @param end the upper bound of the range of message-boards messages (not inclusive)
1551             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1552             * @return the ordered range of matching message-boards messages
1553             */
1554            @Override
1555            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1556                    OrderByComparator<MBMessage> orderByComparator) {
1557                    return findByGroupId(groupId, start, end, orderByComparator, true);
1558            }
1559    
1560            /**
1561             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1562             *
1563             * <p>
1564             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1565             * </p>
1566             *
1567             * @param groupId the group ID
1568             * @param start the lower bound of the range of message-boards messages
1569             * @param end the upper bound of the range of message-boards messages (not inclusive)
1570             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1571             * @param retrieveFromCache whether to retrieve from the finder cache
1572             * @return the ordered range of matching message-boards messages
1573             */
1574            @Override
1575            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1576                    OrderByComparator<MBMessage> orderByComparator,
1577                    boolean retrieveFromCache) {
1578                    boolean pagination = true;
1579                    FinderPath finderPath = null;
1580                    Object[] finderArgs = null;
1581    
1582                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1583                                    (orderByComparator == null)) {
1584                            pagination = false;
1585                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1586                            finderArgs = new Object[] { groupId };
1587                    }
1588                    else {
1589                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1590                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1591                    }
1592    
1593                    List<MBMessage> list = null;
1594    
1595                    if (retrieveFromCache) {
1596                            list = (List<MBMessage>)finderCache.getResult(finderPath,
1597                                            finderArgs, this);
1598    
1599                            if ((list != null) && !list.isEmpty()) {
1600                                    for (MBMessage mbMessage : list) {
1601                                            if ((groupId != mbMessage.getGroupId())) {
1602                                                    list = null;
1603    
1604                                                    break;
1605                                            }
1606                                    }
1607                            }
1608                    }
1609    
1610                    if (list == null) {
1611                            StringBundler query = null;
1612    
1613                            if (orderByComparator != null) {
1614                                    query = new StringBundler(3 +
1615                                                    (orderByComparator.getOrderByFields().length * 2));
1616                            }
1617                            else {
1618                                    query = new StringBundler(3);
1619                            }
1620    
1621                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1622    
1623                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1624    
1625                            if (orderByComparator != null) {
1626                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1627                                            orderByComparator);
1628                            }
1629                            else
1630                             if (pagination) {
1631                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1632                            }
1633    
1634                            String sql = query.toString();
1635    
1636                            Session session = null;
1637    
1638                            try {
1639                                    session = openSession();
1640    
1641                                    Query q = session.createQuery(sql);
1642    
1643                                    QueryPos qPos = QueryPos.getInstance(q);
1644    
1645                                    qPos.add(groupId);
1646    
1647                                    if (!pagination) {
1648                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1649                                                            start, end, false);
1650    
1651                                            Collections.sort(list);
1652    
1653                                            list = Collections.unmodifiableList(list);
1654                                    }
1655                                    else {
1656                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1657                                                            start, end);
1658                                    }
1659    
1660                                    cacheResult(list);
1661    
1662                                    finderCache.putResult(finderPath, finderArgs, list);
1663                            }
1664                            catch (Exception e) {
1665                                    finderCache.removeResult(finderPath, finderArgs);
1666    
1667                                    throw processException(e);
1668                            }
1669                            finally {
1670                                    closeSession(session);
1671                            }
1672                    }
1673    
1674                    return list;
1675            }
1676    
1677            /**
1678             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1679             *
1680             * @param groupId the group ID
1681             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1682             * @return the first matching message-boards message
1683             * @throws NoSuchMessageException if a matching message-boards message could not be found
1684             */
1685            @Override
1686            public MBMessage findByGroupId_First(long groupId,
1687                    OrderByComparator<MBMessage> orderByComparator)
1688                    throws NoSuchMessageException {
1689                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1690    
1691                    if (mbMessage != null) {
1692                            return mbMessage;
1693                    }
1694    
1695                    StringBundler msg = new StringBundler(4);
1696    
1697                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1698    
1699                    msg.append("groupId=");
1700                    msg.append(groupId);
1701    
1702                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1703    
1704                    throw new NoSuchMessageException(msg.toString());
1705            }
1706    
1707            /**
1708             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1709             *
1710             * @param groupId the group ID
1711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1712             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1713             */
1714            @Override
1715            public MBMessage fetchByGroupId_First(long groupId,
1716                    OrderByComparator<MBMessage> orderByComparator) {
1717                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1718    
1719                    if (!list.isEmpty()) {
1720                            return list.get(0);
1721                    }
1722    
1723                    return null;
1724            }
1725    
1726            /**
1727             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1728             *
1729             * @param groupId the group ID
1730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1731             * @return the last matching message-boards message
1732             * @throws NoSuchMessageException if a matching message-boards message could not be found
1733             */
1734            @Override
1735            public MBMessage findByGroupId_Last(long groupId,
1736                    OrderByComparator<MBMessage> orderByComparator)
1737                    throws NoSuchMessageException {
1738                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1739    
1740                    if (mbMessage != null) {
1741                            return mbMessage;
1742                    }
1743    
1744                    StringBundler msg = new StringBundler(4);
1745    
1746                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1747    
1748                    msg.append("groupId=");
1749                    msg.append(groupId);
1750    
1751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1752    
1753                    throw new NoSuchMessageException(msg.toString());
1754            }
1755    
1756            /**
1757             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1758             *
1759             * @param groupId the group ID
1760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1761             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1762             */
1763            @Override
1764            public MBMessage fetchByGroupId_Last(long groupId,
1765                    OrderByComparator<MBMessage> orderByComparator) {
1766                    int count = countByGroupId(groupId);
1767    
1768                    if (count == 0) {
1769                            return null;
1770                    }
1771    
1772                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1773                                    orderByComparator);
1774    
1775                    if (!list.isEmpty()) {
1776                            return list.get(0);
1777                    }
1778    
1779                    return null;
1780            }
1781    
1782            /**
1783             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1784             *
1785             * @param messageId the primary key of the current message-boards message
1786             * @param groupId the group ID
1787             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1788             * @return the previous, current, and next message-boards message
1789             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
1790             */
1791            @Override
1792            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1793                    OrderByComparator<MBMessage> orderByComparator)
1794                    throws NoSuchMessageException {
1795                    MBMessage mbMessage = findByPrimaryKey(messageId);
1796    
1797                    Session session = null;
1798    
1799                    try {
1800                            session = openSession();
1801    
1802                            MBMessage[] array = new MBMessageImpl[3];
1803    
1804                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1805                                            orderByComparator, true);
1806    
1807                            array[1] = mbMessage;
1808    
1809                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1810                                            orderByComparator, false);
1811    
1812                            return array;
1813                    }
1814                    catch (Exception e) {
1815                            throw processException(e);
1816                    }
1817                    finally {
1818                            closeSession(session);
1819                    }
1820            }
1821    
1822            protected MBMessage getByGroupId_PrevAndNext(Session session,
1823                    MBMessage mbMessage, long groupId,
1824                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
1825                    StringBundler query = null;
1826    
1827                    if (orderByComparator != null) {
1828                            query = new StringBundler(4 +
1829                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1830                                            (orderByComparator.getOrderByFields().length * 3));
1831                    }
1832                    else {
1833                            query = new StringBundler(3);
1834                    }
1835    
1836                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1837    
1838                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1839    
1840                    if (orderByComparator != null) {
1841                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1842    
1843                            if (orderByConditionFields.length > 0) {
1844                                    query.append(WHERE_AND);
1845                            }
1846    
1847                            for (int i = 0; i < orderByConditionFields.length; i++) {
1848                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1849                                    query.append(orderByConditionFields[i]);
1850    
1851                                    if ((i + 1) < orderByConditionFields.length) {
1852                                            if (orderByComparator.isAscending() ^ previous) {
1853                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1854                                            }
1855                                            else {
1856                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1857                                            }
1858                                    }
1859                                    else {
1860                                            if (orderByComparator.isAscending() ^ previous) {
1861                                                    query.append(WHERE_GREATER_THAN);
1862                                            }
1863                                            else {
1864                                                    query.append(WHERE_LESSER_THAN);
1865                                            }
1866                                    }
1867                            }
1868    
1869                            query.append(ORDER_BY_CLAUSE);
1870    
1871                            String[] orderByFields = orderByComparator.getOrderByFields();
1872    
1873                            for (int i = 0; i < orderByFields.length; i++) {
1874                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1875                                    query.append(orderByFields[i]);
1876    
1877                                    if ((i + 1) < orderByFields.length) {
1878                                            if (orderByComparator.isAscending() ^ previous) {
1879                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1880                                            }
1881                                            else {
1882                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1883                                            }
1884                                    }
1885                                    else {
1886                                            if (orderByComparator.isAscending() ^ previous) {
1887                                                    query.append(ORDER_BY_ASC);
1888                                            }
1889                                            else {
1890                                                    query.append(ORDER_BY_DESC);
1891                                            }
1892                                    }
1893                            }
1894                    }
1895                    else {
1896                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1897                    }
1898    
1899                    String sql = query.toString();
1900    
1901                    Query q = session.createQuery(sql);
1902    
1903                    q.setFirstResult(0);
1904                    q.setMaxResults(2);
1905    
1906                    QueryPos qPos = QueryPos.getInstance(q);
1907    
1908                    qPos.add(groupId);
1909    
1910                    if (orderByComparator != null) {
1911                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1912    
1913                            for (Object value : values) {
1914                                    qPos.add(value);
1915                            }
1916                    }
1917    
1918                    List<MBMessage> list = q.list();
1919    
1920                    if (list.size() == 2) {
1921                            return list.get(1);
1922                    }
1923                    else {
1924                            return null;
1925                    }
1926            }
1927    
1928            /**
1929             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1930             *
1931             * @param groupId the group ID
1932             * @return the matching message-boards messages that the user has permission to view
1933             */
1934            @Override
1935            public List<MBMessage> filterFindByGroupId(long groupId) {
1936                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1937                            QueryUtil.ALL_POS, null);
1938            }
1939    
1940            /**
1941             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1942             *
1943             * <p>
1944             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1945             * </p>
1946             *
1947             * @param groupId the group ID
1948             * @param start the lower bound of the range of message-boards messages
1949             * @param end the upper bound of the range of message-boards messages (not inclusive)
1950             * @return the range of matching message-boards messages that the user has permission to view
1951             */
1952            @Override
1953            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end) {
1954                    return filterFindByGroupId(groupId, start, end, null);
1955            }
1956    
1957            /**
1958             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1959             *
1960             * <p>
1961             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1962             * </p>
1963             *
1964             * @param groupId the group ID
1965             * @param start the lower bound of the range of message-boards messages
1966             * @param end the upper bound of the range of message-boards messages (not inclusive)
1967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1968             * @return the ordered range of matching message-boards messages that the user has permission to view
1969             */
1970            @Override
1971            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1972                    int end, OrderByComparator<MBMessage> orderByComparator) {
1973                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1974                            return findByGroupId(groupId, start, end, orderByComparator);
1975                    }
1976    
1977                    StringBundler query = null;
1978    
1979                    if (orderByComparator != null) {
1980                            query = new StringBundler(3 +
1981                                            (orderByComparator.getOrderByFields().length * 2));
1982                    }
1983                    else {
1984                            query = new StringBundler(4);
1985                    }
1986    
1987                    if (getDB().isSupportsInlineDistinct()) {
1988                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1989                    }
1990                    else {
1991                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1992                    }
1993    
1994                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1995    
1996                    if (!getDB().isSupportsInlineDistinct()) {
1997                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1998                    }
1999    
2000                    if (orderByComparator != null) {
2001                            if (getDB().isSupportsInlineDistinct()) {
2002                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2003                                            orderByComparator, true);
2004                            }
2005                            else {
2006                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2007                                            orderByComparator, true);
2008                            }
2009                    }
2010                    else {
2011                            if (getDB().isSupportsInlineDistinct()) {
2012                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2013                            }
2014                            else {
2015                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2016                            }
2017                    }
2018    
2019                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2020                                    MBMessage.class.getName(),
2021                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2022    
2023                    Session session = null;
2024    
2025                    try {
2026                            session = openSession();
2027    
2028                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2029    
2030                            if (getDB().isSupportsInlineDistinct()) {
2031                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2032                            }
2033                            else {
2034                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2035                            }
2036    
2037                            QueryPos qPos = QueryPos.getInstance(q);
2038    
2039                            qPos.add(groupId);
2040    
2041                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2042                    }
2043                    catch (Exception e) {
2044                            throw processException(e);
2045                    }
2046                    finally {
2047                            closeSession(session);
2048                    }
2049            }
2050    
2051            /**
2052             * 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;.
2053             *
2054             * @param messageId the primary key of the current message-boards message
2055             * @param groupId the group ID
2056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2057             * @return the previous, current, and next message-boards message
2058             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2059             */
2060            @Override
2061            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2062                    long groupId, OrderByComparator<MBMessage> orderByComparator)
2063                    throws NoSuchMessageException {
2064                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2065                            return findByGroupId_PrevAndNext(messageId, groupId,
2066                                    orderByComparator);
2067                    }
2068    
2069                    MBMessage mbMessage = findByPrimaryKey(messageId);
2070    
2071                    Session session = null;
2072    
2073                    try {
2074                            session = openSession();
2075    
2076                            MBMessage[] array = new MBMessageImpl[3];
2077    
2078                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2079                                            groupId, orderByComparator, true);
2080    
2081                            array[1] = mbMessage;
2082    
2083                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2084                                            groupId, orderByComparator, false);
2085    
2086                            return array;
2087                    }
2088                    catch (Exception e) {
2089                            throw processException(e);
2090                    }
2091                    finally {
2092                            closeSession(session);
2093                    }
2094            }
2095    
2096            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2097                    MBMessage mbMessage, long groupId,
2098                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2099                    StringBundler query = null;
2100    
2101                    if (orderByComparator != null) {
2102                            query = new StringBundler(5 +
2103                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2104                                            (orderByComparator.getOrderByFields().length * 3));
2105                    }
2106                    else {
2107                            query = new StringBundler(4);
2108                    }
2109    
2110                    if (getDB().isSupportsInlineDistinct()) {
2111                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2112                    }
2113                    else {
2114                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2115                    }
2116    
2117                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2118    
2119                    if (!getDB().isSupportsInlineDistinct()) {
2120                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2121                    }
2122    
2123                    if (orderByComparator != null) {
2124                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2125    
2126                            if (orderByConditionFields.length > 0) {
2127                                    query.append(WHERE_AND);
2128                            }
2129    
2130                            for (int i = 0; i < orderByConditionFields.length; i++) {
2131                                    if (getDB().isSupportsInlineDistinct()) {
2132                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2133                                    }
2134                                    else {
2135                                            query.append(_ORDER_BY_ENTITY_TABLE);
2136                                    }
2137    
2138                                    query.append(orderByConditionFields[i]);
2139    
2140                                    if ((i + 1) < orderByConditionFields.length) {
2141                                            if (orderByComparator.isAscending() ^ previous) {
2142                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2143                                            }
2144                                            else {
2145                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2146                                            }
2147                                    }
2148                                    else {
2149                                            if (orderByComparator.isAscending() ^ previous) {
2150                                                    query.append(WHERE_GREATER_THAN);
2151                                            }
2152                                            else {
2153                                                    query.append(WHERE_LESSER_THAN);
2154                                            }
2155                                    }
2156                            }
2157    
2158                            query.append(ORDER_BY_CLAUSE);
2159    
2160                            String[] orderByFields = orderByComparator.getOrderByFields();
2161    
2162                            for (int i = 0; i < orderByFields.length; i++) {
2163                                    if (getDB().isSupportsInlineDistinct()) {
2164                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2165                                    }
2166                                    else {
2167                                            query.append(_ORDER_BY_ENTITY_TABLE);
2168                                    }
2169    
2170                                    query.append(orderByFields[i]);
2171    
2172                                    if ((i + 1) < orderByFields.length) {
2173                                            if (orderByComparator.isAscending() ^ previous) {
2174                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2175                                            }
2176                                            else {
2177                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2178                                            }
2179                                    }
2180                                    else {
2181                                            if (orderByComparator.isAscending() ^ previous) {
2182                                                    query.append(ORDER_BY_ASC);
2183                                            }
2184                                            else {
2185                                                    query.append(ORDER_BY_DESC);
2186                                            }
2187                                    }
2188                            }
2189                    }
2190                    else {
2191                            if (getDB().isSupportsInlineDistinct()) {
2192                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2193                            }
2194                            else {
2195                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2196                            }
2197                    }
2198    
2199                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2200                                    MBMessage.class.getName(),
2201                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2202    
2203                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2204    
2205                    q.setFirstResult(0);
2206                    q.setMaxResults(2);
2207    
2208                    if (getDB().isSupportsInlineDistinct()) {
2209                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2210                    }
2211                    else {
2212                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2213                    }
2214    
2215                    QueryPos qPos = QueryPos.getInstance(q);
2216    
2217                    qPos.add(groupId);
2218    
2219                    if (orderByComparator != null) {
2220                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2221    
2222                            for (Object value : values) {
2223                                    qPos.add(value);
2224                            }
2225                    }
2226    
2227                    List<MBMessage> list = q.list();
2228    
2229                    if (list.size() == 2) {
2230                            return list.get(1);
2231                    }
2232                    else {
2233                            return null;
2234                    }
2235            }
2236    
2237            /**
2238             * Removes all the message-boards messages where groupId = &#63; from the database.
2239             *
2240             * @param groupId the group ID
2241             */
2242            @Override
2243            public void removeByGroupId(long groupId) {
2244                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2245                                    QueryUtil.ALL_POS, null)) {
2246                            remove(mbMessage);
2247                    }
2248            }
2249    
2250            /**
2251             * Returns the number of message-boards messages where groupId = &#63;.
2252             *
2253             * @param groupId the group ID
2254             * @return the number of matching message-boards messages
2255             */
2256            @Override
2257            public int countByGroupId(long groupId) {
2258                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2259    
2260                    Object[] finderArgs = new Object[] { groupId };
2261    
2262                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2263    
2264                    if (count == null) {
2265                            StringBundler query = new StringBundler(2);
2266    
2267                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2268    
2269                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2270    
2271                            String sql = query.toString();
2272    
2273                            Session session = null;
2274    
2275                            try {
2276                                    session = openSession();
2277    
2278                                    Query q = session.createQuery(sql);
2279    
2280                                    QueryPos qPos = QueryPos.getInstance(q);
2281    
2282                                    qPos.add(groupId);
2283    
2284                                    count = (Long)q.uniqueResult();
2285    
2286                                    finderCache.putResult(finderPath, finderArgs, count);
2287                            }
2288                            catch (Exception e) {
2289                                    finderCache.removeResult(finderPath, finderArgs);
2290    
2291                                    throw processException(e);
2292                            }
2293                            finally {
2294                                    closeSession(session);
2295                            }
2296                    }
2297    
2298                    return count.intValue();
2299            }
2300    
2301            /**
2302             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2303             *
2304             * @param groupId the group ID
2305             * @return the number of matching message-boards messages that the user has permission to view
2306             */
2307            @Override
2308            public int filterCountByGroupId(long groupId) {
2309                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2310                            return countByGroupId(groupId);
2311                    }
2312    
2313                    StringBundler query = new StringBundler(2);
2314    
2315                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2316    
2317                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2318    
2319                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2320                                    MBMessage.class.getName(),
2321                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2322    
2323                    Session session = null;
2324    
2325                    try {
2326                            session = openSession();
2327    
2328                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2329    
2330                            q.addScalar(COUNT_COLUMN_NAME,
2331                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2332    
2333                            QueryPos qPos = QueryPos.getInstance(q);
2334    
2335                            qPos.add(groupId);
2336    
2337                            Long count = (Long)q.uniqueResult();
2338    
2339                            return count.intValue();
2340                    }
2341                    catch (Exception e) {
2342                            throw processException(e);
2343                    }
2344                    finally {
2345                            closeSession(session);
2346                    }
2347            }
2348    
2349            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2350            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2351                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2352                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2353                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2354                            new String[] {
2355                                    Long.class.getName(),
2356                                    
2357                            Integer.class.getName(), Integer.class.getName(),
2358                                    OrderByComparator.class.getName()
2359                            });
2360            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2361                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2362                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2363                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2364                            new String[] { Long.class.getName() },
2365                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2366                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2367            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2368                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2369                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2370                            new String[] { Long.class.getName() });
2371    
2372            /**
2373             * Returns all the message-boards messages where companyId = &#63;.
2374             *
2375             * @param companyId the company ID
2376             * @return the matching message-boards messages
2377             */
2378            @Override
2379            public List<MBMessage> findByCompanyId(long companyId) {
2380                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2381                            null);
2382            }
2383    
2384            /**
2385             * Returns a range of all the message-boards messages where companyId = &#63;.
2386             *
2387             * <p>
2388             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2389             * </p>
2390             *
2391             * @param companyId the company ID
2392             * @param start the lower bound of the range of message-boards messages
2393             * @param end the upper bound of the range of message-boards messages (not inclusive)
2394             * @return the range of matching message-boards messages
2395             */
2396            @Override
2397            public List<MBMessage> findByCompanyId(long companyId, int start, int end) {
2398                    return findByCompanyId(companyId, start, end, null);
2399            }
2400    
2401            /**
2402             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2403             *
2404             * <p>
2405             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2406             * </p>
2407             *
2408             * @param companyId the company ID
2409             * @param start the lower bound of the range of message-boards messages
2410             * @param end the upper bound of the range of message-boards messages (not inclusive)
2411             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2412             * @return the ordered range of matching message-boards messages
2413             */
2414            @Override
2415            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2416                    OrderByComparator<MBMessage> orderByComparator) {
2417                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2418            }
2419    
2420            /**
2421             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2422             *
2423             * <p>
2424             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2425             * </p>
2426             *
2427             * @param companyId the company ID
2428             * @param start the lower bound of the range of message-boards messages
2429             * @param end the upper bound of the range of message-boards messages (not inclusive)
2430             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2431             * @param retrieveFromCache whether to retrieve from the finder cache
2432             * @return the ordered range of matching message-boards messages
2433             */
2434            @Override
2435            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2436                    OrderByComparator<MBMessage> orderByComparator,
2437                    boolean retrieveFromCache) {
2438                    boolean pagination = true;
2439                    FinderPath finderPath = null;
2440                    Object[] finderArgs = null;
2441    
2442                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2443                                    (orderByComparator == null)) {
2444                            pagination = false;
2445                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2446                            finderArgs = new Object[] { companyId };
2447                    }
2448                    else {
2449                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2450                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2451                    }
2452    
2453                    List<MBMessage> list = null;
2454    
2455                    if (retrieveFromCache) {
2456                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2457                                            finderArgs, this);
2458    
2459                            if ((list != null) && !list.isEmpty()) {
2460                                    for (MBMessage mbMessage : list) {
2461                                            if ((companyId != mbMessage.getCompanyId())) {
2462                                                    list = null;
2463    
2464                                                    break;
2465                                            }
2466                                    }
2467                            }
2468                    }
2469    
2470                    if (list == null) {
2471                            StringBundler query = null;
2472    
2473                            if (orderByComparator != null) {
2474                                    query = new StringBundler(3 +
2475                                                    (orderByComparator.getOrderByFields().length * 2));
2476                            }
2477                            else {
2478                                    query = new StringBundler(3);
2479                            }
2480    
2481                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2482    
2483                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2484    
2485                            if (orderByComparator != null) {
2486                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2487                                            orderByComparator);
2488                            }
2489                            else
2490                             if (pagination) {
2491                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2492                            }
2493    
2494                            String sql = query.toString();
2495    
2496                            Session session = null;
2497    
2498                            try {
2499                                    session = openSession();
2500    
2501                                    Query q = session.createQuery(sql);
2502    
2503                                    QueryPos qPos = QueryPos.getInstance(q);
2504    
2505                                    qPos.add(companyId);
2506    
2507                                    if (!pagination) {
2508                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2509                                                            start, end, false);
2510    
2511                                            Collections.sort(list);
2512    
2513                                            list = Collections.unmodifiableList(list);
2514                                    }
2515                                    else {
2516                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2517                                                            start, end);
2518                                    }
2519    
2520                                    cacheResult(list);
2521    
2522                                    finderCache.putResult(finderPath, finderArgs, list);
2523                            }
2524                            catch (Exception e) {
2525                                    finderCache.removeResult(finderPath, finderArgs);
2526    
2527                                    throw processException(e);
2528                            }
2529                            finally {
2530                                    closeSession(session);
2531                            }
2532                    }
2533    
2534                    return list;
2535            }
2536    
2537            /**
2538             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2539             *
2540             * @param companyId the company ID
2541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2542             * @return the first matching message-boards message
2543             * @throws NoSuchMessageException if a matching message-boards message could not be found
2544             */
2545            @Override
2546            public MBMessage findByCompanyId_First(long companyId,
2547                    OrderByComparator<MBMessage> orderByComparator)
2548                    throws NoSuchMessageException {
2549                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2550                                    orderByComparator);
2551    
2552                    if (mbMessage != null) {
2553                            return mbMessage;
2554                    }
2555    
2556                    StringBundler msg = new StringBundler(4);
2557    
2558                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2559    
2560                    msg.append("companyId=");
2561                    msg.append(companyId);
2562    
2563                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2564    
2565                    throw new NoSuchMessageException(msg.toString());
2566            }
2567    
2568            /**
2569             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2570             *
2571             * @param companyId the company ID
2572             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2573             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2574             */
2575            @Override
2576            public MBMessage fetchByCompanyId_First(long companyId,
2577                    OrderByComparator<MBMessage> orderByComparator) {
2578                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2579                                    orderByComparator);
2580    
2581                    if (!list.isEmpty()) {
2582                            return list.get(0);
2583                    }
2584    
2585                    return null;
2586            }
2587    
2588            /**
2589             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2590             *
2591             * @param companyId the company ID
2592             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2593             * @return the last matching message-boards message
2594             * @throws NoSuchMessageException if a matching message-boards message could not be found
2595             */
2596            @Override
2597            public MBMessage findByCompanyId_Last(long companyId,
2598                    OrderByComparator<MBMessage> orderByComparator)
2599                    throws NoSuchMessageException {
2600                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2601    
2602                    if (mbMessage != null) {
2603                            return mbMessage;
2604                    }
2605    
2606                    StringBundler msg = new StringBundler(4);
2607    
2608                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2609    
2610                    msg.append("companyId=");
2611                    msg.append(companyId);
2612    
2613                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2614    
2615                    throw new NoSuchMessageException(msg.toString());
2616            }
2617    
2618            /**
2619             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2620             *
2621             * @param companyId the company ID
2622             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2623             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2624             */
2625            @Override
2626            public MBMessage fetchByCompanyId_Last(long companyId,
2627                    OrderByComparator<MBMessage> orderByComparator) {
2628                    int count = countByCompanyId(companyId);
2629    
2630                    if (count == 0) {
2631                            return null;
2632                    }
2633    
2634                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2635                                    orderByComparator);
2636    
2637                    if (!list.isEmpty()) {
2638                            return list.get(0);
2639                    }
2640    
2641                    return null;
2642            }
2643    
2644            /**
2645             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2646             *
2647             * @param messageId the primary key of the current message-boards message
2648             * @param companyId the company ID
2649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2650             * @return the previous, current, and next message-boards message
2651             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
2652             */
2653            @Override
2654            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2655                    long companyId, OrderByComparator<MBMessage> orderByComparator)
2656                    throws NoSuchMessageException {
2657                    MBMessage mbMessage = findByPrimaryKey(messageId);
2658    
2659                    Session session = null;
2660    
2661                    try {
2662                            session = openSession();
2663    
2664                            MBMessage[] array = new MBMessageImpl[3];
2665    
2666                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2667                                            companyId, orderByComparator, true);
2668    
2669                            array[1] = mbMessage;
2670    
2671                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2672                                            companyId, orderByComparator, false);
2673    
2674                            return array;
2675                    }
2676                    catch (Exception e) {
2677                            throw processException(e);
2678                    }
2679                    finally {
2680                            closeSession(session);
2681                    }
2682            }
2683    
2684            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2685                    MBMessage mbMessage, long companyId,
2686                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
2687                    StringBundler query = null;
2688    
2689                    if (orderByComparator != null) {
2690                            query = new StringBundler(4 +
2691                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2692                                            (orderByComparator.getOrderByFields().length * 3));
2693                    }
2694                    else {
2695                            query = new StringBundler(3);
2696                    }
2697    
2698                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2699    
2700                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2701    
2702                    if (orderByComparator != null) {
2703                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2704    
2705                            if (orderByConditionFields.length > 0) {
2706                                    query.append(WHERE_AND);
2707                            }
2708    
2709                            for (int i = 0; i < orderByConditionFields.length; i++) {
2710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2711                                    query.append(orderByConditionFields[i]);
2712    
2713                                    if ((i + 1) < orderByConditionFields.length) {
2714                                            if (orderByComparator.isAscending() ^ previous) {
2715                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2716                                            }
2717                                            else {
2718                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2719                                            }
2720                                    }
2721                                    else {
2722                                            if (orderByComparator.isAscending() ^ previous) {
2723                                                    query.append(WHERE_GREATER_THAN);
2724                                            }
2725                                            else {
2726                                                    query.append(WHERE_LESSER_THAN);
2727                                            }
2728                                    }
2729                            }
2730    
2731                            query.append(ORDER_BY_CLAUSE);
2732    
2733                            String[] orderByFields = orderByComparator.getOrderByFields();
2734    
2735                            for (int i = 0; i < orderByFields.length; i++) {
2736                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2737                                    query.append(orderByFields[i]);
2738    
2739                                    if ((i + 1) < orderByFields.length) {
2740                                            if (orderByComparator.isAscending() ^ previous) {
2741                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2742                                            }
2743                                            else {
2744                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2745                                            }
2746                                    }
2747                                    else {
2748                                            if (orderByComparator.isAscending() ^ previous) {
2749                                                    query.append(ORDER_BY_ASC);
2750                                            }
2751                                            else {
2752                                                    query.append(ORDER_BY_DESC);
2753                                            }
2754                                    }
2755                            }
2756                    }
2757                    else {
2758                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2759                    }
2760    
2761                    String sql = query.toString();
2762    
2763                    Query q = session.createQuery(sql);
2764    
2765                    q.setFirstResult(0);
2766                    q.setMaxResults(2);
2767    
2768                    QueryPos qPos = QueryPos.getInstance(q);
2769    
2770                    qPos.add(companyId);
2771    
2772                    if (orderByComparator != null) {
2773                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2774    
2775                            for (Object value : values) {
2776                                    qPos.add(value);
2777                            }
2778                    }
2779    
2780                    List<MBMessage> list = q.list();
2781    
2782                    if (list.size() == 2) {
2783                            return list.get(1);
2784                    }
2785                    else {
2786                            return null;
2787                    }
2788            }
2789    
2790            /**
2791             * Removes all the message-boards messages where companyId = &#63; from the database.
2792             *
2793             * @param companyId the company ID
2794             */
2795            @Override
2796            public void removeByCompanyId(long companyId) {
2797                    for (MBMessage mbMessage : findByCompanyId(companyId,
2798                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2799                            remove(mbMessage);
2800                    }
2801            }
2802    
2803            /**
2804             * Returns the number of message-boards messages where companyId = &#63;.
2805             *
2806             * @param companyId the company ID
2807             * @return the number of matching message-boards messages
2808             */
2809            @Override
2810            public int countByCompanyId(long companyId) {
2811                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2812    
2813                    Object[] finderArgs = new Object[] { companyId };
2814    
2815                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2816    
2817                    if (count == null) {
2818                            StringBundler query = new StringBundler(2);
2819    
2820                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2821    
2822                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2823    
2824                            String sql = query.toString();
2825    
2826                            Session session = null;
2827    
2828                            try {
2829                                    session = openSession();
2830    
2831                                    Query q = session.createQuery(sql);
2832    
2833                                    QueryPos qPos = QueryPos.getInstance(q);
2834    
2835                                    qPos.add(companyId);
2836    
2837                                    count = (Long)q.uniqueResult();
2838    
2839                                    finderCache.putResult(finderPath, finderArgs, count);
2840                            }
2841                            catch (Exception e) {
2842                                    finderCache.removeResult(finderPath, finderArgs);
2843    
2844                                    throw processException(e);
2845                            }
2846                            finally {
2847                                    closeSession(session);
2848                            }
2849                    }
2850    
2851                    return count.intValue();
2852            }
2853    
2854            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2855            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2856                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2857                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
2858                            new String[] {
2859                                    Long.class.getName(),
2860                                    
2861                            Integer.class.getName(), Integer.class.getName(),
2862                                    OrderByComparator.class.getName()
2863                            });
2864            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2865                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2866                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2867                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
2868                            new String[] { Long.class.getName() },
2869                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
2870                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2871            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2872                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2873                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2874                            new String[] { Long.class.getName() });
2875    
2876            /**
2877             * Returns all the message-boards messages where userId = &#63;.
2878             *
2879             * @param userId the user ID
2880             * @return the matching message-boards messages
2881             */
2882            @Override
2883            public List<MBMessage> findByUserId(long userId) {
2884                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2885            }
2886    
2887            /**
2888             * Returns a range of all the message-boards messages where userId = &#63;.
2889             *
2890             * <p>
2891             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2892             * </p>
2893             *
2894             * @param userId the user ID
2895             * @param start the lower bound of the range of message-boards messages
2896             * @param end the upper bound of the range of message-boards messages (not inclusive)
2897             * @return the range of matching message-boards messages
2898             */
2899            @Override
2900            public List<MBMessage> findByUserId(long userId, int start, int end) {
2901                    return findByUserId(userId, start, end, null);
2902            }
2903    
2904            /**
2905             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2906             *
2907             * <p>
2908             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2909             * </p>
2910             *
2911             * @param userId the user ID
2912             * @param start the lower bound of the range of message-boards messages
2913             * @param end the upper bound of the range of message-boards messages (not inclusive)
2914             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2915             * @return the ordered range of matching message-boards messages
2916             */
2917            @Override
2918            public List<MBMessage> findByUserId(long userId, int start, int end,
2919                    OrderByComparator<MBMessage> orderByComparator) {
2920                    return findByUserId(userId, start, end, orderByComparator, true);
2921            }
2922    
2923            /**
2924             * Returns an ordered range of all the message-boards messages where userId = &#63;.
2925             *
2926             * <p>
2927             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2928             * </p>
2929             *
2930             * @param userId the user ID
2931             * @param start the lower bound of the range of message-boards messages
2932             * @param end the upper bound of the range of message-boards messages (not inclusive)
2933             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2934             * @param retrieveFromCache whether to retrieve from the finder cache
2935             * @return the ordered range of matching message-boards messages
2936             */
2937            @Override
2938            public List<MBMessage> findByUserId(long userId, int start, int end,
2939                    OrderByComparator<MBMessage> orderByComparator,
2940                    boolean retrieveFromCache) {
2941                    boolean pagination = true;
2942                    FinderPath finderPath = null;
2943                    Object[] finderArgs = null;
2944    
2945                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2946                                    (orderByComparator == null)) {
2947                            pagination = false;
2948                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2949                            finderArgs = new Object[] { userId };
2950                    }
2951                    else {
2952                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2953                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2954                    }
2955    
2956                    List<MBMessage> list = null;
2957    
2958                    if (retrieveFromCache) {
2959                            list = (List<MBMessage>)finderCache.getResult(finderPath,
2960                                            finderArgs, this);
2961    
2962                            if ((list != null) && !list.isEmpty()) {
2963                                    for (MBMessage mbMessage : list) {
2964                                            if ((userId != mbMessage.getUserId())) {
2965                                                    list = null;
2966    
2967                                                    break;
2968                                            }
2969                                    }
2970                            }
2971                    }
2972    
2973                    if (list == null) {
2974                            StringBundler query = null;
2975    
2976                            if (orderByComparator != null) {
2977                                    query = new StringBundler(3 +
2978                                                    (orderByComparator.getOrderByFields().length * 2));
2979                            }
2980                            else {
2981                                    query = new StringBundler(3);
2982                            }
2983    
2984                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2985    
2986                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2987    
2988                            if (orderByComparator != null) {
2989                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2990                                            orderByComparator);
2991                            }
2992                            else
2993                             if (pagination) {
2994                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2995                            }
2996    
2997                            String sql = query.toString();
2998    
2999                            Session session = null;
3000    
3001                            try {
3002                                    session = openSession();
3003    
3004                                    Query q = session.createQuery(sql);
3005    
3006                                    QueryPos qPos = QueryPos.getInstance(q);
3007    
3008                                    qPos.add(userId);
3009    
3010                                    if (!pagination) {
3011                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3012                                                            start, end, false);
3013    
3014                                            Collections.sort(list);
3015    
3016                                            list = Collections.unmodifiableList(list);
3017                                    }
3018                                    else {
3019                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3020                                                            start, end);
3021                                    }
3022    
3023                                    cacheResult(list);
3024    
3025                                    finderCache.putResult(finderPath, finderArgs, list);
3026                            }
3027                            catch (Exception e) {
3028                                    finderCache.removeResult(finderPath, finderArgs);
3029    
3030                                    throw processException(e);
3031                            }
3032                            finally {
3033                                    closeSession(session);
3034                            }
3035                    }
3036    
3037                    return list;
3038            }
3039    
3040            /**
3041             * Returns the first message-boards message in the ordered set where userId = &#63;.
3042             *
3043             * @param userId the user ID
3044             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3045             * @return the first matching message-boards message
3046             * @throws NoSuchMessageException if a matching message-boards message could not be found
3047             */
3048            @Override
3049            public MBMessage findByUserId_First(long userId,
3050                    OrderByComparator<MBMessage> orderByComparator)
3051                    throws NoSuchMessageException {
3052                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3053    
3054                    if (mbMessage != null) {
3055                            return mbMessage;
3056                    }
3057    
3058                    StringBundler msg = new StringBundler(4);
3059    
3060                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3061    
3062                    msg.append("userId=");
3063                    msg.append(userId);
3064    
3065                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3066    
3067                    throw new NoSuchMessageException(msg.toString());
3068            }
3069    
3070            /**
3071             * Returns the first message-boards message in the ordered set where userId = &#63;.
3072             *
3073             * @param userId the user ID
3074             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3075             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3076             */
3077            @Override
3078            public MBMessage fetchByUserId_First(long userId,
3079                    OrderByComparator<MBMessage> orderByComparator) {
3080                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3081    
3082                    if (!list.isEmpty()) {
3083                            return list.get(0);
3084                    }
3085    
3086                    return null;
3087            }
3088    
3089            /**
3090             * Returns the last message-boards message in the ordered set where userId = &#63;.
3091             *
3092             * @param userId the user ID
3093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3094             * @return the last matching message-boards message
3095             * @throws NoSuchMessageException if a matching message-boards message could not be found
3096             */
3097            @Override
3098            public MBMessage findByUserId_Last(long userId,
3099                    OrderByComparator<MBMessage> orderByComparator)
3100                    throws NoSuchMessageException {
3101                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3102    
3103                    if (mbMessage != null) {
3104                            return mbMessage;
3105                    }
3106    
3107                    StringBundler msg = new StringBundler(4);
3108    
3109                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3110    
3111                    msg.append("userId=");
3112                    msg.append(userId);
3113    
3114                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3115    
3116                    throw new NoSuchMessageException(msg.toString());
3117            }
3118    
3119            /**
3120             * Returns the last message-boards message in the ordered set where userId = &#63;.
3121             *
3122             * @param userId the user ID
3123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3124             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3125             */
3126            @Override
3127            public MBMessage fetchByUserId_Last(long userId,
3128                    OrderByComparator<MBMessage> orderByComparator) {
3129                    int count = countByUserId(userId);
3130    
3131                    if (count == 0) {
3132                            return null;
3133                    }
3134    
3135                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3136                                    orderByComparator);
3137    
3138                    if (!list.isEmpty()) {
3139                            return list.get(0);
3140                    }
3141    
3142                    return null;
3143            }
3144    
3145            /**
3146             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3147             *
3148             * @param messageId the primary key of the current message-boards message
3149             * @param userId the user ID
3150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3151             * @return the previous, current, and next message-boards message
3152             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3153             */
3154            @Override
3155            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3156                    OrderByComparator<MBMessage> orderByComparator)
3157                    throws NoSuchMessageException {
3158                    MBMessage mbMessage = findByPrimaryKey(messageId);
3159    
3160                    Session session = null;
3161    
3162                    try {
3163                            session = openSession();
3164    
3165                            MBMessage[] array = new MBMessageImpl[3];
3166    
3167                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3168                                            orderByComparator, true);
3169    
3170                            array[1] = mbMessage;
3171    
3172                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3173                                            orderByComparator, false);
3174    
3175                            return array;
3176                    }
3177                    catch (Exception e) {
3178                            throw processException(e);
3179                    }
3180                    finally {
3181                            closeSession(session);
3182                    }
3183            }
3184    
3185            protected MBMessage getByUserId_PrevAndNext(Session session,
3186                    MBMessage mbMessage, long userId,
3187                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3188                    StringBundler query = null;
3189    
3190                    if (orderByComparator != null) {
3191                            query = new StringBundler(4 +
3192                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3193                                            (orderByComparator.getOrderByFields().length * 3));
3194                    }
3195                    else {
3196                            query = new StringBundler(3);
3197                    }
3198    
3199                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3200    
3201                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3202    
3203                    if (orderByComparator != null) {
3204                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3205    
3206                            if (orderByConditionFields.length > 0) {
3207                                    query.append(WHERE_AND);
3208                            }
3209    
3210                            for (int i = 0; i < orderByConditionFields.length; i++) {
3211                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3212                                    query.append(orderByConditionFields[i]);
3213    
3214                                    if ((i + 1) < orderByConditionFields.length) {
3215                                            if (orderByComparator.isAscending() ^ previous) {
3216                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3217                                            }
3218                                            else {
3219                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3220                                            }
3221                                    }
3222                                    else {
3223                                            if (orderByComparator.isAscending() ^ previous) {
3224                                                    query.append(WHERE_GREATER_THAN);
3225                                            }
3226                                            else {
3227                                                    query.append(WHERE_LESSER_THAN);
3228                                            }
3229                                    }
3230                            }
3231    
3232                            query.append(ORDER_BY_CLAUSE);
3233    
3234                            String[] orderByFields = orderByComparator.getOrderByFields();
3235    
3236                            for (int i = 0; i < orderByFields.length; i++) {
3237                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3238                                    query.append(orderByFields[i]);
3239    
3240                                    if ((i + 1) < orderByFields.length) {
3241                                            if (orderByComparator.isAscending() ^ previous) {
3242                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3243                                            }
3244                                            else {
3245                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3246                                            }
3247                                    }
3248                                    else {
3249                                            if (orderByComparator.isAscending() ^ previous) {
3250                                                    query.append(ORDER_BY_ASC);
3251                                            }
3252                                            else {
3253                                                    query.append(ORDER_BY_DESC);
3254                                            }
3255                                    }
3256                            }
3257                    }
3258                    else {
3259                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3260                    }
3261    
3262                    String sql = query.toString();
3263    
3264                    Query q = session.createQuery(sql);
3265    
3266                    q.setFirstResult(0);
3267                    q.setMaxResults(2);
3268    
3269                    QueryPos qPos = QueryPos.getInstance(q);
3270    
3271                    qPos.add(userId);
3272    
3273                    if (orderByComparator != null) {
3274                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3275    
3276                            for (Object value : values) {
3277                                    qPos.add(value);
3278                            }
3279                    }
3280    
3281                    List<MBMessage> list = q.list();
3282    
3283                    if (list.size() == 2) {
3284                            return list.get(1);
3285                    }
3286                    else {
3287                            return null;
3288                    }
3289            }
3290    
3291            /**
3292             * Removes all the message-boards messages where userId = &#63; from the database.
3293             *
3294             * @param userId the user ID
3295             */
3296            @Override
3297            public void removeByUserId(long userId) {
3298                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
3299                                    QueryUtil.ALL_POS, null)) {
3300                            remove(mbMessage);
3301                    }
3302            }
3303    
3304            /**
3305             * Returns the number of message-boards messages where userId = &#63;.
3306             *
3307             * @param userId the user ID
3308             * @return the number of matching message-boards messages
3309             */
3310            @Override
3311            public int countByUserId(long userId) {
3312                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
3313    
3314                    Object[] finderArgs = new Object[] { userId };
3315    
3316                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3317    
3318                    if (count == null) {
3319                            StringBundler query = new StringBundler(2);
3320    
3321                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3322    
3323                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3324    
3325                            String sql = query.toString();
3326    
3327                            Session session = null;
3328    
3329                            try {
3330                                    session = openSession();
3331    
3332                                    Query q = session.createQuery(sql);
3333    
3334                                    QueryPos qPos = QueryPos.getInstance(q);
3335    
3336                                    qPos.add(userId);
3337    
3338                                    count = (Long)q.uniqueResult();
3339    
3340                                    finderCache.putResult(finderPath, finderArgs, count);
3341                            }
3342                            catch (Exception e) {
3343                                    finderCache.removeResult(finderPath, finderArgs);
3344    
3345                                    throw processException(e);
3346                            }
3347                            finally {
3348                                    closeSession(session);
3349                            }
3350                    }
3351    
3352                    return count.intValue();
3353            }
3354    
3355            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
3356            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3357                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3358                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
3359                            new String[] {
3360                                    Long.class.getName(),
3361                                    
3362                            Integer.class.getName(), Integer.class.getName(),
3363                                    OrderByComparator.class.getName()
3364                            });
3365            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
3366                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3367                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3368                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
3369                            new String[] { Long.class.getName() },
3370                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3371                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3372            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3373                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3374                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
3375                            new String[] { Long.class.getName() });
3376    
3377            /**
3378             * Returns all the message-boards messages where threadId = &#63;.
3379             *
3380             * @param threadId the thread ID
3381             * @return the matching message-boards messages
3382             */
3383            @Override
3384            public List<MBMessage> findByThreadId(long threadId) {
3385                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3386                            null);
3387            }
3388    
3389            /**
3390             * Returns a range of all the message-boards messages where threadId = &#63;.
3391             *
3392             * <p>
3393             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3394             * </p>
3395             *
3396             * @param threadId the thread ID
3397             * @param start the lower bound of the range of message-boards messages
3398             * @param end the upper bound of the range of message-boards messages (not inclusive)
3399             * @return the range of matching message-boards messages
3400             */
3401            @Override
3402            public List<MBMessage> findByThreadId(long threadId, int start, int end) {
3403                    return findByThreadId(threadId, start, end, null);
3404            }
3405    
3406            /**
3407             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3408             *
3409             * <p>
3410             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3411             * </p>
3412             *
3413             * @param threadId the thread ID
3414             * @param start the lower bound of the range of message-boards messages
3415             * @param end the upper bound of the range of message-boards messages (not inclusive)
3416             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3417             * @return the ordered range of matching message-boards messages
3418             */
3419            @Override
3420            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3421                    OrderByComparator<MBMessage> orderByComparator) {
3422                    return findByThreadId(threadId, start, end, orderByComparator, true);
3423            }
3424    
3425            /**
3426             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3427             *
3428             * <p>
3429             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3430             * </p>
3431             *
3432             * @param threadId the thread ID
3433             * @param start the lower bound of the range of message-boards messages
3434             * @param end the upper bound of the range of message-boards messages (not inclusive)
3435             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3436             * @param retrieveFromCache whether to retrieve from the finder cache
3437             * @return the ordered range of matching message-boards messages
3438             */
3439            @Override
3440            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3441                    OrderByComparator<MBMessage> orderByComparator,
3442                    boolean retrieveFromCache) {
3443                    boolean pagination = true;
3444                    FinderPath finderPath = null;
3445                    Object[] finderArgs = null;
3446    
3447                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3448                                    (orderByComparator == null)) {
3449                            pagination = false;
3450                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3451                            finderArgs = new Object[] { threadId };
3452                    }
3453                    else {
3454                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3455                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3456                    }
3457    
3458                    List<MBMessage> list = null;
3459    
3460                    if (retrieveFromCache) {
3461                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3462                                            finderArgs, this);
3463    
3464                            if ((list != null) && !list.isEmpty()) {
3465                                    for (MBMessage mbMessage : list) {
3466                                            if ((threadId != mbMessage.getThreadId())) {
3467                                                    list = null;
3468    
3469                                                    break;
3470                                            }
3471                                    }
3472                            }
3473                    }
3474    
3475                    if (list == null) {
3476                            StringBundler query = null;
3477    
3478                            if (orderByComparator != null) {
3479                                    query = new StringBundler(3 +
3480                                                    (orderByComparator.getOrderByFields().length * 2));
3481                            }
3482                            else {
3483                                    query = new StringBundler(3);
3484                            }
3485    
3486                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3487    
3488                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3489    
3490                            if (orderByComparator != null) {
3491                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3492                                            orderByComparator);
3493                            }
3494                            else
3495                             if (pagination) {
3496                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3497                            }
3498    
3499                            String sql = query.toString();
3500    
3501                            Session session = null;
3502    
3503                            try {
3504                                    session = openSession();
3505    
3506                                    Query q = session.createQuery(sql);
3507    
3508                                    QueryPos qPos = QueryPos.getInstance(q);
3509    
3510                                    qPos.add(threadId);
3511    
3512                                    if (!pagination) {
3513                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3514                                                            start, end, false);
3515    
3516                                            Collections.sort(list);
3517    
3518                                            list = Collections.unmodifiableList(list);
3519                                    }
3520                                    else {
3521                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3522                                                            start, end);
3523                                    }
3524    
3525                                    cacheResult(list);
3526    
3527                                    finderCache.putResult(finderPath, finderArgs, list);
3528                            }
3529                            catch (Exception e) {
3530                                    finderCache.removeResult(finderPath, finderArgs);
3531    
3532                                    throw processException(e);
3533                            }
3534                            finally {
3535                                    closeSession(session);
3536                            }
3537                    }
3538    
3539                    return list;
3540            }
3541    
3542            /**
3543             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3544             *
3545             * @param threadId the thread ID
3546             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3547             * @return the first matching message-boards message
3548             * @throws NoSuchMessageException if a matching message-boards message could not be found
3549             */
3550            @Override
3551            public MBMessage findByThreadId_First(long threadId,
3552                    OrderByComparator<MBMessage> orderByComparator)
3553                    throws NoSuchMessageException {
3554                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3555    
3556                    if (mbMessage != null) {
3557                            return mbMessage;
3558                    }
3559    
3560                    StringBundler msg = new StringBundler(4);
3561    
3562                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3563    
3564                    msg.append("threadId=");
3565                    msg.append(threadId);
3566    
3567                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3568    
3569                    throw new NoSuchMessageException(msg.toString());
3570            }
3571    
3572            /**
3573             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3574             *
3575             * @param threadId the thread ID
3576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3577             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3578             */
3579            @Override
3580            public MBMessage fetchByThreadId_First(long threadId,
3581                    OrderByComparator<MBMessage> orderByComparator) {
3582                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3583    
3584                    if (!list.isEmpty()) {
3585                            return list.get(0);
3586                    }
3587    
3588                    return null;
3589            }
3590    
3591            /**
3592             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3593             *
3594             * @param threadId the thread ID
3595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3596             * @return the last matching message-boards message
3597             * @throws NoSuchMessageException if a matching message-boards message could not be found
3598             */
3599            @Override
3600            public MBMessage findByThreadId_Last(long threadId,
3601                    OrderByComparator<MBMessage> orderByComparator)
3602                    throws NoSuchMessageException {
3603                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3604    
3605                    if (mbMessage != null) {
3606                            return mbMessage;
3607                    }
3608    
3609                    StringBundler msg = new StringBundler(4);
3610    
3611                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3612    
3613                    msg.append("threadId=");
3614                    msg.append(threadId);
3615    
3616                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3617    
3618                    throw new NoSuchMessageException(msg.toString());
3619            }
3620    
3621            /**
3622             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3623             *
3624             * @param threadId the thread ID
3625             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3626             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3627             */
3628            @Override
3629            public MBMessage fetchByThreadId_Last(long threadId,
3630                    OrderByComparator<MBMessage> orderByComparator) {
3631                    int count = countByThreadId(threadId);
3632    
3633                    if (count == 0) {
3634                            return null;
3635                    }
3636    
3637                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3638                                    orderByComparator);
3639    
3640                    if (!list.isEmpty()) {
3641                            return list.get(0);
3642                    }
3643    
3644                    return null;
3645            }
3646    
3647            /**
3648             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3649             *
3650             * @param messageId the primary key of the current message-boards message
3651             * @param threadId the thread ID
3652             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3653             * @return the previous, current, and next message-boards message
3654             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
3655             */
3656            @Override
3657            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3658                    long threadId, OrderByComparator<MBMessage> orderByComparator)
3659                    throws NoSuchMessageException {
3660                    MBMessage mbMessage = findByPrimaryKey(messageId);
3661    
3662                    Session session = null;
3663    
3664                    try {
3665                            session = openSession();
3666    
3667                            MBMessage[] array = new MBMessageImpl[3];
3668    
3669                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3670                                            orderByComparator, true);
3671    
3672                            array[1] = mbMessage;
3673    
3674                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3675                                            orderByComparator, false);
3676    
3677                            return array;
3678                    }
3679                    catch (Exception e) {
3680                            throw processException(e);
3681                    }
3682                    finally {
3683                            closeSession(session);
3684                    }
3685            }
3686    
3687            protected MBMessage getByThreadId_PrevAndNext(Session session,
3688                    MBMessage mbMessage, long threadId,
3689                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
3690                    StringBundler query = null;
3691    
3692                    if (orderByComparator != null) {
3693                            query = new StringBundler(4 +
3694                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3695                                            (orderByComparator.getOrderByFields().length * 3));
3696                    }
3697                    else {
3698                            query = new StringBundler(3);
3699                    }
3700    
3701                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3702    
3703                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3704    
3705                    if (orderByComparator != null) {
3706                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3707    
3708                            if (orderByConditionFields.length > 0) {
3709                                    query.append(WHERE_AND);
3710                            }
3711    
3712                            for (int i = 0; i < orderByConditionFields.length; i++) {
3713                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3714                                    query.append(orderByConditionFields[i]);
3715    
3716                                    if ((i + 1) < orderByConditionFields.length) {
3717                                            if (orderByComparator.isAscending() ^ previous) {
3718                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3719                                            }
3720                                            else {
3721                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3722                                            }
3723                                    }
3724                                    else {
3725                                            if (orderByComparator.isAscending() ^ previous) {
3726                                                    query.append(WHERE_GREATER_THAN);
3727                                            }
3728                                            else {
3729                                                    query.append(WHERE_LESSER_THAN);
3730                                            }
3731                                    }
3732                            }
3733    
3734                            query.append(ORDER_BY_CLAUSE);
3735    
3736                            String[] orderByFields = orderByComparator.getOrderByFields();
3737    
3738                            for (int i = 0; i < orderByFields.length; i++) {
3739                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3740                                    query.append(orderByFields[i]);
3741    
3742                                    if ((i + 1) < orderByFields.length) {
3743                                            if (orderByComparator.isAscending() ^ previous) {
3744                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3745                                            }
3746                                            else {
3747                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3748                                            }
3749                                    }
3750                                    else {
3751                                            if (orderByComparator.isAscending() ^ previous) {
3752                                                    query.append(ORDER_BY_ASC);
3753                                            }
3754                                            else {
3755                                                    query.append(ORDER_BY_DESC);
3756                                            }
3757                                    }
3758                            }
3759                    }
3760                    else {
3761                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3762                    }
3763    
3764                    String sql = query.toString();
3765    
3766                    Query q = session.createQuery(sql);
3767    
3768                    q.setFirstResult(0);
3769                    q.setMaxResults(2);
3770    
3771                    QueryPos qPos = QueryPos.getInstance(q);
3772    
3773                    qPos.add(threadId);
3774    
3775                    if (orderByComparator != null) {
3776                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3777    
3778                            for (Object value : values) {
3779                                    qPos.add(value);
3780                            }
3781                    }
3782    
3783                    List<MBMessage> list = q.list();
3784    
3785                    if (list.size() == 2) {
3786                            return list.get(1);
3787                    }
3788                    else {
3789                            return null;
3790                    }
3791            }
3792    
3793            /**
3794             * Removes all the message-boards messages where threadId = &#63; from the database.
3795             *
3796             * @param threadId the thread ID
3797             */
3798            @Override
3799            public void removeByThreadId(long threadId) {
3800                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3801                                    QueryUtil.ALL_POS, null)) {
3802                            remove(mbMessage);
3803                    }
3804            }
3805    
3806            /**
3807             * Returns the number of message-boards messages where threadId = &#63;.
3808             *
3809             * @param threadId the thread ID
3810             * @return the number of matching message-boards messages
3811             */
3812            @Override
3813            public int countByThreadId(long threadId) {
3814                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3815    
3816                    Object[] finderArgs = new Object[] { threadId };
3817    
3818                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3819    
3820                    if (count == null) {
3821                            StringBundler query = new StringBundler(2);
3822    
3823                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3824    
3825                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3826    
3827                            String sql = query.toString();
3828    
3829                            Session session = null;
3830    
3831                            try {
3832                                    session = openSession();
3833    
3834                                    Query q = session.createQuery(sql);
3835    
3836                                    QueryPos qPos = QueryPos.getInstance(q);
3837    
3838                                    qPos.add(threadId);
3839    
3840                                    count = (Long)q.uniqueResult();
3841    
3842                                    finderCache.putResult(finderPath, finderArgs, count);
3843                            }
3844                            catch (Exception e) {
3845                                    finderCache.removeResult(finderPath, finderArgs);
3846    
3847                                    throw processException(e);
3848                            }
3849                            finally {
3850                                    closeSession(session);
3851                            }
3852                    }
3853    
3854                    return count.intValue();
3855            }
3856    
3857            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3858            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3859                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3860                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3861                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3862                            new String[] {
3863                                    Long.class.getName(),
3864                                    
3865                            Integer.class.getName(), Integer.class.getName(),
3866                                    OrderByComparator.class.getName()
3867                            });
3868            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3869                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3870                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3872                            new String[] { Long.class.getName() },
3873                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3874                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3875            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3876                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3877                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3878                            new String[] { Long.class.getName() });
3879    
3880            /**
3881             * Returns all the message-boards messages where threadId = &#63;.
3882             *
3883             * @param threadId the thread ID
3884             * @return the matching message-boards messages
3885             */
3886            @Override
3887            public List<MBMessage> findByThreadReplies(long threadId) {
3888                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3889                            QueryUtil.ALL_POS, null);
3890            }
3891    
3892            /**
3893             * Returns a range of all the message-boards messages where threadId = &#63;.
3894             *
3895             * <p>
3896             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3897             * </p>
3898             *
3899             * @param threadId the thread ID
3900             * @param start the lower bound of the range of message-boards messages
3901             * @param end the upper bound of the range of message-boards messages (not inclusive)
3902             * @return the range of matching message-boards messages
3903             */
3904            @Override
3905            public List<MBMessage> findByThreadReplies(long threadId, int start, int end) {
3906                    return findByThreadReplies(threadId, start, end, null);
3907            }
3908    
3909            /**
3910             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3911             *
3912             * <p>
3913             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3914             * </p>
3915             *
3916             * @param threadId the thread ID
3917             * @param start the lower bound of the range of message-boards messages
3918             * @param end the upper bound of the range of message-boards messages (not inclusive)
3919             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3920             * @return the ordered range of matching message-boards messages
3921             */
3922            @Override
3923            public List<MBMessage> findByThreadReplies(long threadId, int start,
3924                    int end, OrderByComparator<MBMessage> orderByComparator) {
3925                    return findByThreadReplies(threadId, start, end, orderByComparator, true);
3926            }
3927    
3928            /**
3929             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3930             *
3931             * <p>
3932             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3933             * </p>
3934             *
3935             * @param threadId the thread ID
3936             * @param start the lower bound of the range of message-boards messages
3937             * @param end the upper bound of the range of message-boards messages (not inclusive)
3938             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3939             * @param retrieveFromCache whether to retrieve from the finder cache
3940             * @return the ordered range of matching message-boards messages
3941             */
3942            @Override
3943            public List<MBMessage> findByThreadReplies(long threadId, int start,
3944                    int end, OrderByComparator<MBMessage> orderByComparator,
3945                    boolean retrieveFromCache) {
3946                    boolean pagination = true;
3947                    FinderPath finderPath = null;
3948                    Object[] finderArgs = null;
3949    
3950                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3951                                    (orderByComparator == null)) {
3952                            pagination = false;
3953                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3954                            finderArgs = new Object[] { threadId };
3955                    }
3956                    else {
3957                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3958                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3959                    }
3960    
3961                    List<MBMessage> list = null;
3962    
3963                    if (retrieveFromCache) {
3964                            list = (List<MBMessage>)finderCache.getResult(finderPath,
3965                                            finderArgs, this);
3966    
3967                            if ((list != null) && !list.isEmpty()) {
3968                                    for (MBMessage mbMessage : list) {
3969                                            if ((threadId != mbMessage.getThreadId())) {
3970                                                    list = null;
3971    
3972                                                    break;
3973                                            }
3974                                    }
3975                            }
3976                    }
3977    
3978                    if (list == null) {
3979                            StringBundler query = null;
3980    
3981                            if (orderByComparator != null) {
3982                                    query = new StringBundler(3 +
3983                                                    (orderByComparator.getOrderByFields().length * 2));
3984                            }
3985                            else {
3986                                    query = new StringBundler(3);
3987                            }
3988    
3989                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3990    
3991                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3992    
3993                            if (orderByComparator != null) {
3994                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3995                                            orderByComparator);
3996                            }
3997                            else
3998                             if (pagination) {
3999                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4000                            }
4001    
4002                            String sql = query.toString();
4003    
4004                            Session session = null;
4005    
4006                            try {
4007                                    session = openSession();
4008    
4009                                    Query q = session.createQuery(sql);
4010    
4011                                    QueryPos qPos = QueryPos.getInstance(q);
4012    
4013                                    qPos.add(threadId);
4014    
4015                                    if (!pagination) {
4016                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4017                                                            start, end, false);
4018    
4019                                            Collections.sort(list);
4020    
4021                                            list = Collections.unmodifiableList(list);
4022                                    }
4023                                    else {
4024                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4025                                                            start, end);
4026                                    }
4027    
4028                                    cacheResult(list);
4029    
4030                                    finderCache.putResult(finderPath, finderArgs, list);
4031                            }
4032                            catch (Exception e) {
4033                                    finderCache.removeResult(finderPath, finderArgs);
4034    
4035                                    throw processException(e);
4036                            }
4037                            finally {
4038                                    closeSession(session);
4039                            }
4040                    }
4041    
4042                    return list;
4043            }
4044    
4045            /**
4046             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4047             *
4048             * @param threadId the thread ID
4049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4050             * @return the first matching message-boards message
4051             * @throws NoSuchMessageException if a matching message-boards message could not be found
4052             */
4053            @Override
4054            public MBMessage findByThreadReplies_First(long threadId,
4055                    OrderByComparator<MBMessage> orderByComparator)
4056                    throws NoSuchMessageException {
4057                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4058                                    orderByComparator);
4059    
4060                    if (mbMessage != null) {
4061                            return mbMessage;
4062                    }
4063    
4064                    StringBundler msg = new StringBundler(4);
4065    
4066                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4067    
4068                    msg.append("threadId=");
4069                    msg.append(threadId);
4070    
4071                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4072    
4073                    throw new NoSuchMessageException(msg.toString());
4074            }
4075    
4076            /**
4077             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4078             *
4079             * @param threadId the thread ID
4080             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4081             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4082             */
4083            @Override
4084            public MBMessage fetchByThreadReplies_First(long threadId,
4085                    OrderByComparator<MBMessage> orderByComparator) {
4086                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4087                                    orderByComparator);
4088    
4089                    if (!list.isEmpty()) {
4090                            return list.get(0);
4091                    }
4092    
4093                    return null;
4094            }
4095    
4096            /**
4097             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4098             *
4099             * @param threadId the thread ID
4100             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4101             * @return the last matching message-boards message
4102             * @throws NoSuchMessageException if a matching message-boards message could not be found
4103             */
4104            @Override
4105            public MBMessage findByThreadReplies_Last(long threadId,
4106                    OrderByComparator<MBMessage> orderByComparator)
4107                    throws NoSuchMessageException {
4108                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4109                                    orderByComparator);
4110    
4111                    if (mbMessage != null) {
4112                            return mbMessage;
4113                    }
4114    
4115                    StringBundler msg = new StringBundler(4);
4116    
4117                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4118    
4119                    msg.append("threadId=");
4120                    msg.append(threadId);
4121    
4122                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4123    
4124                    throw new NoSuchMessageException(msg.toString());
4125            }
4126    
4127            /**
4128             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4129             *
4130             * @param threadId the thread ID
4131             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4132             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4133             */
4134            @Override
4135            public MBMessage fetchByThreadReplies_Last(long threadId,
4136                    OrderByComparator<MBMessage> orderByComparator) {
4137                    int count = countByThreadReplies(threadId);
4138    
4139                    if (count == 0) {
4140                            return null;
4141                    }
4142    
4143                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4144                                    orderByComparator);
4145    
4146                    if (!list.isEmpty()) {
4147                            return list.get(0);
4148                    }
4149    
4150                    return null;
4151            }
4152    
4153            /**
4154             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4155             *
4156             * @param messageId the primary key of the current message-boards message
4157             * @param threadId the thread ID
4158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4159             * @return the previous, current, and next message-boards message
4160             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4161             */
4162            @Override
4163            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4164                    long threadId, OrderByComparator<MBMessage> orderByComparator)
4165                    throws NoSuchMessageException {
4166                    MBMessage mbMessage = findByPrimaryKey(messageId);
4167    
4168                    Session session = null;
4169    
4170                    try {
4171                            session = openSession();
4172    
4173                            MBMessage[] array = new MBMessageImpl[3];
4174    
4175                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4176                                            threadId, orderByComparator, true);
4177    
4178                            array[1] = mbMessage;
4179    
4180                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4181                                            threadId, orderByComparator, false);
4182    
4183                            return array;
4184                    }
4185                    catch (Exception e) {
4186                            throw processException(e);
4187                    }
4188                    finally {
4189                            closeSession(session);
4190                    }
4191            }
4192    
4193            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4194                    MBMessage mbMessage, long threadId,
4195                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4196                    StringBundler query = null;
4197    
4198                    if (orderByComparator != null) {
4199                            query = new StringBundler(4 +
4200                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4201                                            (orderByComparator.getOrderByFields().length * 3));
4202                    }
4203                    else {
4204                            query = new StringBundler(3);
4205                    }
4206    
4207                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4208    
4209                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4210    
4211                    if (orderByComparator != null) {
4212                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4213    
4214                            if (orderByConditionFields.length > 0) {
4215                                    query.append(WHERE_AND);
4216                            }
4217    
4218                            for (int i = 0; i < orderByConditionFields.length; i++) {
4219                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4220                                    query.append(orderByConditionFields[i]);
4221    
4222                                    if ((i + 1) < orderByConditionFields.length) {
4223                                            if (orderByComparator.isAscending() ^ previous) {
4224                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4225                                            }
4226                                            else {
4227                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4228                                            }
4229                                    }
4230                                    else {
4231                                            if (orderByComparator.isAscending() ^ previous) {
4232                                                    query.append(WHERE_GREATER_THAN);
4233                                            }
4234                                            else {
4235                                                    query.append(WHERE_LESSER_THAN);
4236                                            }
4237                                    }
4238                            }
4239    
4240                            query.append(ORDER_BY_CLAUSE);
4241    
4242                            String[] orderByFields = orderByComparator.getOrderByFields();
4243    
4244                            for (int i = 0; i < orderByFields.length; i++) {
4245                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4246                                    query.append(orderByFields[i]);
4247    
4248                                    if ((i + 1) < orderByFields.length) {
4249                                            if (orderByComparator.isAscending() ^ previous) {
4250                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4251                                            }
4252                                            else {
4253                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4254                                            }
4255                                    }
4256                                    else {
4257                                            if (orderByComparator.isAscending() ^ previous) {
4258                                                    query.append(ORDER_BY_ASC);
4259                                            }
4260                                            else {
4261                                                    query.append(ORDER_BY_DESC);
4262                                            }
4263                                    }
4264                            }
4265                    }
4266                    else {
4267                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4268                    }
4269    
4270                    String sql = query.toString();
4271    
4272                    Query q = session.createQuery(sql);
4273    
4274                    q.setFirstResult(0);
4275                    q.setMaxResults(2);
4276    
4277                    QueryPos qPos = QueryPos.getInstance(q);
4278    
4279                    qPos.add(threadId);
4280    
4281                    if (orderByComparator != null) {
4282                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4283    
4284                            for (Object value : values) {
4285                                    qPos.add(value);
4286                            }
4287                    }
4288    
4289                    List<MBMessage> list = q.list();
4290    
4291                    if (list.size() == 2) {
4292                            return list.get(1);
4293                    }
4294                    else {
4295                            return null;
4296                    }
4297            }
4298    
4299            /**
4300             * Removes all the message-boards messages where threadId = &#63; from the database.
4301             *
4302             * @param threadId the thread ID
4303             */
4304            @Override
4305            public void removeByThreadReplies(long threadId) {
4306                    for (MBMessage mbMessage : findByThreadReplies(threadId,
4307                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4308                            remove(mbMessage);
4309                    }
4310            }
4311    
4312            /**
4313             * Returns the number of message-boards messages where threadId = &#63;.
4314             *
4315             * @param threadId the thread ID
4316             * @return the number of matching message-boards messages
4317             */
4318            @Override
4319            public int countByThreadReplies(long threadId) {
4320                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
4321    
4322                    Object[] finderArgs = new Object[] { threadId };
4323    
4324                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4325    
4326                    if (count == null) {
4327                            StringBundler query = new StringBundler(2);
4328    
4329                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4330    
4331                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4332    
4333                            String sql = query.toString();
4334    
4335                            Session session = null;
4336    
4337                            try {
4338                                    session = openSession();
4339    
4340                                    Query q = session.createQuery(sql);
4341    
4342                                    QueryPos qPos = QueryPos.getInstance(q);
4343    
4344                                    qPos.add(threadId);
4345    
4346                                    count = (Long)q.uniqueResult();
4347    
4348                                    finderCache.putResult(finderPath, finderArgs, count);
4349                            }
4350                            catch (Exception e) {
4351                                    finderCache.removeResult(finderPath, finderArgs);
4352    
4353                                    throw processException(e);
4354                            }
4355                            finally {
4356                                    closeSession(session);
4357                            }
4358                    }
4359    
4360                    return count.intValue();
4361            }
4362    
4363            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4364            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4365                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4366                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4367                            new String[] {
4368                                    Long.class.getName(), Long.class.getName(),
4369                                    
4370                            Integer.class.getName(), Integer.class.getName(),
4371                                    OrderByComparator.class.getName()
4372                            });
4373            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4374                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4375                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4376                            new String[] { Long.class.getName(), Long.class.getName() },
4377                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4378                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4379                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4380            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4381                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4382                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4383                            new String[] { Long.class.getName(), Long.class.getName() });
4384    
4385            /**
4386             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4387             *
4388             * @param groupId the group ID
4389             * @param userId the user ID
4390             * @return the matching message-boards messages
4391             */
4392            @Override
4393            public List<MBMessage> findByG_U(long groupId, long userId) {
4394                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4395                            null);
4396            }
4397    
4398            /**
4399             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4400             *
4401             * <p>
4402             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4403             * </p>
4404             *
4405             * @param groupId the group ID
4406             * @param userId the user ID
4407             * @param start the lower bound of the range of message-boards messages
4408             * @param end the upper bound of the range of message-boards messages (not inclusive)
4409             * @return the range of matching message-boards messages
4410             */
4411            @Override
4412            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4413                    int end) {
4414                    return findByG_U(groupId, userId, start, end, null);
4415            }
4416    
4417            /**
4418             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4419             *
4420             * <p>
4421             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4422             * </p>
4423             *
4424             * @param groupId the group ID
4425             * @param userId the user ID
4426             * @param start the lower bound of the range of message-boards messages
4427             * @param end the upper bound of the range of message-boards messages (not inclusive)
4428             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4429             * @return the ordered range of matching message-boards messages
4430             */
4431            @Override
4432            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4433                    int end, OrderByComparator<MBMessage> orderByComparator) {
4434                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
4435            }
4436    
4437            /**
4438             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4439             *
4440             * <p>
4441             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4442             * </p>
4443             *
4444             * @param groupId the group ID
4445             * @param userId the user ID
4446             * @param start the lower bound of the range of message-boards messages
4447             * @param end the upper bound of the range of message-boards messages (not inclusive)
4448             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4449             * @param retrieveFromCache whether to retrieve from the finder cache
4450             * @return the ordered range of matching message-boards messages
4451             */
4452            @Override
4453            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4454                    int end, OrderByComparator<MBMessage> orderByComparator,
4455                    boolean retrieveFromCache) {
4456                    boolean pagination = true;
4457                    FinderPath finderPath = null;
4458                    Object[] finderArgs = null;
4459    
4460                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4461                                    (orderByComparator == null)) {
4462                            pagination = false;
4463                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4464                            finderArgs = new Object[] { groupId, userId };
4465                    }
4466                    else {
4467                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4468                            finderArgs = new Object[] {
4469                                            groupId, userId,
4470                                            
4471                                            start, end, orderByComparator
4472                                    };
4473                    }
4474    
4475                    List<MBMessage> list = null;
4476    
4477                    if (retrieveFromCache) {
4478                            list = (List<MBMessage>)finderCache.getResult(finderPath,
4479                                            finderArgs, this);
4480    
4481                            if ((list != null) && !list.isEmpty()) {
4482                                    for (MBMessage mbMessage : list) {
4483                                            if ((groupId != mbMessage.getGroupId()) ||
4484                                                            (userId != mbMessage.getUserId())) {
4485                                                    list = null;
4486    
4487                                                    break;
4488                                            }
4489                                    }
4490                            }
4491                    }
4492    
4493                    if (list == null) {
4494                            StringBundler query = null;
4495    
4496                            if (orderByComparator != null) {
4497                                    query = new StringBundler(4 +
4498                                                    (orderByComparator.getOrderByFields().length * 2));
4499                            }
4500                            else {
4501                                    query = new StringBundler(4);
4502                            }
4503    
4504                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4505    
4506                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4507    
4508                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4509    
4510                            if (orderByComparator != null) {
4511                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4512                                            orderByComparator);
4513                            }
4514                            else
4515                             if (pagination) {
4516                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4517                            }
4518    
4519                            String sql = query.toString();
4520    
4521                            Session session = null;
4522    
4523                            try {
4524                                    session = openSession();
4525    
4526                                    Query q = session.createQuery(sql);
4527    
4528                                    QueryPos qPos = QueryPos.getInstance(q);
4529    
4530                                    qPos.add(groupId);
4531    
4532                                    qPos.add(userId);
4533    
4534                                    if (!pagination) {
4535                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4536                                                            start, end, false);
4537    
4538                                            Collections.sort(list);
4539    
4540                                            list = Collections.unmodifiableList(list);
4541                                    }
4542                                    else {
4543                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4544                                                            start, end);
4545                                    }
4546    
4547                                    cacheResult(list);
4548    
4549                                    finderCache.putResult(finderPath, finderArgs, list);
4550                            }
4551                            catch (Exception e) {
4552                                    finderCache.removeResult(finderPath, finderArgs);
4553    
4554                                    throw processException(e);
4555                            }
4556                            finally {
4557                                    closeSession(session);
4558                            }
4559                    }
4560    
4561                    return list;
4562            }
4563    
4564            /**
4565             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4566             *
4567             * @param groupId the group ID
4568             * @param userId the user ID
4569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4570             * @return the first matching message-boards message
4571             * @throws NoSuchMessageException if a matching message-boards message could not be found
4572             */
4573            @Override
4574            public MBMessage findByG_U_First(long groupId, long userId,
4575                    OrderByComparator<MBMessage> orderByComparator)
4576                    throws NoSuchMessageException {
4577                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4578                                    orderByComparator);
4579    
4580                    if (mbMessage != null) {
4581                            return mbMessage;
4582                    }
4583    
4584                    StringBundler msg = new StringBundler(6);
4585    
4586                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4587    
4588                    msg.append("groupId=");
4589                    msg.append(groupId);
4590    
4591                    msg.append(", userId=");
4592                    msg.append(userId);
4593    
4594                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4595    
4596                    throw new NoSuchMessageException(msg.toString());
4597            }
4598    
4599            /**
4600             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4601             *
4602             * @param groupId the group ID
4603             * @param userId the user ID
4604             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4605             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4606             */
4607            @Override
4608            public MBMessage fetchByG_U_First(long groupId, long userId,
4609                    OrderByComparator<MBMessage> orderByComparator) {
4610                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4611                                    orderByComparator);
4612    
4613                    if (!list.isEmpty()) {
4614                            return list.get(0);
4615                    }
4616    
4617                    return null;
4618            }
4619    
4620            /**
4621             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4622             *
4623             * @param groupId the group ID
4624             * @param userId the user ID
4625             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4626             * @return the last matching message-boards message
4627             * @throws NoSuchMessageException if a matching message-boards message could not be found
4628             */
4629            @Override
4630            public MBMessage findByG_U_Last(long groupId, long userId,
4631                    OrderByComparator<MBMessage> orderByComparator)
4632                    throws NoSuchMessageException {
4633                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4634    
4635                    if (mbMessage != null) {
4636                            return mbMessage;
4637                    }
4638    
4639                    StringBundler msg = new StringBundler(6);
4640    
4641                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4642    
4643                    msg.append("groupId=");
4644                    msg.append(groupId);
4645    
4646                    msg.append(", userId=");
4647                    msg.append(userId);
4648    
4649                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4650    
4651                    throw new NoSuchMessageException(msg.toString());
4652            }
4653    
4654            /**
4655             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4656             *
4657             * @param groupId the group ID
4658             * @param userId the user ID
4659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4660             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4661             */
4662            @Override
4663            public MBMessage fetchByG_U_Last(long groupId, long userId,
4664                    OrderByComparator<MBMessage> orderByComparator) {
4665                    int count = countByG_U(groupId, userId);
4666    
4667                    if (count == 0) {
4668                            return null;
4669                    }
4670    
4671                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4672                                    orderByComparator);
4673    
4674                    if (!list.isEmpty()) {
4675                            return list.get(0);
4676                    }
4677    
4678                    return null;
4679            }
4680    
4681            /**
4682             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4683             *
4684             * @param messageId the primary key of the current message-boards message
4685             * @param groupId the group ID
4686             * @param userId the user ID
4687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4688             * @return the previous, current, and next message-boards message
4689             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4690             */
4691            @Override
4692            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4693                    long userId, OrderByComparator<MBMessage> orderByComparator)
4694                    throws NoSuchMessageException {
4695                    MBMessage mbMessage = findByPrimaryKey(messageId);
4696    
4697                    Session session = null;
4698    
4699                    try {
4700                            session = openSession();
4701    
4702                            MBMessage[] array = new MBMessageImpl[3];
4703    
4704                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4705                                            userId, orderByComparator, true);
4706    
4707                            array[1] = mbMessage;
4708    
4709                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4710                                            userId, orderByComparator, false);
4711    
4712                            return array;
4713                    }
4714                    catch (Exception e) {
4715                            throw processException(e);
4716                    }
4717                    finally {
4718                            closeSession(session);
4719                    }
4720            }
4721    
4722            protected MBMessage getByG_U_PrevAndNext(Session session,
4723                    MBMessage mbMessage, long groupId, long userId,
4724                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
4725                    StringBundler query = null;
4726    
4727                    if (orderByComparator != null) {
4728                            query = new StringBundler(5 +
4729                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4730                                            (orderByComparator.getOrderByFields().length * 3));
4731                    }
4732                    else {
4733                            query = new StringBundler(4);
4734                    }
4735    
4736                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4737    
4738                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4739    
4740                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4741    
4742                    if (orderByComparator != null) {
4743                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4744    
4745                            if (orderByConditionFields.length > 0) {
4746                                    query.append(WHERE_AND);
4747                            }
4748    
4749                            for (int i = 0; i < orderByConditionFields.length; i++) {
4750                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4751                                    query.append(orderByConditionFields[i]);
4752    
4753                                    if ((i + 1) < orderByConditionFields.length) {
4754                                            if (orderByComparator.isAscending() ^ previous) {
4755                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4756                                            }
4757                                            else {
4758                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4759                                            }
4760                                    }
4761                                    else {
4762                                            if (orderByComparator.isAscending() ^ previous) {
4763                                                    query.append(WHERE_GREATER_THAN);
4764                                            }
4765                                            else {
4766                                                    query.append(WHERE_LESSER_THAN);
4767                                            }
4768                                    }
4769                            }
4770    
4771                            query.append(ORDER_BY_CLAUSE);
4772    
4773                            String[] orderByFields = orderByComparator.getOrderByFields();
4774    
4775                            for (int i = 0; i < orderByFields.length; i++) {
4776                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4777                                    query.append(orderByFields[i]);
4778    
4779                                    if ((i + 1) < orderByFields.length) {
4780                                            if (orderByComparator.isAscending() ^ previous) {
4781                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4782                                            }
4783                                            else {
4784                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4785                                            }
4786                                    }
4787                                    else {
4788                                            if (orderByComparator.isAscending() ^ previous) {
4789                                                    query.append(ORDER_BY_ASC);
4790                                            }
4791                                            else {
4792                                                    query.append(ORDER_BY_DESC);
4793                                            }
4794                                    }
4795                            }
4796                    }
4797                    else {
4798                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4799                    }
4800    
4801                    String sql = query.toString();
4802    
4803                    Query q = session.createQuery(sql);
4804    
4805                    q.setFirstResult(0);
4806                    q.setMaxResults(2);
4807    
4808                    QueryPos qPos = QueryPos.getInstance(q);
4809    
4810                    qPos.add(groupId);
4811    
4812                    qPos.add(userId);
4813    
4814                    if (orderByComparator != null) {
4815                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4816    
4817                            for (Object value : values) {
4818                                    qPos.add(value);
4819                            }
4820                    }
4821    
4822                    List<MBMessage> list = q.list();
4823    
4824                    if (list.size() == 2) {
4825                            return list.get(1);
4826                    }
4827                    else {
4828                            return null;
4829                    }
4830            }
4831    
4832            /**
4833             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4834             *
4835             * @param groupId the group ID
4836             * @param userId the user ID
4837             * @return the matching message-boards messages that the user has permission to view
4838             */
4839            @Override
4840            public List<MBMessage> filterFindByG_U(long groupId, long userId) {
4841                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4842                            QueryUtil.ALL_POS, null);
4843            }
4844    
4845            /**
4846             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4847             *
4848             * <p>
4849             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4850             * </p>
4851             *
4852             * @param groupId the group ID
4853             * @param userId the user ID
4854             * @param start the lower bound of the range of message-boards messages
4855             * @param end the upper bound of the range of message-boards messages (not inclusive)
4856             * @return the range of matching message-boards messages that the user has permission to view
4857             */
4858            @Override
4859            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4860                    int start, int end) {
4861                    return filterFindByG_U(groupId, userId, start, end, null);
4862            }
4863    
4864            /**
4865             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4866             *
4867             * <p>
4868             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4869             * </p>
4870             *
4871             * @param groupId the group ID
4872             * @param userId the user ID
4873             * @param start the lower bound of the range of message-boards messages
4874             * @param end the upper bound of the range of message-boards messages (not inclusive)
4875             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4876             * @return the ordered range of matching message-boards messages that the user has permission to view
4877             */
4878            @Override
4879            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4880                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
4881                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4882                            return findByG_U(groupId, userId, start, end, orderByComparator);
4883                    }
4884    
4885                    StringBundler query = null;
4886    
4887                    if (orderByComparator != null) {
4888                            query = new StringBundler(4 +
4889                                            (orderByComparator.getOrderByFields().length * 2));
4890                    }
4891                    else {
4892                            query = new StringBundler(5);
4893                    }
4894    
4895                    if (getDB().isSupportsInlineDistinct()) {
4896                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4897                    }
4898                    else {
4899                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4900                    }
4901    
4902                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4903    
4904                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4905    
4906                    if (!getDB().isSupportsInlineDistinct()) {
4907                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4908                    }
4909    
4910                    if (orderByComparator != null) {
4911                            if (getDB().isSupportsInlineDistinct()) {
4912                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4913                                            orderByComparator, true);
4914                            }
4915                            else {
4916                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4917                                            orderByComparator, true);
4918                            }
4919                    }
4920                    else {
4921                            if (getDB().isSupportsInlineDistinct()) {
4922                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4923                            }
4924                            else {
4925                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4926                            }
4927                    }
4928    
4929                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4930                                    MBMessage.class.getName(),
4931                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4932    
4933                    Session session = null;
4934    
4935                    try {
4936                            session = openSession();
4937    
4938                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4939    
4940                            if (getDB().isSupportsInlineDistinct()) {
4941                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4942                            }
4943                            else {
4944                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4945                            }
4946    
4947                            QueryPos qPos = QueryPos.getInstance(q);
4948    
4949                            qPos.add(groupId);
4950    
4951                            qPos.add(userId);
4952    
4953                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4954                    }
4955                    catch (Exception e) {
4956                            throw processException(e);
4957                    }
4958                    finally {
4959                            closeSession(session);
4960                    }
4961            }
4962    
4963            /**
4964             * 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;.
4965             *
4966             * @param messageId the primary key of the current message-boards message
4967             * @param groupId the group ID
4968             * @param userId the user ID
4969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4970             * @return the previous, current, and next message-boards message
4971             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
4972             */
4973            @Override
4974            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4975                    long groupId, long userId,
4976                    OrderByComparator<MBMessage> orderByComparator)
4977                    throws NoSuchMessageException {
4978                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4979                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4980                                    orderByComparator);
4981                    }
4982    
4983                    MBMessage mbMessage = findByPrimaryKey(messageId);
4984    
4985                    Session session = null;
4986    
4987                    try {
4988                            session = openSession();
4989    
4990                            MBMessage[] array = new MBMessageImpl[3];
4991    
4992                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4993                                            userId, orderByComparator, true);
4994    
4995                            array[1] = mbMessage;
4996    
4997                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4998                                            userId, orderByComparator, false);
4999    
5000                            return array;
5001                    }
5002                    catch (Exception e) {
5003                            throw processException(e);
5004                    }
5005                    finally {
5006                            closeSession(session);
5007                    }
5008            }
5009    
5010            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5011                    MBMessage mbMessage, long groupId, long userId,
5012                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5013                    StringBundler query = null;
5014    
5015                    if (orderByComparator != null) {
5016                            query = new StringBundler(6 +
5017                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5018                                            (orderByComparator.getOrderByFields().length * 3));
5019                    }
5020                    else {
5021                            query = new StringBundler(5);
5022                    }
5023    
5024                    if (getDB().isSupportsInlineDistinct()) {
5025                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5026                    }
5027                    else {
5028                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5029                    }
5030    
5031                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5032    
5033                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5034    
5035                    if (!getDB().isSupportsInlineDistinct()) {
5036                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5037                    }
5038    
5039                    if (orderByComparator != null) {
5040                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5041    
5042                            if (orderByConditionFields.length > 0) {
5043                                    query.append(WHERE_AND);
5044                            }
5045    
5046                            for (int i = 0; i < orderByConditionFields.length; i++) {
5047                                    if (getDB().isSupportsInlineDistinct()) {
5048                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5049                                    }
5050                                    else {
5051                                            query.append(_ORDER_BY_ENTITY_TABLE);
5052                                    }
5053    
5054                                    query.append(orderByConditionFields[i]);
5055    
5056                                    if ((i + 1) < orderByConditionFields.length) {
5057                                            if (orderByComparator.isAscending() ^ previous) {
5058                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5059                                            }
5060                                            else {
5061                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5062                                            }
5063                                    }
5064                                    else {
5065                                            if (orderByComparator.isAscending() ^ previous) {
5066                                                    query.append(WHERE_GREATER_THAN);
5067                                            }
5068                                            else {
5069                                                    query.append(WHERE_LESSER_THAN);
5070                                            }
5071                                    }
5072                            }
5073    
5074                            query.append(ORDER_BY_CLAUSE);
5075    
5076                            String[] orderByFields = orderByComparator.getOrderByFields();
5077    
5078                            for (int i = 0; i < orderByFields.length; i++) {
5079                                    if (getDB().isSupportsInlineDistinct()) {
5080                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5081                                    }
5082                                    else {
5083                                            query.append(_ORDER_BY_ENTITY_TABLE);
5084                                    }
5085    
5086                                    query.append(orderByFields[i]);
5087    
5088                                    if ((i + 1) < orderByFields.length) {
5089                                            if (orderByComparator.isAscending() ^ previous) {
5090                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5091                                            }
5092                                            else {
5093                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5094                                            }
5095                                    }
5096                                    else {
5097                                            if (orderByComparator.isAscending() ^ previous) {
5098                                                    query.append(ORDER_BY_ASC);
5099                                            }
5100                                            else {
5101                                                    query.append(ORDER_BY_DESC);
5102                                            }
5103                                    }
5104                            }
5105                    }
5106                    else {
5107                            if (getDB().isSupportsInlineDistinct()) {
5108                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5109                            }
5110                            else {
5111                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5112                            }
5113                    }
5114    
5115                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5116                                    MBMessage.class.getName(),
5117                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5118    
5119                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5120    
5121                    q.setFirstResult(0);
5122                    q.setMaxResults(2);
5123    
5124                    if (getDB().isSupportsInlineDistinct()) {
5125                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5126                    }
5127                    else {
5128                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5129                    }
5130    
5131                    QueryPos qPos = QueryPos.getInstance(q);
5132    
5133                    qPos.add(groupId);
5134    
5135                    qPos.add(userId);
5136    
5137                    if (orderByComparator != null) {
5138                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5139    
5140                            for (Object value : values) {
5141                                    qPos.add(value);
5142                            }
5143                    }
5144    
5145                    List<MBMessage> list = q.list();
5146    
5147                    if (list.size() == 2) {
5148                            return list.get(1);
5149                    }
5150                    else {
5151                            return null;
5152                    }
5153            }
5154    
5155            /**
5156             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
5157             *
5158             * @param groupId the group ID
5159             * @param userId the user ID
5160             */
5161            @Override
5162            public void removeByG_U(long groupId, long userId) {
5163                    for (MBMessage mbMessage : findByG_U(groupId, userId,
5164                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5165                            remove(mbMessage);
5166                    }
5167            }
5168    
5169            /**
5170             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
5171             *
5172             * @param groupId the group ID
5173             * @param userId the user ID
5174             * @return the number of matching message-boards messages
5175             */
5176            @Override
5177            public int countByG_U(long groupId, long userId) {
5178                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
5179    
5180                    Object[] finderArgs = new Object[] { groupId, userId };
5181    
5182                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5183    
5184                    if (count == null) {
5185                            StringBundler query = new StringBundler(3);
5186    
5187                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5188    
5189                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5190    
5191                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5192    
5193                            String sql = query.toString();
5194    
5195                            Session session = null;
5196    
5197                            try {
5198                                    session = openSession();
5199    
5200                                    Query q = session.createQuery(sql);
5201    
5202                                    QueryPos qPos = QueryPos.getInstance(q);
5203    
5204                                    qPos.add(groupId);
5205    
5206                                    qPos.add(userId);
5207    
5208                                    count = (Long)q.uniqueResult();
5209    
5210                                    finderCache.putResult(finderPath, finderArgs, count);
5211                            }
5212                            catch (Exception e) {
5213                                    finderCache.removeResult(finderPath, finderArgs);
5214    
5215                                    throw processException(e);
5216                            }
5217                            finally {
5218                                    closeSession(session);
5219                            }
5220                    }
5221    
5222                    return count.intValue();
5223            }
5224    
5225            /**
5226             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5227             *
5228             * @param groupId the group ID
5229             * @param userId the user ID
5230             * @return the number of matching message-boards messages that the user has permission to view
5231             */
5232            @Override
5233            public int filterCountByG_U(long groupId, long userId) {
5234                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5235                            return countByG_U(groupId, userId);
5236                    }
5237    
5238                    StringBundler query = new StringBundler(3);
5239    
5240                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5241    
5242                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5243    
5244                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5245    
5246                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5247                                    MBMessage.class.getName(),
5248                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5249    
5250                    Session session = null;
5251    
5252                    try {
5253                            session = openSession();
5254    
5255                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5256    
5257                            q.addScalar(COUNT_COLUMN_NAME,
5258                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5259    
5260                            QueryPos qPos = QueryPos.getInstance(q);
5261    
5262                            qPos.add(groupId);
5263    
5264                            qPos.add(userId);
5265    
5266                            Long count = (Long)q.uniqueResult();
5267    
5268                            return count.intValue();
5269                    }
5270                    catch (Exception e) {
5271                            throw processException(e);
5272                    }
5273                    finally {
5274                            closeSession(session);
5275                    }
5276            }
5277    
5278            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5279            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5280            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5281                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5282                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5283                            new String[] {
5284                                    Long.class.getName(), Long.class.getName(),
5285                                    
5286                            Integer.class.getName(), Integer.class.getName(),
5287                                    OrderByComparator.class.getName()
5288                            });
5289            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5290                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5291                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5292                            new String[] { Long.class.getName(), Long.class.getName() },
5293                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5294                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5295                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5296            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5297                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5298                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5299                            new String[] { Long.class.getName(), Long.class.getName() });
5300    
5301            /**
5302             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5303             *
5304             * @param groupId the group ID
5305             * @param categoryId the category ID
5306             * @return the matching message-boards messages
5307             */
5308            @Override
5309            public List<MBMessage> findByG_C(long groupId, long categoryId) {
5310                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5311                            QueryUtil.ALL_POS, null);
5312            }
5313    
5314            /**
5315             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5316             *
5317             * <p>
5318             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5319             * </p>
5320             *
5321             * @param groupId the group ID
5322             * @param categoryId the category ID
5323             * @param start the lower bound of the range of message-boards messages
5324             * @param end the upper bound of the range of message-boards messages (not inclusive)
5325             * @return the range of matching message-boards messages
5326             */
5327            @Override
5328            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5329                    int end) {
5330                    return findByG_C(groupId, categoryId, start, end, null);
5331            }
5332    
5333            /**
5334             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5335             *
5336             * <p>
5337             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5338             * </p>
5339             *
5340             * @param groupId the group ID
5341             * @param categoryId the category ID
5342             * @param start the lower bound of the range of message-boards messages
5343             * @param end the upper bound of the range of message-boards messages (not inclusive)
5344             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5345             * @return the ordered range of matching message-boards messages
5346             */
5347            @Override
5348            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5349                    int end, OrderByComparator<MBMessage> orderByComparator) {
5350                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
5351                            true);
5352            }
5353    
5354            /**
5355             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5356             *
5357             * <p>
5358             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5359             * </p>
5360             *
5361             * @param groupId the group ID
5362             * @param categoryId the category ID
5363             * @param start the lower bound of the range of message-boards messages
5364             * @param end the upper bound of the range of message-boards messages (not inclusive)
5365             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5366             * @param retrieveFromCache whether to retrieve from the finder cache
5367             * @return the ordered range of matching message-boards messages
5368             */
5369            @Override
5370            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5371                    int end, OrderByComparator<MBMessage> orderByComparator,
5372                    boolean retrieveFromCache) {
5373                    boolean pagination = true;
5374                    FinderPath finderPath = null;
5375                    Object[] finderArgs = null;
5376    
5377                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5378                                    (orderByComparator == null)) {
5379                            pagination = false;
5380                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5381                            finderArgs = new Object[] { groupId, categoryId };
5382                    }
5383                    else {
5384                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5385                            finderArgs = new Object[] {
5386                                            groupId, categoryId,
5387                                            
5388                                            start, end, orderByComparator
5389                                    };
5390                    }
5391    
5392                    List<MBMessage> list = null;
5393    
5394                    if (retrieveFromCache) {
5395                            list = (List<MBMessage>)finderCache.getResult(finderPath,
5396                                            finderArgs, this);
5397    
5398                            if ((list != null) && !list.isEmpty()) {
5399                                    for (MBMessage mbMessage : list) {
5400                                            if ((groupId != mbMessage.getGroupId()) ||
5401                                                            (categoryId != mbMessage.getCategoryId())) {
5402                                                    list = null;
5403    
5404                                                    break;
5405                                            }
5406                                    }
5407                            }
5408                    }
5409    
5410                    if (list == null) {
5411                            StringBundler query = null;
5412    
5413                            if (orderByComparator != null) {
5414                                    query = new StringBundler(4 +
5415                                                    (orderByComparator.getOrderByFields().length * 2));
5416                            }
5417                            else {
5418                                    query = new StringBundler(4);
5419                            }
5420    
5421                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5422    
5423                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5424    
5425                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5426    
5427                            if (orderByComparator != null) {
5428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5429                                            orderByComparator);
5430                            }
5431                            else
5432                             if (pagination) {
5433                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5434                            }
5435    
5436                            String sql = query.toString();
5437    
5438                            Session session = null;
5439    
5440                            try {
5441                                    session = openSession();
5442    
5443                                    Query q = session.createQuery(sql);
5444    
5445                                    QueryPos qPos = QueryPos.getInstance(q);
5446    
5447                                    qPos.add(groupId);
5448    
5449                                    qPos.add(categoryId);
5450    
5451                                    if (!pagination) {
5452                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5453                                                            start, end, false);
5454    
5455                                            Collections.sort(list);
5456    
5457                                            list = Collections.unmodifiableList(list);
5458                                    }
5459                                    else {
5460                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5461                                                            start, end);
5462                                    }
5463    
5464                                    cacheResult(list);
5465    
5466                                    finderCache.putResult(finderPath, finderArgs, list);
5467                            }
5468                            catch (Exception e) {
5469                                    finderCache.removeResult(finderPath, finderArgs);
5470    
5471                                    throw processException(e);
5472                            }
5473                            finally {
5474                                    closeSession(session);
5475                            }
5476                    }
5477    
5478                    return list;
5479            }
5480    
5481            /**
5482             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5483             *
5484             * @param groupId the group ID
5485             * @param categoryId the category ID
5486             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5487             * @return the first matching message-boards message
5488             * @throws NoSuchMessageException if a matching message-boards message could not be found
5489             */
5490            @Override
5491            public MBMessage findByG_C_First(long groupId, long categoryId,
5492                    OrderByComparator<MBMessage> orderByComparator)
5493                    throws NoSuchMessageException {
5494                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5495                                    orderByComparator);
5496    
5497                    if (mbMessage != null) {
5498                            return mbMessage;
5499                    }
5500    
5501                    StringBundler msg = new StringBundler(6);
5502    
5503                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5504    
5505                    msg.append("groupId=");
5506                    msg.append(groupId);
5507    
5508                    msg.append(", categoryId=");
5509                    msg.append(categoryId);
5510    
5511                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5512    
5513                    throw new NoSuchMessageException(msg.toString());
5514            }
5515    
5516            /**
5517             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5518             *
5519             * @param groupId the group ID
5520             * @param categoryId the category ID
5521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5522             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5523             */
5524            @Override
5525            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5526                    OrderByComparator<MBMessage> orderByComparator) {
5527                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5528                                    orderByComparator);
5529    
5530                    if (!list.isEmpty()) {
5531                            return list.get(0);
5532                    }
5533    
5534                    return null;
5535            }
5536    
5537            /**
5538             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5539             *
5540             * @param groupId the group ID
5541             * @param categoryId the category ID
5542             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5543             * @return the last matching message-boards message
5544             * @throws NoSuchMessageException if a matching message-boards message could not be found
5545             */
5546            @Override
5547            public MBMessage findByG_C_Last(long groupId, long categoryId,
5548                    OrderByComparator<MBMessage> orderByComparator)
5549                    throws NoSuchMessageException {
5550                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5551                                    orderByComparator);
5552    
5553                    if (mbMessage != null) {
5554                            return mbMessage;
5555                    }
5556    
5557                    StringBundler msg = new StringBundler(6);
5558    
5559                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5560    
5561                    msg.append("groupId=");
5562                    msg.append(groupId);
5563    
5564                    msg.append(", categoryId=");
5565                    msg.append(categoryId);
5566    
5567                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5568    
5569                    throw new NoSuchMessageException(msg.toString());
5570            }
5571    
5572            /**
5573             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5574             *
5575             * @param groupId the group ID
5576             * @param categoryId the category ID
5577             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5578             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5579             */
5580            @Override
5581            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5582                    OrderByComparator<MBMessage> orderByComparator) {
5583                    int count = countByG_C(groupId, categoryId);
5584    
5585                    if (count == 0) {
5586                            return null;
5587                    }
5588    
5589                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5590                                    orderByComparator);
5591    
5592                    if (!list.isEmpty()) {
5593                            return list.get(0);
5594                    }
5595    
5596                    return null;
5597            }
5598    
5599            /**
5600             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5601             *
5602             * @param messageId the primary key of the current message-boards message
5603             * @param groupId the group ID
5604             * @param categoryId the category ID
5605             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5606             * @return the previous, current, and next message-boards message
5607             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5608             */
5609            @Override
5610            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5611                    long categoryId, OrderByComparator<MBMessage> orderByComparator)
5612                    throws NoSuchMessageException {
5613                    MBMessage mbMessage = findByPrimaryKey(messageId);
5614    
5615                    Session session = null;
5616    
5617                    try {
5618                            session = openSession();
5619    
5620                            MBMessage[] array = new MBMessageImpl[3];
5621    
5622                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5623                                            categoryId, orderByComparator, true);
5624    
5625                            array[1] = mbMessage;
5626    
5627                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5628                                            categoryId, orderByComparator, false);
5629    
5630                            return array;
5631                    }
5632                    catch (Exception e) {
5633                            throw processException(e);
5634                    }
5635                    finally {
5636                            closeSession(session);
5637                    }
5638            }
5639    
5640            protected MBMessage getByG_C_PrevAndNext(Session session,
5641                    MBMessage mbMessage, long groupId, long categoryId,
5642                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5643                    StringBundler query = null;
5644    
5645                    if (orderByComparator != null) {
5646                            query = new StringBundler(5 +
5647                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5648                                            (orderByComparator.getOrderByFields().length * 3));
5649                    }
5650                    else {
5651                            query = new StringBundler(4);
5652                    }
5653    
5654                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5655    
5656                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5657    
5658                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5659    
5660                    if (orderByComparator != null) {
5661                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5662    
5663                            if (orderByConditionFields.length > 0) {
5664                                    query.append(WHERE_AND);
5665                            }
5666    
5667                            for (int i = 0; i < orderByConditionFields.length; i++) {
5668                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5669                                    query.append(orderByConditionFields[i]);
5670    
5671                                    if ((i + 1) < orderByConditionFields.length) {
5672                                            if (orderByComparator.isAscending() ^ previous) {
5673                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5674                                            }
5675                                            else {
5676                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5677                                            }
5678                                    }
5679                                    else {
5680                                            if (orderByComparator.isAscending() ^ previous) {
5681                                                    query.append(WHERE_GREATER_THAN);
5682                                            }
5683                                            else {
5684                                                    query.append(WHERE_LESSER_THAN);
5685                                            }
5686                                    }
5687                            }
5688    
5689                            query.append(ORDER_BY_CLAUSE);
5690    
5691                            String[] orderByFields = orderByComparator.getOrderByFields();
5692    
5693                            for (int i = 0; i < orderByFields.length; i++) {
5694                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5695                                    query.append(orderByFields[i]);
5696    
5697                                    if ((i + 1) < orderByFields.length) {
5698                                            if (orderByComparator.isAscending() ^ previous) {
5699                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5700                                            }
5701                                            else {
5702                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5703                                            }
5704                                    }
5705                                    else {
5706                                            if (orderByComparator.isAscending() ^ previous) {
5707                                                    query.append(ORDER_BY_ASC);
5708                                            }
5709                                            else {
5710                                                    query.append(ORDER_BY_DESC);
5711                                            }
5712                                    }
5713                            }
5714                    }
5715                    else {
5716                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5717                    }
5718    
5719                    String sql = query.toString();
5720    
5721                    Query q = session.createQuery(sql);
5722    
5723                    q.setFirstResult(0);
5724                    q.setMaxResults(2);
5725    
5726                    QueryPos qPos = QueryPos.getInstance(q);
5727    
5728                    qPos.add(groupId);
5729    
5730                    qPos.add(categoryId);
5731    
5732                    if (orderByComparator != null) {
5733                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5734    
5735                            for (Object value : values) {
5736                                    qPos.add(value);
5737                            }
5738                    }
5739    
5740                    List<MBMessage> list = q.list();
5741    
5742                    if (list.size() == 2) {
5743                            return list.get(1);
5744                    }
5745                    else {
5746                            return null;
5747                    }
5748            }
5749    
5750            /**
5751             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5752             *
5753             * @param groupId the group ID
5754             * @param categoryId the category ID
5755             * @return the matching message-boards messages that the user has permission to view
5756             */
5757            @Override
5758            public List<MBMessage> filterFindByG_C(long groupId, long categoryId) {
5759                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5760                            QueryUtil.ALL_POS, null);
5761            }
5762    
5763            /**
5764             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5765             *
5766             * <p>
5767             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5768             * </p>
5769             *
5770             * @param groupId the group ID
5771             * @param categoryId the category ID
5772             * @param start the lower bound of the range of message-boards messages
5773             * @param end the upper bound of the range of message-boards messages (not inclusive)
5774             * @return the range of matching message-boards messages that the user has permission to view
5775             */
5776            @Override
5777            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5778                    int start, int end) {
5779                    return filterFindByG_C(groupId, categoryId, start, end, null);
5780            }
5781    
5782            /**
5783             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5784             *
5785             * <p>
5786             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5787             * </p>
5788             *
5789             * @param groupId the group ID
5790             * @param categoryId the category ID
5791             * @param start the lower bound of the range of message-boards messages
5792             * @param end the upper bound of the range of message-boards messages (not inclusive)
5793             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5794             * @return the ordered range of matching message-boards messages that the user has permission to view
5795             */
5796            @Override
5797            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5798                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
5799                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5800                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5801                    }
5802    
5803                    StringBundler query = null;
5804    
5805                    if (orderByComparator != null) {
5806                            query = new StringBundler(4 +
5807                                            (orderByComparator.getOrderByFields().length * 2));
5808                    }
5809                    else {
5810                            query = new StringBundler(5);
5811                    }
5812    
5813                    if (getDB().isSupportsInlineDistinct()) {
5814                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5815                    }
5816                    else {
5817                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5818                    }
5819    
5820                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5821    
5822                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5823    
5824                    if (!getDB().isSupportsInlineDistinct()) {
5825                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5826                    }
5827    
5828                    if (orderByComparator != null) {
5829                            if (getDB().isSupportsInlineDistinct()) {
5830                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5831                                            orderByComparator, true);
5832                            }
5833                            else {
5834                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5835                                            orderByComparator, true);
5836                            }
5837                    }
5838                    else {
5839                            if (getDB().isSupportsInlineDistinct()) {
5840                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5841                            }
5842                            else {
5843                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5844                            }
5845                    }
5846    
5847                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5848                                    MBMessage.class.getName(),
5849                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5850    
5851                    Session session = null;
5852    
5853                    try {
5854                            session = openSession();
5855    
5856                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5857    
5858                            if (getDB().isSupportsInlineDistinct()) {
5859                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5860                            }
5861                            else {
5862                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5863                            }
5864    
5865                            QueryPos qPos = QueryPos.getInstance(q);
5866    
5867                            qPos.add(groupId);
5868    
5869                            qPos.add(categoryId);
5870    
5871                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5872                    }
5873                    catch (Exception e) {
5874                            throw processException(e);
5875                    }
5876                    finally {
5877                            closeSession(session);
5878                    }
5879            }
5880    
5881            /**
5882             * 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;.
5883             *
5884             * @param messageId the primary key of the current message-boards message
5885             * @param groupId the group ID
5886             * @param categoryId the category ID
5887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5888             * @return the previous, current, and next message-boards message
5889             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
5890             */
5891            @Override
5892            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5893                    long groupId, long categoryId,
5894                    OrderByComparator<MBMessage> orderByComparator)
5895                    throws NoSuchMessageException {
5896                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5897                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5898                                    orderByComparator);
5899                    }
5900    
5901                    MBMessage mbMessage = findByPrimaryKey(messageId);
5902    
5903                    Session session = null;
5904    
5905                    try {
5906                            session = openSession();
5907    
5908                            MBMessage[] array = new MBMessageImpl[3];
5909    
5910                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5911                                            categoryId, orderByComparator, true);
5912    
5913                            array[1] = mbMessage;
5914    
5915                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5916                                            categoryId, orderByComparator, false);
5917    
5918                            return array;
5919                    }
5920                    catch (Exception e) {
5921                            throw processException(e);
5922                    }
5923                    finally {
5924                            closeSession(session);
5925                    }
5926            }
5927    
5928            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5929                    MBMessage mbMessage, long groupId, long categoryId,
5930                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
5931                    StringBundler query = null;
5932    
5933                    if (orderByComparator != null) {
5934                            query = new StringBundler(6 +
5935                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5936                                            (orderByComparator.getOrderByFields().length * 3));
5937                    }
5938                    else {
5939                            query = new StringBundler(5);
5940                    }
5941    
5942                    if (getDB().isSupportsInlineDistinct()) {
5943                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5944                    }
5945                    else {
5946                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5947                    }
5948    
5949                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5950    
5951                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5952    
5953                    if (!getDB().isSupportsInlineDistinct()) {
5954                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5955                    }
5956    
5957                    if (orderByComparator != null) {
5958                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5959    
5960                            if (orderByConditionFields.length > 0) {
5961                                    query.append(WHERE_AND);
5962                            }
5963    
5964                            for (int i = 0; i < orderByConditionFields.length; i++) {
5965                                    if (getDB().isSupportsInlineDistinct()) {
5966                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5967                                    }
5968                                    else {
5969                                            query.append(_ORDER_BY_ENTITY_TABLE);
5970                                    }
5971    
5972                                    query.append(orderByConditionFields[i]);
5973    
5974                                    if ((i + 1) < orderByConditionFields.length) {
5975                                            if (orderByComparator.isAscending() ^ previous) {
5976                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5977                                            }
5978                                            else {
5979                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5980                                            }
5981                                    }
5982                                    else {
5983                                            if (orderByComparator.isAscending() ^ previous) {
5984                                                    query.append(WHERE_GREATER_THAN);
5985                                            }
5986                                            else {
5987                                                    query.append(WHERE_LESSER_THAN);
5988                                            }
5989                                    }
5990                            }
5991    
5992                            query.append(ORDER_BY_CLAUSE);
5993    
5994                            String[] orderByFields = orderByComparator.getOrderByFields();
5995    
5996                            for (int i = 0; i < orderByFields.length; i++) {
5997                                    if (getDB().isSupportsInlineDistinct()) {
5998                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5999                                    }
6000                                    else {
6001                                            query.append(_ORDER_BY_ENTITY_TABLE);
6002                                    }
6003    
6004                                    query.append(orderByFields[i]);
6005    
6006                                    if ((i + 1) < orderByFields.length) {
6007                                            if (orderByComparator.isAscending() ^ previous) {
6008                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6009                                            }
6010                                            else {
6011                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6012                                            }
6013                                    }
6014                                    else {
6015                                            if (orderByComparator.isAscending() ^ previous) {
6016                                                    query.append(ORDER_BY_ASC);
6017                                            }
6018                                            else {
6019                                                    query.append(ORDER_BY_DESC);
6020                                            }
6021                                    }
6022                            }
6023                    }
6024                    else {
6025                            if (getDB().isSupportsInlineDistinct()) {
6026                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6027                            }
6028                            else {
6029                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6030                            }
6031                    }
6032    
6033                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6034                                    MBMessage.class.getName(),
6035                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6036    
6037                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6038    
6039                    q.setFirstResult(0);
6040                    q.setMaxResults(2);
6041    
6042                    if (getDB().isSupportsInlineDistinct()) {
6043                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6044                    }
6045                    else {
6046                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6047                    }
6048    
6049                    QueryPos qPos = QueryPos.getInstance(q);
6050    
6051                    qPos.add(groupId);
6052    
6053                    qPos.add(categoryId);
6054    
6055                    if (orderByComparator != null) {
6056                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6057    
6058                            for (Object value : values) {
6059                                    qPos.add(value);
6060                            }
6061                    }
6062    
6063                    List<MBMessage> list = q.list();
6064    
6065                    if (list.size() == 2) {
6066                            return list.get(1);
6067                    }
6068                    else {
6069                            return null;
6070                    }
6071            }
6072    
6073            /**
6074             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
6075             *
6076             * @param groupId the group ID
6077             * @param categoryId the category ID
6078             */
6079            @Override
6080            public void removeByG_C(long groupId, long categoryId) {
6081                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
6082                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6083                            remove(mbMessage);
6084                    }
6085            }
6086    
6087            /**
6088             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
6089             *
6090             * @param groupId the group ID
6091             * @param categoryId the category ID
6092             * @return the number of matching message-boards messages
6093             */
6094            @Override
6095            public int countByG_C(long groupId, long categoryId) {
6096                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6097    
6098                    Object[] finderArgs = new Object[] { groupId, categoryId };
6099    
6100                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6101    
6102                    if (count == null) {
6103                            StringBundler query = new StringBundler(3);
6104    
6105                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6106    
6107                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6108    
6109                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6110    
6111                            String sql = query.toString();
6112    
6113                            Session session = null;
6114    
6115                            try {
6116                                    session = openSession();
6117    
6118                                    Query q = session.createQuery(sql);
6119    
6120                                    QueryPos qPos = QueryPos.getInstance(q);
6121    
6122                                    qPos.add(groupId);
6123    
6124                                    qPos.add(categoryId);
6125    
6126                                    count = (Long)q.uniqueResult();
6127    
6128                                    finderCache.putResult(finderPath, finderArgs, count);
6129                            }
6130                            catch (Exception e) {
6131                                    finderCache.removeResult(finderPath, finderArgs);
6132    
6133                                    throw processException(e);
6134                            }
6135                            finally {
6136                                    closeSession(session);
6137                            }
6138                    }
6139    
6140                    return count.intValue();
6141            }
6142    
6143            /**
6144             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6145             *
6146             * @param groupId the group ID
6147             * @param categoryId the category ID
6148             * @return the number of matching message-boards messages that the user has permission to view
6149             */
6150            @Override
6151            public int filterCountByG_C(long groupId, long categoryId) {
6152                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6153                            return countByG_C(groupId, categoryId);
6154                    }
6155    
6156                    StringBundler query = new StringBundler(3);
6157    
6158                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6159    
6160                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6161    
6162                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6163    
6164                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6165                                    MBMessage.class.getName(),
6166                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6167    
6168                    Session session = null;
6169    
6170                    try {
6171                            session = openSession();
6172    
6173                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6174    
6175                            q.addScalar(COUNT_COLUMN_NAME,
6176                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6177    
6178                            QueryPos qPos = QueryPos.getInstance(q);
6179    
6180                            qPos.add(groupId);
6181    
6182                            qPos.add(categoryId);
6183    
6184                            Long count = (Long)q.uniqueResult();
6185    
6186                            return count.intValue();
6187                    }
6188                    catch (Exception e) {
6189                            throw processException(e);
6190                    }
6191                    finally {
6192                            closeSession(session);
6193                    }
6194            }
6195    
6196            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
6197            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
6198            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6199                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6200                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
6201                            new String[] {
6202                                    Long.class.getName(), Integer.class.getName(),
6203                                    
6204                            Integer.class.getName(), Integer.class.getName(),
6205                                    OrderByComparator.class.getName()
6206                            });
6207            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
6210                            new String[] { Long.class.getName(), Integer.class.getName() },
6211                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
6212                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6213                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6214            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6215                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6216                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
6217                            new String[] { Long.class.getName(), Integer.class.getName() });
6218    
6219            /**
6220             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6221             *
6222             * @param groupId the group ID
6223             * @param status the status
6224             * @return the matching message-boards messages
6225             */
6226            @Override
6227            public List<MBMessage> findByG_S(long groupId, int status) {
6228                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6229                            null);
6230            }
6231    
6232            /**
6233             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6234             *
6235             * <p>
6236             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6237             * </p>
6238             *
6239             * @param groupId the group ID
6240             * @param status the status
6241             * @param start the lower bound of the range of message-boards messages
6242             * @param end the upper bound of the range of message-boards messages (not inclusive)
6243             * @return the range of matching message-boards messages
6244             */
6245            @Override
6246            public List<MBMessage> findByG_S(long groupId, int status, int start,
6247                    int end) {
6248                    return findByG_S(groupId, status, start, end, null);
6249            }
6250    
6251            /**
6252             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6253             *
6254             * <p>
6255             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6256             * </p>
6257             *
6258             * @param groupId the group ID
6259             * @param status the status
6260             * @param start the lower bound of the range of message-boards messages
6261             * @param end the upper bound of the range of message-boards messages (not inclusive)
6262             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6263             * @return the ordered range of matching message-boards messages
6264             */
6265            @Override
6266            public List<MBMessage> findByG_S(long groupId, int status, int start,
6267                    int end, OrderByComparator<MBMessage> orderByComparator) {
6268                    return findByG_S(groupId, status, start, end, orderByComparator, true);
6269            }
6270    
6271            /**
6272             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6273             *
6274             * <p>
6275             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6276             * </p>
6277             *
6278             * @param groupId the group ID
6279             * @param status the status
6280             * @param start the lower bound of the range of message-boards messages
6281             * @param end the upper bound of the range of message-boards messages (not inclusive)
6282             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6283             * @param retrieveFromCache whether to retrieve from the finder cache
6284             * @return the ordered range of matching message-boards messages
6285             */
6286            @Override
6287            public List<MBMessage> findByG_S(long groupId, int status, int start,
6288                    int end, OrderByComparator<MBMessage> orderByComparator,
6289                    boolean retrieveFromCache) {
6290                    boolean pagination = true;
6291                    FinderPath finderPath = null;
6292                    Object[] finderArgs = null;
6293    
6294                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6295                                    (orderByComparator == null)) {
6296                            pagination = false;
6297                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6298                            finderArgs = new Object[] { groupId, status };
6299                    }
6300                    else {
6301                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6302                            finderArgs = new Object[] {
6303                                            groupId, status,
6304                                            
6305                                            start, end, orderByComparator
6306                                    };
6307                    }
6308    
6309                    List<MBMessage> list = null;
6310    
6311                    if (retrieveFromCache) {
6312                            list = (List<MBMessage>)finderCache.getResult(finderPath,
6313                                            finderArgs, this);
6314    
6315                            if ((list != null) && !list.isEmpty()) {
6316                                    for (MBMessage mbMessage : list) {
6317                                            if ((groupId != mbMessage.getGroupId()) ||
6318                                                            (status != mbMessage.getStatus())) {
6319                                                    list = null;
6320    
6321                                                    break;
6322                                            }
6323                                    }
6324                            }
6325                    }
6326    
6327                    if (list == null) {
6328                            StringBundler query = null;
6329    
6330                            if (orderByComparator != null) {
6331                                    query = new StringBundler(4 +
6332                                                    (orderByComparator.getOrderByFields().length * 2));
6333                            }
6334                            else {
6335                                    query = new StringBundler(4);
6336                            }
6337    
6338                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6339    
6340                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6341    
6342                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6343    
6344                            if (orderByComparator != null) {
6345                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6346                                            orderByComparator);
6347                            }
6348                            else
6349                             if (pagination) {
6350                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6351                            }
6352    
6353                            String sql = query.toString();
6354    
6355                            Session session = null;
6356    
6357                            try {
6358                                    session = openSession();
6359    
6360                                    Query q = session.createQuery(sql);
6361    
6362                                    QueryPos qPos = QueryPos.getInstance(q);
6363    
6364                                    qPos.add(groupId);
6365    
6366                                    qPos.add(status);
6367    
6368                                    if (!pagination) {
6369                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6370                                                            start, end, false);
6371    
6372                                            Collections.sort(list);
6373    
6374                                            list = Collections.unmodifiableList(list);
6375                                    }
6376                                    else {
6377                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6378                                                            start, end);
6379                                    }
6380    
6381                                    cacheResult(list);
6382    
6383                                    finderCache.putResult(finderPath, finderArgs, list);
6384                            }
6385                            catch (Exception e) {
6386                                    finderCache.removeResult(finderPath, finderArgs);
6387    
6388                                    throw processException(e);
6389                            }
6390                            finally {
6391                                    closeSession(session);
6392                            }
6393                    }
6394    
6395                    return list;
6396            }
6397    
6398            /**
6399             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6400             *
6401             * @param groupId the group ID
6402             * @param status the status
6403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6404             * @return the first matching message-boards message
6405             * @throws NoSuchMessageException if a matching message-boards message could not be found
6406             */
6407            @Override
6408            public MBMessage findByG_S_First(long groupId, int status,
6409                    OrderByComparator<MBMessage> orderByComparator)
6410                    throws NoSuchMessageException {
6411                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6412                                    orderByComparator);
6413    
6414                    if (mbMessage != null) {
6415                            return mbMessage;
6416                    }
6417    
6418                    StringBundler msg = new StringBundler(6);
6419    
6420                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6421    
6422                    msg.append("groupId=");
6423                    msg.append(groupId);
6424    
6425                    msg.append(", status=");
6426                    msg.append(status);
6427    
6428                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6429    
6430                    throw new NoSuchMessageException(msg.toString());
6431            }
6432    
6433            /**
6434             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6435             *
6436             * @param groupId the group ID
6437             * @param status the status
6438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6439             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6440             */
6441            @Override
6442            public MBMessage fetchByG_S_First(long groupId, int status,
6443                    OrderByComparator<MBMessage> orderByComparator) {
6444                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6445                                    orderByComparator);
6446    
6447                    if (!list.isEmpty()) {
6448                            return list.get(0);
6449                    }
6450    
6451                    return null;
6452            }
6453    
6454            /**
6455             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6456             *
6457             * @param groupId the group ID
6458             * @param status the status
6459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6460             * @return the last matching message-boards message
6461             * @throws NoSuchMessageException if a matching message-boards message could not be found
6462             */
6463            @Override
6464            public MBMessage findByG_S_Last(long groupId, int status,
6465                    OrderByComparator<MBMessage> orderByComparator)
6466                    throws NoSuchMessageException {
6467                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6468    
6469                    if (mbMessage != null) {
6470                            return mbMessage;
6471                    }
6472    
6473                    StringBundler msg = new StringBundler(6);
6474    
6475                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6476    
6477                    msg.append("groupId=");
6478                    msg.append(groupId);
6479    
6480                    msg.append(", status=");
6481                    msg.append(status);
6482    
6483                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6484    
6485                    throw new NoSuchMessageException(msg.toString());
6486            }
6487    
6488            /**
6489             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6490             *
6491             * @param groupId the group ID
6492             * @param status the status
6493             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6494             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6495             */
6496            @Override
6497            public MBMessage fetchByG_S_Last(long groupId, int status,
6498                    OrderByComparator<MBMessage> orderByComparator) {
6499                    int count = countByG_S(groupId, status);
6500    
6501                    if (count == 0) {
6502                            return null;
6503                    }
6504    
6505                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6506                                    orderByComparator);
6507    
6508                    if (!list.isEmpty()) {
6509                            return list.get(0);
6510                    }
6511    
6512                    return null;
6513            }
6514    
6515            /**
6516             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6517             *
6518             * @param messageId the primary key of the current message-boards message
6519             * @param groupId the group ID
6520             * @param status the status
6521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6522             * @return the previous, current, and next message-boards message
6523             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6524             */
6525            @Override
6526            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6527                    int status, OrderByComparator<MBMessage> orderByComparator)
6528                    throws NoSuchMessageException {
6529                    MBMessage mbMessage = findByPrimaryKey(messageId);
6530    
6531                    Session session = null;
6532    
6533                    try {
6534                            session = openSession();
6535    
6536                            MBMessage[] array = new MBMessageImpl[3];
6537    
6538                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6539                                            status, orderByComparator, true);
6540    
6541                            array[1] = mbMessage;
6542    
6543                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6544                                            status, orderByComparator, false);
6545    
6546                            return array;
6547                    }
6548                    catch (Exception e) {
6549                            throw processException(e);
6550                    }
6551                    finally {
6552                            closeSession(session);
6553                    }
6554            }
6555    
6556            protected MBMessage getByG_S_PrevAndNext(Session session,
6557                    MBMessage mbMessage, long groupId, int status,
6558                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6559                    StringBundler query = null;
6560    
6561                    if (orderByComparator != null) {
6562                            query = new StringBundler(5 +
6563                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6564                                            (orderByComparator.getOrderByFields().length * 3));
6565                    }
6566                    else {
6567                            query = new StringBundler(4);
6568                    }
6569    
6570                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6571    
6572                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6573    
6574                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6575    
6576                    if (orderByComparator != null) {
6577                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6578    
6579                            if (orderByConditionFields.length > 0) {
6580                                    query.append(WHERE_AND);
6581                            }
6582    
6583                            for (int i = 0; i < orderByConditionFields.length; i++) {
6584                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6585                                    query.append(orderByConditionFields[i]);
6586    
6587                                    if ((i + 1) < orderByConditionFields.length) {
6588                                            if (orderByComparator.isAscending() ^ previous) {
6589                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6590                                            }
6591                                            else {
6592                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6593                                            }
6594                                    }
6595                                    else {
6596                                            if (orderByComparator.isAscending() ^ previous) {
6597                                                    query.append(WHERE_GREATER_THAN);
6598                                            }
6599                                            else {
6600                                                    query.append(WHERE_LESSER_THAN);
6601                                            }
6602                                    }
6603                            }
6604    
6605                            query.append(ORDER_BY_CLAUSE);
6606    
6607                            String[] orderByFields = orderByComparator.getOrderByFields();
6608    
6609                            for (int i = 0; i < orderByFields.length; i++) {
6610                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6611                                    query.append(orderByFields[i]);
6612    
6613                                    if ((i + 1) < orderByFields.length) {
6614                                            if (orderByComparator.isAscending() ^ previous) {
6615                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6616                                            }
6617                                            else {
6618                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6619                                            }
6620                                    }
6621                                    else {
6622                                            if (orderByComparator.isAscending() ^ previous) {
6623                                                    query.append(ORDER_BY_ASC);
6624                                            }
6625                                            else {
6626                                                    query.append(ORDER_BY_DESC);
6627                                            }
6628                                    }
6629                            }
6630                    }
6631                    else {
6632                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6633                    }
6634    
6635                    String sql = query.toString();
6636    
6637                    Query q = session.createQuery(sql);
6638    
6639                    q.setFirstResult(0);
6640                    q.setMaxResults(2);
6641    
6642                    QueryPos qPos = QueryPos.getInstance(q);
6643    
6644                    qPos.add(groupId);
6645    
6646                    qPos.add(status);
6647    
6648                    if (orderByComparator != null) {
6649                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6650    
6651                            for (Object value : values) {
6652                                    qPos.add(value);
6653                            }
6654                    }
6655    
6656                    List<MBMessage> list = q.list();
6657    
6658                    if (list.size() == 2) {
6659                            return list.get(1);
6660                    }
6661                    else {
6662                            return null;
6663                    }
6664            }
6665    
6666            /**
6667             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6668             *
6669             * @param groupId the group ID
6670             * @param status the status
6671             * @return the matching message-boards messages that the user has permission to view
6672             */
6673            @Override
6674            public List<MBMessage> filterFindByG_S(long groupId, int status) {
6675                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6676                            QueryUtil.ALL_POS, null);
6677            }
6678    
6679            /**
6680             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6681             *
6682             * <p>
6683             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6684             * </p>
6685             *
6686             * @param groupId the group ID
6687             * @param status the status
6688             * @param start the lower bound of the range of message-boards messages
6689             * @param end the upper bound of the range of message-boards messages (not inclusive)
6690             * @return the range of matching message-boards messages that the user has permission to view
6691             */
6692            @Override
6693            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6694                    int end) {
6695                    return filterFindByG_S(groupId, status, start, end, null);
6696            }
6697    
6698            /**
6699             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6700             *
6701             * <p>
6702             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6703             * </p>
6704             *
6705             * @param groupId the group ID
6706             * @param status the status
6707             * @param start the lower bound of the range of message-boards messages
6708             * @param end the upper bound of the range of message-boards messages (not inclusive)
6709             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6710             * @return the ordered range of matching message-boards messages that the user has permission to view
6711             */
6712            @Override
6713            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6714                    int end, OrderByComparator<MBMessage> orderByComparator) {
6715                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6716                            return findByG_S(groupId, status, start, end, orderByComparator);
6717                    }
6718    
6719                    StringBundler query = null;
6720    
6721                    if (orderByComparator != null) {
6722                            query = new StringBundler(4 +
6723                                            (orderByComparator.getOrderByFields().length * 2));
6724                    }
6725                    else {
6726                            query = new StringBundler(5);
6727                    }
6728    
6729                    if (getDB().isSupportsInlineDistinct()) {
6730                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6731                    }
6732                    else {
6733                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6734                    }
6735    
6736                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6737    
6738                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6739    
6740                    if (!getDB().isSupportsInlineDistinct()) {
6741                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6742                    }
6743    
6744                    if (orderByComparator != null) {
6745                            if (getDB().isSupportsInlineDistinct()) {
6746                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6747                                            orderByComparator, true);
6748                            }
6749                            else {
6750                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6751                                            orderByComparator, true);
6752                            }
6753                    }
6754                    else {
6755                            if (getDB().isSupportsInlineDistinct()) {
6756                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6757                            }
6758                            else {
6759                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6760                            }
6761                    }
6762    
6763                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6764                                    MBMessage.class.getName(),
6765                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6766    
6767                    Session session = null;
6768    
6769                    try {
6770                            session = openSession();
6771    
6772                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6773    
6774                            if (getDB().isSupportsInlineDistinct()) {
6775                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6776                            }
6777                            else {
6778                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6779                            }
6780    
6781                            QueryPos qPos = QueryPos.getInstance(q);
6782    
6783                            qPos.add(groupId);
6784    
6785                            qPos.add(status);
6786    
6787                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6788                    }
6789                    catch (Exception e) {
6790                            throw processException(e);
6791                    }
6792                    finally {
6793                            closeSession(session);
6794                    }
6795            }
6796    
6797            /**
6798             * 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;.
6799             *
6800             * @param messageId the primary key of the current message-boards message
6801             * @param groupId the group ID
6802             * @param status the status
6803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6804             * @return the previous, current, and next message-boards message
6805             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
6806             */
6807            @Override
6808            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6809                    long groupId, int status, OrderByComparator<MBMessage> orderByComparator)
6810                    throws NoSuchMessageException {
6811                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6812                            return findByG_S_PrevAndNext(messageId, groupId, status,
6813                                    orderByComparator);
6814                    }
6815    
6816                    MBMessage mbMessage = findByPrimaryKey(messageId);
6817    
6818                    Session session = null;
6819    
6820                    try {
6821                            session = openSession();
6822    
6823                            MBMessage[] array = new MBMessageImpl[3];
6824    
6825                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6826                                            status, orderByComparator, true);
6827    
6828                            array[1] = mbMessage;
6829    
6830                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6831                                            status, orderByComparator, false);
6832    
6833                            return array;
6834                    }
6835                    catch (Exception e) {
6836                            throw processException(e);
6837                    }
6838                    finally {
6839                            closeSession(session);
6840                    }
6841            }
6842    
6843            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6844                    MBMessage mbMessage, long groupId, int status,
6845                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
6846                    StringBundler query = null;
6847    
6848                    if (orderByComparator != null) {
6849                            query = new StringBundler(6 +
6850                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6851                                            (orderByComparator.getOrderByFields().length * 3));
6852                    }
6853                    else {
6854                            query = new StringBundler(5);
6855                    }
6856    
6857                    if (getDB().isSupportsInlineDistinct()) {
6858                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6859                    }
6860                    else {
6861                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6862                    }
6863    
6864                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6865    
6866                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6867    
6868                    if (!getDB().isSupportsInlineDistinct()) {
6869                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6870                    }
6871    
6872                    if (orderByComparator != null) {
6873                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6874    
6875                            if (orderByConditionFields.length > 0) {
6876                                    query.append(WHERE_AND);
6877                            }
6878    
6879                            for (int i = 0; i < orderByConditionFields.length; i++) {
6880                                    if (getDB().isSupportsInlineDistinct()) {
6881                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6882                                    }
6883                                    else {
6884                                            query.append(_ORDER_BY_ENTITY_TABLE);
6885                                    }
6886    
6887                                    query.append(orderByConditionFields[i]);
6888    
6889                                    if ((i + 1) < orderByConditionFields.length) {
6890                                            if (orderByComparator.isAscending() ^ previous) {
6891                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6892                                            }
6893                                            else {
6894                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6895                                            }
6896                                    }
6897                                    else {
6898                                            if (orderByComparator.isAscending() ^ previous) {
6899                                                    query.append(WHERE_GREATER_THAN);
6900                                            }
6901                                            else {
6902                                                    query.append(WHERE_LESSER_THAN);
6903                                            }
6904                                    }
6905                            }
6906    
6907                            query.append(ORDER_BY_CLAUSE);
6908    
6909                            String[] orderByFields = orderByComparator.getOrderByFields();
6910    
6911                            for (int i = 0; i < orderByFields.length; i++) {
6912                                    if (getDB().isSupportsInlineDistinct()) {
6913                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6914                                    }
6915                                    else {
6916                                            query.append(_ORDER_BY_ENTITY_TABLE);
6917                                    }
6918    
6919                                    query.append(orderByFields[i]);
6920    
6921                                    if ((i + 1) < orderByFields.length) {
6922                                            if (orderByComparator.isAscending() ^ previous) {
6923                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6924                                            }
6925                                            else {
6926                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6927                                            }
6928                                    }
6929                                    else {
6930                                            if (orderByComparator.isAscending() ^ previous) {
6931                                                    query.append(ORDER_BY_ASC);
6932                                            }
6933                                            else {
6934                                                    query.append(ORDER_BY_DESC);
6935                                            }
6936                                    }
6937                            }
6938                    }
6939                    else {
6940                            if (getDB().isSupportsInlineDistinct()) {
6941                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6942                            }
6943                            else {
6944                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6945                            }
6946                    }
6947    
6948                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6949                                    MBMessage.class.getName(),
6950                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6951    
6952                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6953    
6954                    q.setFirstResult(0);
6955                    q.setMaxResults(2);
6956    
6957                    if (getDB().isSupportsInlineDistinct()) {
6958                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6959                    }
6960                    else {
6961                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6962                    }
6963    
6964                    QueryPos qPos = QueryPos.getInstance(q);
6965    
6966                    qPos.add(groupId);
6967    
6968                    qPos.add(status);
6969    
6970                    if (orderByComparator != null) {
6971                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6972    
6973                            for (Object value : values) {
6974                                    qPos.add(value);
6975                            }
6976                    }
6977    
6978                    List<MBMessage> list = q.list();
6979    
6980                    if (list.size() == 2) {
6981                            return list.get(1);
6982                    }
6983                    else {
6984                            return null;
6985                    }
6986            }
6987    
6988            /**
6989             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6990             *
6991             * @param groupId the group ID
6992             * @param status the status
6993             */
6994            @Override
6995            public void removeByG_S(long groupId, int status) {
6996                    for (MBMessage mbMessage : findByG_S(groupId, status,
6997                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6998                            remove(mbMessage);
6999                    }
7000            }
7001    
7002            /**
7003             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
7004             *
7005             * @param groupId the group ID
7006             * @param status the status
7007             * @return the number of matching message-boards messages
7008             */
7009            @Override
7010            public int countByG_S(long groupId, int status) {
7011                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
7012    
7013                    Object[] finderArgs = new Object[] { groupId, status };
7014    
7015                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7016    
7017                    if (count == null) {
7018                            StringBundler query = new StringBundler(3);
7019    
7020                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7021    
7022                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7023    
7024                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
7025    
7026                            String sql = query.toString();
7027    
7028                            Session session = null;
7029    
7030                            try {
7031                                    session = openSession();
7032    
7033                                    Query q = session.createQuery(sql);
7034    
7035                                    QueryPos qPos = QueryPos.getInstance(q);
7036    
7037                                    qPos.add(groupId);
7038    
7039                                    qPos.add(status);
7040    
7041                                    count = (Long)q.uniqueResult();
7042    
7043                                    finderCache.putResult(finderPath, finderArgs, count);
7044                            }
7045                            catch (Exception e) {
7046                                    finderCache.removeResult(finderPath, finderArgs);
7047    
7048                                    throw processException(e);
7049                            }
7050                            finally {
7051                                    closeSession(session);
7052                            }
7053                    }
7054    
7055                    return count.intValue();
7056            }
7057    
7058            /**
7059             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
7060             *
7061             * @param groupId the group ID
7062             * @param status the status
7063             * @return the number of matching message-boards messages that the user has permission to view
7064             */
7065            @Override
7066            public int filterCountByG_S(long groupId, int status) {
7067                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7068                            return countByG_S(groupId, status);
7069                    }
7070    
7071                    StringBundler query = new StringBundler(3);
7072    
7073                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
7074    
7075                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
7076    
7077                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
7078    
7079                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7080                                    MBMessage.class.getName(),
7081                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7082    
7083                    Session session = null;
7084    
7085                    try {
7086                            session = openSession();
7087    
7088                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7089    
7090                            q.addScalar(COUNT_COLUMN_NAME,
7091                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7092    
7093                            QueryPos qPos = QueryPos.getInstance(q);
7094    
7095                            qPos.add(groupId);
7096    
7097                            qPos.add(status);
7098    
7099                            Long count = (Long)q.uniqueResult();
7100    
7101                            return count.intValue();
7102                    }
7103                    catch (Exception e) {
7104                            throw processException(e);
7105                    }
7106                    finally {
7107                            closeSession(session);
7108                    }
7109            }
7110    
7111            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
7112            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7113            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7114                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7115                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
7116                            new String[] {
7117                                    Long.class.getName(), Integer.class.getName(),
7118                                    
7119                            Integer.class.getName(), Integer.class.getName(),
7120                                    OrderByComparator.class.getName()
7121                            });
7122            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7123                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
7125                            new String[] { Long.class.getName(), Integer.class.getName() },
7126                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
7127                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
7128                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7129            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7130                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
7132                            new String[] { Long.class.getName(), Integer.class.getName() });
7133    
7134            /**
7135             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7136             *
7137             * @param companyId the company ID
7138             * @param status the status
7139             * @return the matching message-boards messages
7140             */
7141            @Override
7142            public List<MBMessage> findByC_S(long companyId, int status) {
7143                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7144                            QueryUtil.ALL_POS, null);
7145            }
7146    
7147            /**
7148             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7149             *
7150             * <p>
7151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7152             * </p>
7153             *
7154             * @param companyId the company ID
7155             * @param status the status
7156             * @param start the lower bound of the range of message-boards messages
7157             * @param end the upper bound of the range of message-boards messages (not inclusive)
7158             * @return the range of matching message-boards messages
7159             */
7160            @Override
7161            public List<MBMessage> findByC_S(long companyId, int status, int start,
7162                    int end) {
7163                    return findByC_S(companyId, status, start, end, null);
7164            }
7165    
7166            /**
7167             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7168             *
7169             * <p>
7170             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7171             * </p>
7172             *
7173             * @param companyId the company ID
7174             * @param status the status
7175             * @param start the lower bound of the range of message-boards messages
7176             * @param end the upper bound of the range of message-boards messages (not inclusive)
7177             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7178             * @return the ordered range of matching message-boards messages
7179             */
7180            @Override
7181            public List<MBMessage> findByC_S(long companyId, int status, int start,
7182                    int end, OrderByComparator<MBMessage> orderByComparator) {
7183                    return findByC_S(companyId, status, start, end, orderByComparator, true);
7184            }
7185    
7186            /**
7187             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7188             *
7189             * <p>
7190             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7191             * </p>
7192             *
7193             * @param companyId the company ID
7194             * @param status the status
7195             * @param start the lower bound of the range of message-boards messages
7196             * @param end the upper bound of the range of message-boards messages (not inclusive)
7197             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7198             * @param retrieveFromCache whether to retrieve from the finder cache
7199             * @return the ordered range of matching message-boards messages
7200             */
7201            @Override
7202            public List<MBMessage> findByC_S(long companyId, int status, int start,
7203                    int end, OrderByComparator<MBMessage> orderByComparator,
7204                    boolean retrieveFromCache) {
7205                    boolean pagination = true;
7206                    FinderPath finderPath = null;
7207                    Object[] finderArgs = null;
7208    
7209                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7210                                    (orderByComparator == null)) {
7211                            pagination = false;
7212                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7213                            finderArgs = new Object[] { companyId, status };
7214                    }
7215                    else {
7216                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7217                            finderArgs = new Object[] {
7218                                            companyId, status,
7219                                            
7220                                            start, end, orderByComparator
7221                                    };
7222                    }
7223    
7224                    List<MBMessage> list = null;
7225    
7226                    if (retrieveFromCache) {
7227                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7228                                            finderArgs, this);
7229    
7230                            if ((list != null) && !list.isEmpty()) {
7231                                    for (MBMessage mbMessage : list) {
7232                                            if ((companyId != mbMessage.getCompanyId()) ||
7233                                                            (status != mbMessage.getStatus())) {
7234                                                    list = null;
7235    
7236                                                    break;
7237                                            }
7238                                    }
7239                            }
7240                    }
7241    
7242                    if (list == null) {
7243                            StringBundler query = null;
7244    
7245                            if (orderByComparator != null) {
7246                                    query = new StringBundler(4 +
7247                                                    (orderByComparator.getOrderByFields().length * 2));
7248                            }
7249                            else {
7250                                    query = new StringBundler(4);
7251                            }
7252    
7253                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7254    
7255                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7256    
7257                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7258    
7259                            if (orderByComparator != null) {
7260                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7261                                            orderByComparator);
7262                            }
7263                            else
7264                             if (pagination) {
7265                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7266                            }
7267    
7268                            String sql = query.toString();
7269    
7270                            Session session = null;
7271    
7272                            try {
7273                                    session = openSession();
7274    
7275                                    Query q = session.createQuery(sql);
7276    
7277                                    QueryPos qPos = QueryPos.getInstance(q);
7278    
7279                                    qPos.add(companyId);
7280    
7281                                    qPos.add(status);
7282    
7283                                    if (!pagination) {
7284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7285                                                            start, end, false);
7286    
7287                                            Collections.sort(list);
7288    
7289                                            list = Collections.unmodifiableList(list);
7290                                    }
7291                                    else {
7292                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7293                                                            start, end);
7294                                    }
7295    
7296                                    cacheResult(list);
7297    
7298                                    finderCache.putResult(finderPath, finderArgs, list);
7299                            }
7300                            catch (Exception e) {
7301                                    finderCache.removeResult(finderPath, finderArgs);
7302    
7303                                    throw processException(e);
7304                            }
7305                            finally {
7306                                    closeSession(session);
7307                            }
7308                    }
7309    
7310                    return list;
7311            }
7312    
7313            /**
7314             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7315             *
7316             * @param companyId the company ID
7317             * @param status the status
7318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7319             * @return the first matching message-boards message
7320             * @throws NoSuchMessageException if a matching message-boards message could not be found
7321             */
7322            @Override
7323            public MBMessage findByC_S_First(long companyId, int status,
7324                    OrderByComparator<MBMessage> orderByComparator)
7325                    throws NoSuchMessageException {
7326                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7327                                    orderByComparator);
7328    
7329                    if (mbMessage != null) {
7330                            return mbMessage;
7331                    }
7332    
7333                    StringBundler msg = new StringBundler(6);
7334    
7335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7336    
7337                    msg.append("companyId=");
7338                    msg.append(companyId);
7339    
7340                    msg.append(", status=");
7341                    msg.append(status);
7342    
7343                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7344    
7345                    throw new NoSuchMessageException(msg.toString());
7346            }
7347    
7348            /**
7349             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7350             *
7351             * @param companyId the company ID
7352             * @param status the status
7353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7354             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7355             */
7356            @Override
7357            public MBMessage fetchByC_S_First(long companyId, int status,
7358                    OrderByComparator<MBMessage> orderByComparator) {
7359                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7360                                    orderByComparator);
7361    
7362                    if (!list.isEmpty()) {
7363                            return list.get(0);
7364                    }
7365    
7366                    return null;
7367            }
7368    
7369            /**
7370             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7371             *
7372             * @param companyId the company ID
7373             * @param status the status
7374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7375             * @return the last matching message-boards message
7376             * @throws NoSuchMessageException if a matching message-boards message could not be found
7377             */
7378            @Override
7379            public MBMessage findByC_S_Last(long companyId, int status,
7380                    OrderByComparator<MBMessage> orderByComparator)
7381                    throws NoSuchMessageException {
7382                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7383                                    orderByComparator);
7384    
7385                    if (mbMessage != null) {
7386                            return mbMessage;
7387                    }
7388    
7389                    StringBundler msg = new StringBundler(6);
7390    
7391                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7392    
7393                    msg.append("companyId=");
7394                    msg.append(companyId);
7395    
7396                    msg.append(", status=");
7397                    msg.append(status);
7398    
7399                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7400    
7401                    throw new NoSuchMessageException(msg.toString());
7402            }
7403    
7404            /**
7405             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7406             *
7407             * @param companyId the company ID
7408             * @param status the status
7409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7410             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7411             */
7412            @Override
7413            public MBMessage fetchByC_S_Last(long companyId, int status,
7414                    OrderByComparator<MBMessage> orderByComparator) {
7415                    int count = countByC_S(companyId, status);
7416    
7417                    if (count == 0) {
7418                            return null;
7419                    }
7420    
7421                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7422                                    orderByComparator);
7423    
7424                    if (!list.isEmpty()) {
7425                            return list.get(0);
7426                    }
7427    
7428                    return null;
7429            }
7430    
7431            /**
7432             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7433             *
7434             * @param messageId the primary key of the current message-boards message
7435             * @param companyId the company ID
7436             * @param status the status
7437             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7438             * @return the previous, current, and next message-boards message
7439             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7440             */
7441            @Override
7442            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7443                    int status, OrderByComparator<MBMessage> orderByComparator)
7444                    throws NoSuchMessageException {
7445                    MBMessage mbMessage = findByPrimaryKey(messageId);
7446    
7447                    Session session = null;
7448    
7449                    try {
7450                            session = openSession();
7451    
7452                            MBMessage[] array = new MBMessageImpl[3];
7453    
7454                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7455                                            status, orderByComparator, true);
7456    
7457                            array[1] = mbMessage;
7458    
7459                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7460                                            status, orderByComparator, false);
7461    
7462                            return array;
7463                    }
7464                    catch (Exception e) {
7465                            throw processException(e);
7466                    }
7467                    finally {
7468                            closeSession(session);
7469                    }
7470            }
7471    
7472            protected MBMessage getByC_S_PrevAndNext(Session session,
7473                    MBMessage mbMessage, long companyId, int status,
7474                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
7475                    StringBundler query = null;
7476    
7477                    if (orderByComparator != null) {
7478                            query = new StringBundler(5 +
7479                                            (orderByComparator.getOrderByConditionFields().length * 3) +
7480                                            (orderByComparator.getOrderByFields().length * 3));
7481                    }
7482                    else {
7483                            query = new StringBundler(4);
7484                    }
7485    
7486                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7487    
7488                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7489    
7490                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7491    
7492                    if (orderByComparator != null) {
7493                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7494    
7495                            if (orderByConditionFields.length > 0) {
7496                                    query.append(WHERE_AND);
7497                            }
7498    
7499                            for (int i = 0; i < orderByConditionFields.length; i++) {
7500                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7501                                    query.append(orderByConditionFields[i]);
7502    
7503                                    if ((i + 1) < orderByConditionFields.length) {
7504                                            if (orderByComparator.isAscending() ^ previous) {
7505                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7506                                            }
7507                                            else {
7508                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7509                                            }
7510                                    }
7511                                    else {
7512                                            if (orderByComparator.isAscending() ^ previous) {
7513                                                    query.append(WHERE_GREATER_THAN);
7514                                            }
7515                                            else {
7516                                                    query.append(WHERE_LESSER_THAN);
7517                                            }
7518                                    }
7519                            }
7520    
7521                            query.append(ORDER_BY_CLAUSE);
7522    
7523                            String[] orderByFields = orderByComparator.getOrderByFields();
7524    
7525                            for (int i = 0; i < orderByFields.length; i++) {
7526                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7527                                    query.append(orderByFields[i]);
7528    
7529                                    if ((i + 1) < orderByFields.length) {
7530                                            if (orderByComparator.isAscending() ^ previous) {
7531                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7532                                            }
7533                                            else {
7534                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7535                                            }
7536                                    }
7537                                    else {
7538                                            if (orderByComparator.isAscending() ^ previous) {
7539                                                    query.append(ORDER_BY_ASC);
7540                                            }
7541                                            else {
7542                                                    query.append(ORDER_BY_DESC);
7543                                            }
7544                                    }
7545                            }
7546                    }
7547                    else {
7548                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7549                    }
7550    
7551                    String sql = query.toString();
7552    
7553                    Query q = session.createQuery(sql);
7554    
7555                    q.setFirstResult(0);
7556                    q.setMaxResults(2);
7557    
7558                    QueryPos qPos = QueryPos.getInstance(q);
7559    
7560                    qPos.add(companyId);
7561    
7562                    qPos.add(status);
7563    
7564                    if (orderByComparator != null) {
7565                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7566    
7567                            for (Object value : values) {
7568                                    qPos.add(value);
7569                            }
7570                    }
7571    
7572                    List<MBMessage> list = q.list();
7573    
7574                    if (list.size() == 2) {
7575                            return list.get(1);
7576                    }
7577                    else {
7578                            return null;
7579                    }
7580            }
7581    
7582            /**
7583             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7584             *
7585             * @param companyId the company ID
7586             * @param status the status
7587             */
7588            @Override
7589            public void removeByC_S(long companyId, int status) {
7590                    for (MBMessage mbMessage : findByC_S(companyId, status,
7591                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7592                            remove(mbMessage);
7593                    }
7594            }
7595    
7596            /**
7597             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7598             *
7599             * @param companyId the company ID
7600             * @param status the status
7601             * @return the number of matching message-boards messages
7602             */
7603            @Override
7604            public int countByC_S(long companyId, int status) {
7605                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7606    
7607                    Object[] finderArgs = new Object[] { companyId, status };
7608    
7609                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7610    
7611                    if (count == null) {
7612                            StringBundler query = new StringBundler(3);
7613    
7614                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7615    
7616                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7617    
7618                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7619    
7620                            String sql = query.toString();
7621    
7622                            Session session = null;
7623    
7624                            try {
7625                                    session = openSession();
7626    
7627                                    Query q = session.createQuery(sql);
7628    
7629                                    QueryPos qPos = QueryPos.getInstance(q);
7630    
7631                                    qPos.add(companyId);
7632    
7633                                    qPos.add(status);
7634    
7635                                    count = (Long)q.uniqueResult();
7636    
7637                                    finderCache.putResult(finderPath, finderArgs, count);
7638                            }
7639                            catch (Exception e) {
7640                                    finderCache.removeResult(finderPath, finderArgs);
7641    
7642                                    throw processException(e);
7643                            }
7644                            finally {
7645                                    closeSession(session);
7646                            }
7647                    }
7648    
7649                    return count.intValue();
7650            }
7651    
7652            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7653            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7654            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7655                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7656                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7657                            new String[] {
7658                                    Long.class.getName(), Long.class.getName(),
7659                                    
7660                            Integer.class.getName(), Integer.class.getName(),
7661                                    OrderByComparator.class.getName()
7662                            });
7663            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7664                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7665                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7666                            new String[] { Long.class.getName(), Long.class.getName() },
7667                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7668                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7669                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7670            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7671                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7672                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7673                            new String[] { Long.class.getName(), Long.class.getName() });
7674            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7675                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7676                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7677                            new String[] { Long.class.getName(), Long.class.getName() });
7678    
7679            /**
7680             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7681             *
7682             * @param userId the user ID
7683             * @param classNameId the class name ID
7684             * @return the matching message-boards messages
7685             */
7686            @Override
7687            public List<MBMessage> findByU_C(long userId, long classNameId) {
7688                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7689                            QueryUtil.ALL_POS, null);
7690            }
7691    
7692            /**
7693             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7694             *
7695             * <p>
7696             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7697             * </p>
7698             *
7699             * @param userId the user ID
7700             * @param classNameId the class name ID
7701             * @param start the lower bound of the range of message-boards messages
7702             * @param end the upper bound of the range of message-boards messages (not inclusive)
7703             * @return the range of matching message-boards messages
7704             */
7705            @Override
7706            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7707                    int end) {
7708                    return findByU_C(userId, classNameId, start, end, null);
7709            }
7710    
7711            /**
7712             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7713             *
7714             * <p>
7715             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7716             * </p>
7717             *
7718             * @param userId the user ID
7719             * @param classNameId the class name ID
7720             * @param start the lower bound of the range of message-boards messages
7721             * @param end the upper bound of the range of message-boards messages (not inclusive)
7722             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7723             * @return the ordered range of matching message-boards messages
7724             */
7725            @Override
7726            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7727                    int end, OrderByComparator<MBMessage> orderByComparator) {
7728                    return findByU_C(userId, classNameId, start, end, orderByComparator,
7729                            true);
7730            }
7731    
7732            /**
7733             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7734             *
7735             * <p>
7736             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7737             * </p>
7738             *
7739             * @param userId the user ID
7740             * @param classNameId the class name ID
7741             * @param start the lower bound of the range of message-boards messages
7742             * @param end the upper bound of the range of message-boards messages (not inclusive)
7743             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7744             * @param retrieveFromCache whether to retrieve from the finder cache
7745             * @return the ordered range of matching message-boards messages
7746             */
7747            @Override
7748            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7749                    int end, OrderByComparator<MBMessage> orderByComparator,
7750                    boolean retrieveFromCache) {
7751                    boolean pagination = true;
7752                    FinderPath finderPath = null;
7753                    Object[] finderArgs = null;
7754    
7755                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7756                                    (orderByComparator == null)) {
7757                            pagination = false;
7758                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7759                            finderArgs = new Object[] { userId, classNameId };
7760                    }
7761                    else {
7762                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7763                            finderArgs = new Object[] {
7764                                            userId, classNameId,
7765                                            
7766                                            start, end, orderByComparator
7767                                    };
7768                    }
7769    
7770                    List<MBMessage> list = null;
7771    
7772                    if (retrieveFromCache) {
7773                            list = (List<MBMessage>)finderCache.getResult(finderPath,
7774                                            finderArgs, this);
7775    
7776                            if ((list != null) && !list.isEmpty()) {
7777                                    for (MBMessage mbMessage : list) {
7778                                            if ((userId != mbMessage.getUserId()) ||
7779                                                            (classNameId != mbMessage.getClassNameId())) {
7780                                                    list = null;
7781    
7782                                                    break;
7783                                            }
7784                                    }
7785                            }
7786                    }
7787    
7788                    if (list == null) {
7789                            StringBundler query = null;
7790    
7791                            if (orderByComparator != null) {
7792                                    query = new StringBundler(4 +
7793                                                    (orderByComparator.getOrderByFields().length * 2));
7794                            }
7795                            else {
7796                                    query = new StringBundler(4);
7797                            }
7798    
7799                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7800    
7801                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7802    
7803                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7804    
7805                            if (orderByComparator != null) {
7806                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7807                                            orderByComparator);
7808                            }
7809                            else
7810                             if (pagination) {
7811                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7812                            }
7813    
7814                            String sql = query.toString();
7815    
7816                            Session session = null;
7817    
7818                            try {
7819                                    session = openSession();
7820    
7821                                    Query q = session.createQuery(sql);
7822    
7823                                    QueryPos qPos = QueryPos.getInstance(q);
7824    
7825                                    qPos.add(userId);
7826    
7827                                    qPos.add(classNameId);
7828    
7829                                    if (!pagination) {
7830                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7831                                                            start, end, false);
7832    
7833                                            Collections.sort(list);
7834    
7835                                            list = Collections.unmodifiableList(list);
7836                                    }
7837                                    else {
7838                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7839                                                            start, end);
7840                                    }
7841    
7842                                    cacheResult(list);
7843    
7844                                    finderCache.putResult(finderPath, finderArgs, list);
7845                            }
7846                            catch (Exception e) {
7847                                    finderCache.removeResult(finderPath, finderArgs);
7848    
7849                                    throw processException(e);
7850                            }
7851                            finally {
7852                                    closeSession(session);
7853                            }
7854                    }
7855    
7856                    return list;
7857            }
7858    
7859            /**
7860             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7861             *
7862             * @param userId the user ID
7863             * @param classNameId the class name ID
7864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7865             * @return the first matching message-boards message
7866             * @throws NoSuchMessageException if a matching message-boards message could not be found
7867             */
7868            @Override
7869            public MBMessage findByU_C_First(long userId, long classNameId,
7870                    OrderByComparator<MBMessage> orderByComparator)
7871                    throws NoSuchMessageException {
7872                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7873                                    orderByComparator);
7874    
7875                    if (mbMessage != null) {
7876                            return mbMessage;
7877                    }
7878    
7879                    StringBundler msg = new StringBundler(6);
7880    
7881                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7882    
7883                    msg.append("userId=");
7884                    msg.append(userId);
7885    
7886                    msg.append(", classNameId=");
7887                    msg.append(classNameId);
7888    
7889                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7890    
7891                    throw new NoSuchMessageException(msg.toString());
7892            }
7893    
7894            /**
7895             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7896             *
7897             * @param userId the user ID
7898             * @param classNameId the class name ID
7899             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7900             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7901             */
7902            @Override
7903            public MBMessage fetchByU_C_First(long userId, long classNameId,
7904                    OrderByComparator<MBMessage> orderByComparator) {
7905                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7906                                    orderByComparator);
7907    
7908                    if (!list.isEmpty()) {
7909                            return list.get(0);
7910                    }
7911    
7912                    return null;
7913            }
7914    
7915            /**
7916             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7917             *
7918             * @param userId the user ID
7919             * @param classNameId the class name ID
7920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7921             * @return the last matching message-boards message
7922             * @throws NoSuchMessageException if a matching message-boards message could not be found
7923             */
7924            @Override
7925            public MBMessage findByU_C_Last(long userId, long classNameId,
7926                    OrderByComparator<MBMessage> orderByComparator)
7927                    throws NoSuchMessageException {
7928                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7929                                    orderByComparator);
7930    
7931                    if (mbMessage != null) {
7932                            return mbMessage;
7933                    }
7934    
7935                    StringBundler msg = new StringBundler(6);
7936    
7937                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7938    
7939                    msg.append("userId=");
7940                    msg.append(userId);
7941    
7942                    msg.append(", classNameId=");
7943                    msg.append(classNameId);
7944    
7945                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7946    
7947                    throw new NoSuchMessageException(msg.toString());
7948            }
7949    
7950            /**
7951             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7952             *
7953             * @param userId the user ID
7954             * @param classNameId the class name ID
7955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7956             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7957             */
7958            @Override
7959            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7960                    OrderByComparator<MBMessage> orderByComparator) {
7961                    int count = countByU_C(userId, classNameId);
7962    
7963                    if (count == 0) {
7964                            return null;
7965                    }
7966    
7967                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7968                                    orderByComparator);
7969    
7970                    if (!list.isEmpty()) {
7971                            return list.get(0);
7972                    }
7973    
7974                    return null;
7975            }
7976    
7977            /**
7978             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7979             *
7980             * @param messageId the primary key of the current message-boards message
7981             * @param userId the user ID
7982             * @param classNameId the class name ID
7983             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7984             * @return the previous, current, and next message-boards message
7985             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
7986             */
7987            @Override
7988            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7989                    long classNameId, OrderByComparator<MBMessage> orderByComparator)
7990                    throws NoSuchMessageException {
7991                    MBMessage mbMessage = findByPrimaryKey(messageId);
7992    
7993                    Session session = null;
7994    
7995                    try {
7996                            session = openSession();
7997    
7998                            MBMessage[] array = new MBMessageImpl[3];
7999    
8000                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
8001                                            classNameId, orderByComparator, true);
8002    
8003                            array[1] = mbMessage;
8004    
8005                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
8006                                            classNameId, orderByComparator, false);
8007    
8008                            return array;
8009                    }
8010                    catch (Exception e) {
8011                            throw processException(e);
8012                    }
8013                    finally {
8014                            closeSession(session);
8015                    }
8016            }
8017    
8018            protected MBMessage getByU_C_PrevAndNext(Session session,
8019                    MBMessage mbMessage, long userId, long classNameId,
8020                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8021                    StringBundler query = null;
8022    
8023                    if (orderByComparator != null) {
8024                            query = new StringBundler(5 +
8025                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8026                                            (orderByComparator.getOrderByFields().length * 3));
8027                    }
8028                    else {
8029                            query = new StringBundler(4);
8030                    }
8031    
8032                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8033    
8034                    query.append(_FINDER_COLUMN_U_C_USERID_2);
8035    
8036                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8037    
8038                    if (orderByComparator != null) {
8039                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8040    
8041                            if (orderByConditionFields.length > 0) {
8042                                    query.append(WHERE_AND);
8043                            }
8044    
8045                            for (int i = 0; i < orderByConditionFields.length; i++) {
8046                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8047                                    query.append(orderByConditionFields[i]);
8048    
8049                                    if ((i + 1) < orderByConditionFields.length) {
8050                                            if (orderByComparator.isAscending() ^ previous) {
8051                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8052                                            }
8053                                            else {
8054                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8055                                            }
8056                                    }
8057                                    else {
8058                                            if (orderByComparator.isAscending() ^ previous) {
8059                                                    query.append(WHERE_GREATER_THAN);
8060                                            }
8061                                            else {
8062                                                    query.append(WHERE_LESSER_THAN);
8063                                            }
8064                                    }
8065                            }
8066    
8067                            query.append(ORDER_BY_CLAUSE);
8068    
8069                            String[] orderByFields = orderByComparator.getOrderByFields();
8070    
8071                            for (int i = 0; i < orderByFields.length; i++) {
8072                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8073                                    query.append(orderByFields[i]);
8074    
8075                                    if ((i + 1) < orderByFields.length) {
8076                                            if (orderByComparator.isAscending() ^ previous) {
8077                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8078                                            }
8079                                            else {
8080                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8081                                            }
8082                                    }
8083                                    else {
8084                                            if (orderByComparator.isAscending() ^ previous) {
8085                                                    query.append(ORDER_BY_ASC);
8086                                            }
8087                                            else {
8088                                                    query.append(ORDER_BY_DESC);
8089                                            }
8090                                    }
8091                            }
8092                    }
8093                    else {
8094                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8095                    }
8096    
8097                    String sql = query.toString();
8098    
8099                    Query q = session.createQuery(sql);
8100    
8101                    q.setFirstResult(0);
8102                    q.setMaxResults(2);
8103    
8104                    QueryPos qPos = QueryPos.getInstance(q);
8105    
8106                    qPos.add(userId);
8107    
8108                    qPos.add(classNameId);
8109    
8110                    if (orderByComparator != null) {
8111                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8112    
8113                            for (Object value : values) {
8114                                    qPos.add(value);
8115                            }
8116                    }
8117    
8118                    List<MBMessage> list = q.list();
8119    
8120                    if (list.size() == 2) {
8121                            return list.get(1);
8122                    }
8123                    else {
8124                            return null;
8125                    }
8126            }
8127    
8128            /**
8129             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8130             *
8131             * <p>
8132             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8133             * </p>
8134             *
8135             * @param userId the user ID
8136             * @param classNameIds the class name IDs
8137             * @return the matching message-boards messages
8138             */
8139            @Override
8140            public List<MBMessage> findByU_C(long userId, long[] classNameIds) {
8141                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
8142                            QueryUtil.ALL_POS, null);
8143            }
8144    
8145            /**
8146             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8147             *
8148             * <p>
8149             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8150             * </p>
8151             *
8152             * @param userId the user ID
8153             * @param classNameIds the class name IDs
8154             * @param start the lower bound of the range of message-boards messages
8155             * @param end the upper bound of the range of message-boards messages (not inclusive)
8156             * @return the range of matching message-boards messages
8157             */
8158            @Override
8159            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8160                    int start, int end) {
8161                    return findByU_C(userId, classNameIds, start, end, null);
8162            }
8163    
8164            /**
8165             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
8166             *
8167             * <p>
8168             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8169             * </p>
8170             *
8171             * @param userId the user ID
8172             * @param classNameIds the class name IDs
8173             * @param start the lower bound of the range of message-boards messages
8174             * @param end the upper bound of the range of message-boards messages (not inclusive)
8175             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8176             * @return the ordered range of matching message-boards messages
8177             */
8178            @Override
8179            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8180                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
8181                    return findByU_C(userId, classNameIds, start, end, orderByComparator,
8182                            true);
8183            }
8184    
8185            /**
8186             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;, optionally using the finder cache.
8187             *
8188             * <p>
8189             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8190             * </p>
8191             *
8192             * @param userId the user ID
8193             * @param classNameId the class name ID
8194             * @param start the lower bound of the range of message-boards messages
8195             * @param end the upper bound of the range of message-boards messages (not inclusive)
8196             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8197             * @param retrieveFromCache whether to retrieve from the finder cache
8198             * @return the ordered range of matching message-boards messages
8199             */
8200            @Override
8201            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
8202                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
8203                    boolean retrieveFromCache) {
8204                    if (classNameIds == null) {
8205                            classNameIds = new long[0];
8206                    }
8207                    else if (classNameIds.length > 1) {
8208                            classNameIds = ArrayUtil.unique(classNameIds);
8209    
8210                            Arrays.sort(classNameIds);
8211                    }
8212    
8213                    if (classNameIds.length == 1) {
8214                            return findByU_C(userId, classNameIds[0], start, end,
8215                                    orderByComparator);
8216                    }
8217    
8218                    boolean pagination = true;
8219                    Object[] finderArgs = null;
8220    
8221                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8222                                    (orderByComparator == null)) {
8223                            pagination = false;
8224                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
8225                    }
8226                    else {
8227                            finderArgs = new Object[] {
8228                                            userId, StringUtil.merge(classNameIds),
8229                                            
8230                                            start, end, orderByComparator
8231                                    };
8232                    }
8233    
8234                    List<MBMessage> list = null;
8235    
8236                    if (retrieveFromCache) {
8237                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8238                                            finderArgs, this);
8239    
8240                            if ((list != null) && !list.isEmpty()) {
8241                                    for (MBMessage mbMessage : list) {
8242                                            if ((userId != mbMessage.getUserId()) ||
8243                                                            !ArrayUtil.contains(classNameIds,
8244                                                                    mbMessage.getClassNameId())) {
8245                                                    list = null;
8246    
8247                                                    break;
8248                                            }
8249                                    }
8250                            }
8251                    }
8252    
8253                    if (list == null) {
8254                            StringBundler query = new StringBundler();
8255    
8256                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8257    
8258                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8259    
8260                            if (classNameIds.length > 0) {
8261                                    query.append(StringPool.OPEN_PARENTHESIS);
8262    
8263                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8264    
8265                                    query.append(StringUtil.merge(classNameIds));
8266    
8267                                    query.append(StringPool.CLOSE_PARENTHESIS);
8268    
8269                                    query.append(StringPool.CLOSE_PARENTHESIS);
8270                            }
8271    
8272                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8273                                                    1)), query.index() - 1);
8274    
8275                            if (orderByComparator != null) {
8276                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8277                                            orderByComparator);
8278                            }
8279                            else
8280                             if (pagination) {
8281                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8282                            }
8283    
8284                            String sql = query.toString();
8285    
8286                            Session session = null;
8287    
8288                            try {
8289                                    session = openSession();
8290    
8291                                    Query q = session.createQuery(sql);
8292    
8293                                    QueryPos qPos = QueryPos.getInstance(q);
8294    
8295                                    qPos.add(userId);
8296    
8297                                    if (!pagination) {
8298                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8299                                                            start, end, false);
8300    
8301                                            Collections.sort(list);
8302    
8303                                            list = Collections.unmodifiableList(list);
8304                                    }
8305                                    else {
8306                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8307                                                            start, end);
8308                                    }
8309    
8310                                    cacheResult(list);
8311    
8312                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8313                                            finderArgs, list);
8314                            }
8315                            catch (Exception e) {
8316                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
8317                                            finderArgs);
8318    
8319                                    throw processException(e);
8320                            }
8321                            finally {
8322                                    closeSession(session);
8323                            }
8324                    }
8325    
8326                    return list;
8327            }
8328    
8329            /**
8330             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
8331             *
8332             * @param userId the user ID
8333             * @param classNameId the class name ID
8334             */
8335            @Override
8336            public void removeByU_C(long userId, long classNameId) {
8337                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
8338                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8339                            remove(mbMessage);
8340                    }
8341            }
8342    
8343            /**
8344             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
8345             *
8346             * @param userId the user ID
8347             * @param classNameId the class name ID
8348             * @return the number of matching message-boards messages
8349             */
8350            @Override
8351            public int countByU_C(long userId, long classNameId) {
8352                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
8353    
8354                    Object[] finderArgs = new Object[] { userId, classNameId };
8355    
8356                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8357    
8358                    if (count == null) {
8359                            StringBundler query = new StringBundler(3);
8360    
8361                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8362    
8363                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8364    
8365                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8366    
8367                            String sql = query.toString();
8368    
8369                            Session session = null;
8370    
8371                            try {
8372                                    session = openSession();
8373    
8374                                    Query q = session.createQuery(sql);
8375    
8376                                    QueryPos qPos = QueryPos.getInstance(q);
8377    
8378                                    qPos.add(userId);
8379    
8380                                    qPos.add(classNameId);
8381    
8382                                    count = (Long)q.uniqueResult();
8383    
8384                                    finderCache.putResult(finderPath, finderArgs, count);
8385                            }
8386                            catch (Exception e) {
8387                                    finderCache.removeResult(finderPath, finderArgs);
8388    
8389                                    throw processException(e);
8390                            }
8391                            finally {
8392                                    closeSession(session);
8393                            }
8394                    }
8395    
8396                    return count.intValue();
8397            }
8398    
8399            /**
8400             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8401             *
8402             * @param userId the user ID
8403             * @param classNameIds the class name IDs
8404             * @return the number of matching message-boards messages
8405             */
8406            @Override
8407            public int countByU_C(long userId, long[] classNameIds) {
8408                    if (classNameIds == null) {
8409                            classNameIds = new long[0];
8410                    }
8411                    else if (classNameIds.length > 1) {
8412                            classNameIds = ArrayUtil.unique(classNameIds);
8413    
8414                            Arrays.sort(classNameIds);
8415                    }
8416    
8417                    Object[] finderArgs = new Object[] {
8418                                    userId, StringUtil.merge(classNameIds)
8419                            };
8420    
8421                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8422                                    finderArgs, this);
8423    
8424                    if (count == null) {
8425                            StringBundler query = new StringBundler();
8426    
8427                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8428    
8429                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8430    
8431                            if (classNameIds.length > 0) {
8432                                    query.append(StringPool.OPEN_PARENTHESIS);
8433    
8434                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_7);
8435    
8436                                    query.append(StringUtil.merge(classNameIds));
8437    
8438                                    query.append(StringPool.CLOSE_PARENTHESIS);
8439    
8440                                    query.append(StringPool.CLOSE_PARENTHESIS);
8441                            }
8442    
8443                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8444                                                    1)), query.index() - 1);
8445    
8446                            String sql = query.toString();
8447    
8448                            Session session = null;
8449    
8450                            try {
8451                                    session = openSession();
8452    
8453                                    Query q = session.createQuery(sql);
8454    
8455                                    QueryPos qPos = QueryPos.getInstance(q);
8456    
8457                                    qPos.add(userId);
8458    
8459                                    count = (Long)q.uniqueResult();
8460    
8461                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8462                                            finderArgs, count);
8463                            }
8464                            catch (Exception e) {
8465                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8466                                            finderArgs);
8467    
8468                                    throw processException(e);
8469                            }
8470                            finally {
8471                                    closeSession(session);
8472                            }
8473                    }
8474    
8475                    return count.intValue();
8476            }
8477    
8478            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8479            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8480            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
8481            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8482                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8483                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8484                            new String[] {
8485                                    Long.class.getName(), Long.class.getName(),
8486                                    
8487                            Integer.class.getName(), Integer.class.getName(),
8488                                    OrderByComparator.class.getName()
8489                            });
8490            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8491                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8492                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8493                            new String[] { Long.class.getName(), Long.class.getName() },
8494                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8495                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8496                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8497            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8498                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8499                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8500                            new String[] { Long.class.getName(), Long.class.getName() });
8501    
8502            /**
8503             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8504             *
8505             * @param classNameId the class name ID
8506             * @param classPK the class p k
8507             * @return the matching message-boards messages
8508             */
8509            @Override
8510            public List<MBMessage> findByC_C(long classNameId, long classPK) {
8511                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8512                            QueryUtil.ALL_POS, null);
8513            }
8514    
8515            /**
8516             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8517             *
8518             * <p>
8519             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8520             * </p>
8521             *
8522             * @param classNameId the class name ID
8523             * @param classPK the class p k
8524             * @param start the lower bound of the range of message-boards messages
8525             * @param end the upper bound of the range of message-boards messages (not inclusive)
8526             * @return the range of matching message-boards messages
8527             */
8528            @Override
8529            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8530                    int end) {
8531                    return findByC_C(classNameId, classPK, start, end, null);
8532            }
8533    
8534            /**
8535             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8536             *
8537             * <p>
8538             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8539             * </p>
8540             *
8541             * @param classNameId the class name ID
8542             * @param classPK the class p k
8543             * @param start the lower bound of the range of message-boards messages
8544             * @param end the upper bound of the range of message-boards messages (not inclusive)
8545             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8546             * @return the ordered range of matching message-boards messages
8547             */
8548            @Override
8549            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8550                    int end, OrderByComparator<MBMessage> orderByComparator) {
8551                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
8552                            true);
8553            }
8554    
8555            /**
8556             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8557             *
8558             * <p>
8559             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8560             * </p>
8561             *
8562             * @param classNameId the class name ID
8563             * @param classPK the class p k
8564             * @param start the lower bound of the range of message-boards messages
8565             * @param end the upper bound of the range of message-boards messages (not inclusive)
8566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8567             * @param retrieveFromCache whether to retrieve from the finder cache
8568             * @return the ordered range of matching message-boards messages
8569             */
8570            @Override
8571            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8572                    int end, OrderByComparator<MBMessage> orderByComparator,
8573                    boolean retrieveFromCache) {
8574                    boolean pagination = true;
8575                    FinderPath finderPath = null;
8576                    Object[] finderArgs = null;
8577    
8578                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8579                                    (orderByComparator == null)) {
8580                            pagination = false;
8581                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8582                            finderArgs = new Object[] { classNameId, classPK };
8583                    }
8584                    else {
8585                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8586                            finderArgs = new Object[] {
8587                                            classNameId, classPK,
8588                                            
8589                                            start, end, orderByComparator
8590                                    };
8591                    }
8592    
8593                    List<MBMessage> list = null;
8594    
8595                    if (retrieveFromCache) {
8596                            list = (List<MBMessage>)finderCache.getResult(finderPath,
8597                                            finderArgs, this);
8598    
8599                            if ((list != null) && !list.isEmpty()) {
8600                                    for (MBMessage mbMessage : list) {
8601                                            if ((classNameId != mbMessage.getClassNameId()) ||
8602                                                            (classPK != mbMessage.getClassPK())) {
8603                                                    list = null;
8604    
8605                                                    break;
8606                                            }
8607                                    }
8608                            }
8609                    }
8610    
8611                    if (list == null) {
8612                            StringBundler query = null;
8613    
8614                            if (orderByComparator != null) {
8615                                    query = new StringBundler(4 +
8616                                                    (orderByComparator.getOrderByFields().length * 2));
8617                            }
8618                            else {
8619                                    query = new StringBundler(4);
8620                            }
8621    
8622                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8623    
8624                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8625    
8626                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8627    
8628                            if (orderByComparator != null) {
8629                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8630                                            orderByComparator);
8631                            }
8632                            else
8633                             if (pagination) {
8634                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8635                            }
8636    
8637                            String sql = query.toString();
8638    
8639                            Session session = null;
8640    
8641                            try {
8642                                    session = openSession();
8643    
8644                                    Query q = session.createQuery(sql);
8645    
8646                                    QueryPos qPos = QueryPos.getInstance(q);
8647    
8648                                    qPos.add(classNameId);
8649    
8650                                    qPos.add(classPK);
8651    
8652                                    if (!pagination) {
8653                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8654                                                            start, end, false);
8655    
8656                                            Collections.sort(list);
8657    
8658                                            list = Collections.unmodifiableList(list);
8659                                    }
8660                                    else {
8661                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8662                                                            start, end);
8663                                    }
8664    
8665                                    cacheResult(list);
8666    
8667                                    finderCache.putResult(finderPath, finderArgs, list);
8668                            }
8669                            catch (Exception e) {
8670                                    finderCache.removeResult(finderPath, finderArgs);
8671    
8672                                    throw processException(e);
8673                            }
8674                            finally {
8675                                    closeSession(session);
8676                            }
8677                    }
8678    
8679                    return list;
8680            }
8681    
8682            /**
8683             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8684             *
8685             * @param classNameId the class name ID
8686             * @param classPK the class p k
8687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8688             * @return the first matching message-boards message
8689             * @throws NoSuchMessageException if a matching message-boards message could not be found
8690             */
8691            @Override
8692            public MBMessage findByC_C_First(long classNameId, long classPK,
8693                    OrderByComparator<MBMessage> orderByComparator)
8694                    throws NoSuchMessageException {
8695                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8696                                    orderByComparator);
8697    
8698                    if (mbMessage != null) {
8699                            return mbMessage;
8700                    }
8701    
8702                    StringBundler msg = new StringBundler(6);
8703    
8704                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8705    
8706                    msg.append("classNameId=");
8707                    msg.append(classNameId);
8708    
8709                    msg.append(", classPK=");
8710                    msg.append(classPK);
8711    
8712                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8713    
8714                    throw new NoSuchMessageException(msg.toString());
8715            }
8716    
8717            /**
8718             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8719             *
8720             * @param classNameId the class name ID
8721             * @param classPK the class p k
8722             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8723             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8724             */
8725            @Override
8726            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8727                    OrderByComparator<MBMessage> orderByComparator) {
8728                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8729                                    orderByComparator);
8730    
8731                    if (!list.isEmpty()) {
8732                            return list.get(0);
8733                    }
8734    
8735                    return null;
8736            }
8737    
8738            /**
8739             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8740             *
8741             * @param classNameId the class name ID
8742             * @param classPK the class p k
8743             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8744             * @return the last matching message-boards message
8745             * @throws NoSuchMessageException if a matching message-boards message could not be found
8746             */
8747            @Override
8748            public MBMessage findByC_C_Last(long classNameId, long classPK,
8749                    OrderByComparator<MBMessage> orderByComparator)
8750                    throws NoSuchMessageException {
8751                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8752                                    orderByComparator);
8753    
8754                    if (mbMessage != null) {
8755                            return mbMessage;
8756                    }
8757    
8758                    StringBundler msg = new StringBundler(6);
8759    
8760                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8761    
8762                    msg.append("classNameId=");
8763                    msg.append(classNameId);
8764    
8765                    msg.append(", classPK=");
8766                    msg.append(classPK);
8767    
8768                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8769    
8770                    throw new NoSuchMessageException(msg.toString());
8771            }
8772    
8773            /**
8774             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8775             *
8776             * @param classNameId the class name ID
8777             * @param classPK the class p k
8778             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8779             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8780             */
8781            @Override
8782            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8783                    OrderByComparator<MBMessage> orderByComparator) {
8784                    int count = countByC_C(classNameId, classPK);
8785    
8786                    if (count == 0) {
8787                            return null;
8788                    }
8789    
8790                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8791                                    count, orderByComparator);
8792    
8793                    if (!list.isEmpty()) {
8794                            return list.get(0);
8795                    }
8796    
8797                    return null;
8798            }
8799    
8800            /**
8801             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8802             *
8803             * @param messageId the primary key of the current message-boards message
8804             * @param classNameId the class name ID
8805             * @param classPK the class p k
8806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8807             * @return the previous, current, and next message-boards message
8808             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
8809             */
8810            @Override
8811            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8812                    long classPK, OrderByComparator<MBMessage> orderByComparator)
8813                    throws NoSuchMessageException {
8814                    MBMessage mbMessage = findByPrimaryKey(messageId);
8815    
8816                    Session session = null;
8817    
8818                    try {
8819                            session = openSession();
8820    
8821                            MBMessage[] array = new MBMessageImpl[3];
8822    
8823                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8824                                            classPK, orderByComparator, true);
8825    
8826                            array[1] = mbMessage;
8827    
8828                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8829                                            classPK, orderByComparator, false);
8830    
8831                            return array;
8832                    }
8833                    catch (Exception e) {
8834                            throw processException(e);
8835                    }
8836                    finally {
8837                            closeSession(session);
8838                    }
8839            }
8840    
8841            protected MBMessage getByC_C_PrevAndNext(Session session,
8842                    MBMessage mbMessage, long classNameId, long classPK,
8843                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
8844                    StringBundler query = null;
8845    
8846                    if (orderByComparator != null) {
8847                            query = new StringBundler(5 +
8848                                            (orderByComparator.getOrderByConditionFields().length * 3) +
8849                                            (orderByComparator.getOrderByFields().length * 3));
8850                    }
8851                    else {
8852                            query = new StringBundler(4);
8853                    }
8854    
8855                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8856    
8857                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8858    
8859                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8860    
8861                    if (orderByComparator != null) {
8862                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8863    
8864                            if (orderByConditionFields.length > 0) {
8865                                    query.append(WHERE_AND);
8866                            }
8867    
8868                            for (int i = 0; i < orderByConditionFields.length; i++) {
8869                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8870                                    query.append(orderByConditionFields[i]);
8871    
8872                                    if ((i + 1) < orderByConditionFields.length) {
8873                                            if (orderByComparator.isAscending() ^ previous) {
8874                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8875                                            }
8876                                            else {
8877                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8878                                            }
8879                                    }
8880                                    else {
8881                                            if (orderByComparator.isAscending() ^ previous) {
8882                                                    query.append(WHERE_GREATER_THAN);
8883                                            }
8884                                            else {
8885                                                    query.append(WHERE_LESSER_THAN);
8886                                            }
8887                                    }
8888                            }
8889    
8890                            query.append(ORDER_BY_CLAUSE);
8891    
8892                            String[] orderByFields = orderByComparator.getOrderByFields();
8893    
8894                            for (int i = 0; i < orderByFields.length; i++) {
8895                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8896                                    query.append(orderByFields[i]);
8897    
8898                                    if ((i + 1) < orderByFields.length) {
8899                                            if (orderByComparator.isAscending() ^ previous) {
8900                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8901                                            }
8902                                            else {
8903                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8904                                            }
8905                                    }
8906                                    else {
8907                                            if (orderByComparator.isAscending() ^ previous) {
8908                                                    query.append(ORDER_BY_ASC);
8909                                            }
8910                                            else {
8911                                                    query.append(ORDER_BY_DESC);
8912                                            }
8913                                    }
8914                            }
8915                    }
8916                    else {
8917                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8918                    }
8919    
8920                    String sql = query.toString();
8921    
8922                    Query q = session.createQuery(sql);
8923    
8924                    q.setFirstResult(0);
8925                    q.setMaxResults(2);
8926    
8927                    QueryPos qPos = QueryPos.getInstance(q);
8928    
8929                    qPos.add(classNameId);
8930    
8931                    qPos.add(classPK);
8932    
8933                    if (orderByComparator != null) {
8934                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8935    
8936                            for (Object value : values) {
8937                                    qPos.add(value);
8938                            }
8939                    }
8940    
8941                    List<MBMessage> list = q.list();
8942    
8943                    if (list.size() == 2) {
8944                            return list.get(1);
8945                    }
8946                    else {
8947                            return null;
8948                    }
8949            }
8950    
8951            /**
8952             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8953             *
8954             * @param classNameId the class name ID
8955             * @param classPK the class p k
8956             */
8957            @Override
8958            public void removeByC_C(long classNameId, long classPK) {
8959                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8960                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8961                            remove(mbMessage);
8962                    }
8963            }
8964    
8965            /**
8966             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8967             *
8968             * @param classNameId the class name ID
8969             * @param classPK the class p k
8970             * @return the number of matching message-boards messages
8971             */
8972            @Override
8973            public int countByC_C(long classNameId, long classPK) {
8974                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8975    
8976                    Object[] finderArgs = new Object[] { classNameId, classPK };
8977    
8978                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8979    
8980                    if (count == null) {
8981                            StringBundler query = new StringBundler(3);
8982    
8983                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8984    
8985                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8986    
8987                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8988    
8989                            String sql = query.toString();
8990    
8991                            Session session = null;
8992    
8993                            try {
8994                                    session = openSession();
8995    
8996                                    Query q = session.createQuery(sql);
8997    
8998                                    QueryPos qPos = QueryPos.getInstance(q);
8999    
9000                                    qPos.add(classNameId);
9001    
9002                                    qPos.add(classPK);
9003    
9004                                    count = (Long)q.uniqueResult();
9005    
9006                                    finderCache.putResult(finderPath, finderArgs, count);
9007                            }
9008                            catch (Exception e) {
9009                                    finderCache.removeResult(finderPath, finderArgs);
9010    
9011                                    throw processException(e);
9012                            }
9013                            finally {
9014                                    closeSession(session);
9015                            }
9016                    }
9017    
9018                    return count.intValue();
9019            }
9020    
9021            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
9022            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
9023            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9024                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9025                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
9026                            new String[] {
9027                                    Long.class.getName(), Long.class.getName(),
9028                                    
9029                            Integer.class.getName(), Integer.class.getName(),
9030                                    OrderByComparator.class.getName()
9031                            });
9032            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9033                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9034                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
9035                            new String[] { Long.class.getName(), Long.class.getName() },
9036                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9037                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
9038                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9039            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9040                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9041                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
9042                            new String[] { Long.class.getName(), Long.class.getName() });
9043    
9044            /**
9045             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9046             *
9047             * @param threadId the thread ID
9048             * @param parentMessageId the parent message ID
9049             * @return the matching message-boards messages
9050             */
9051            @Override
9052            public List<MBMessage> findByT_P(long threadId, long parentMessageId) {
9053                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
9054                            QueryUtil.ALL_POS, null);
9055            }
9056    
9057            /**
9058             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9059             *
9060             * <p>
9061             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9062             * </p>
9063             *
9064             * @param threadId the thread ID
9065             * @param parentMessageId the parent message ID
9066             * @param start the lower bound of the range of message-boards messages
9067             * @param end the upper bound of the range of message-boards messages (not inclusive)
9068             * @return the range of matching message-boards messages
9069             */
9070            @Override
9071            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9072                    int start, int end) {
9073                    return findByT_P(threadId, parentMessageId, start, end, null);
9074            }
9075    
9076            /**
9077             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9078             *
9079             * <p>
9080             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9081             * </p>
9082             *
9083             * @param threadId the thread ID
9084             * @param parentMessageId the parent message ID
9085             * @param start the lower bound of the range of message-boards messages
9086             * @param end the upper bound of the range of message-boards messages (not inclusive)
9087             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9088             * @return the ordered range of matching message-boards messages
9089             */
9090            @Override
9091            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9092                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
9093                    return findByT_P(threadId, parentMessageId, start, end,
9094                            orderByComparator, true);
9095            }
9096    
9097            /**
9098             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9099             *
9100             * <p>
9101             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9102             * </p>
9103             *
9104             * @param threadId the thread ID
9105             * @param parentMessageId the parent message ID
9106             * @param start the lower bound of the range of message-boards messages
9107             * @param end the upper bound of the range of message-boards messages (not inclusive)
9108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9109             * @param retrieveFromCache whether to retrieve from the finder cache
9110             * @return the ordered range of matching message-boards messages
9111             */
9112            @Override
9113            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
9114                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
9115                    boolean retrieveFromCache) {
9116                    boolean pagination = true;
9117                    FinderPath finderPath = null;
9118                    Object[] finderArgs = null;
9119    
9120                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9121                                    (orderByComparator == null)) {
9122                            pagination = false;
9123                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
9124                            finderArgs = new Object[] { threadId, parentMessageId };
9125                    }
9126                    else {
9127                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
9128                            finderArgs = new Object[] {
9129                                            threadId, parentMessageId,
9130                                            
9131                                            start, end, orderByComparator
9132                                    };
9133                    }
9134    
9135                    List<MBMessage> list = null;
9136    
9137                    if (retrieveFromCache) {
9138                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9139                                            finderArgs, this);
9140    
9141                            if ((list != null) && !list.isEmpty()) {
9142                                    for (MBMessage mbMessage : list) {
9143                                            if ((threadId != mbMessage.getThreadId()) ||
9144                                                            (parentMessageId != mbMessage.getParentMessageId())) {
9145                                                    list = null;
9146    
9147                                                    break;
9148                                            }
9149                                    }
9150                            }
9151                    }
9152    
9153                    if (list == null) {
9154                            StringBundler query = null;
9155    
9156                            if (orderByComparator != null) {
9157                                    query = new StringBundler(4 +
9158                                                    (orderByComparator.getOrderByFields().length * 2));
9159                            }
9160                            else {
9161                                    query = new StringBundler(4);
9162                            }
9163    
9164                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9165    
9166                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9167    
9168                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9169    
9170                            if (orderByComparator != null) {
9171                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9172                                            orderByComparator);
9173                            }
9174                            else
9175                             if (pagination) {
9176                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9177                            }
9178    
9179                            String sql = query.toString();
9180    
9181                            Session session = null;
9182    
9183                            try {
9184                                    session = openSession();
9185    
9186                                    Query q = session.createQuery(sql);
9187    
9188                                    QueryPos qPos = QueryPos.getInstance(q);
9189    
9190                                    qPos.add(threadId);
9191    
9192                                    qPos.add(parentMessageId);
9193    
9194                                    if (!pagination) {
9195                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9196                                                            start, end, false);
9197    
9198                                            Collections.sort(list);
9199    
9200                                            list = Collections.unmodifiableList(list);
9201                                    }
9202                                    else {
9203                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9204                                                            start, end);
9205                                    }
9206    
9207                                    cacheResult(list);
9208    
9209                                    finderCache.putResult(finderPath, finderArgs, list);
9210                            }
9211                            catch (Exception e) {
9212                                    finderCache.removeResult(finderPath, finderArgs);
9213    
9214                                    throw processException(e);
9215                            }
9216                            finally {
9217                                    closeSession(session);
9218                            }
9219                    }
9220    
9221                    return list;
9222            }
9223    
9224            /**
9225             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9226             *
9227             * @param threadId the thread ID
9228             * @param parentMessageId the parent message ID
9229             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9230             * @return the first matching message-boards message
9231             * @throws NoSuchMessageException if a matching message-boards message could not be found
9232             */
9233            @Override
9234            public MBMessage findByT_P_First(long threadId, long parentMessageId,
9235                    OrderByComparator<MBMessage> orderByComparator)
9236                    throws NoSuchMessageException {
9237                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
9238                                    orderByComparator);
9239    
9240                    if (mbMessage != null) {
9241                            return mbMessage;
9242                    }
9243    
9244                    StringBundler msg = new StringBundler(6);
9245    
9246                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9247    
9248                    msg.append("threadId=");
9249                    msg.append(threadId);
9250    
9251                    msg.append(", parentMessageId=");
9252                    msg.append(parentMessageId);
9253    
9254                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9255    
9256                    throw new NoSuchMessageException(msg.toString());
9257            }
9258    
9259            /**
9260             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9261             *
9262             * @param threadId the thread ID
9263             * @param parentMessageId the parent message ID
9264             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9265             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9266             */
9267            @Override
9268            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
9269                    OrderByComparator<MBMessage> orderByComparator) {
9270                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
9271                                    orderByComparator);
9272    
9273                    if (!list.isEmpty()) {
9274                            return list.get(0);
9275                    }
9276    
9277                    return null;
9278            }
9279    
9280            /**
9281             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9282             *
9283             * @param threadId the thread ID
9284             * @param parentMessageId the parent message ID
9285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9286             * @return the last matching message-boards message
9287             * @throws NoSuchMessageException if a matching message-boards message could not be found
9288             */
9289            @Override
9290            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
9291                    OrderByComparator<MBMessage> orderByComparator)
9292                    throws NoSuchMessageException {
9293                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
9294                                    orderByComparator);
9295    
9296                    if (mbMessage != null) {
9297                            return mbMessage;
9298                    }
9299    
9300                    StringBundler msg = new StringBundler(6);
9301    
9302                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9303    
9304                    msg.append("threadId=");
9305                    msg.append(threadId);
9306    
9307                    msg.append(", parentMessageId=");
9308                    msg.append(parentMessageId);
9309    
9310                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9311    
9312                    throw new NoSuchMessageException(msg.toString());
9313            }
9314    
9315            /**
9316             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9317             *
9318             * @param threadId the thread ID
9319             * @param parentMessageId the parent message ID
9320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9321             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9322             */
9323            @Override
9324            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
9325                    OrderByComparator<MBMessage> orderByComparator) {
9326                    int count = countByT_P(threadId, parentMessageId);
9327    
9328                    if (count == 0) {
9329                            return null;
9330                    }
9331    
9332                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
9333                                    count, orderByComparator);
9334    
9335                    if (!list.isEmpty()) {
9336                            return list.get(0);
9337                    }
9338    
9339                    return null;
9340            }
9341    
9342            /**
9343             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
9344             *
9345             * @param messageId the primary key of the current message-boards message
9346             * @param threadId the thread ID
9347             * @param parentMessageId the parent message ID
9348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9349             * @return the previous, current, and next message-boards message
9350             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9351             */
9352            @Override
9353            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
9354                    long parentMessageId, OrderByComparator<MBMessage> orderByComparator)
9355                    throws NoSuchMessageException {
9356                    MBMessage mbMessage = findByPrimaryKey(messageId);
9357    
9358                    Session session = null;
9359    
9360                    try {
9361                            session = openSession();
9362    
9363                            MBMessage[] array = new MBMessageImpl[3];
9364    
9365                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9366                                            parentMessageId, orderByComparator, true);
9367    
9368                            array[1] = mbMessage;
9369    
9370                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
9371                                            parentMessageId, orderByComparator, false);
9372    
9373                            return array;
9374                    }
9375                    catch (Exception e) {
9376                            throw processException(e);
9377                    }
9378                    finally {
9379                            closeSession(session);
9380                    }
9381            }
9382    
9383            protected MBMessage getByT_P_PrevAndNext(Session session,
9384                    MBMessage mbMessage, long threadId, long parentMessageId,
9385                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9386                    StringBundler query = null;
9387    
9388                    if (orderByComparator != null) {
9389                            query = new StringBundler(5 +
9390                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9391                                            (orderByComparator.getOrderByFields().length * 3));
9392                    }
9393                    else {
9394                            query = new StringBundler(4);
9395                    }
9396    
9397                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9398    
9399                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9400    
9401                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9402    
9403                    if (orderByComparator != null) {
9404                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9405    
9406                            if (orderByConditionFields.length > 0) {
9407                                    query.append(WHERE_AND);
9408                            }
9409    
9410                            for (int i = 0; i < orderByConditionFields.length; i++) {
9411                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9412                                    query.append(orderByConditionFields[i]);
9413    
9414                                    if ((i + 1) < orderByConditionFields.length) {
9415                                            if (orderByComparator.isAscending() ^ previous) {
9416                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9417                                            }
9418                                            else {
9419                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9420                                            }
9421                                    }
9422                                    else {
9423                                            if (orderByComparator.isAscending() ^ previous) {
9424                                                    query.append(WHERE_GREATER_THAN);
9425                                            }
9426                                            else {
9427                                                    query.append(WHERE_LESSER_THAN);
9428                                            }
9429                                    }
9430                            }
9431    
9432                            query.append(ORDER_BY_CLAUSE);
9433    
9434                            String[] orderByFields = orderByComparator.getOrderByFields();
9435    
9436                            for (int i = 0; i < orderByFields.length; i++) {
9437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9438                                    query.append(orderByFields[i]);
9439    
9440                                    if ((i + 1) < orderByFields.length) {
9441                                            if (orderByComparator.isAscending() ^ previous) {
9442                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9443                                            }
9444                                            else {
9445                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9446                                            }
9447                                    }
9448                                    else {
9449                                            if (orderByComparator.isAscending() ^ previous) {
9450                                                    query.append(ORDER_BY_ASC);
9451                                            }
9452                                            else {
9453                                                    query.append(ORDER_BY_DESC);
9454                                            }
9455                                    }
9456                            }
9457                    }
9458                    else {
9459                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9460                    }
9461    
9462                    String sql = query.toString();
9463    
9464                    Query q = session.createQuery(sql);
9465    
9466                    q.setFirstResult(0);
9467                    q.setMaxResults(2);
9468    
9469                    QueryPos qPos = QueryPos.getInstance(q);
9470    
9471                    qPos.add(threadId);
9472    
9473                    qPos.add(parentMessageId);
9474    
9475                    if (orderByComparator != null) {
9476                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9477    
9478                            for (Object value : values) {
9479                                    qPos.add(value);
9480                            }
9481                    }
9482    
9483                    List<MBMessage> list = q.list();
9484    
9485                    if (list.size() == 2) {
9486                            return list.get(1);
9487                    }
9488                    else {
9489                            return null;
9490                    }
9491            }
9492    
9493            /**
9494             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9495             *
9496             * @param threadId the thread ID
9497             * @param parentMessageId the parent message ID
9498             */
9499            @Override
9500            public void removeByT_P(long threadId, long parentMessageId) {
9501                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9502                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9503                            remove(mbMessage);
9504                    }
9505            }
9506    
9507            /**
9508             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9509             *
9510             * @param threadId the thread ID
9511             * @param parentMessageId the parent message ID
9512             * @return the number of matching message-boards messages
9513             */
9514            @Override
9515            public int countByT_P(long threadId, long parentMessageId) {
9516                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9517    
9518                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9519    
9520                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9521    
9522                    if (count == null) {
9523                            StringBundler query = new StringBundler(3);
9524    
9525                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9526    
9527                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9528    
9529                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9530    
9531                            String sql = query.toString();
9532    
9533                            Session session = null;
9534    
9535                            try {
9536                                    session = openSession();
9537    
9538                                    Query q = session.createQuery(sql);
9539    
9540                                    QueryPos qPos = QueryPos.getInstance(q);
9541    
9542                                    qPos.add(threadId);
9543    
9544                                    qPos.add(parentMessageId);
9545    
9546                                    count = (Long)q.uniqueResult();
9547    
9548                                    finderCache.putResult(finderPath, finderArgs, count);
9549                            }
9550                            catch (Exception e) {
9551                                    finderCache.removeResult(finderPath, finderArgs);
9552    
9553                                    throw processException(e);
9554                            }
9555                            finally {
9556                                    closeSession(session);
9557                            }
9558                    }
9559    
9560                    return count.intValue();
9561            }
9562    
9563            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9564            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9565            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9566                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9567                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9568                            new String[] {
9569                                    Long.class.getName(), Boolean.class.getName(),
9570                                    
9571                            Integer.class.getName(), Integer.class.getName(),
9572                                    OrderByComparator.class.getName()
9573                            });
9574            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9575                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9577                            new String[] { Long.class.getName(), Boolean.class.getName() },
9578                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9579                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9580                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9581            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9582                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9583                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9584                            new String[] { Long.class.getName(), Boolean.class.getName() });
9585    
9586            /**
9587             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9588             *
9589             * @param threadId the thread ID
9590             * @param answer the answer
9591             * @return the matching message-boards messages
9592             */
9593            @Override
9594            public List<MBMessage> findByT_A(long threadId, boolean answer) {
9595                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9596                            QueryUtil.ALL_POS, null);
9597            }
9598    
9599            /**
9600             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9601             *
9602             * <p>
9603             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9604             * </p>
9605             *
9606             * @param threadId the thread ID
9607             * @param answer the answer
9608             * @param start the lower bound of the range of message-boards messages
9609             * @param end the upper bound of the range of message-boards messages (not inclusive)
9610             * @return the range of matching message-boards messages
9611             */
9612            @Override
9613            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9614                    int end) {
9615                    return findByT_A(threadId, answer, start, end, null);
9616            }
9617    
9618            /**
9619             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9620             *
9621             * <p>
9622             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9623             * </p>
9624             *
9625             * @param threadId the thread ID
9626             * @param answer the answer
9627             * @param start the lower bound of the range of message-boards messages
9628             * @param end the upper bound of the range of message-boards messages (not inclusive)
9629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9630             * @return the ordered range of matching message-boards messages
9631             */
9632            @Override
9633            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9634                    int end, OrderByComparator<MBMessage> orderByComparator) {
9635                    return findByT_A(threadId, answer, start, end, orderByComparator, true);
9636            }
9637    
9638            /**
9639             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9640             *
9641             * <p>
9642             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9643             * </p>
9644             *
9645             * @param threadId the thread ID
9646             * @param answer the answer
9647             * @param start the lower bound of the range of message-boards messages
9648             * @param end the upper bound of the range of message-boards messages (not inclusive)
9649             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9650             * @param retrieveFromCache whether to retrieve from the finder cache
9651             * @return the ordered range of matching message-boards messages
9652             */
9653            @Override
9654            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9655                    int end, OrderByComparator<MBMessage> orderByComparator,
9656                    boolean retrieveFromCache) {
9657                    boolean pagination = true;
9658                    FinderPath finderPath = null;
9659                    Object[] finderArgs = null;
9660    
9661                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9662                                    (orderByComparator == null)) {
9663                            pagination = false;
9664                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9665                            finderArgs = new Object[] { threadId, answer };
9666                    }
9667                    else {
9668                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9669                            finderArgs = new Object[] {
9670                                            threadId, answer,
9671                                            
9672                                            start, end, orderByComparator
9673                                    };
9674                    }
9675    
9676                    List<MBMessage> list = null;
9677    
9678                    if (retrieveFromCache) {
9679                            list = (List<MBMessage>)finderCache.getResult(finderPath,
9680                                            finderArgs, this);
9681    
9682                            if ((list != null) && !list.isEmpty()) {
9683                                    for (MBMessage mbMessage : list) {
9684                                            if ((threadId != mbMessage.getThreadId()) ||
9685                                                            (answer != mbMessage.getAnswer())) {
9686                                                    list = null;
9687    
9688                                                    break;
9689                                            }
9690                                    }
9691                            }
9692                    }
9693    
9694                    if (list == null) {
9695                            StringBundler query = null;
9696    
9697                            if (orderByComparator != null) {
9698                                    query = new StringBundler(4 +
9699                                                    (orderByComparator.getOrderByFields().length * 2));
9700                            }
9701                            else {
9702                                    query = new StringBundler(4);
9703                            }
9704    
9705                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9706    
9707                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9708    
9709                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9710    
9711                            if (orderByComparator != null) {
9712                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9713                                            orderByComparator);
9714                            }
9715                            else
9716                             if (pagination) {
9717                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9718                            }
9719    
9720                            String sql = query.toString();
9721    
9722                            Session session = null;
9723    
9724                            try {
9725                                    session = openSession();
9726    
9727                                    Query q = session.createQuery(sql);
9728    
9729                                    QueryPos qPos = QueryPos.getInstance(q);
9730    
9731                                    qPos.add(threadId);
9732    
9733                                    qPos.add(answer);
9734    
9735                                    if (!pagination) {
9736                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9737                                                            start, end, false);
9738    
9739                                            Collections.sort(list);
9740    
9741                                            list = Collections.unmodifiableList(list);
9742                                    }
9743                                    else {
9744                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9745                                                            start, end);
9746                                    }
9747    
9748                                    cacheResult(list);
9749    
9750                                    finderCache.putResult(finderPath, finderArgs, list);
9751                            }
9752                            catch (Exception e) {
9753                                    finderCache.removeResult(finderPath, finderArgs);
9754    
9755                                    throw processException(e);
9756                            }
9757                            finally {
9758                                    closeSession(session);
9759                            }
9760                    }
9761    
9762                    return list;
9763            }
9764    
9765            /**
9766             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9767             *
9768             * @param threadId the thread ID
9769             * @param answer the answer
9770             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9771             * @return the first matching message-boards message
9772             * @throws NoSuchMessageException if a matching message-boards message could not be found
9773             */
9774            @Override
9775            public MBMessage findByT_A_First(long threadId, boolean answer,
9776                    OrderByComparator<MBMessage> orderByComparator)
9777                    throws NoSuchMessageException {
9778                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9779                                    orderByComparator);
9780    
9781                    if (mbMessage != null) {
9782                            return mbMessage;
9783                    }
9784    
9785                    StringBundler msg = new StringBundler(6);
9786    
9787                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9788    
9789                    msg.append("threadId=");
9790                    msg.append(threadId);
9791    
9792                    msg.append(", answer=");
9793                    msg.append(answer);
9794    
9795                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9796    
9797                    throw new NoSuchMessageException(msg.toString());
9798            }
9799    
9800            /**
9801             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9802             *
9803             * @param threadId the thread ID
9804             * @param answer the answer
9805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9806             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9807             */
9808            @Override
9809            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9810                    OrderByComparator<MBMessage> orderByComparator) {
9811                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9812                                    orderByComparator);
9813    
9814                    if (!list.isEmpty()) {
9815                            return list.get(0);
9816                    }
9817    
9818                    return null;
9819            }
9820    
9821            /**
9822             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9823             *
9824             * @param threadId the thread ID
9825             * @param answer the answer
9826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9827             * @return the last matching message-boards message
9828             * @throws NoSuchMessageException if a matching message-boards message could not be found
9829             */
9830            @Override
9831            public MBMessage findByT_A_Last(long threadId, boolean answer,
9832                    OrderByComparator<MBMessage> orderByComparator)
9833                    throws NoSuchMessageException {
9834                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9835                                    orderByComparator);
9836    
9837                    if (mbMessage != null) {
9838                            return mbMessage;
9839                    }
9840    
9841                    StringBundler msg = new StringBundler(6);
9842    
9843                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9844    
9845                    msg.append("threadId=");
9846                    msg.append(threadId);
9847    
9848                    msg.append(", answer=");
9849                    msg.append(answer);
9850    
9851                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9852    
9853                    throw new NoSuchMessageException(msg.toString());
9854            }
9855    
9856            /**
9857             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9858             *
9859             * @param threadId the thread ID
9860             * @param answer the answer
9861             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9862             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9863             */
9864            @Override
9865            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9866                    OrderByComparator<MBMessage> orderByComparator) {
9867                    int count = countByT_A(threadId, answer);
9868    
9869                    if (count == 0) {
9870                            return null;
9871                    }
9872    
9873                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9874                                    orderByComparator);
9875    
9876                    if (!list.isEmpty()) {
9877                            return list.get(0);
9878                    }
9879    
9880                    return null;
9881            }
9882    
9883            /**
9884             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9885             *
9886             * @param messageId the primary key of the current message-boards message
9887             * @param threadId the thread ID
9888             * @param answer the answer
9889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9890             * @return the previous, current, and next message-boards message
9891             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
9892             */
9893            @Override
9894            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9895                    boolean answer, OrderByComparator<MBMessage> orderByComparator)
9896                    throws NoSuchMessageException {
9897                    MBMessage mbMessage = findByPrimaryKey(messageId);
9898    
9899                    Session session = null;
9900    
9901                    try {
9902                            session = openSession();
9903    
9904                            MBMessage[] array = new MBMessageImpl[3];
9905    
9906                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9907                                            answer, orderByComparator, true);
9908    
9909                            array[1] = mbMessage;
9910    
9911                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9912                                            answer, orderByComparator, false);
9913    
9914                            return array;
9915                    }
9916                    catch (Exception e) {
9917                            throw processException(e);
9918                    }
9919                    finally {
9920                            closeSession(session);
9921                    }
9922            }
9923    
9924            protected MBMessage getByT_A_PrevAndNext(Session session,
9925                    MBMessage mbMessage, long threadId, boolean answer,
9926                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
9927                    StringBundler query = null;
9928    
9929                    if (orderByComparator != null) {
9930                            query = new StringBundler(5 +
9931                                            (orderByComparator.getOrderByConditionFields().length * 3) +
9932                                            (orderByComparator.getOrderByFields().length * 3));
9933                    }
9934                    else {
9935                            query = new StringBundler(4);
9936                    }
9937    
9938                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9939    
9940                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9941    
9942                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9943    
9944                    if (orderByComparator != null) {
9945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9946    
9947                            if (orderByConditionFields.length > 0) {
9948                                    query.append(WHERE_AND);
9949                            }
9950    
9951                            for (int i = 0; i < orderByConditionFields.length; i++) {
9952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9953                                    query.append(orderByConditionFields[i]);
9954    
9955                                    if ((i + 1) < orderByConditionFields.length) {
9956                                            if (orderByComparator.isAscending() ^ previous) {
9957                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9958                                            }
9959                                            else {
9960                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9961                                            }
9962                                    }
9963                                    else {
9964                                            if (orderByComparator.isAscending() ^ previous) {
9965                                                    query.append(WHERE_GREATER_THAN);
9966                                            }
9967                                            else {
9968                                                    query.append(WHERE_LESSER_THAN);
9969                                            }
9970                                    }
9971                            }
9972    
9973                            query.append(ORDER_BY_CLAUSE);
9974    
9975                            String[] orderByFields = orderByComparator.getOrderByFields();
9976    
9977                            for (int i = 0; i < orderByFields.length; i++) {
9978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9979                                    query.append(orderByFields[i]);
9980    
9981                                    if ((i + 1) < orderByFields.length) {
9982                                            if (orderByComparator.isAscending() ^ previous) {
9983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9984                                            }
9985                                            else {
9986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9987                                            }
9988                                    }
9989                                    else {
9990                                            if (orderByComparator.isAscending() ^ previous) {
9991                                                    query.append(ORDER_BY_ASC);
9992                                            }
9993                                            else {
9994                                                    query.append(ORDER_BY_DESC);
9995                                            }
9996                                    }
9997                            }
9998                    }
9999                    else {
10000                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10001                    }
10002    
10003                    String sql = query.toString();
10004    
10005                    Query q = session.createQuery(sql);
10006    
10007                    q.setFirstResult(0);
10008                    q.setMaxResults(2);
10009    
10010                    QueryPos qPos = QueryPos.getInstance(q);
10011    
10012                    qPos.add(threadId);
10013    
10014                    qPos.add(answer);
10015    
10016                    if (orderByComparator != null) {
10017                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10018    
10019                            for (Object value : values) {
10020                                    qPos.add(value);
10021                            }
10022                    }
10023    
10024                    List<MBMessage> list = q.list();
10025    
10026                    if (list.size() == 2) {
10027                            return list.get(1);
10028                    }
10029                    else {
10030                            return null;
10031                    }
10032            }
10033    
10034            /**
10035             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
10036             *
10037             * @param threadId the thread ID
10038             * @param answer the answer
10039             */
10040            @Override
10041            public void removeByT_A(long threadId, boolean answer) {
10042                    for (MBMessage mbMessage : findByT_A(threadId, answer,
10043                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10044                            remove(mbMessage);
10045                    }
10046            }
10047    
10048            /**
10049             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
10050             *
10051             * @param threadId the thread ID
10052             * @param answer the answer
10053             * @return the number of matching message-boards messages
10054             */
10055            @Override
10056            public int countByT_A(long threadId, boolean answer) {
10057                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
10058    
10059                    Object[] finderArgs = new Object[] { threadId, answer };
10060    
10061                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10062    
10063                    if (count == null) {
10064                            StringBundler query = new StringBundler(3);
10065    
10066                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10067    
10068                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
10069    
10070                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
10071    
10072                            String sql = query.toString();
10073    
10074                            Session session = null;
10075    
10076                            try {
10077                                    session = openSession();
10078    
10079                                    Query q = session.createQuery(sql);
10080    
10081                                    QueryPos qPos = QueryPos.getInstance(q);
10082    
10083                                    qPos.add(threadId);
10084    
10085                                    qPos.add(answer);
10086    
10087                                    count = (Long)q.uniqueResult();
10088    
10089                                    finderCache.putResult(finderPath, finderArgs, count);
10090                            }
10091                            catch (Exception e) {
10092                                    finderCache.removeResult(finderPath, finderArgs);
10093    
10094                                    throw processException(e);
10095                            }
10096                            finally {
10097                                    closeSession(session);
10098                            }
10099                    }
10100    
10101                    return count.intValue();
10102            }
10103    
10104            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
10105            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
10106            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10107                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10108                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
10109                            new String[] {
10110                                    Long.class.getName(), Integer.class.getName(),
10111                                    
10112                            Integer.class.getName(), Integer.class.getName(),
10113                                    OrderByComparator.class.getName()
10114                            });
10115            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10116                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
10118                            new String[] { Long.class.getName(), Integer.class.getName() },
10119                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10120                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10121                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10122            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10123                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
10125                            new String[] { Long.class.getName(), Integer.class.getName() });
10126    
10127            /**
10128             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10129             *
10130             * @param threadId the thread ID
10131             * @param status the status
10132             * @return the matching message-boards messages
10133             */
10134            @Override
10135            public List<MBMessage> findByT_S(long threadId, int status) {
10136                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
10137                            QueryUtil.ALL_POS, null);
10138            }
10139    
10140            /**
10141             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10142             *
10143             * <p>
10144             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10145             * </p>
10146             *
10147             * @param threadId the thread ID
10148             * @param status the status
10149             * @param start the lower bound of the range of message-boards messages
10150             * @param end the upper bound of the range of message-boards messages (not inclusive)
10151             * @return the range of matching message-boards messages
10152             */
10153            @Override
10154            public List<MBMessage> findByT_S(long threadId, int status, int start,
10155                    int end) {
10156                    return findByT_S(threadId, status, start, end, null);
10157            }
10158    
10159            /**
10160             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10161             *
10162             * <p>
10163             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10164             * </p>
10165             *
10166             * @param threadId the thread ID
10167             * @param status the status
10168             * @param start the lower bound of the range of message-boards messages
10169             * @param end the upper bound of the range of message-boards messages (not inclusive)
10170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10171             * @return the ordered range of matching message-boards messages
10172             */
10173            @Override
10174            public List<MBMessage> findByT_S(long threadId, int status, int start,
10175                    int end, OrderByComparator<MBMessage> orderByComparator) {
10176                    return findByT_S(threadId, status, start, end, orderByComparator, true);
10177            }
10178    
10179            /**
10180             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10181             *
10182             * <p>
10183             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10184             * </p>
10185             *
10186             * @param threadId the thread ID
10187             * @param status the status
10188             * @param start the lower bound of the range of message-boards messages
10189             * @param end the upper bound of the range of message-boards messages (not inclusive)
10190             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10191             * @param retrieveFromCache whether to retrieve from the finder cache
10192             * @return the ordered range of matching message-boards messages
10193             */
10194            @Override
10195            public List<MBMessage> findByT_S(long threadId, int status, int start,
10196                    int end, OrderByComparator<MBMessage> orderByComparator,
10197                    boolean retrieveFromCache) {
10198                    boolean pagination = true;
10199                    FinderPath finderPath = null;
10200                    Object[] finderArgs = null;
10201    
10202                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10203                                    (orderByComparator == null)) {
10204                            pagination = false;
10205                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
10206                            finderArgs = new Object[] { threadId, status };
10207                    }
10208                    else {
10209                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
10210                            finderArgs = new Object[] {
10211                                            threadId, status,
10212                                            
10213                                            start, end, orderByComparator
10214                                    };
10215                    }
10216    
10217                    List<MBMessage> list = null;
10218    
10219                    if (retrieveFromCache) {
10220                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10221                                            finderArgs, this);
10222    
10223                            if ((list != null) && !list.isEmpty()) {
10224                                    for (MBMessage mbMessage : list) {
10225                                            if ((threadId != mbMessage.getThreadId()) ||
10226                                                            (status != mbMessage.getStatus())) {
10227                                                    list = null;
10228    
10229                                                    break;
10230                                            }
10231                                    }
10232                            }
10233                    }
10234    
10235                    if (list == null) {
10236                            StringBundler query = null;
10237    
10238                            if (orderByComparator != null) {
10239                                    query = new StringBundler(4 +
10240                                                    (orderByComparator.getOrderByFields().length * 2));
10241                            }
10242                            else {
10243                                    query = new StringBundler(4);
10244                            }
10245    
10246                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10247    
10248                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10249    
10250                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10251    
10252                            if (orderByComparator != null) {
10253                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10254                                            orderByComparator);
10255                            }
10256                            else
10257                             if (pagination) {
10258                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10259                            }
10260    
10261                            String sql = query.toString();
10262    
10263                            Session session = null;
10264    
10265                            try {
10266                                    session = openSession();
10267    
10268                                    Query q = session.createQuery(sql);
10269    
10270                                    QueryPos qPos = QueryPos.getInstance(q);
10271    
10272                                    qPos.add(threadId);
10273    
10274                                    qPos.add(status);
10275    
10276                                    if (!pagination) {
10277                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10278                                                            start, end, false);
10279    
10280                                            Collections.sort(list);
10281    
10282                                            list = Collections.unmodifiableList(list);
10283                                    }
10284                                    else {
10285                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10286                                                            start, end);
10287                                    }
10288    
10289                                    cacheResult(list);
10290    
10291                                    finderCache.putResult(finderPath, finderArgs, list);
10292                            }
10293                            catch (Exception e) {
10294                                    finderCache.removeResult(finderPath, finderArgs);
10295    
10296                                    throw processException(e);
10297                            }
10298                            finally {
10299                                    closeSession(session);
10300                            }
10301                    }
10302    
10303                    return list;
10304            }
10305    
10306            /**
10307             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10308             *
10309             * @param threadId the thread ID
10310             * @param status the status
10311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10312             * @return the first matching message-boards message
10313             * @throws NoSuchMessageException if a matching message-boards message could not be found
10314             */
10315            @Override
10316            public MBMessage findByT_S_First(long threadId, int status,
10317                    OrderByComparator<MBMessage> orderByComparator)
10318                    throws NoSuchMessageException {
10319                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
10320                                    orderByComparator);
10321    
10322                    if (mbMessage != null) {
10323                            return mbMessage;
10324                    }
10325    
10326                    StringBundler msg = new StringBundler(6);
10327    
10328                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10329    
10330                    msg.append("threadId=");
10331                    msg.append(threadId);
10332    
10333                    msg.append(", status=");
10334                    msg.append(status);
10335    
10336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10337    
10338                    throw new NoSuchMessageException(msg.toString());
10339            }
10340    
10341            /**
10342             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10343             *
10344             * @param threadId the thread ID
10345             * @param status the status
10346             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10347             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10348             */
10349            @Override
10350            public MBMessage fetchByT_S_First(long threadId, int status,
10351                    OrderByComparator<MBMessage> orderByComparator) {
10352                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
10353                                    orderByComparator);
10354    
10355                    if (!list.isEmpty()) {
10356                            return list.get(0);
10357                    }
10358    
10359                    return null;
10360            }
10361    
10362            /**
10363             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10364             *
10365             * @param threadId the thread ID
10366             * @param status the status
10367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10368             * @return the last matching message-boards message
10369             * @throws NoSuchMessageException if a matching message-boards message could not be found
10370             */
10371            @Override
10372            public MBMessage findByT_S_Last(long threadId, int status,
10373                    OrderByComparator<MBMessage> orderByComparator)
10374                    throws NoSuchMessageException {
10375                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
10376                                    orderByComparator);
10377    
10378                    if (mbMessage != null) {
10379                            return mbMessage;
10380                    }
10381    
10382                    StringBundler msg = new StringBundler(6);
10383    
10384                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10385    
10386                    msg.append("threadId=");
10387                    msg.append(threadId);
10388    
10389                    msg.append(", status=");
10390                    msg.append(status);
10391    
10392                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10393    
10394                    throw new NoSuchMessageException(msg.toString());
10395            }
10396    
10397            /**
10398             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10399             *
10400             * @param threadId the thread ID
10401             * @param status the status
10402             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10403             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10404             */
10405            @Override
10406            public MBMessage fetchByT_S_Last(long threadId, int status,
10407                    OrderByComparator<MBMessage> orderByComparator) {
10408                    int count = countByT_S(threadId, status);
10409    
10410                    if (count == 0) {
10411                            return null;
10412                    }
10413    
10414                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
10415                                    orderByComparator);
10416    
10417                    if (!list.isEmpty()) {
10418                            return list.get(0);
10419                    }
10420    
10421                    return null;
10422            }
10423    
10424            /**
10425             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10426             *
10427             * @param messageId the primary key of the current message-boards message
10428             * @param threadId the thread ID
10429             * @param status the status
10430             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10431             * @return the previous, current, and next message-boards message
10432             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10433             */
10434            @Override
10435            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
10436                    int status, OrderByComparator<MBMessage> orderByComparator)
10437                    throws NoSuchMessageException {
10438                    MBMessage mbMessage = findByPrimaryKey(messageId);
10439    
10440                    Session session = null;
10441    
10442                    try {
10443                            session = openSession();
10444    
10445                            MBMessage[] array = new MBMessageImpl[3];
10446    
10447                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10448                                            status, orderByComparator, true);
10449    
10450                            array[1] = mbMessage;
10451    
10452                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10453                                            status, orderByComparator, false);
10454    
10455                            return array;
10456                    }
10457                    catch (Exception e) {
10458                            throw processException(e);
10459                    }
10460                    finally {
10461                            closeSession(session);
10462                    }
10463            }
10464    
10465            protected MBMessage getByT_S_PrevAndNext(Session session,
10466                    MBMessage mbMessage, long threadId, int status,
10467                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
10468                    StringBundler query = null;
10469    
10470                    if (orderByComparator != null) {
10471                            query = new StringBundler(5 +
10472                                            (orderByComparator.getOrderByConditionFields().length * 3) +
10473                                            (orderByComparator.getOrderByFields().length * 3));
10474                    }
10475                    else {
10476                            query = new StringBundler(4);
10477                    }
10478    
10479                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10480    
10481                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10482    
10483                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10484    
10485                    if (orderByComparator != null) {
10486                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10487    
10488                            if (orderByConditionFields.length > 0) {
10489                                    query.append(WHERE_AND);
10490                            }
10491    
10492                            for (int i = 0; i < orderByConditionFields.length; i++) {
10493                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10494                                    query.append(orderByConditionFields[i]);
10495    
10496                                    if ((i + 1) < orderByConditionFields.length) {
10497                                            if (orderByComparator.isAscending() ^ previous) {
10498                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10499                                            }
10500                                            else {
10501                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10502                                            }
10503                                    }
10504                                    else {
10505                                            if (orderByComparator.isAscending() ^ previous) {
10506                                                    query.append(WHERE_GREATER_THAN);
10507                                            }
10508                                            else {
10509                                                    query.append(WHERE_LESSER_THAN);
10510                                            }
10511                                    }
10512                            }
10513    
10514                            query.append(ORDER_BY_CLAUSE);
10515    
10516                            String[] orderByFields = orderByComparator.getOrderByFields();
10517    
10518                            for (int i = 0; i < orderByFields.length; i++) {
10519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10520                                    query.append(orderByFields[i]);
10521    
10522                                    if ((i + 1) < orderByFields.length) {
10523                                            if (orderByComparator.isAscending() ^ previous) {
10524                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10525                                            }
10526                                            else {
10527                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10528                                            }
10529                                    }
10530                                    else {
10531                                            if (orderByComparator.isAscending() ^ previous) {
10532                                                    query.append(ORDER_BY_ASC);
10533                                            }
10534                                            else {
10535                                                    query.append(ORDER_BY_DESC);
10536                                            }
10537                                    }
10538                            }
10539                    }
10540                    else {
10541                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10542                    }
10543    
10544                    String sql = query.toString();
10545    
10546                    Query q = session.createQuery(sql);
10547    
10548                    q.setFirstResult(0);
10549                    q.setMaxResults(2);
10550    
10551                    QueryPos qPos = QueryPos.getInstance(q);
10552    
10553                    qPos.add(threadId);
10554    
10555                    qPos.add(status);
10556    
10557                    if (orderByComparator != null) {
10558                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10559    
10560                            for (Object value : values) {
10561                                    qPos.add(value);
10562                            }
10563                    }
10564    
10565                    List<MBMessage> list = q.list();
10566    
10567                    if (list.size() == 2) {
10568                            return list.get(1);
10569                    }
10570                    else {
10571                            return null;
10572                    }
10573            }
10574    
10575            /**
10576             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10577             *
10578             * @param threadId the thread ID
10579             * @param status the status
10580             */
10581            @Override
10582            public void removeByT_S(long threadId, int status) {
10583                    for (MBMessage mbMessage : findByT_S(threadId, status,
10584                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10585                            remove(mbMessage);
10586                    }
10587            }
10588    
10589            /**
10590             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10591             *
10592             * @param threadId the thread ID
10593             * @param status the status
10594             * @return the number of matching message-boards messages
10595             */
10596            @Override
10597            public int countByT_S(long threadId, int status) {
10598                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10599    
10600                    Object[] finderArgs = new Object[] { threadId, status };
10601    
10602                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10603    
10604                    if (count == null) {
10605                            StringBundler query = new StringBundler(3);
10606    
10607                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10608    
10609                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10610    
10611                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10612    
10613                            String sql = query.toString();
10614    
10615                            Session session = null;
10616    
10617                            try {
10618                                    session = openSession();
10619    
10620                                    Query q = session.createQuery(sql);
10621    
10622                                    QueryPos qPos = QueryPos.getInstance(q);
10623    
10624                                    qPos.add(threadId);
10625    
10626                                    qPos.add(status);
10627    
10628                                    count = (Long)q.uniqueResult();
10629    
10630                                    finderCache.putResult(finderPath, finderArgs, count);
10631                            }
10632                            catch (Exception e) {
10633                                    finderCache.removeResult(finderPath, finderArgs);
10634    
10635                                    throw processException(e);
10636                            }
10637                            finally {
10638                                    closeSession(session);
10639                            }
10640                    }
10641    
10642                    return count.intValue();
10643            }
10644    
10645            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10646            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10647            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10648                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10649                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10650                            new String[] {
10651                                    Long.class.getName(), Integer.class.getName(),
10652                                    
10653                            Integer.class.getName(), Integer.class.getName(),
10654                                    OrderByComparator.class.getName()
10655                            });
10656            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10657                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10658                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10659                            new String[] { Long.class.getName(), Integer.class.getName() },
10660                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10661                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10662                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10663            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10664                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10665                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10666                            new String[] { Long.class.getName(), Integer.class.getName() });
10667    
10668            /**
10669             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10670             *
10671             * @param threadId the thread ID
10672             * @param status the status
10673             * @return the matching message-boards messages
10674             */
10675            @Override
10676            public List<MBMessage> findByTR_S(long threadId, int status) {
10677                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10678                            QueryUtil.ALL_POS, null);
10679            }
10680    
10681            /**
10682             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10683             *
10684             * <p>
10685             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10686             * </p>
10687             *
10688             * @param threadId the thread ID
10689             * @param status the status
10690             * @param start the lower bound of the range of message-boards messages
10691             * @param end the upper bound of the range of message-boards messages (not inclusive)
10692             * @return the range of matching message-boards messages
10693             */
10694            @Override
10695            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10696                    int end) {
10697                    return findByTR_S(threadId, status, start, end, null);
10698            }
10699    
10700            /**
10701             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10702             *
10703             * <p>
10704             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10705             * </p>
10706             *
10707             * @param threadId the thread ID
10708             * @param status the status
10709             * @param start the lower bound of the range of message-boards messages
10710             * @param end the upper bound of the range of message-boards messages (not inclusive)
10711             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10712             * @return the ordered range of matching message-boards messages
10713             */
10714            @Override
10715            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10716                    int end, OrderByComparator<MBMessage> orderByComparator) {
10717                    return findByTR_S(threadId, status, start, end, orderByComparator, true);
10718            }
10719    
10720            /**
10721             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10722             *
10723             * <p>
10724             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10725             * </p>
10726             *
10727             * @param threadId the thread ID
10728             * @param status the status
10729             * @param start the lower bound of the range of message-boards messages
10730             * @param end the upper bound of the range of message-boards messages (not inclusive)
10731             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10732             * @param retrieveFromCache whether to retrieve from the finder cache
10733             * @return the ordered range of matching message-boards messages
10734             */
10735            @Override
10736            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10737                    int end, OrderByComparator<MBMessage> orderByComparator,
10738                    boolean retrieveFromCache) {
10739                    boolean pagination = true;
10740                    FinderPath finderPath = null;
10741                    Object[] finderArgs = null;
10742    
10743                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10744                                    (orderByComparator == null)) {
10745                            pagination = false;
10746                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10747                            finderArgs = new Object[] { threadId, status };
10748                    }
10749                    else {
10750                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10751                            finderArgs = new Object[] {
10752                                            threadId, status,
10753                                            
10754                                            start, end, orderByComparator
10755                                    };
10756                    }
10757    
10758                    List<MBMessage> list = null;
10759    
10760                    if (retrieveFromCache) {
10761                            list = (List<MBMessage>)finderCache.getResult(finderPath,
10762                                            finderArgs, this);
10763    
10764                            if ((list != null) && !list.isEmpty()) {
10765                                    for (MBMessage mbMessage : list) {
10766                                            if ((threadId != mbMessage.getThreadId()) ||
10767                                                            (status != mbMessage.getStatus())) {
10768                                                    list = null;
10769    
10770                                                    break;
10771                                            }
10772                                    }
10773                            }
10774                    }
10775    
10776                    if (list == null) {
10777                            StringBundler query = null;
10778    
10779                            if (orderByComparator != null) {
10780                                    query = new StringBundler(4 +
10781                                                    (orderByComparator.getOrderByFields().length * 2));
10782                            }
10783                            else {
10784                                    query = new StringBundler(4);
10785                            }
10786    
10787                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10788    
10789                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10790    
10791                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10792    
10793                            if (orderByComparator != null) {
10794                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10795                                            orderByComparator);
10796                            }
10797                            else
10798                             if (pagination) {
10799                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10800                            }
10801    
10802                            String sql = query.toString();
10803    
10804                            Session session = null;
10805    
10806                            try {
10807                                    session = openSession();
10808    
10809                                    Query q = session.createQuery(sql);
10810    
10811                                    QueryPos qPos = QueryPos.getInstance(q);
10812    
10813                                    qPos.add(threadId);
10814    
10815                                    qPos.add(status);
10816    
10817                                    if (!pagination) {
10818                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10819                                                            start, end, false);
10820    
10821                                            Collections.sort(list);
10822    
10823                                            list = Collections.unmodifiableList(list);
10824                                    }
10825                                    else {
10826                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10827                                                            start, end);
10828                                    }
10829    
10830                                    cacheResult(list);
10831    
10832                                    finderCache.putResult(finderPath, finderArgs, list);
10833                            }
10834                            catch (Exception e) {
10835                                    finderCache.removeResult(finderPath, finderArgs);
10836    
10837                                    throw processException(e);
10838                            }
10839                            finally {
10840                                    closeSession(session);
10841                            }
10842                    }
10843    
10844                    return list;
10845            }
10846    
10847            /**
10848             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10849             *
10850             * @param threadId the thread ID
10851             * @param status the status
10852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10853             * @return the first matching message-boards message
10854             * @throws NoSuchMessageException if a matching message-boards message could not be found
10855             */
10856            @Override
10857            public MBMessage findByTR_S_First(long threadId, int status,
10858                    OrderByComparator<MBMessage> orderByComparator)
10859                    throws NoSuchMessageException {
10860                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10861                                    orderByComparator);
10862    
10863                    if (mbMessage != null) {
10864                            return mbMessage;
10865                    }
10866    
10867                    StringBundler msg = new StringBundler(6);
10868    
10869                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10870    
10871                    msg.append("threadId=");
10872                    msg.append(threadId);
10873    
10874                    msg.append(", status=");
10875                    msg.append(status);
10876    
10877                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10878    
10879                    throw new NoSuchMessageException(msg.toString());
10880            }
10881    
10882            /**
10883             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10884             *
10885             * @param threadId the thread ID
10886             * @param status the status
10887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10888             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10889             */
10890            @Override
10891            public MBMessage fetchByTR_S_First(long threadId, int status,
10892                    OrderByComparator<MBMessage> orderByComparator) {
10893                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10894                                    orderByComparator);
10895    
10896                    if (!list.isEmpty()) {
10897                            return list.get(0);
10898                    }
10899    
10900                    return null;
10901            }
10902    
10903            /**
10904             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10905             *
10906             * @param threadId the thread ID
10907             * @param status the status
10908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10909             * @return the last matching message-boards message
10910             * @throws NoSuchMessageException if a matching message-boards message could not be found
10911             */
10912            @Override
10913            public MBMessage findByTR_S_Last(long threadId, int status,
10914                    OrderByComparator<MBMessage> orderByComparator)
10915                    throws NoSuchMessageException {
10916                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10917                                    orderByComparator);
10918    
10919                    if (mbMessage != null) {
10920                            return mbMessage;
10921                    }
10922    
10923                    StringBundler msg = new StringBundler(6);
10924    
10925                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10926    
10927                    msg.append("threadId=");
10928                    msg.append(threadId);
10929    
10930                    msg.append(", status=");
10931                    msg.append(status);
10932    
10933                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10934    
10935                    throw new NoSuchMessageException(msg.toString());
10936            }
10937    
10938            /**
10939             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10940             *
10941             * @param threadId the thread ID
10942             * @param status the status
10943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10944             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10945             */
10946            @Override
10947            public MBMessage fetchByTR_S_Last(long threadId, int status,
10948                    OrderByComparator<MBMessage> orderByComparator) {
10949                    int count = countByTR_S(threadId, status);
10950    
10951                    if (count == 0) {
10952                            return null;
10953                    }
10954    
10955                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10956                                    orderByComparator);
10957    
10958                    if (!list.isEmpty()) {
10959                            return list.get(0);
10960                    }
10961    
10962                    return null;
10963            }
10964    
10965            /**
10966             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10967             *
10968             * @param messageId the primary key of the current message-boards message
10969             * @param threadId the thread ID
10970             * @param status the status
10971             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10972             * @return the previous, current, and next message-boards message
10973             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
10974             */
10975            @Override
10976            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10977                    int status, OrderByComparator<MBMessage> orderByComparator)
10978                    throws NoSuchMessageException {
10979                    MBMessage mbMessage = findByPrimaryKey(messageId);
10980    
10981                    Session session = null;
10982    
10983                    try {
10984                            session = openSession();
10985    
10986                            MBMessage[] array = new MBMessageImpl[3];
10987    
10988                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10989                                            status, orderByComparator, true);
10990    
10991                            array[1] = mbMessage;
10992    
10993                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10994                                            status, orderByComparator, false);
10995    
10996                            return array;
10997                    }
10998                    catch (Exception e) {
10999                            throw processException(e);
11000                    }
11001                    finally {
11002                            closeSession(session);
11003                    }
11004            }
11005    
11006            protected MBMessage getByTR_S_PrevAndNext(Session session,
11007                    MBMessage mbMessage, long threadId, int status,
11008                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11009                    StringBundler query = null;
11010    
11011                    if (orderByComparator != null) {
11012                            query = new StringBundler(5 +
11013                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11014                                            (orderByComparator.getOrderByFields().length * 3));
11015                    }
11016                    else {
11017                            query = new StringBundler(4);
11018                    }
11019    
11020                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11021    
11022                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11023    
11024                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11025    
11026                    if (orderByComparator != null) {
11027                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11028    
11029                            if (orderByConditionFields.length > 0) {
11030                                    query.append(WHERE_AND);
11031                            }
11032    
11033                            for (int i = 0; i < orderByConditionFields.length; i++) {
11034                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11035                                    query.append(orderByConditionFields[i]);
11036    
11037                                    if ((i + 1) < orderByConditionFields.length) {
11038                                            if (orderByComparator.isAscending() ^ previous) {
11039                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11040                                            }
11041                                            else {
11042                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11043                                            }
11044                                    }
11045                                    else {
11046                                            if (orderByComparator.isAscending() ^ previous) {
11047                                                    query.append(WHERE_GREATER_THAN);
11048                                            }
11049                                            else {
11050                                                    query.append(WHERE_LESSER_THAN);
11051                                            }
11052                                    }
11053                            }
11054    
11055                            query.append(ORDER_BY_CLAUSE);
11056    
11057                            String[] orderByFields = orderByComparator.getOrderByFields();
11058    
11059                            for (int i = 0; i < orderByFields.length; i++) {
11060                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11061                                    query.append(orderByFields[i]);
11062    
11063                                    if ((i + 1) < orderByFields.length) {
11064                                            if (orderByComparator.isAscending() ^ previous) {
11065                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11066                                            }
11067                                            else {
11068                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11069                                            }
11070                                    }
11071                                    else {
11072                                            if (orderByComparator.isAscending() ^ previous) {
11073                                                    query.append(ORDER_BY_ASC);
11074                                            }
11075                                            else {
11076                                                    query.append(ORDER_BY_DESC);
11077                                            }
11078                                    }
11079                            }
11080                    }
11081                    else {
11082                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11083                    }
11084    
11085                    String sql = query.toString();
11086    
11087                    Query q = session.createQuery(sql);
11088    
11089                    q.setFirstResult(0);
11090                    q.setMaxResults(2);
11091    
11092                    QueryPos qPos = QueryPos.getInstance(q);
11093    
11094                    qPos.add(threadId);
11095    
11096                    qPos.add(status);
11097    
11098                    if (orderByComparator != null) {
11099                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11100    
11101                            for (Object value : values) {
11102                                    qPos.add(value);
11103                            }
11104                    }
11105    
11106                    List<MBMessage> list = q.list();
11107    
11108                    if (list.size() == 2) {
11109                            return list.get(1);
11110                    }
11111                    else {
11112                            return null;
11113                    }
11114            }
11115    
11116            /**
11117             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
11118             *
11119             * @param threadId the thread ID
11120             * @param status the status
11121             */
11122            @Override
11123            public void removeByTR_S(long threadId, int status) {
11124                    for (MBMessage mbMessage : findByTR_S(threadId, status,
11125                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11126                            remove(mbMessage);
11127                    }
11128            }
11129    
11130            /**
11131             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
11132             *
11133             * @param threadId the thread ID
11134             * @param status the status
11135             * @return the number of matching message-boards messages
11136             */
11137            @Override
11138            public int countByTR_S(long threadId, int status) {
11139                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
11140    
11141                    Object[] finderArgs = new Object[] { threadId, status };
11142    
11143                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
11144    
11145                    if (count == null) {
11146                            StringBundler query = new StringBundler(3);
11147    
11148                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11149    
11150                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
11151    
11152                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
11153    
11154                            String sql = query.toString();
11155    
11156                            Session session = null;
11157    
11158                            try {
11159                                    session = openSession();
11160    
11161                                    Query q = session.createQuery(sql);
11162    
11163                                    QueryPos qPos = QueryPos.getInstance(q);
11164    
11165                                    qPos.add(threadId);
11166    
11167                                    qPos.add(status);
11168    
11169                                    count = (Long)q.uniqueResult();
11170    
11171                                    finderCache.putResult(finderPath, finderArgs, count);
11172                            }
11173                            catch (Exception e) {
11174                                    finderCache.removeResult(finderPath, finderArgs);
11175    
11176                                    throw processException(e);
11177                            }
11178                            finally {
11179                                    closeSession(session);
11180                            }
11181                    }
11182    
11183                    return count.intValue();
11184            }
11185    
11186            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11187            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11188            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11189                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11190                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
11191                            new String[] {
11192                                    Long.class.getName(), Long.class.getName(),
11193                                    Integer.class.getName(),
11194                                    
11195                            Integer.class.getName(), Integer.class.getName(),
11196                                    OrderByComparator.class.getName()
11197                            });
11198            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11199                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
11201                            new String[] {
11202                                    Long.class.getName(), Long.class.getName(),
11203                                    Integer.class.getName()
11204                            },
11205                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11206                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
11207                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
11208                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11209            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11210                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11211                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
11212                            new String[] {
11213                                    Long.class.getName(), Long.class.getName(),
11214                                    Integer.class.getName()
11215                            });
11216    
11217            /**
11218             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11219             *
11220             * @param groupId the group ID
11221             * @param userId the user ID
11222             * @param status the status
11223             * @return the matching message-boards messages
11224             */
11225            @Override
11226            public List<MBMessage> findByG_U_S(long groupId, long userId, int status) {
11227                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11228                            QueryUtil.ALL_POS, null);
11229            }
11230    
11231            /**
11232             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11233             *
11234             * <p>
11235             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11236             * </p>
11237             *
11238             * @param groupId the group ID
11239             * @param userId the user ID
11240             * @param status the status
11241             * @param start the lower bound of the range of message-boards messages
11242             * @param end the upper bound of the range of message-boards messages (not inclusive)
11243             * @return the range of matching message-boards messages
11244             */
11245            @Override
11246            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11247                    int start, int end) {
11248                    return findByG_U_S(groupId, userId, status, start, end, null);
11249            }
11250    
11251            /**
11252             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11253             *
11254             * <p>
11255             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11256             * </p>
11257             *
11258             * @param groupId the group ID
11259             * @param userId the user ID
11260             * @param status the status
11261             * @param start the lower bound of the range of message-boards messages
11262             * @param end the upper bound of the range of message-boards messages (not inclusive)
11263             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11264             * @return the ordered range of matching message-boards messages
11265             */
11266            @Override
11267            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11268                    int start, int end, OrderByComparator<MBMessage> orderByComparator) {
11269                    return findByG_U_S(groupId, userId, status, start, end,
11270                            orderByComparator, true);
11271            }
11272    
11273            /**
11274             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11275             *
11276             * <p>
11277             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11278             * </p>
11279             *
11280             * @param groupId the group ID
11281             * @param userId the user ID
11282             * @param status the status
11283             * @param start the lower bound of the range of message-boards messages
11284             * @param end the upper bound of the range of message-boards messages (not inclusive)
11285             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11286             * @param retrieveFromCache whether to retrieve from the finder cache
11287             * @return the ordered range of matching message-boards messages
11288             */
11289            @Override
11290            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
11291                    int start, int end, OrderByComparator<MBMessage> orderByComparator,
11292                    boolean retrieveFromCache) {
11293                    boolean pagination = true;
11294                    FinderPath finderPath = null;
11295                    Object[] finderArgs = null;
11296    
11297                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11298                                    (orderByComparator == null)) {
11299                            pagination = false;
11300                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
11301                            finderArgs = new Object[] { groupId, userId, status };
11302                    }
11303                    else {
11304                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
11305                            finderArgs = new Object[] {
11306                                            groupId, userId, status,
11307                                            
11308                                            start, end, orderByComparator
11309                                    };
11310                    }
11311    
11312                    List<MBMessage> list = null;
11313    
11314                    if (retrieveFromCache) {
11315                            list = (List<MBMessage>)finderCache.getResult(finderPath,
11316                                            finderArgs, this);
11317    
11318                            if ((list != null) && !list.isEmpty()) {
11319                                    for (MBMessage mbMessage : list) {
11320                                            if ((groupId != mbMessage.getGroupId()) ||
11321                                                            (userId != mbMessage.getUserId()) ||
11322                                                            (status != mbMessage.getStatus())) {
11323                                                    list = null;
11324    
11325                                                    break;
11326                                            }
11327                                    }
11328                            }
11329                    }
11330    
11331                    if (list == null) {
11332                            StringBundler query = null;
11333    
11334                            if (orderByComparator != null) {
11335                                    query = new StringBundler(5 +
11336                                                    (orderByComparator.getOrderByFields().length * 2));
11337                            }
11338                            else {
11339                                    query = new StringBundler(5);
11340                            }
11341    
11342                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11343    
11344                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11345    
11346                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11347    
11348                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11349    
11350                            if (orderByComparator != null) {
11351                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11352                                            orderByComparator);
11353                            }
11354                            else
11355                             if (pagination) {
11356                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11357                            }
11358    
11359                            String sql = query.toString();
11360    
11361                            Session session = null;
11362    
11363                            try {
11364                                    session = openSession();
11365    
11366                                    Query q = session.createQuery(sql);
11367    
11368                                    QueryPos qPos = QueryPos.getInstance(q);
11369    
11370                                    qPos.add(groupId);
11371    
11372                                    qPos.add(userId);
11373    
11374                                    qPos.add(status);
11375    
11376                                    if (!pagination) {
11377                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11378                                                            start, end, false);
11379    
11380                                            Collections.sort(list);
11381    
11382                                            list = Collections.unmodifiableList(list);
11383                                    }
11384                                    else {
11385                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11386                                                            start, end);
11387                                    }
11388    
11389                                    cacheResult(list);
11390    
11391                                    finderCache.putResult(finderPath, finderArgs, list);
11392                            }
11393                            catch (Exception e) {
11394                                    finderCache.removeResult(finderPath, finderArgs);
11395    
11396                                    throw processException(e);
11397                            }
11398                            finally {
11399                                    closeSession(session);
11400                            }
11401                    }
11402    
11403                    return list;
11404            }
11405    
11406            /**
11407             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11408             *
11409             * @param groupId the group ID
11410             * @param userId the user ID
11411             * @param status the status
11412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11413             * @return the first matching message-boards message
11414             * @throws NoSuchMessageException if a matching message-boards message could not be found
11415             */
11416            @Override
11417            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
11418                    OrderByComparator<MBMessage> orderByComparator)
11419                    throws NoSuchMessageException {
11420                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
11421                                    orderByComparator);
11422    
11423                    if (mbMessage != null) {
11424                            return mbMessage;
11425                    }
11426    
11427                    StringBundler msg = new StringBundler(8);
11428    
11429                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11430    
11431                    msg.append("groupId=");
11432                    msg.append(groupId);
11433    
11434                    msg.append(", userId=");
11435                    msg.append(userId);
11436    
11437                    msg.append(", status=");
11438                    msg.append(status);
11439    
11440                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11441    
11442                    throw new NoSuchMessageException(msg.toString());
11443            }
11444    
11445            /**
11446             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11447             *
11448             * @param groupId the group ID
11449             * @param userId the user ID
11450             * @param status the status
11451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11452             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11453             */
11454            @Override
11455            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
11456                    OrderByComparator<MBMessage> orderByComparator) {
11457                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
11458                                    orderByComparator);
11459    
11460                    if (!list.isEmpty()) {
11461                            return list.get(0);
11462                    }
11463    
11464                    return null;
11465            }
11466    
11467            /**
11468             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11469             *
11470             * @param groupId the group ID
11471             * @param userId the user ID
11472             * @param status the status
11473             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11474             * @return the last matching message-boards message
11475             * @throws NoSuchMessageException if a matching message-boards message could not be found
11476             */
11477            @Override
11478            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
11479                    OrderByComparator<MBMessage> orderByComparator)
11480                    throws NoSuchMessageException {
11481                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
11482                                    orderByComparator);
11483    
11484                    if (mbMessage != null) {
11485                            return mbMessage;
11486                    }
11487    
11488                    StringBundler msg = new StringBundler(8);
11489    
11490                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11491    
11492                    msg.append("groupId=");
11493                    msg.append(groupId);
11494    
11495                    msg.append(", userId=");
11496                    msg.append(userId);
11497    
11498                    msg.append(", status=");
11499                    msg.append(status);
11500    
11501                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11502    
11503                    throw new NoSuchMessageException(msg.toString());
11504            }
11505    
11506            /**
11507             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11508             *
11509             * @param groupId the group ID
11510             * @param userId the user ID
11511             * @param status the status
11512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11513             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11514             */
11515            @Override
11516            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11517                    OrderByComparator<MBMessage> orderByComparator) {
11518                    int count = countByG_U_S(groupId, userId, status);
11519    
11520                    if (count == 0) {
11521                            return null;
11522                    }
11523    
11524                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11525                                    count, orderByComparator);
11526    
11527                    if (!list.isEmpty()) {
11528                            return list.get(0);
11529                    }
11530    
11531                    return null;
11532            }
11533    
11534            /**
11535             * 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;.
11536             *
11537             * @param messageId the primary key of the current message-boards message
11538             * @param groupId the group ID
11539             * @param userId the user ID
11540             * @param status the status
11541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11542             * @return the previous, current, and next message-boards message
11543             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11544             */
11545            @Override
11546            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11547                    long userId, int status, OrderByComparator<MBMessage> orderByComparator)
11548                    throws NoSuchMessageException {
11549                    MBMessage mbMessage = findByPrimaryKey(messageId);
11550    
11551                    Session session = null;
11552    
11553                    try {
11554                            session = openSession();
11555    
11556                            MBMessage[] array = new MBMessageImpl[3];
11557    
11558                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11559                                            userId, status, orderByComparator, true);
11560    
11561                            array[1] = mbMessage;
11562    
11563                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11564                                            userId, status, orderByComparator, false);
11565    
11566                            return array;
11567                    }
11568                    catch (Exception e) {
11569                            throw processException(e);
11570                    }
11571                    finally {
11572                            closeSession(session);
11573                    }
11574            }
11575    
11576            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11577                    MBMessage mbMessage, long groupId, long userId, int status,
11578                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11579                    StringBundler query = null;
11580    
11581                    if (orderByComparator != null) {
11582                            query = new StringBundler(6 +
11583                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11584                                            (orderByComparator.getOrderByFields().length * 3));
11585                    }
11586                    else {
11587                            query = new StringBundler(5);
11588                    }
11589    
11590                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11591    
11592                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11593    
11594                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11595    
11596                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11597    
11598                    if (orderByComparator != null) {
11599                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11600    
11601                            if (orderByConditionFields.length > 0) {
11602                                    query.append(WHERE_AND);
11603                            }
11604    
11605                            for (int i = 0; i < orderByConditionFields.length; i++) {
11606                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11607                                    query.append(orderByConditionFields[i]);
11608    
11609                                    if ((i + 1) < orderByConditionFields.length) {
11610                                            if (orderByComparator.isAscending() ^ previous) {
11611                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11612                                            }
11613                                            else {
11614                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11615                                            }
11616                                    }
11617                                    else {
11618                                            if (orderByComparator.isAscending() ^ previous) {
11619                                                    query.append(WHERE_GREATER_THAN);
11620                                            }
11621                                            else {
11622                                                    query.append(WHERE_LESSER_THAN);
11623                                            }
11624                                    }
11625                            }
11626    
11627                            query.append(ORDER_BY_CLAUSE);
11628    
11629                            String[] orderByFields = orderByComparator.getOrderByFields();
11630    
11631                            for (int i = 0; i < orderByFields.length; i++) {
11632                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11633                                    query.append(orderByFields[i]);
11634    
11635                                    if ((i + 1) < orderByFields.length) {
11636                                            if (orderByComparator.isAscending() ^ previous) {
11637                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11638                                            }
11639                                            else {
11640                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11641                                            }
11642                                    }
11643                                    else {
11644                                            if (orderByComparator.isAscending() ^ previous) {
11645                                                    query.append(ORDER_BY_ASC);
11646                                            }
11647                                            else {
11648                                                    query.append(ORDER_BY_DESC);
11649                                            }
11650                                    }
11651                            }
11652                    }
11653                    else {
11654                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11655                    }
11656    
11657                    String sql = query.toString();
11658    
11659                    Query q = session.createQuery(sql);
11660    
11661                    q.setFirstResult(0);
11662                    q.setMaxResults(2);
11663    
11664                    QueryPos qPos = QueryPos.getInstance(q);
11665    
11666                    qPos.add(groupId);
11667    
11668                    qPos.add(userId);
11669    
11670                    qPos.add(status);
11671    
11672                    if (orderByComparator != null) {
11673                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11674    
11675                            for (Object value : values) {
11676                                    qPos.add(value);
11677                            }
11678                    }
11679    
11680                    List<MBMessage> list = q.list();
11681    
11682                    if (list.size() == 2) {
11683                            return list.get(1);
11684                    }
11685                    else {
11686                            return null;
11687                    }
11688            }
11689    
11690            /**
11691             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11692             *
11693             * @param groupId the group ID
11694             * @param userId the user ID
11695             * @param status the status
11696             * @return the matching message-boards messages that the user has permission to view
11697             */
11698            @Override
11699            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11700                    int status) {
11701                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11702                            QueryUtil.ALL_POS, null);
11703            }
11704    
11705            /**
11706             * 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;.
11707             *
11708             * <p>
11709             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11710             * </p>
11711             *
11712             * @param groupId the group ID
11713             * @param userId the user ID
11714             * @param status the status
11715             * @param start the lower bound of the range of message-boards messages
11716             * @param end the upper bound of the range of message-boards messages (not inclusive)
11717             * @return the range of matching message-boards messages that the user has permission to view
11718             */
11719            @Override
11720            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11721                    int status, int start, int end) {
11722                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11723            }
11724    
11725            /**
11726             * 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;.
11727             *
11728             * <p>
11729             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11730             * </p>
11731             *
11732             * @param groupId the group ID
11733             * @param userId the user ID
11734             * @param status the status
11735             * @param start the lower bound of the range of message-boards messages
11736             * @param end the upper bound of the range of message-boards messages (not inclusive)
11737             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11738             * @return the ordered range of matching message-boards messages that the user has permission to view
11739             */
11740            @Override
11741            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11742                    int status, int start, int end,
11743                    OrderByComparator<MBMessage> orderByComparator) {
11744                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11745                            return findByG_U_S(groupId, userId, status, start, end,
11746                                    orderByComparator);
11747                    }
11748    
11749                    StringBundler query = null;
11750    
11751                    if (orderByComparator != null) {
11752                            query = new StringBundler(5 +
11753                                            (orderByComparator.getOrderByFields().length * 2));
11754                    }
11755                    else {
11756                            query = new StringBundler(6);
11757                    }
11758    
11759                    if (getDB().isSupportsInlineDistinct()) {
11760                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11761                    }
11762                    else {
11763                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11764                    }
11765    
11766                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11767    
11768                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11769    
11770                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11771    
11772                    if (!getDB().isSupportsInlineDistinct()) {
11773                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11774                    }
11775    
11776                    if (orderByComparator != null) {
11777                            if (getDB().isSupportsInlineDistinct()) {
11778                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11779                                            orderByComparator, true);
11780                            }
11781                            else {
11782                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11783                                            orderByComparator, true);
11784                            }
11785                    }
11786                    else {
11787                            if (getDB().isSupportsInlineDistinct()) {
11788                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11789                            }
11790                            else {
11791                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11792                            }
11793                    }
11794    
11795                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11796                                    MBMessage.class.getName(),
11797                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11798    
11799                    Session session = null;
11800    
11801                    try {
11802                            session = openSession();
11803    
11804                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11805    
11806                            if (getDB().isSupportsInlineDistinct()) {
11807                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11808                            }
11809                            else {
11810                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11811                            }
11812    
11813                            QueryPos qPos = QueryPos.getInstance(q);
11814    
11815                            qPos.add(groupId);
11816    
11817                            qPos.add(userId);
11818    
11819                            qPos.add(status);
11820    
11821                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11822                    }
11823                    catch (Exception e) {
11824                            throw processException(e);
11825                    }
11826                    finally {
11827                            closeSession(session);
11828                    }
11829            }
11830    
11831            /**
11832             * 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;.
11833             *
11834             * @param messageId the primary key of the current message-boards message
11835             * @param groupId the group ID
11836             * @param userId the user ID
11837             * @param status the status
11838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11839             * @return the previous, current, and next message-boards message
11840             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
11841             */
11842            @Override
11843            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11844                    long groupId, long userId, int status,
11845                    OrderByComparator<MBMessage> orderByComparator)
11846                    throws NoSuchMessageException {
11847                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11848                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11849                                    orderByComparator);
11850                    }
11851    
11852                    MBMessage mbMessage = findByPrimaryKey(messageId);
11853    
11854                    Session session = null;
11855    
11856                    try {
11857                            session = openSession();
11858    
11859                            MBMessage[] array = new MBMessageImpl[3];
11860    
11861                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11862                                            groupId, userId, status, orderByComparator, true);
11863    
11864                            array[1] = mbMessage;
11865    
11866                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11867                                            groupId, userId, status, orderByComparator, false);
11868    
11869                            return array;
11870                    }
11871                    catch (Exception e) {
11872                            throw processException(e);
11873                    }
11874                    finally {
11875                            closeSession(session);
11876                    }
11877            }
11878    
11879            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11880                    MBMessage mbMessage, long groupId, long userId, int status,
11881                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
11882                    StringBundler query = null;
11883    
11884                    if (orderByComparator != null) {
11885                            query = new StringBundler(7 +
11886                                            (orderByComparator.getOrderByConditionFields().length * 3) +
11887                                            (orderByComparator.getOrderByFields().length * 3));
11888                    }
11889                    else {
11890                            query = new StringBundler(6);
11891                    }
11892    
11893                    if (getDB().isSupportsInlineDistinct()) {
11894                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11895                    }
11896                    else {
11897                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11898                    }
11899    
11900                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11901    
11902                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11903    
11904                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11905    
11906                    if (!getDB().isSupportsInlineDistinct()) {
11907                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11908                    }
11909    
11910                    if (orderByComparator != null) {
11911                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11912    
11913                            if (orderByConditionFields.length > 0) {
11914                                    query.append(WHERE_AND);
11915                            }
11916    
11917                            for (int i = 0; i < orderByConditionFields.length; i++) {
11918                                    if (getDB().isSupportsInlineDistinct()) {
11919                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11920                                    }
11921                                    else {
11922                                            query.append(_ORDER_BY_ENTITY_TABLE);
11923                                    }
11924    
11925                                    query.append(orderByConditionFields[i]);
11926    
11927                                    if ((i + 1) < orderByConditionFields.length) {
11928                                            if (orderByComparator.isAscending() ^ previous) {
11929                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11930                                            }
11931                                            else {
11932                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11933                                            }
11934                                    }
11935                                    else {
11936                                            if (orderByComparator.isAscending() ^ previous) {
11937                                                    query.append(WHERE_GREATER_THAN);
11938                                            }
11939                                            else {
11940                                                    query.append(WHERE_LESSER_THAN);
11941                                            }
11942                                    }
11943                            }
11944    
11945                            query.append(ORDER_BY_CLAUSE);
11946    
11947                            String[] orderByFields = orderByComparator.getOrderByFields();
11948    
11949                            for (int i = 0; i < orderByFields.length; i++) {
11950                                    if (getDB().isSupportsInlineDistinct()) {
11951                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11952                                    }
11953                                    else {
11954                                            query.append(_ORDER_BY_ENTITY_TABLE);
11955                                    }
11956    
11957                                    query.append(orderByFields[i]);
11958    
11959                                    if ((i + 1) < orderByFields.length) {
11960                                            if (orderByComparator.isAscending() ^ previous) {
11961                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11962                                            }
11963                                            else {
11964                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11965                                            }
11966                                    }
11967                                    else {
11968                                            if (orderByComparator.isAscending() ^ previous) {
11969                                                    query.append(ORDER_BY_ASC);
11970                                            }
11971                                            else {
11972                                                    query.append(ORDER_BY_DESC);
11973                                            }
11974                                    }
11975                            }
11976                    }
11977                    else {
11978                            if (getDB().isSupportsInlineDistinct()) {
11979                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11980                            }
11981                            else {
11982                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11983                            }
11984                    }
11985    
11986                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11987                                    MBMessage.class.getName(),
11988                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11989    
11990                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11991    
11992                    q.setFirstResult(0);
11993                    q.setMaxResults(2);
11994    
11995                    if (getDB().isSupportsInlineDistinct()) {
11996                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11997                    }
11998                    else {
11999                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12000                    }
12001    
12002                    QueryPos qPos = QueryPos.getInstance(q);
12003    
12004                    qPos.add(groupId);
12005    
12006                    qPos.add(userId);
12007    
12008                    qPos.add(status);
12009    
12010                    if (orderByComparator != null) {
12011                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12012    
12013                            for (Object value : values) {
12014                                    qPos.add(value);
12015                            }
12016                    }
12017    
12018                    List<MBMessage> list = q.list();
12019    
12020                    if (list.size() == 2) {
12021                            return list.get(1);
12022                    }
12023                    else {
12024                            return null;
12025                    }
12026            }
12027    
12028            /**
12029             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
12030             *
12031             * @param groupId the group ID
12032             * @param userId the user ID
12033             * @param status the status
12034             */
12035            @Override
12036            public void removeByG_U_S(long groupId, long userId, int status) {
12037                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
12038                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12039                            remove(mbMessage);
12040                    }
12041            }
12042    
12043            /**
12044             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
12045             *
12046             * @param groupId the group ID
12047             * @param userId the user ID
12048             * @param status the status
12049             * @return the number of matching message-boards messages
12050             */
12051            @Override
12052            public int countByG_U_S(long groupId, long userId, int status) {
12053                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
12054    
12055                    Object[] finderArgs = new Object[] { groupId, userId, status };
12056    
12057                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
12058    
12059                    if (count == null) {
12060                            StringBundler query = new StringBundler(4);
12061    
12062                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12063    
12064                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12065    
12066                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12067    
12068                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12069    
12070                            String sql = query.toString();
12071    
12072                            Session session = null;
12073    
12074                            try {
12075                                    session = openSession();
12076    
12077                                    Query q = session.createQuery(sql);
12078    
12079                                    QueryPos qPos = QueryPos.getInstance(q);
12080    
12081                                    qPos.add(groupId);
12082    
12083                                    qPos.add(userId);
12084    
12085                                    qPos.add(status);
12086    
12087                                    count = (Long)q.uniqueResult();
12088    
12089                                    finderCache.putResult(finderPath, finderArgs, count);
12090                            }
12091                            catch (Exception e) {
12092                                    finderCache.removeResult(finderPath, finderArgs);
12093    
12094                                    throw processException(e);
12095                            }
12096                            finally {
12097                                    closeSession(session);
12098                            }
12099                    }
12100    
12101                    return count.intValue();
12102            }
12103    
12104            /**
12105             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
12106             *
12107             * @param groupId the group ID
12108             * @param userId the user ID
12109             * @param status the status
12110             * @return the number of matching message-boards messages that the user has permission to view
12111             */
12112            @Override
12113            public int filterCountByG_U_S(long groupId, long userId, int status) {
12114                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12115                            return countByG_U_S(groupId, userId, status);
12116                    }
12117    
12118                    StringBundler query = new StringBundler(4);
12119    
12120                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12121    
12122                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
12123    
12124                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
12125    
12126                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
12127    
12128                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12129                                    MBMessage.class.getName(),
12130                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12131    
12132                    Session session = null;
12133    
12134                    try {
12135                            session = openSession();
12136    
12137                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12138    
12139                            q.addScalar(COUNT_COLUMN_NAME,
12140                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12141    
12142                            QueryPos qPos = QueryPos.getInstance(q);
12143    
12144                            qPos.add(groupId);
12145    
12146                            qPos.add(userId);
12147    
12148                            qPos.add(status);
12149    
12150                            Long count = (Long)q.uniqueResult();
12151    
12152                            return count.intValue();
12153                    }
12154                    catch (Exception e) {
12155                            throw processException(e);
12156                    }
12157                    finally {
12158                            closeSession(session);
12159                    }
12160            }
12161    
12162            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
12163            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
12164            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
12165            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12167                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
12168                            new String[] {
12169                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12170                                    
12171                            Integer.class.getName(), Integer.class.getName(),
12172                                    OrderByComparator.class.getName()
12173                            });
12174            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12175                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
12177                            new String[] {
12178                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12179                            },
12180                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12181                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12182                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
12183                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12184            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12186                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
12187                            new String[] {
12188                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
12189                            });
12190    
12191            /**
12192             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12193             *
12194             * @param groupId the group ID
12195             * @param categoryId the category ID
12196             * @param threadId the thread ID
12197             * @return the matching message-boards messages
12198             */
12199            @Override
12200            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12201                    long threadId) {
12202                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
12203                            QueryUtil.ALL_POS, null);
12204            }
12205    
12206            /**
12207             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12208             *
12209             * <p>
12210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12211             * </p>
12212             *
12213             * @param groupId the group ID
12214             * @param categoryId the category ID
12215             * @param threadId the thread ID
12216             * @param start the lower bound of the range of message-boards messages
12217             * @param end the upper bound of the range of message-boards messages (not inclusive)
12218             * @return the range of matching message-boards messages
12219             */
12220            @Override
12221            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12222                    long threadId, int start, int end) {
12223                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
12224            }
12225    
12226            /**
12227             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12228             *
12229             * <p>
12230             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12231             * </p>
12232             *
12233             * @param groupId the group ID
12234             * @param categoryId the category ID
12235             * @param threadId the thread ID
12236             * @param start the lower bound of the range of message-boards messages
12237             * @param end the upper bound of the range of message-boards messages (not inclusive)
12238             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12239             * @return the ordered range of matching message-boards messages
12240             */
12241            @Override
12242            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12243                    long threadId, int start, int end,
12244                    OrderByComparator<MBMessage> orderByComparator) {
12245                    return findByG_C_T(groupId, categoryId, threadId, start, end,
12246                            orderByComparator, true);
12247            }
12248    
12249            /**
12250             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12251             *
12252             * <p>
12253             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12254             * </p>
12255             *
12256             * @param groupId the group ID
12257             * @param categoryId the category ID
12258             * @param threadId the thread ID
12259             * @param start the lower bound of the range of message-boards messages
12260             * @param end the upper bound of the range of message-boards messages (not inclusive)
12261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12262             * @param retrieveFromCache whether to retrieve from the finder cache
12263             * @return the ordered range of matching message-boards messages
12264             */
12265            @Override
12266            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
12267                    long threadId, int start, int end,
12268                    OrderByComparator<MBMessage> orderByComparator,
12269                    boolean retrieveFromCache) {
12270                    boolean pagination = true;
12271                    FinderPath finderPath = null;
12272                    Object[] finderArgs = null;
12273    
12274                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12275                                    (orderByComparator == null)) {
12276                            pagination = false;
12277                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
12278                            finderArgs = new Object[] { groupId, categoryId, threadId };
12279                    }
12280                    else {
12281                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
12282                            finderArgs = new Object[] {
12283                                            groupId, categoryId, threadId,
12284                                            
12285                                            start, end, orderByComparator
12286                                    };
12287                    }
12288    
12289                    List<MBMessage> list = null;
12290    
12291                    if (retrieveFromCache) {
12292                            list = (List<MBMessage>)finderCache.getResult(finderPath,
12293                                            finderArgs, this);
12294    
12295                            if ((list != null) && !list.isEmpty()) {
12296                                    for (MBMessage mbMessage : list) {
12297                                            if ((groupId != mbMessage.getGroupId()) ||
12298                                                            (categoryId != mbMessage.getCategoryId()) ||
12299                                                            (threadId != mbMessage.getThreadId())) {
12300                                                    list = null;
12301    
12302                                                    break;
12303                                            }
12304                                    }
12305                            }
12306                    }
12307    
12308                    if (list == null) {
12309                            StringBundler query = null;
12310    
12311                            if (orderByComparator != null) {
12312                                    query = new StringBundler(5 +
12313                                                    (orderByComparator.getOrderByFields().length * 2));
12314                            }
12315                            else {
12316                                    query = new StringBundler(5);
12317                            }
12318    
12319                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12320    
12321                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12322    
12323                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12324    
12325                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12326    
12327                            if (orderByComparator != null) {
12328                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12329                                            orderByComparator);
12330                            }
12331                            else
12332                             if (pagination) {
12333                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12334                            }
12335    
12336                            String sql = query.toString();
12337    
12338                            Session session = null;
12339    
12340                            try {
12341                                    session = openSession();
12342    
12343                                    Query q = session.createQuery(sql);
12344    
12345                                    QueryPos qPos = QueryPos.getInstance(q);
12346    
12347                                    qPos.add(groupId);
12348    
12349                                    qPos.add(categoryId);
12350    
12351                                    qPos.add(threadId);
12352    
12353                                    if (!pagination) {
12354                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12355                                                            start, end, false);
12356    
12357                                            Collections.sort(list);
12358    
12359                                            list = Collections.unmodifiableList(list);
12360                                    }
12361                                    else {
12362                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12363                                                            start, end);
12364                                    }
12365    
12366                                    cacheResult(list);
12367    
12368                                    finderCache.putResult(finderPath, finderArgs, list);
12369                            }
12370                            catch (Exception e) {
12371                                    finderCache.removeResult(finderPath, finderArgs);
12372    
12373                                    throw processException(e);
12374                            }
12375                            finally {
12376                                    closeSession(session);
12377                            }
12378                    }
12379    
12380                    return list;
12381            }
12382    
12383            /**
12384             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12385             *
12386             * @param groupId the group ID
12387             * @param categoryId the category ID
12388             * @param threadId the thread ID
12389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12390             * @return the first matching message-boards message
12391             * @throws NoSuchMessageException if a matching message-boards message could not be found
12392             */
12393            @Override
12394            public MBMessage findByG_C_T_First(long groupId, long categoryId,
12395                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12396                    throws NoSuchMessageException {
12397                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
12398                                    orderByComparator);
12399    
12400                    if (mbMessage != null) {
12401                            return mbMessage;
12402                    }
12403    
12404                    StringBundler msg = new StringBundler(8);
12405    
12406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12407    
12408                    msg.append("groupId=");
12409                    msg.append(groupId);
12410    
12411                    msg.append(", categoryId=");
12412                    msg.append(categoryId);
12413    
12414                    msg.append(", threadId=");
12415                    msg.append(threadId);
12416    
12417                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12418    
12419                    throw new NoSuchMessageException(msg.toString());
12420            }
12421    
12422            /**
12423             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12424             *
12425             * @param groupId the group ID
12426             * @param categoryId the category ID
12427             * @param threadId the thread ID
12428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12429             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12430             */
12431            @Override
12432            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
12433                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12434                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
12435                                    orderByComparator);
12436    
12437                    if (!list.isEmpty()) {
12438                            return list.get(0);
12439                    }
12440    
12441                    return null;
12442            }
12443    
12444            /**
12445             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12446             *
12447             * @param groupId the group ID
12448             * @param categoryId the category ID
12449             * @param threadId the thread ID
12450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12451             * @return the last matching message-boards message
12452             * @throws NoSuchMessageException if a matching message-boards message could not be found
12453             */
12454            @Override
12455            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
12456                    long threadId, OrderByComparator<MBMessage> orderByComparator)
12457                    throws NoSuchMessageException {
12458                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
12459                                    orderByComparator);
12460    
12461                    if (mbMessage != null) {
12462                            return mbMessage;
12463                    }
12464    
12465                    StringBundler msg = new StringBundler(8);
12466    
12467                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12468    
12469                    msg.append("groupId=");
12470                    msg.append(groupId);
12471    
12472                    msg.append(", categoryId=");
12473                    msg.append(categoryId);
12474    
12475                    msg.append(", threadId=");
12476                    msg.append(threadId);
12477    
12478                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12479    
12480                    throw new NoSuchMessageException(msg.toString());
12481            }
12482    
12483            /**
12484             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12485             *
12486             * @param groupId the group ID
12487             * @param categoryId the category ID
12488             * @param threadId the thread ID
12489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12490             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12491             */
12492            @Override
12493            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
12494                    long threadId, OrderByComparator<MBMessage> orderByComparator) {
12495                    int count = countByG_C_T(groupId, categoryId, threadId);
12496    
12497                    if (count == 0) {
12498                            return null;
12499                    }
12500    
12501                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
12502                                    count - 1, count, orderByComparator);
12503    
12504                    if (!list.isEmpty()) {
12505                            return list.get(0);
12506                    }
12507    
12508                    return null;
12509            }
12510    
12511            /**
12512             * 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;.
12513             *
12514             * @param messageId the primary key of the current message-boards message
12515             * @param groupId the group ID
12516             * @param categoryId the category ID
12517             * @param threadId the thread ID
12518             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12519             * @return the previous, current, and next message-boards message
12520             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12521             */
12522            @Override
12523            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
12524                    long categoryId, long threadId,
12525                    OrderByComparator<MBMessage> orderByComparator)
12526                    throws NoSuchMessageException {
12527                    MBMessage mbMessage = findByPrimaryKey(messageId);
12528    
12529                    Session session = null;
12530    
12531                    try {
12532                            session = openSession();
12533    
12534                            MBMessage[] array = new MBMessageImpl[3];
12535    
12536                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12537                                            categoryId, threadId, orderByComparator, true);
12538    
12539                            array[1] = mbMessage;
12540    
12541                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12542                                            categoryId, threadId, orderByComparator, false);
12543    
12544                            return array;
12545                    }
12546                    catch (Exception e) {
12547                            throw processException(e);
12548                    }
12549                    finally {
12550                            closeSession(session);
12551                    }
12552            }
12553    
12554            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12555                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12556                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12557                    StringBundler query = null;
12558    
12559                    if (orderByComparator != null) {
12560                            query = new StringBundler(6 +
12561                                            (orderByComparator.getOrderByConditionFields().length * 3) +
12562                                            (orderByComparator.getOrderByFields().length * 3));
12563                    }
12564                    else {
12565                            query = new StringBundler(5);
12566                    }
12567    
12568                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12569    
12570                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12571    
12572                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12573    
12574                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12575    
12576                    if (orderByComparator != null) {
12577                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12578    
12579                            if (orderByConditionFields.length > 0) {
12580                                    query.append(WHERE_AND);
12581                            }
12582    
12583                            for (int i = 0; i < orderByConditionFields.length; i++) {
12584                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12585                                    query.append(orderByConditionFields[i]);
12586    
12587                                    if ((i + 1) < orderByConditionFields.length) {
12588                                            if (orderByComparator.isAscending() ^ previous) {
12589                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12590                                            }
12591                                            else {
12592                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12593                                            }
12594                                    }
12595                                    else {
12596                                            if (orderByComparator.isAscending() ^ previous) {
12597                                                    query.append(WHERE_GREATER_THAN);
12598                                            }
12599                                            else {
12600                                                    query.append(WHERE_LESSER_THAN);
12601                                            }
12602                                    }
12603                            }
12604    
12605                            query.append(ORDER_BY_CLAUSE);
12606    
12607                            String[] orderByFields = orderByComparator.getOrderByFields();
12608    
12609                            for (int i = 0; i < orderByFields.length; i++) {
12610                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12611                                    query.append(orderByFields[i]);
12612    
12613                                    if ((i + 1) < orderByFields.length) {
12614                                            if (orderByComparator.isAscending() ^ previous) {
12615                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12616                                            }
12617                                            else {
12618                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12619                                            }
12620                                    }
12621                                    else {
12622                                            if (orderByComparator.isAscending() ^ previous) {
12623                                                    query.append(ORDER_BY_ASC);
12624                                            }
12625                                            else {
12626                                                    query.append(ORDER_BY_DESC);
12627                                            }
12628                                    }
12629                            }
12630                    }
12631                    else {
12632                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12633                    }
12634    
12635                    String sql = query.toString();
12636    
12637                    Query q = session.createQuery(sql);
12638    
12639                    q.setFirstResult(0);
12640                    q.setMaxResults(2);
12641    
12642                    QueryPos qPos = QueryPos.getInstance(q);
12643    
12644                    qPos.add(groupId);
12645    
12646                    qPos.add(categoryId);
12647    
12648                    qPos.add(threadId);
12649    
12650                    if (orderByComparator != null) {
12651                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12652    
12653                            for (Object value : values) {
12654                                    qPos.add(value);
12655                            }
12656                    }
12657    
12658                    List<MBMessage> list = q.list();
12659    
12660                    if (list.size() == 2) {
12661                            return list.get(1);
12662                    }
12663                    else {
12664                            return null;
12665                    }
12666            }
12667    
12668            /**
12669             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12670             *
12671             * @param groupId the group ID
12672             * @param categoryId the category ID
12673             * @param threadId the thread ID
12674             * @return the matching message-boards messages that the user has permission to view
12675             */
12676            @Override
12677            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12678                    long threadId) {
12679                    return filterFindByG_C_T(groupId, categoryId, threadId,
12680                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12681            }
12682    
12683            /**
12684             * 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;.
12685             *
12686             * <p>
12687             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12688             * </p>
12689             *
12690             * @param groupId the group ID
12691             * @param categoryId the category ID
12692             * @param threadId the thread ID
12693             * @param start the lower bound of the range of message-boards messages
12694             * @param end the upper bound of the range of message-boards messages (not inclusive)
12695             * @return the range of matching message-boards messages that the user has permission to view
12696             */
12697            @Override
12698            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12699                    long threadId, int start, int end) {
12700                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12701            }
12702    
12703            /**
12704             * 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;.
12705             *
12706             * <p>
12707             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12708             * </p>
12709             *
12710             * @param groupId the group ID
12711             * @param categoryId the category ID
12712             * @param threadId the thread ID
12713             * @param start the lower bound of the range of message-boards messages
12714             * @param end the upper bound of the range of message-boards messages (not inclusive)
12715             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12716             * @return the ordered range of matching message-boards messages that the user has permission to view
12717             */
12718            @Override
12719            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12720                    long threadId, int start, int end,
12721                    OrderByComparator<MBMessage> orderByComparator) {
12722                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12723                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12724                                    orderByComparator);
12725                    }
12726    
12727                    StringBundler query = null;
12728    
12729                    if (orderByComparator != null) {
12730                            query = new StringBundler(5 +
12731                                            (orderByComparator.getOrderByFields().length * 2));
12732                    }
12733                    else {
12734                            query = new StringBundler(6);
12735                    }
12736    
12737                    if (getDB().isSupportsInlineDistinct()) {
12738                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12739                    }
12740                    else {
12741                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12742                    }
12743    
12744                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12745    
12746                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12747    
12748                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12749    
12750                    if (!getDB().isSupportsInlineDistinct()) {
12751                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12752                    }
12753    
12754                    if (orderByComparator != null) {
12755                            if (getDB().isSupportsInlineDistinct()) {
12756                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12757                                            orderByComparator, true);
12758                            }
12759                            else {
12760                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12761                                            orderByComparator, true);
12762                            }
12763                    }
12764                    else {
12765                            if (getDB().isSupportsInlineDistinct()) {
12766                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12767                            }
12768                            else {
12769                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12770                            }
12771                    }
12772    
12773                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12774                                    MBMessage.class.getName(),
12775                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12776    
12777                    Session session = null;
12778    
12779                    try {
12780                            session = openSession();
12781    
12782                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12783    
12784                            if (getDB().isSupportsInlineDistinct()) {
12785                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12786                            }
12787                            else {
12788                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12789                            }
12790    
12791                            QueryPos qPos = QueryPos.getInstance(q);
12792    
12793                            qPos.add(groupId);
12794    
12795                            qPos.add(categoryId);
12796    
12797                            qPos.add(threadId);
12798    
12799                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12800                    }
12801                    catch (Exception e) {
12802                            throw processException(e);
12803                    }
12804                    finally {
12805                            closeSession(session);
12806                    }
12807            }
12808    
12809            /**
12810             * 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;.
12811             *
12812             * @param messageId the primary key of the current message-boards message
12813             * @param groupId the group ID
12814             * @param categoryId the category ID
12815             * @param threadId the thread ID
12816             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12817             * @return the previous, current, and next message-boards message
12818             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
12819             */
12820            @Override
12821            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12822                    long groupId, long categoryId, long threadId,
12823                    OrderByComparator<MBMessage> orderByComparator)
12824                    throws NoSuchMessageException {
12825                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12826                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12827                                    threadId, orderByComparator);
12828                    }
12829    
12830                    MBMessage mbMessage = findByPrimaryKey(messageId);
12831    
12832                    Session session = null;
12833    
12834                    try {
12835                            session = openSession();
12836    
12837                            MBMessage[] array = new MBMessageImpl[3];
12838    
12839                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12840                                            groupId, categoryId, threadId, orderByComparator, true);
12841    
12842                            array[1] = mbMessage;
12843    
12844                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12845                                            groupId, categoryId, threadId, orderByComparator, false);
12846    
12847                            return array;
12848                    }
12849                    catch (Exception e) {
12850                            throw processException(e);
12851                    }
12852                    finally {
12853                            closeSession(session);
12854                    }
12855            }
12856    
12857            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12858                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12859                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
12860                    StringBundler query = null;
12861    
12862                    if (orderByComparator != null) {
12863                            query = new StringBundler(7 +
12864                                            (orderByComparator.getOrderByConditionFields().length * 3) +
12865                                            (orderByComparator.getOrderByFields().length * 3));
12866                    }
12867                    else {
12868                            query = new StringBundler(6);
12869                    }
12870    
12871                    if (getDB().isSupportsInlineDistinct()) {
12872                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12873                    }
12874                    else {
12875                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12876                    }
12877    
12878                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12879    
12880                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12881    
12882                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12883    
12884                    if (!getDB().isSupportsInlineDistinct()) {
12885                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12886                    }
12887    
12888                    if (orderByComparator != null) {
12889                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12890    
12891                            if (orderByConditionFields.length > 0) {
12892                                    query.append(WHERE_AND);
12893                            }
12894    
12895                            for (int i = 0; i < orderByConditionFields.length; i++) {
12896                                    if (getDB().isSupportsInlineDistinct()) {
12897                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12898                                    }
12899                                    else {
12900                                            query.append(_ORDER_BY_ENTITY_TABLE);
12901                                    }
12902    
12903                                    query.append(orderByConditionFields[i]);
12904    
12905                                    if ((i + 1) < orderByConditionFields.length) {
12906                                            if (orderByComparator.isAscending() ^ previous) {
12907                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12908                                            }
12909                                            else {
12910                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12911                                            }
12912                                    }
12913                                    else {
12914                                            if (orderByComparator.isAscending() ^ previous) {
12915                                                    query.append(WHERE_GREATER_THAN);
12916                                            }
12917                                            else {
12918                                                    query.append(WHERE_LESSER_THAN);
12919                                            }
12920                                    }
12921                            }
12922    
12923                            query.append(ORDER_BY_CLAUSE);
12924    
12925                            String[] orderByFields = orderByComparator.getOrderByFields();
12926    
12927                            for (int i = 0; i < orderByFields.length; i++) {
12928                                    if (getDB().isSupportsInlineDistinct()) {
12929                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12930                                    }
12931                                    else {
12932                                            query.append(_ORDER_BY_ENTITY_TABLE);
12933                                    }
12934    
12935                                    query.append(orderByFields[i]);
12936    
12937                                    if ((i + 1) < orderByFields.length) {
12938                                            if (orderByComparator.isAscending() ^ previous) {
12939                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12940                                            }
12941                                            else {
12942                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12943                                            }
12944                                    }
12945                                    else {
12946                                            if (orderByComparator.isAscending() ^ previous) {
12947                                                    query.append(ORDER_BY_ASC);
12948                                            }
12949                                            else {
12950                                                    query.append(ORDER_BY_DESC);
12951                                            }
12952                                    }
12953                            }
12954                    }
12955                    else {
12956                            if (getDB().isSupportsInlineDistinct()) {
12957                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12958                            }
12959                            else {
12960                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12961                            }
12962                    }
12963    
12964                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12965                                    MBMessage.class.getName(),
12966                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12967    
12968                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12969    
12970                    q.setFirstResult(0);
12971                    q.setMaxResults(2);
12972    
12973                    if (getDB().isSupportsInlineDistinct()) {
12974                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12975                    }
12976                    else {
12977                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12978                    }
12979    
12980                    QueryPos qPos = QueryPos.getInstance(q);
12981    
12982                    qPos.add(groupId);
12983    
12984                    qPos.add(categoryId);
12985    
12986                    qPos.add(threadId);
12987    
12988                    if (orderByComparator != null) {
12989                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12990    
12991                            for (Object value : values) {
12992                                    qPos.add(value);
12993                            }
12994                    }
12995    
12996                    List<MBMessage> list = q.list();
12997    
12998                    if (list.size() == 2) {
12999                            return list.get(1);
13000                    }
13001                    else {
13002                            return null;
13003                    }
13004            }
13005    
13006            /**
13007             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
13008             *
13009             * @param groupId the group ID
13010             * @param categoryId the category ID
13011             * @param threadId the thread ID
13012             */
13013            @Override
13014            public void removeByG_C_T(long groupId, long categoryId, long threadId) {
13015                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
13016                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13017                            remove(mbMessage);
13018                    }
13019            }
13020    
13021            /**
13022             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13023             *
13024             * @param groupId the group ID
13025             * @param categoryId the category ID
13026             * @param threadId the thread ID
13027             * @return the number of matching message-boards messages
13028             */
13029            @Override
13030            public int countByG_C_T(long groupId, long categoryId, long threadId) {
13031                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
13032    
13033                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
13034    
13035                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
13036    
13037                    if (count == null) {
13038                            StringBundler query = new StringBundler(4);
13039    
13040                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13041    
13042                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13043    
13044                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13045    
13046                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13047    
13048                            String sql = query.toString();
13049    
13050                            Session session = null;
13051    
13052                            try {
13053                                    session = openSession();
13054    
13055                                    Query q = session.createQuery(sql);
13056    
13057                                    QueryPos qPos = QueryPos.getInstance(q);
13058    
13059                                    qPos.add(groupId);
13060    
13061                                    qPos.add(categoryId);
13062    
13063                                    qPos.add(threadId);
13064    
13065                                    count = (Long)q.uniqueResult();
13066    
13067                                    finderCache.putResult(finderPath, finderArgs, count);
13068                            }
13069                            catch (Exception e) {
13070                                    finderCache.removeResult(finderPath, finderArgs);
13071    
13072                                    throw processException(e);
13073                            }
13074                            finally {
13075                                    closeSession(session);
13076                            }
13077                    }
13078    
13079                    return count.intValue();
13080            }
13081    
13082            /**
13083             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
13084             *
13085             * @param groupId the group ID
13086             * @param categoryId the category ID
13087             * @param threadId the thread ID
13088             * @return the number of matching message-boards messages that the user has permission to view
13089             */
13090            @Override
13091            public int filterCountByG_C_T(long groupId, long categoryId, long threadId) {
13092                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13093                            return countByG_C_T(groupId, categoryId, threadId);
13094                    }
13095    
13096                    StringBundler query = new StringBundler(4);
13097    
13098                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13099    
13100                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
13101    
13102                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
13103    
13104                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
13105    
13106                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13107                                    MBMessage.class.getName(),
13108                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13109    
13110                    Session session = null;
13111    
13112                    try {
13113                            session = openSession();
13114    
13115                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13116    
13117                            q.addScalar(COUNT_COLUMN_NAME,
13118                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13119    
13120                            QueryPos qPos = QueryPos.getInstance(q);
13121    
13122                            qPos.add(groupId);
13123    
13124                            qPos.add(categoryId);
13125    
13126                            qPos.add(threadId);
13127    
13128                            Long count = (Long)q.uniqueResult();
13129    
13130                            return count.intValue();
13131                    }
13132                    catch (Exception e) {
13133                            throw processException(e);
13134                    }
13135                    finally {
13136                            closeSession(session);
13137                    }
13138            }
13139    
13140            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
13141            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13142            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
13143            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13144                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13145                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
13146                            new String[] {
13147                                    Long.class.getName(), Long.class.getName(),
13148                                    Integer.class.getName(),
13149                                    
13150                            Integer.class.getName(), Integer.class.getName(),
13151                                    OrderByComparator.class.getName()
13152                            });
13153            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13154                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13155                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
13156                            new String[] {
13157                                    Long.class.getName(), Long.class.getName(),
13158                                    Integer.class.getName()
13159                            },
13160                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
13161                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
13162                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
13163                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13164            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13165                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
13167                            new String[] {
13168                                    Long.class.getName(), Long.class.getName(),
13169                                    Integer.class.getName()
13170                            });
13171    
13172            /**
13173             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13174             *
13175             * @param groupId the group ID
13176             * @param categoryId the category ID
13177             * @param status the status
13178             * @return the matching message-boards messages
13179             */
13180            @Override
13181            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status) {
13182                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
13183                            QueryUtil.ALL_POS, null);
13184            }
13185    
13186            /**
13187             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13188             *
13189             * <p>
13190             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13191             * </p>
13192             *
13193             * @param groupId the group ID
13194             * @param categoryId the category ID
13195             * @param status the status
13196             * @param start the lower bound of the range of message-boards messages
13197             * @param end the upper bound of the range of message-boards messages (not inclusive)
13198             * @return the range of matching message-boards messages
13199             */
13200            @Override
13201            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13202                    int status, int start, int end) {
13203                    return findByG_C_S(groupId, categoryId, status, start, end, null);
13204            }
13205    
13206            /**
13207             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13208             *
13209             * <p>
13210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13211             * </p>
13212             *
13213             * @param groupId the group ID
13214             * @param categoryId the category ID
13215             * @param status the status
13216             * @param start the lower bound of the range of message-boards messages
13217             * @param end the upper bound of the range of message-boards messages (not inclusive)
13218             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13219             * @return the ordered range of matching message-boards messages
13220             */
13221            @Override
13222            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13223                    int status, int start, int end,
13224                    OrderByComparator<MBMessage> orderByComparator) {
13225                    return findByG_C_S(groupId, categoryId, status, start, end,
13226                            orderByComparator, true);
13227            }
13228    
13229            /**
13230             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13231             *
13232             * <p>
13233             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13234             * </p>
13235             *
13236             * @param groupId the group ID
13237             * @param categoryId the category ID
13238             * @param status the status
13239             * @param start the lower bound of the range of message-boards messages
13240             * @param end the upper bound of the range of message-boards messages (not inclusive)
13241             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13242             * @param retrieveFromCache whether to retrieve from the finder cache
13243             * @return the ordered range of matching message-boards messages
13244             */
13245            @Override
13246            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
13247                    int status, int start, int end,
13248                    OrderByComparator<MBMessage> orderByComparator,
13249                    boolean retrieveFromCache) {
13250                    boolean pagination = true;
13251                    FinderPath finderPath = null;
13252                    Object[] finderArgs = null;
13253    
13254                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13255                                    (orderByComparator == null)) {
13256                            pagination = false;
13257                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
13258                            finderArgs = new Object[] { groupId, categoryId, status };
13259                    }
13260                    else {
13261                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
13262                            finderArgs = new Object[] {
13263                                            groupId, categoryId, status,
13264                                            
13265                                            start, end, orderByComparator
13266                                    };
13267                    }
13268    
13269                    List<MBMessage> list = null;
13270    
13271                    if (retrieveFromCache) {
13272                            list = (List<MBMessage>)finderCache.getResult(finderPath,
13273                                            finderArgs, this);
13274    
13275                            if ((list != null) && !list.isEmpty()) {
13276                                    for (MBMessage mbMessage : list) {
13277                                            if ((groupId != mbMessage.getGroupId()) ||
13278                                                            (categoryId != mbMessage.getCategoryId()) ||
13279                                                            (status != mbMessage.getStatus())) {
13280                                                    list = null;
13281    
13282                                                    break;
13283                                            }
13284                                    }
13285                            }
13286                    }
13287    
13288                    if (list == null) {
13289                            StringBundler query = null;
13290    
13291                            if (orderByComparator != null) {
13292                                    query = new StringBundler(5 +
13293                                                    (orderByComparator.getOrderByFields().length * 2));
13294                            }
13295                            else {
13296                                    query = new StringBundler(5);
13297                            }
13298    
13299                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13300    
13301                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13302    
13303                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13304    
13305                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13306    
13307                            if (orderByComparator != null) {
13308                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13309                                            orderByComparator);
13310                            }
13311                            else
13312                             if (pagination) {
13313                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13314                            }
13315    
13316                            String sql = query.toString();
13317    
13318                            Session session = null;
13319    
13320                            try {
13321                                    session = openSession();
13322    
13323                                    Query q = session.createQuery(sql);
13324    
13325                                    QueryPos qPos = QueryPos.getInstance(q);
13326    
13327                                    qPos.add(groupId);
13328    
13329                                    qPos.add(categoryId);
13330    
13331                                    qPos.add(status);
13332    
13333                                    if (!pagination) {
13334                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13335                                                            start, end, false);
13336    
13337                                            Collections.sort(list);
13338    
13339                                            list = Collections.unmodifiableList(list);
13340                                    }
13341                                    else {
13342                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13343                                                            start, end);
13344                                    }
13345    
13346                                    cacheResult(list);
13347    
13348                                    finderCache.putResult(finderPath, finderArgs, list);
13349                            }
13350                            catch (Exception e) {
13351                                    finderCache.removeResult(finderPath, finderArgs);
13352    
13353                                    throw processException(e);
13354                            }
13355                            finally {
13356                                    closeSession(session);
13357                            }
13358                    }
13359    
13360                    return list;
13361            }
13362    
13363            /**
13364             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13365             *
13366             * @param groupId the group ID
13367             * @param categoryId the category ID
13368             * @param status the status
13369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13370             * @return the first matching message-boards message
13371             * @throws NoSuchMessageException if a matching message-boards message could not be found
13372             */
13373            @Override
13374            public MBMessage findByG_C_S_First(long groupId, long categoryId,
13375                    int status, OrderByComparator<MBMessage> orderByComparator)
13376                    throws NoSuchMessageException {
13377                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
13378                                    orderByComparator);
13379    
13380                    if (mbMessage != null) {
13381                            return mbMessage;
13382                    }
13383    
13384                    StringBundler msg = new StringBundler(8);
13385    
13386                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13387    
13388                    msg.append("groupId=");
13389                    msg.append(groupId);
13390    
13391                    msg.append(", categoryId=");
13392                    msg.append(categoryId);
13393    
13394                    msg.append(", status=");
13395                    msg.append(status);
13396    
13397                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13398    
13399                    throw new NoSuchMessageException(msg.toString());
13400            }
13401    
13402            /**
13403             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13404             *
13405             * @param groupId the group ID
13406             * @param categoryId the category ID
13407             * @param status the status
13408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13409             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13410             */
13411            @Override
13412            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
13413                    int status, OrderByComparator<MBMessage> orderByComparator) {
13414                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
13415                                    orderByComparator);
13416    
13417                    if (!list.isEmpty()) {
13418                            return list.get(0);
13419                    }
13420    
13421                    return null;
13422            }
13423    
13424            /**
13425             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13426             *
13427             * @param groupId the group ID
13428             * @param categoryId the category ID
13429             * @param status the status
13430             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13431             * @return the last matching message-boards message
13432             * @throws NoSuchMessageException if a matching message-boards message could not be found
13433             */
13434            @Override
13435            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
13436                    int status, OrderByComparator<MBMessage> orderByComparator)
13437                    throws NoSuchMessageException {
13438                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
13439                                    orderByComparator);
13440    
13441                    if (mbMessage != null) {
13442                            return mbMessage;
13443                    }
13444    
13445                    StringBundler msg = new StringBundler(8);
13446    
13447                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13448    
13449                    msg.append("groupId=");
13450                    msg.append(groupId);
13451    
13452                    msg.append(", categoryId=");
13453                    msg.append(categoryId);
13454    
13455                    msg.append(", status=");
13456                    msg.append(status);
13457    
13458                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13459    
13460                    throw new NoSuchMessageException(msg.toString());
13461            }
13462    
13463            /**
13464             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
13465             *
13466             * @param groupId the group ID
13467             * @param categoryId the category ID
13468             * @param status the status
13469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13470             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13471             */
13472            @Override
13473            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
13474                    int status, OrderByComparator<MBMessage> orderByComparator) {
13475                    int count = countByG_C_S(groupId, categoryId, status);
13476    
13477                    if (count == 0) {
13478                            return null;
13479                    }
13480    
13481                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
13482                                    count - 1, count, orderByComparator);
13483    
13484                    if (!list.isEmpty()) {
13485                            return list.get(0);
13486                    }
13487    
13488                    return null;
13489            }
13490    
13491            /**
13492             * 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;.
13493             *
13494             * @param messageId the primary key of the current message-boards message
13495             * @param groupId the group ID
13496             * @param categoryId the category ID
13497             * @param status the status
13498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13499             * @return the previous, current, and next message-boards message
13500             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13501             */
13502            @Override
13503            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
13504                    long categoryId, int status,
13505                    OrderByComparator<MBMessage> orderByComparator)
13506                    throws NoSuchMessageException {
13507                    MBMessage mbMessage = findByPrimaryKey(messageId);
13508    
13509                    Session session = null;
13510    
13511                    try {
13512                            session = openSession();
13513    
13514                            MBMessage[] array = new MBMessageImpl[3];
13515    
13516                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13517                                            categoryId, status, orderByComparator, true);
13518    
13519                            array[1] = mbMessage;
13520    
13521                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
13522                                            categoryId, status, orderByComparator, false);
13523    
13524                            return array;
13525                    }
13526                    catch (Exception e) {
13527                            throw processException(e);
13528                    }
13529                    finally {
13530                            closeSession(session);
13531                    }
13532            }
13533    
13534            protected MBMessage getByG_C_S_PrevAndNext(Session session,
13535                    MBMessage mbMessage, long groupId, long categoryId, int status,
13536                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13537                    StringBundler query = null;
13538    
13539                    if (orderByComparator != null) {
13540                            query = new StringBundler(6 +
13541                                            (orderByComparator.getOrderByConditionFields().length * 3) +
13542                                            (orderByComparator.getOrderByFields().length * 3));
13543                    }
13544                    else {
13545                            query = new StringBundler(5);
13546                    }
13547    
13548                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13549    
13550                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13551    
13552                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13553    
13554                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13555    
13556                    if (orderByComparator != null) {
13557                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13558    
13559                            if (orderByConditionFields.length > 0) {
13560                                    query.append(WHERE_AND);
13561                            }
13562    
13563                            for (int i = 0; i < orderByConditionFields.length; i++) {
13564                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13565                                    query.append(orderByConditionFields[i]);
13566    
13567                                    if ((i + 1) < orderByConditionFields.length) {
13568                                            if (orderByComparator.isAscending() ^ previous) {
13569                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13570                                            }
13571                                            else {
13572                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13573                                            }
13574                                    }
13575                                    else {
13576                                            if (orderByComparator.isAscending() ^ previous) {
13577                                                    query.append(WHERE_GREATER_THAN);
13578                                            }
13579                                            else {
13580                                                    query.append(WHERE_LESSER_THAN);
13581                                            }
13582                                    }
13583                            }
13584    
13585                            query.append(ORDER_BY_CLAUSE);
13586    
13587                            String[] orderByFields = orderByComparator.getOrderByFields();
13588    
13589                            for (int i = 0; i < orderByFields.length; i++) {
13590                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13591                                    query.append(orderByFields[i]);
13592    
13593                                    if ((i + 1) < orderByFields.length) {
13594                                            if (orderByComparator.isAscending() ^ previous) {
13595                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13596                                            }
13597                                            else {
13598                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13599                                            }
13600                                    }
13601                                    else {
13602                                            if (orderByComparator.isAscending() ^ previous) {
13603                                                    query.append(ORDER_BY_ASC);
13604                                            }
13605                                            else {
13606                                                    query.append(ORDER_BY_DESC);
13607                                            }
13608                                    }
13609                            }
13610                    }
13611                    else {
13612                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13613                    }
13614    
13615                    String sql = query.toString();
13616    
13617                    Query q = session.createQuery(sql);
13618    
13619                    q.setFirstResult(0);
13620                    q.setMaxResults(2);
13621    
13622                    QueryPos qPos = QueryPos.getInstance(q);
13623    
13624                    qPos.add(groupId);
13625    
13626                    qPos.add(categoryId);
13627    
13628                    qPos.add(status);
13629    
13630                    if (orderByComparator != null) {
13631                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13632    
13633                            for (Object value : values) {
13634                                    qPos.add(value);
13635                            }
13636                    }
13637    
13638                    List<MBMessage> list = q.list();
13639    
13640                    if (list.size() == 2) {
13641                            return list.get(1);
13642                    }
13643                    else {
13644                            return null;
13645                    }
13646            }
13647    
13648            /**
13649             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13650             *
13651             * @param groupId the group ID
13652             * @param categoryId the category ID
13653             * @param status the status
13654             * @return the matching message-boards messages that the user has permission to view
13655             */
13656            @Override
13657            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13658                    int status) {
13659                    return filterFindByG_C_S(groupId, categoryId, status,
13660                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13661            }
13662    
13663            /**
13664             * 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;.
13665             *
13666             * <p>
13667             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13668             * </p>
13669             *
13670             * @param groupId the group ID
13671             * @param categoryId the category ID
13672             * @param status the status
13673             * @param start the lower bound of the range of message-boards messages
13674             * @param end the upper bound of the range of message-boards messages (not inclusive)
13675             * @return the range of matching message-boards messages that the user has permission to view
13676             */
13677            @Override
13678            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13679                    int status, int start, int end) {
13680                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13681            }
13682    
13683            /**
13684             * 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;.
13685             *
13686             * <p>
13687             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13688             * </p>
13689             *
13690             * @param groupId the group ID
13691             * @param categoryId the category ID
13692             * @param status the status
13693             * @param start the lower bound of the range of message-boards messages
13694             * @param end the upper bound of the range of message-boards messages (not inclusive)
13695             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13696             * @return the ordered range of matching message-boards messages that the user has permission to view
13697             */
13698            @Override
13699            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13700                    int status, int start, int end,
13701                    OrderByComparator<MBMessage> orderByComparator) {
13702                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13703                            return findByG_C_S(groupId, categoryId, status, start, end,
13704                                    orderByComparator);
13705                    }
13706    
13707                    StringBundler query = null;
13708    
13709                    if (orderByComparator != null) {
13710                            query = new StringBundler(5 +
13711                                            (orderByComparator.getOrderByFields().length * 2));
13712                    }
13713                    else {
13714                            query = new StringBundler(6);
13715                    }
13716    
13717                    if (getDB().isSupportsInlineDistinct()) {
13718                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13719                    }
13720                    else {
13721                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13722                    }
13723    
13724                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13725    
13726                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13727    
13728                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13729    
13730                    if (!getDB().isSupportsInlineDistinct()) {
13731                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13732                    }
13733    
13734                    if (orderByComparator != null) {
13735                            if (getDB().isSupportsInlineDistinct()) {
13736                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13737                                            orderByComparator, true);
13738                            }
13739                            else {
13740                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13741                                            orderByComparator, true);
13742                            }
13743                    }
13744                    else {
13745                            if (getDB().isSupportsInlineDistinct()) {
13746                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13747                            }
13748                            else {
13749                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13750                            }
13751                    }
13752    
13753                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13754                                    MBMessage.class.getName(),
13755                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13756    
13757                    Session session = null;
13758    
13759                    try {
13760                            session = openSession();
13761    
13762                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
13763    
13764                            if (getDB().isSupportsInlineDistinct()) {
13765                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13766                            }
13767                            else {
13768                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13769                            }
13770    
13771                            QueryPos qPos = QueryPos.getInstance(q);
13772    
13773                            qPos.add(groupId);
13774    
13775                            qPos.add(categoryId);
13776    
13777                            qPos.add(status);
13778    
13779                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13780                    }
13781                    catch (Exception e) {
13782                            throw processException(e);
13783                    }
13784                    finally {
13785                            closeSession(session);
13786                    }
13787            }
13788    
13789            /**
13790             * 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;.
13791             *
13792             * @param messageId the primary key of the current message-boards message
13793             * @param groupId the group ID
13794             * @param categoryId the category ID
13795             * @param status the status
13796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13797             * @return the previous, current, and next message-boards message
13798             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
13799             */
13800            @Override
13801            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13802                    long groupId, long categoryId, int status,
13803                    OrderByComparator<MBMessage> orderByComparator)
13804                    throws NoSuchMessageException {
13805                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13806                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13807                                    status, orderByComparator);
13808                    }
13809    
13810                    MBMessage mbMessage = findByPrimaryKey(messageId);
13811    
13812                    Session session = null;
13813    
13814                    try {
13815                            session = openSession();
13816    
13817                            MBMessage[] array = new MBMessageImpl[3];
13818    
13819                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13820                                            groupId, categoryId, status, orderByComparator, true);
13821    
13822                            array[1] = mbMessage;
13823    
13824                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13825                                            groupId, categoryId, status, orderByComparator, false);
13826    
13827                            return array;
13828                    }
13829                    catch (Exception e) {
13830                            throw processException(e);
13831                    }
13832                    finally {
13833                            closeSession(session);
13834                    }
13835            }
13836    
13837            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13838                    MBMessage mbMessage, long groupId, long categoryId, int status,
13839                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
13840                    StringBundler query = null;
13841    
13842                    if (orderByComparator != null) {
13843                            query = new StringBundler(7 +
13844                                            (orderByComparator.getOrderByConditionFields().length * 3) +
13845                                            (orderByComparator.getOrderByFields().length * 3));
13846                    }
13847                    else {
13848                            query = new StringBundler(6);
13849                    }
13850    
13851                    if (getDB().isSupportsInlineDistinct()) {
13852                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13853                    }
13854                    else {
13855                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13856                    }
13857    
13858                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13859    
13860                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13861    
13862                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13863    
13864                    if (!getDB().isSupportsInlineDistinct()) {
13865                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13866                    }
13867    
13868                    if (orderByComparator != null) {
13869                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13870    
13871                            if (orderByConditionFields.length > 0) {
13872                                    query.append(WHERE_AND);
13873                            }
13874    
13875                            for (int i = 0; i < orderByConditionFields.length; i++) {
13876                                    if (getDB().isSupportsInlineDistinct()) {
13877                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13878                                    }
13879                                    else {
13880                                            query.append(_ORDER_BY_ENTITY_TABLE);
13881                                    }
13882    
13883                                    query.append(orderByConditionFields[i]);
13884    
13885                                    if ((i + 1) < orderByConditionFields.length) {
13886                                            if (orderByComparator.isAscending() ^ previous) {
13887                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13888                                            }
13889                                            else {
13890                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13891                                            }
13892                                    }
13893                                    else {
13894                                            if (orderByComparator.isAscending() ^ previous) {
13895                                                    query.append(WHERE_GREATER_THAN);
13896                                            }
13897                                            else {
13898                                                    query.append(WHERE_LESSER_THAN);
13899                                            }
13900                                    }
13901                            }
13902    
13903                            query.append(ORDER_BY_CLAUSE);
13904    
13905                            String[] orderByFields = orderByComparator.getOrderByFields();
13906    
13907                            for (int i = 0; i < orderByFields.length; i++) {
13908                                    if (getDB().isSupportsInlineDistinct()) {
13909                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13910                                    }
13911                                    else {
13912                                            query.append(_ORDER_BY_ENTITY_TABLE);
13913                                    }
13914    
13915                                    query.append(orderByFields[i]);
13916    
13917                                    if ((i + 1) < orderByFields.length) {
13918                                            if (orderByComparator.isAscending() ^ previous) {
13919                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13920                                            }
13921                                            else {
13922                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13923                                            }
13924                                    }
13925                                    else {
13926                                            if (orderByComparator.isAscending() ^ previous) {
13927                                                    query.append(ORDER_BY_ASC);
13928                                            }
13929                                            else {
13930                                                    query.append(ORDER_BY_DESC);
13931                                            }
13932                                    }
13933                            }
13934                    }
13935                    else {
13936                            if (getDB().isSupportsInlineDistinct()) {
13937                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13938                            }
13939                            else {
13940                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13941                            }
13942                    }
13943    
13944                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13945                                    MBMessage.class.getName(),
13946                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13947    
13948                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
13949    
13950                    q.setFirstResult(0);
13951                    q.setMaxResults(2);
13952    
13953                    if (getDB().isSupportsInlineDistinct()) {
13954                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13955                    }
13956                    else {
13957                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13958                    }
13959    
13960                    QueryPos qPos = QueryPos.getInstance(q);
13961    
13962                    qPos.add(groupId);
13963    
13964                    qPos.add(categoryId);
13965    
13966                    qPos.add(status);
13967    
13968                    if (orderByComparator != null) {
13969                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13970    
13971                            for (Object value : values) {
13972                                    qPos.add(value);
13973                            }
13974                    }
13975    
13976                    List<MBMessage> list = q.list();
13977    
13978                    if (list.size() == 2) {
13979                            return list.get(1);
13980                    }
13981                    else {
13982                            return null;
13983                    }
13984            }
13985    
13986            /**
13987             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13988             *
13989             * @param groupId the group ID
13990             * @param categoryId the category ID
13991             * @param status the status
13992             */
13993            @Override
13994            public void removeByG_C_S(long groupId, long categoryId, int status) {
13995                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13996                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13997                            remove(mbMessage);
13998                    }
13999            }
14000    
14001            /**
14002             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
14003             *
14004             * @param groupId the group ID
14005             * @param categoryId the category ID
14006             * @param status the status
14007             * @return the number of matching message-boards messages
14008             */
14009            @Override
14010            public int countByG_C_S(long groupId, long categoryId, int status) {
14011                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
14012    
14013                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
14014    
14015                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14016    
14017                    if (count == null) {
14018                            StringBundler query = new StringBundler(4);
14019    
14020                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14021    
14022                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14023    
14024                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14025    
14026                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14027    
14028                            String sql = query.toString();
14029    
14030                            Session session = null;
14031    
14032                            try {
14033                                    session = openSession();
14034    
14035                                    Query q = session.createQuery(sql);
14036    
14037                                    QueryPos qPos = QueryPos.getInstance(q);
14038    
14039                                    qPos.add(groupId);
14040    
14041                                    qPos.add(categoryId);
14042    
14043                                    qPos.add(status);
14044    
14045                                    count = (Long)q.uniqueResult();
14046    
14047                                    finderCache.putResult(finderPath, finderArgs, count);
14048                            }
14049                            catch (Exception e) {
14050                                    finderCache.removeResult(finderPath, finderArgs);
14051    
14052                                    throw processException(e);
14053                            }
14054                            finally {
14055                                    closeSession(session);
14056                            }
14057                    }
14058    
14059                    return count.intValue();
14060            }
14061    
14062            /**
14063             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
14064             *
14065             * @param groupId the group ID
14066             * @param categoryId the category ID
14067             * @param status the status
14068             * @return the number of matching message-boards messages that the user has permission to view
14069             */
14070            @Override
14071            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
14072                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14073                            return countByG_C_S(groupId, categoryId, status);
14074                    }
14075    
14076                    StringBundler query = new StringBundler(4);
14077    
14078                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
14079    
14080                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
14081    
14082                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
14083    
14084                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
14085    
14086                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14087                                    MBMessage.class.getName(),
14088                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14089    
14090                    Session session = null;
14091    
14092                    try {
14093                            session = openSession();
14094    
14095                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
14096    
14097                            q.addScalar(COUNT_COLUMN_NAME,
14098                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14099    
14100                            QueryPos qPos = QueryPos.getInstance(q);
14101    
14102                            qPos.add(groupId);
14103    
14104                            qPos.add(categoryId);
14105    
14106                            qPos.add(status);
14107    
14108                            Long count = (Long)q.uniqueResult();
14109    
14110                            return count.intValue();
14111                    }
14112                    catch (Exception e) {
14113                            throw processException(e);
14114                    }
14115                    finally {
14116                            closeSession(session);
14117                    }
14118            }
14119    
14120            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
14121            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
14122            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
14123            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14124                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14125                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
14126                            new String[] {
14127                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14128                                    
14129                            Integer.class.getName(), Integer.class.getName(),
14130                                    OrderByComparator.class.getName()
14131                            });
14132            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14133                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14134                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
14135                            new String[] {
14136                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14137                            },
14138                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14139                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14140                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14141                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14142            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14143                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
14145                            new String[] {
14146                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
14147                            });
14148    
14149            /**
14150             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14151             *
14152             * @param userId the user ID
14153             * @param classNameId the class name ID
14154             * @param classPK the class p k
14155             * @return the matching message-boards messages
14156             */
14157            @Override
14158            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14159                    long classPK) {
14160                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
14161                            QueryUtil.ALL_POS, null);
14162            }
14163    
14164            /**
14165             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14166             *
14167             * <p>
14168             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14169             * </p>
14170             *
14171             * @param userId the user ID
14172             * @param classNameId the class name ID
14173             * @param classPK the class p k
14174             * @param start the lower bound of the range of message-boards messages
14175             * @param end the upper bound of the range of message-boards messages (not inclusive)
14176             * @return the range of matching message-boards messages
14177             */
14178            @Override
14179            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14180                    long classPK, int start, int end) {
14181                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
14182            }
14183    
14184            /**
14185             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14186             *
14187             * <p>
14188             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14189             * </p>
14190             *
14191             * @param userId the user ID
14192             * @param classNameId the class name ID
14193             * @param classPK the class p k
14194             * @param start the lower bound of the range of message-boards messages
14195             * @param end the upper bound of the range of message-boards messages (not inclusive)
14196             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14197             * @return the ordered range of matching message-boards messages
14198             */
14199            @Override
14200            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14201                    long classPK, int start, int end,
14202                    OrderByComparator<MBMessage> orderByComparator) {
14203                    return findByU_C_C(userId, classNameId, classPK, start, end,
14204                            orderByComparator, true);
14205            }
14206    
14207            /**
14208             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14209             *
14210             * <p>
14211             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14212             * </p>
14213             *
14214             * @param userId the user ID
14215             * @param classNameId the class name ID
14216             * @param classPK the class p k
14217             * @param start the lower bound of the range of message-boards messages
14218             * @param end the upper bound of the range of message-boards messages (not inclusive)
14219             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14220             * @param retrieveFromCache whether to retrieve from the finder cache
14221             * @return the ordered range of matching message-boards messages
14222             */
14223            @Override
14224            public List<MBMessage> findByU_C_C(long userId, long classNameId,
14225                    long classPK, int start, int end,
14226                    OrderByComparator<MBMessage> orderByComparator,
14227                    boolean retrieveFromCache) {
14228                    boolean pagination = true;
14229                    FinderPath finderPath = null;
14230                    Object[] finderArgs = null;
14231    
14232                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14233                                    (orderByComparator == null)) {
14234                            pagination = false;
14235                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
14236                            finderArgs = new Object[] { userId, classNameId, classPK };
14237                    }
14238                    else {
14239                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
14240                            finderArgs = new Object[] {
14241                                            userId, classNameId, classPK,
14242                                            
14243                                            start, end, orderByComparator
14244                                    };
14245                    }
14246    
14247                    List<MBMessage> list = null;
14248    
14249                    if (retrieveFromCache) {
14250                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14251                                            finderArgs, this);
14252    
14253                            if ((list != null) && !list.isEmpty()) {
14254                                    for (MBMessage mbMessage : list) {
14255                                            if ((userId != mbMessage.getUserId()) ||
14256                                                            (classNameId != mbMessage.getClassNameId()) ||
14257                                                            (classPK != mbMessage.getClassPK())) {
14258                                                    list = null;
14259    
14260                                                    break;
14261                                            }
14262                                    }
14263                            }
14264                    }
14265    
14266                    if (list == null) {
14267                            StringBundler query = null;
14268    
14269                            if (orderByComparator != null) {
14270                                    query = new StringBundler(5 +
14271                                                    (orderByComparator.getOrderByFields().length * 2));
14272                            }
14273                            else {
14274                                    query = new StringBundler(5);
14275                            }
14276    
14277                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14278    
14279                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14280    
14281                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14282    
14283                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14284    
14285                            if (orderByComparator != null) {
14286                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14287                                            orderByComparator);
14288                            }
14289                            else
14290                             if (pagination) {
14291                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14292                            }
14293    
14294                            String sql = query.toString();
14295    
14296                            Session session = null;
14297    
14298                            try {
14299                                    session = openSession();
14300    
14301                                    Query q = session.createQuery(sql);
14302    
14303                                    QueryPos qPos = QueryPos.getInstance(q);
14304    
14305                                    qPos.add(userId);
14306    
14307                                    qPos.add(classNameId);
14308    
14309                                    qPos.add(classPK);
14310    
14311                                    if (!pagination) {
14312                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14313                                                            start, end, false);
14314    
14315                                            Collections.sort(list);
14316    
14317                                            list = Collections.unmodifiableList(list);
14318                                    }
14319                                    else {
14320                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14321                                                            start, end);
14322                                    }
14323    
14324                                    cacheResult(list);
14325    
14326                                    finderCache.putResult(finderPath, finderArgs, list);
14327                            }
14328                            catch (Exception e) {
14329                                    finderCache.removeResult(finderPath, finderArgs);
14330    
14331                                    throw processException(e);
14332                            }
14333                            finally {
14334                                    closeSession(session);
14335                            }
14336                    }
14337    
14338                    return list;
14339            }
14340    
14341            /**
14342             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14343             *
14344             * @param userId the user ID
14345             * @param classNameId the class name ID
14346             * @param classPK the class p k
14347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14348             * @return the first matching message-boards message
14349             * @throws NoSuchMessageException if a matching message-boards message could not be found
14350             */
14351            @Override
14352            public MBMessage findByU_C_C_First(long userId, long classNameId,
14353                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14354                    throws NoSuchMessageException {
14355                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
14356                                    orderByComparator);
14357    
14358                    if (mbMessage != null) {
14359                            return mbMessage;
14360                    }
14361    
14362                    StringBundler msg = new StringBundler(8);
14363    
14364                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14365    
14366                    msg.append("userId=");
14367                    msg.append(userId);
14368    
14369                    msg.append(", classNameId=");
14370                    msg.append(classNameId);
14371    
14372                    msg.append(", classPK=");
14373                    msg.append(classPK);
14374    
14375                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14376    
14377                    throw new NoSuchMessageException(msg.toString());
14378            }
14379    
14380            /**
14381             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14382             *
14383             * @param userId the user ID
14384             * @param classNameId the class name ID
14385             * @param classPK the class p k
14386             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14387             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14388             */
14389            @Override
14390            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
14391                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14392                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
14393                                    orderByComparator);
14394    
14395                    if (!list.isEmpty()) {
14396                            return list.get(0);
14397                    }
14398    
14399                    return null;
14400            }
14401    
14402            /**
14403             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14404             *
14405             * @param userId the user ID
14406             * @param classNameId the class name ID
14407             * @param classPK the class p k
14408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14409             * @return the last matching message-boards message
14410             * @throws NoSuchMessageException if a matching message-boards message could not be found
14411             */
14412            @Override
14413            public MBMessage findByU_C_C_Last(long userId, long classNameId,
14414                    long classPK, OrderByComparator<MBMessage> orderByComparator)
14415                    throws NoSuchMessageException {
14416                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
14417                                    orderByComparator);
14418    
14419                    if (mbMessage != null) {
14420                            return mbMessage;
14421                    }
14422    
14423                    StringBundler msg = new StringBundler(8);
14424    
14425                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14426    
14427                    msg.append("userId=");
14428                    msg.append(userId);
14429    
14430                    msg.append(", classNameId=");
14431                    msg.append(classNameId);
14432    
14433                    msg.append(", classPK=");
14434                    msg.append(classPK);
14435    
14436                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14437    
14438                    throw new NoSuchMessageException(msg.toString());
14439            }
14440    
14441            /**
14442             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14443             *
14444             * @param userId the user ID
14445             * @param classNameId the class name ID
14446             * @param classPK the class p k
14447             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14448             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14449             */
14450            @Override
14451            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
14452                    long classPK, OrderByComparator<MBMessage> orderByComparator) {
14453                    int count = countByU_C_C(userId, classNameId, classPK);
14454    
14455                    if (count == 0) {
14456                            return null;
14457                    }
14458    
14459                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
14460                                    count - 1, count, orderByComparator);
14461    
14462                    if (!list.isEmpty()) {
14463                            return list.get(0);
14464                    }
14465    
14466                    return null;
14467            }
14468    
14469            /**
14470             * 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;.
14471             *
14472             * @param messageId the primary key of the current message-boards message
14473             * @param userId the user ID
14474             * @param classNameId the class name ID
14475             * @param classPK the class p k
14476             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14477             * @return the previous, current, and next message-boards message
14478             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
14479             */
14480            @Override
14481            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
14482                    long classNameId, long classPK,
14483                    OrderByComparator<MBMessage> orderByComparator)
14484                    throws NoSuchMessageException {
14485                    MBMessage mbMessage = findByPrimaryKey(messageId);
14486    
14487                    Session session = null;
14488    
14489                    try {
14490                            session = openSession();
14491    
14492                            MBMessage[] array = new MBMessageImpl[3];
14493    
14494                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14495                                            classNameId, classPK, orderByComparator, true);
14496    
14497                            array[1] = mbMessage;
14498    
14499                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
14500                                            classNameId, classPK, orderByComparator, false);
14501    
14502                            return array;
14503                    }
14504                    catch (Exception e) {
14505                            throw processException(e);
14506                    }
14507                    finally {
14508                            closeSession(session);
14509                    }
14510            }
14511    
14512            protected MBMessage getByU_C_C_PrevAndNext(Session session,
14513                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14514                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
14515                    StringBundler query = null;
14516    
14517                    if (orderByComparator != null) {
14518                            query = new StringBundler(6 +
14519                                            (orderByComparator.getOrderByConditionFields().length * 3) +
14520                                            (orderByComparator.getOrderByFields().length * 3));
14521                    }
14522                    else {
14523                            query = new StringBundler(5);
14524                    }
14525    
14526                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14527    
14528                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14529    
14530                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14531    
14532                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14533    
14534                    if (orderByComparator != null) {
14535                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14536    
14537                            if (orderByConditionFields.length > 0) {
14538                                    query.append(WHERE_AND);
14539                            }
14540    
14541                            for (int i = 0; i < orderByConditionFields.length; i++) {
14542                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14543                                    query.append(orderByConditionFields[i]);
14544    
14545                                    if ((i + 1) < orderByConditionFields.length) {
14546                                            if (orderByComparator.isAscending() ^ previous) {
14547                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14548                                            }
14549                                            else {
14550                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14551                                            }
14552                                    }
14553                                    else {
14554                                            if (orderByComparator.isAscending() ^ previous) {
14555                                                    query.append(WHERE_GREATER_THAN);
14556                                            }
14557                                            else {
14558                                                    query.append(WHERE_LESSER_THAN);
14559                                            }
14560                                    }
14561                            }
14562    
14563                            query.append(ORDER_BY_CLAUSE);
14564    
14565                            String[] orderByFields = orderByComparator.getOrderByFields();
14566    
14567                            for (int i = 0; i < orderByFields.length; i++) {
14568                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14569                                    query.append(orderByFields[i]);
14570    
14571                                    if ((i + 1) < orderByFields.length) {
14572                                            if (orderByComparator.isAscending() ^ previous) {
14573                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14574                                            }
14575                                            else {
14576                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14577                                            }
14578                                    }
14579                                    else {
14580                                            if (orderByComparator.isAscending() ^ previous) {
14581                                                    query.append(ORDER_BY_ASC);
14582                                            }
14583                                            else {
14584                                                    query.append(ORDER_BY_DESC);
14585                                            }
14586                                    }
14587                            }
14588                    }
14589                    else {
14590                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14591                    }
14592    
14593                    String sql = query.toString();
14594    
14595                    Query q = session.createQuery(sql);
14596    
14597                    q.setFirstResult(0);
14598                    q.setMaxResults(2);
14599    
14600                    QueryPos qPos = QueryPos.getInstance(q);
14601    
14602                    qPos.add(userId);
14603    
14604                    qPos.add(classNameId);
14605    
14606                    qPos.add(classPK);
14607    
14608                    if (orderByComparator != null) {
14609                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14610    
14611                            for (Object value : values) {
14612                                    qPos.add(value);
14613                            }
14614                    }
14615    
14616                    List<MBMessage> list = q.list();
14617    
14618                    if (list.size() == 2) {
14619                            return list.get(1);
14620                    }
14621                    else {
14622                            return null;
14623                    }
14624            }
14625    
14626            /**
14627             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14628             *
14629             * @param userId the user ID
14630             * @param classNameId the class name ID
14631             * @param classPK the class p k
14632             */
14633            @Override
14634            public void removeByU_C_C(long userId, long classNameId, long classPK) {
14635                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14636                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14637                            remove(mbMessage);
14638                    }
14639            }
14640    
14641            /**
14642             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14643             *
14644             * @param userId the user ID
14645             * @param classNameId the class name ID
14646             * @param classPK the class p k
14647             * @return the number of matching message-boards messages
14648             */
14649            @Override
14650            public int countByU_C_C(long userId, long classNameId, long classPK) {
14651                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14652    
14653                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14654    
14655                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
14656    
14657                    if (count == null) {
14658                            StringBundler query = new StringBundler(4);
14659    
14660                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14661    
14662                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14663    
14664                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14665    
14666                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14667    
14668                            String sql = query.toString();
14669    
14670                            Session session = null;
14671    
14672                            try {
14673                                    session = openSession();
14674    
14675                                    Query q = session.createQuery(sql);
14676    
14677                                    QueryPos qPos = QueryPos.getInstance(q);
14678    
14679                                    qPos.add(userId);
14680    
14681                                    qPos.add(classNameId);
14682    
14683                                    qPos.add(classPK);
14684    
14685                                    count = (Long)q.uniqueResult();
14686    
14687                                    finderCache.putResult(finderPath, finderArgs, count);
14688                            }
14689                            catch (Exception e) {
14690                                    finderCache.removeResult(finderPath, finderArgs);
14691    
14692                                    throw processException(e);
14693                            }
14694                            finally {
14695                                    closeSession(session);
14696                            }
14697                    }
14698    
14699                    return count.intValue();
14700            }
14701    
14702            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14703            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14704            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14705            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14706                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14707                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14708                            new String[] {
14709                                    Long.class.getName(), Long.class.getName(),
14710                                    Integer.class.getName(),
14711                                    
14712                            Integer.class.getName(), Integer.class.getName(),
14713                                    OrderByComparator.class.getName()
14714                            });
14715            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14716                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14717                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14718                            new String[] {
14719                                    Long.class.getName(), Long.class.getName(),
14720                                    Integer.class.getName()
14721                            },
14722                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14723                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14724                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14725                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14726            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14727                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14728                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14729                            new String[] {
14730                                    Long.class.getName(), Long.class.getName(),
14731                                    Integer.class.getName()
14732                            });
14733            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14734                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14735                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14736                            new String[] {
14737                                    Long.class.getName(), Long.class.getName(),
14738                                    Integer.class.getName()
14739                            });
14740    
14741            /**
14742             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14743             *
14744             * @param userId the user ID
14745             * @param classNameId the class name ID
14746             * @param status the status
14747             * @return the matching message-boards messages
14748             */
14749            @Override
14750            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status) {
14751                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14752                            QueryUtil.ALL_POS, null);
14753            }
14754    
14755            /**
14756             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14757             *
14758             * <p>
14759             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14760             * </p>
14761             *
14762             * @param userId the user ID
14763             * @param classNameId the class name ID
14764             * @param status the status
14765             * @param start the lower bound of the range of message-boards messages
14766             * @param end the upper bound of the range of message-boards messages (not inclusive)
14767             * @return the range of matching message-boards messages
14768             */
14769            @Override
14770            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14771                    int status, int start, int end) {
14772                    return findByU_C_S(userId, classNameId, status, start, end, null);
14773            }
14774    
14775            /**
14776             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14777             *
14778             * <p>
14779             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14780             * </p>
14781             *
14782             * @param userId the user ID
14783             * @param classNameId the class name ID
14784             * @param status the status
14785             * @param start the lower bound of the range of message-boards messages
14786             * @param end the upper bound of the range of message-boards messages (not inclusive)
14787             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14788             * @return the ordered range of matching message-boards messages
14789             */
14790            @Override
14791            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14792                    int status, int start, int end,
14793                    OrderByComparator<MBMessage> orderByComparator) {
14794                    return findByU_C_S(userId, classNameId, status, start, end,
14795                            orderByComparator, true);
14796            }
14797    
14798            /**
14799             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14800             *
14801             * <p>
14802             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14803             * </p>
14804             *
14805             * @param userId the user ID
14806             * @param classNameId the class name ID
14807             * @param status the status
14808             * @param start the lower bound of the range of message-boards messages
14809             * @param end the upper bound of the range of message-boards messages (not inclusive)
14810             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14811             * @param retrieveFromCache whether to retrieve from the finder cache
14812             * @return the ordered range of matching message-boards messages
14813             */
14814            @Override
14815            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14816                    int status, int start, int end,
14817                    OrderByComparator<MBMessage> orderByComparator,
14818                    boolean retrieveFromCache) {
14819                    boolean pagination = true;
14820                    FinderPath finderPath = null;
14821                    Object[] finderArgs = null;
14822    
14823                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14824                                    (orderByComparator == null)) {
14825                            pagination = false;
14826                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14827                            finderArgs = new Object[] { userId, classNameId, status };
14828                    }
14829                    else {
14830                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14831                            finderArgs = new Object[] {
14832                                            userId, classNameId, status,
14833                                            
14834                                            start, end, orderByComparator
14835                                    };
14836                    }
14837    
14838                    List<MBMessage> list = null;
14839    
14840                    if (retrieveFromCache) {
14841                            list = (List<MBMessage>)finderCache.getResult(finderPath,
14842                                            finderArgs, this);
14843    
14844                            if ((list != null) && !list.isEmpty()) {
14845                                    for (MBMessage mbMessage : list) {
14846                                            if ((userId != mbMessage.getUserId()) ||
14847                                                            (classNameId != mbMessage.getClassNameId()) ||
14848                                                            (status != mbMessage.getStatus())) {
14849                                                    list = null;
14850    
14851                                                    break;
14852                                            }
14853                                    }
14854                            }
14855                    }
14856    
14857                    if (list == null) {
14858                            StringBundler query = null;
14859    
14860                            if (orderByComparator != null) {
14861                                    query = new StringBundler(5 +
14862                                                    (orderByComparator.getOrderByFields().length * 2));
14863                            }
14864                            else {
14865                                    query = new StringBundler(5);
14866                            }
14867    
14868                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14869    
14870                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14871    
14872                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14873    
14874                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14875    
14876                            if (orderByComparator != null) {
14877                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14878                                            orderByComparator);
14879                            }
14880                            else
14881                             if (pagination) {
14882                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14883                            }
14884    
14885                            String sql = query.toString();
14886    
14887                            Session session = null;
14888    
14889                            try {
14890                                    session = openSession();
14891    
14892                                    Query q = session.createQuery(sql);
14893    
14894                                    QueryPos qPos = QueryPos.getInstance(q);
14895    
14896                                    qPos.add(userId);
14897    
14898                                    qPos.add(classNameId);
14899    
14900                                    qPos.add(status);
14901    
14902                                    if (!pagination) {
14903                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14904                                                            start, end, false);
14905    
14906                                            Collections.sort(list);
14907    
14908                                            list = Collections.unmodifiableList(list);
14909                                    }
14910                                    else {
14911                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14912                                                            start, end);
14913                                    }
14914    
14915                                    cacheResult(list);
14916    
14917                                    finderCache.putResult(finderPath, finderArgs, list);
14918                            }
14919                            catch (Exception e) {
14920                                    finderCache.removeResult(finderPath, finderArgs);
14921    
14922                                    throw processException(e);
14923                            }
14924                            finally {
14925                                    closeSession(session);
14926                            }
14927                    }
14928    
14929                    return list;
14930            }
14931    
14932            /**
14933             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14934             *
14935             * @param userId the user ID
14936             * @param classNameId the class name ID
14937             * @param status the status
14938             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14939             * @return the first matching message-boards message
14940             * @throws NoSuchMessageException if a matching message-boards message could not be found
14941             */
14942            @Override
14943            public MBMessage findByU_C_S_First(long userId, long classNameId,
14944                    int status, OrderByComparator<MBMessage> orderByComparator)
14945                    throws NoSuchMessageException {
14946                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14947                                    orderByComparator);
14948    
14949                    if (mbMessage != null) {
14950                            return mbMessage;
14951                    }
14952    
14953                    StringBundler msg = new StringBundler(8);
14954    
14955                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14956    
14957                    msg.append("userId=");
14958                    msg.append(userId);
14959    
14960                    msg.append(", classNameId=");
14961                    msg.append(classNameId);
14962    
14963                    msg.append(", status=");
14964                    msg.append(status);
14965    
14966                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14967    
14968                    throw new NoSuchMessageException(msg.toString());
14969            }
14970    
14971            /**
14972             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14973             *
14974             * @param userId the user ID
14975             * @param classNameId the class name ID
14976             * @param status the status
14977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14978             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14979             */
14980            @Override
14981            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14982                    int status, OrderByComparator<MBMessage> orderByComparator) {
14983                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14984                                    orderByComparator);
14985    
14986                    if (!list.isEmpty()) {
14987                            return list.get(0);
14988                    }
14989    
14990                    return null;
14991            }
14992    
14993            /**
14994             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14995             *
14996             * @param userId the user ID
14997             * @param classNameId the class name ID
14998             * @param status the status
14999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15000             * @return the last matching message-boards message
15001             * @throws NoSuchMessageException if a matching message-boards message could not be found
15002             */
15003            @Override
15004            public MBMessage findByU_C_S_Last(long userId, long classNameId,
15005                    int status, OrderByComparator<MBMessage> orderByComparator)
15006                    throws NoSuchMessageException {
15007                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
15008                                    orderByComparator);
15009    
15010                    if (mbMessage != null) {
15011                            return mbMessage;
15012                    }
15013    
15014                    StringBundler msg = new StringBundler(8);
15015    
15016                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15017    
15018                    msg.append("userId=");
15019                    msg.append(userId);
15020    
15021                    msg.append(", classNameId=");
15022                    msg.append(classNameId);
15023    
15024                    msg.append(", status=");
15025                    msg.append(status);
15026    
15027                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15028    
15029                    throw new NoSuchMessageException(msg.toString());
15030            }
15031    
15032            /**
15033             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
15034             *
15035             * @param userId the user ID
15036             * @param classNameId the class name ID
15037             * @param status the status
15038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15039             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15040             */
15041            @Override
15042            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
15043                    int status, OrderByComparator<MBMessage> orderByComparator) {
15044                    int count = countByU_C_S(userId, classNameId, status);
15045    
15046                    if (count == 0) {
15047                            return null;
15048                    }
15049    
15050                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
15051                                    count - 1, count, orderByComparator);
15052    
15053                    if (!list.isEmpty()) {
15054                            return list.get(0);
15055                    }
15056    
15057                    return null;
15058            }
15059    
15060            /**
15061             * 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;.
15062             *
15063             * @param messageId the primary key of the current message-boards message
15064             * @param userId the user ID
15065             * @param classNameId the class name ID
15066             * @param status the status
15067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15068             * @return the previous, current, and next message-boards message
15069             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15070             */
15071            @Override
15072            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
15073                    long classNameId, int status,
15074                    OrderByComparator<MBMessage> orderByComparator)
15075                    throws NoSuchMessageException {
15076                    MBMessage mbMessage = findByPrimaryKey(messageId);
15077    
15078                    Session session = null;
15079    
15080                    try {
15081                            session = openSession();
15082    
15083                            MBMessage[] array = new MBMessageImpl[3];
15084    
15085                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15086                                            classNameId, status, orderByComparator, true);
15087    
15088                            array[1] = mbMessage;
15089    
15090                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
15091                                            classNameId, status, orderByComparator, false);
15092    
15093                            return array;
15094                    }
15095                    catch (Exception e) {
15096                            throw processException(e);
15097                    }
15098                    finally {
15099                            closeSession(session);
15100                    }
15101            }
15102    
15103            protected MBMessage getByU_C_S_PrevAndNext(Session session,
15104                    MBMessage mbMessage, long userId, long classNameId, int status,
15105                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15106                    StringBundler query = null;
15107    
15108                    if (orderByComparator != null) {
15109                            query = new StringBundler(6 +
15110                                            (orderByComparator.getOrderByConditionFields().length * 3) +
15111                                            (orderByComparator.getOrderByFields().length * 3));
15112                    }
15113                    else {
15114                            query = new StringBundler(5);
15115                    }
15116    
15117                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15118    
15119                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15120    
15121                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15122    
15123                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15124    
15125                    if (orderByComparator != null) {
15126                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15127    
15128                            if (orderByConditionFields.length > 0) {
15129                                    query.append(WHERE_AND);
15130                            }
15131    
15132                            for (int i = 0; i < orderByConditionFields.length; i++) {
15133                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15134                                    query.append(orderByConditionFields[i]);
15135    
15136                                    if ((i + 1) < orderByConditionFields.length) {
15137                                            if (orderByComparator.isAscending() ^ previous) {
15138                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15139                                            }
15140                                            else {
15141                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15142                                            }
15143                                    }
15144                                    else {
15145                                            if (orderByComparator.isAscending() ^ previous) {
15146                                                    query.append(WHERE_GREATER_THAN);
15147                                            }
15148                                            else {
15149                                                    query.append(WHERE_LESSER_THAN);
15150                                            }
15151                                    }
15152                            }
15153    
15154                            query.append(ORDER_BY_CLAUSE);
15155    
15156                            String[] orderByFields = orderByComparator.getOrderByFields();
15157    
15158                            for (int i = 0; i < orderByFields.length; i++) {
15159                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15160                                    query.append(orderByFields[i]);
15161    
15162                                    if ((i + 1) < orderByFields.length) {
15163                                            if (orderByComparator.isAscending() ^ previous) {
15164                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15165                                            }
15166                                            else {
15167                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15168                                            }
15169                                    }
15170                                    else {
15171                                            if (orderByComparator.isAscending() ^ previous) {
15172                                                    query.append(ORDER_BY_ASC);
15173                                            }
15174                                            else {
15175                                                    query.append(ORDER_BY_DESC);
15176                                            }
15177                                    }
15178                            }
15179                    }
15180                    else {
15181                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15182                    }
15183    
15184                    String sql = query.toString();
15185    
15186                    Query q = session.createQuery(sql);
15187    
15188                    q.setFirstResult(0);
15189                    q.setMaxResults(2);
15190    
15191                    QueryPos qPos = QueryPos.getInstance(q);
15192    
15193                    qPos.add(userId);
15194    
15195                    qPos.add(classNameId);
15196    
15197                    qPos.add(status);
15198    
15199                    if (orderByComparator != null) {
15200                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15201    
15202                            for (Object value : values) {
15203                                    qPos.add(value);
15204                            }
15205                    }
15206    
15207                    List<MBMessage> list = q.list();
15208    
15209                    if (list.size() == 2) {
15210                            return list.get(1);
15211                    }
15212                    else {
15213                            return null;
15214                    }
15215            }
15216    
15217            /**
15218             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15219             *
15220             * <p>
15221             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15222             * </p>
15223             *
15224             * @param userId the user ID
15225             * @param classNameIds the class name IDs
15226             * @param status the status
15227             * @return the matching message-boards messages
15228             */
15229            @Override
15230            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15231                    int status) {
15232                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
15233                            QueryUtil.ALL_POS, null);
15234            }
15235    
15236            /**
15237             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15238             *
15239             * <p>
15240             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15241             * </p>
15242             *
15243             * @param userId the user ID
15244             * @param classNameIds the class name IDs
15245             * @param status the status
15246             * @param start the lower bound of the range of message-boards messages
15247             * @param end the upper bound of the range of message-boards messages (not inclusive)
15248             * @return the range of matching message-boards messages
15249             */
15250            @Override
15251            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15252                    int status, int start, int end) {
15253                    return findByU_C_S(userId, classNameIds, status, start, end, null);
15254            }
15255    
15256            /**
15257             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15258             *
15259             * <p>
15260             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15261             * </p>
15262             *
15263             * @param userId the user ID
15264             * @param classNameIds the class name IDs
15265             * @param status the status
15266             * @param start the lower bound of the range of message-boards messages
15267             * @param end the upper bound of the range of message-boards messages (not inclusive)
15268             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15269             * @return the ordered range of matching message-boards messages
15270             */
15271            @Override
15272            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15273                    int status, int start, int end,
15274                    OrderByComparator<MBMessage> orderByComparator) {
15275                    return findByU_C_S(userId, classNameIds, status, start, end,
15276                            orderByComparator, true);
15277            }
15278    
15279            /**
15280             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;, optionally using the finder cache.
15281             *
15282             * <p>
15283             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15284             * </p>
15285             *
15286             * @param userId the user ID
15287             * @param classNameId the class name ID
15288             * @param status the status
15289             * @param start the lower bound of the range of message-boards messages
15290             * @param end the upper bound of the range of message-boards messages (not inclusive)
15291             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15292             * @param retrieveFromCache whether to retrieve from the finder cache
15293             * @return the ordered range of matching message-boards messages
15294             */
15295            @Override
15296            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
15297                    int status, int start, int end,
15298                    OrderByComparator<MBMessage> orderByComparator,
15299                    boolean retrieveFromCache) {
15300                    if (classNameIds == null) {
15301                            classNameIds = new long[0];
15302                    }
15303                    else if (classNameIds.length > 1) {
15304                            classNameIds = ArrayUtil.unique(classNameIds);
15305    
15306                            Arrays.sort(classNameIds);
15307                    }
15308    
15309                    if (classNameIds.length == 1) {
15310                            return findByU_C_S(userId, classNameIds[0], status, start, end,
15311                                    orderByComparator);
15312                    }
15313    
15314                    boolean pagination = true;
15315                    Object[] finderArgs = null;
15316    
15317                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15318                                    (orderByComparator == null)) {
15319                            pagination = false;
15320                            finderArgs = new Object[] {
15321                                            userId, StringUtil.merge(classNameIds), status
15322                                    };
15323                    }
15324                    else {
15325                            finderArgs = new Object[] {
15326                                            userId, StringUtil.merge(classNameIds), status,
15327                                            
15328                                            start, end, orderByComparator
15329                                    };
15330                    }
15331    
15332                    List<MBMessage> list = null;
15333    
15334                    if (retrieveFromCache) {
15335                            list = (List<MBMessage>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15336                                            finderArgs, this);
15337    
15338                            if ((list != null) && !list.isEmpty()) {
15339                                    for (MBMessage mbMessage : list) {
15340                                            if ((userId != mbMessage.getUserId()) ||
15341                                                            !ArrayUtil.contains(classNameIds,
15342                                                                    mbMessage.getClassNameId()) ||
15343                                                            (status != mbMessage.getStatus())) {
15344                                                    list = null;
15345    
15346                                                    break;
15347                                            }
15348                                    }
15349                            }
15350                    }
15351    
15352                    if (list == null) {
15353                            StringBundler query = new StringBundler();
15354    
15355                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15356    
15357                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15358    
15359                            if (classNameIds.length > 0) {
15360                                    query.append(StringPool.OPEN_PARENTHESIS);
15361    
15362                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15363    
15364                                    query.append(StringUtil.merge(classNameIds));
15365    
15366                                    query.append(StringPool.CLOSE_PARENTHESIS);
15367    
15368                                    query.append(StringPool.CLOSE_PARENTHESIS);
15369    
15370                                    query.append(WHERE_AND);
15371                            }
15372    
15373                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15374    
15375                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15376                                                    1)), query.index() - 1);
15377    
15378                            if (orderByComparator != null) {
15379                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15380                                            orderByComparator);
15381                            }
15382                            else
15383                             if (pagination) {
15384                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15385                            }
15386    
15387                            String sql = query.toString();
15388    
15389                            Session session = null;
15390    
15391                            try {
15392                                    session = openSession();
15393    
15394                                    Query q = session.createQuery(sql);
15395    
15396                                    QueryPos qPos = QueryPos.getInstance(q);
15397    
15398                                    qPos.add(userId);
15399    
15400                                    qPos.add(status);
15401    
15402                                    if (!pagination) {
15403                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15404                                                            start, end, false);
15405    
15406                                            Collections.sort(list);
15407    
15408                                            list = Collections.unmodifiableList(list);
15409                                    }
15410                                    else {
15411                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15412                                                            start, end);
15413                                    }
15414    
15415                                    cacheResult(list);
15416    
15417                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15418                                            finderArgs, list);
15419                            }
15420                            catch (Exception e) {
15421                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
15422                                            finderArgs);
15423    
15424                                    throw processException(e);
15425                            }
15426                            finally {
15427                                    closeSession(session);
15428                            }
15429                    }
15430    
15431                    return list;
15432            }
15433    
15434            /**
15435             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
15436             *
15437             * @param userId the user ID
15438             * @param classNameId the class name ID
15439             * @param status the status
15440             */
15441            @Override
15442            public void removeByU_C_S(long userId, long classNameId, int status) {
15443                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
15444                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15445                            remove(mbMessage);
15446                    }
15447            }
15448    
15449            /**
15450             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
15451             *
15452             * @param userId the user ID
15453             * @param classNameId the class name ID
15454             * @param status the status
15455             * @return the number of matching message-boards messages
15456             */
15457            @Override
15458            public int countByU_C_S(long userId, long classNameId, int status) {
15459                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
15460    
15461                    Object[] finderArgs = new Object[] { userId, classNameId, status };
15462    
15463                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
15464    
15465                    if (count == null) {
15466                            StringBundler query = new StringBundler(4);
15467    
15468                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15469    
15470                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15471    
15472                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
15473    
15474                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15475    
15476                            String sql = query.toString();
15477    
15478                            Session session = null;
15479    
15480                            try {
15481                                    session = openSession();
15482    
15483                                    Query q = session.createQuery(sql);
15484    
15485                                    QueryPos qPos = QueryPos.getInstance(q);
15486    
15487                                    qPos.add(userId);
15488    
15489                                    qPos.add(classNameId);
15490    
15491                                    qPos.add(status);
15492    
15493                                    count = (Long)q.uniqueResult();
15494    
15495                                    finderCache.putResult(finderPath, finderArgs, count);
15496                            }
15497                            catch (Exception e) {
15498                                    finderCache.removeResult(finderPath, finderArgs);
15499    
15500                                    throw processException(e);
15501                            }
15502                            finally {
15503                                    closeSession(session);
15504                            }
15505                    }
15506    
15507                    return count.intValue();
15508            }
15509    
15510            /**
15511             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
15512             *
15513             * @param userId the user ID
15514             * @param classNameIds the class name IDs
15515             * @param status the status
15516             * @return the number of matching message-boards messages
15517             */
15518            @Override
15519            public int countByU_C_S(long userId, long[] classNameIds, int status) {
15520                    if (classNameIds == null) {
15521                            classNameIds = new long[0];
15522                    }
15523                    else if (classNameIds.length > 1) {
15524                            classNameIds = ArrayUtil.unique(classNameIds);
15525    
15526                            Arrays.sort(classNameIds);
15527                    }
15528    
15529                    Object[] finderArgs = new Object[] {
15530                                    userId, StringUtil.merge(classNameIds), status
15531                            };
15532    
15533                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15534                                    finderArgs, this);
15535    
15536                    if (count == null) {
15537                            StringBundler query = new StringBundler();
15538    
15539                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15540    
15541                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
15542    
15543                            if (classNameIds.length > 0) {
15544                                    query.append(StringPool.OPEN_PARENTHESIS);
15545    
15546                                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_7);
15547    
15548                                    query.append(StringUtil.merge(classNameIds));
15549    
15550                                    query.append(StringPool.CLOSE_PARENTHESIS);
15551    
15552                                    query.append(StringPool.CLOSE_PARENTHESIS);
15553    
15554                                    query.append(WHERE_AND);
15555                            }
15556    
15557                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
15558    
15559                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
15560                                                    1)), query.index() - 1);
15561    
15562                            String sql = query.toString();
15563    
15564                            Session session = null;
15565    
15566                            try {
15567                                    session = openSession();
15568    
15569                                    Query q = session.createQuery(sql);
15570    
15571                                    QueryPos qPos = QueryPos.getInstance(q);
15572    
15573                                    qPos.add(userId);
15574    
15575                                    qPos.add(status);
15576    
15577                                    count = (Long)q.uniqueResult();
15578    
15579                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15580                                            finderArgs, count);
15581                            }
15582                            catch (Exception e) {
15583                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
15584                                            finderArgs);
15585    
15586                                    throw processException(e);
15587                            }
15588                            finally {
15589                                    closeSession(session);
15590                            }
15591                    }
15592    
15593                    return count.intValue();
15594            }
15595    
15596            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
15597            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15598            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_7 = "mbMessage.classNameId IN (";
15599            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
15600            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15601                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15602                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
15603                            new String[] {
15604                                    Long.class.getName(), Long.class.getName(),
15605                                    Integer.class.getName(),
15606                                    
15607                            Integer.class.getName(), Integer.class.getName(),
15608                                    OrderByComparator.class.getName()
15609                            });
15610            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15611                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15612                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
15613                            new String[] {
15614                                    Long.class.getName(), Long.class.getName(),
15615                                    Integer.class.getName()
15616                            },
15617                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
15618                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
15619                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15620                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15621            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15622                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15623                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
15624                            new String[] {
15625                                    Long.class.getName(), Long.class.getName(),
15626                                    Integer.class.getName()
15627                            });
15628    
15629            /**
15630             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15631             *
15632             * @param classNameId the class name ID
15633             * @param classPK the class p k
15634             * @param status the status
15635             * @return the matching message-boards messages
15636             */
15637            @Override
15638            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15639                    int status) {
15640                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15641                            QueryUtil.ALL_POS, null);
15642            }
15643    
15644            /**
15645             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15646             *
15647             * <p>
15648             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15649             * </p>
15650             *
15651             * @param classNameId the class name ID
15652             * @param classPK the class p k
15653             * @param status the status
15654             * @param start the lower bound of the range of message-boards messages
15655             * @param end the upper bound of the range of message-boards messages (not inclusive)
15656             * @return the range of matching message-boards messages
15657             */
15658            @Override
15659            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15660                    int status, int start, int end) {
15661                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15662            }
15663    
15664            /**
15665             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15666             *
15667             * <p>
15668             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15669             * </p>
15670             *
15671             * @param classNameId the class name ID
15672             * @param classPK the class p k
15673             * @param status the status
15674             * @param start the lower bound of the range of message-boards messages
15675             * @param end the upper bound of the range of message-boards messages (not inclusive)
15676             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15677             * @return the ordered range of matching message-boards messages
15678             */
15679            @Override
15680            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15681                    int status, int start, int end,
15682                    OrderByComparator<MBMessage> orderByComparator) {
15683                    return findByC_C_S(classNameId, classPK, status, start, end,
15684                            orderByComparator, true);
15685            }
15686    
15687            /**
15688             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15689             *
15690             * <p>
15691             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15692             * </p>
15693             *
15694             * @param classNameId the class name ID
15695             * @param classPK the class p k
15696             * @param status the status
15697             * @param start the lower bound of the range of message-boards messages
15698             * @param end the upper bound of the range of message-boards messages (not inclusive)
15699             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15700             * @param retrieveFromCache whether to retrieve from the finder cache
15701             * @return the ordered range of matching message-boards messages
15702             */
15703            @Override
15704            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15705                    int status, int start, int end,
15706                    OrderByComparator<MBMessage> orderByComparator,
15707                    boolean retrieveFromCache) {
15708                    boolean pagination = true;
15709                    FinderPath finderPath = null;
15710                    Object[] finderArgs = null;
15711    
15712                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15713                                    (orderByComparator == null)) {
15714                            pagination = false;
15715                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15716                            finderArgs = new Object[] { classNameId, classPK, status };
15717                    }
15718                    else {
15719                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15720                            finderArgs = new Object[] {
15721                                            classNameId, classPK, status,
15722                                            
15723                                            start, end, orderByComparator
15724                                    };
15725                    }
15726    
15727                    List<MBMessage> list = null;
15728    
15729                    if (retrieveFromCache) {
15730                            list = (List<MBMessage>)finderCache.getResult(finderPath,
15731                                            finderArgs, this);
15732    
15733                            if ((list != null) && !list.isEmpty()) {
15734                                    for (MBMessage mbMessage : list) {
15735                                            if ((classNameId != mbMessage.getClassNameId()) ||
15736                                                            (classPK != mbMessage.getClassPK()) ||
15737                                                            (status != mbMessage.getStatus())) {
15738                                                    list = null;
15739    
15740                                                    break;
15741                                            }
15742                                    }
15743                            }
15744                    }
15745    
15746                    if (list == null) {
15747                            StringBundler query = null;
15748    
15749                            if (orderByComparator != null) {
15750                                    query = new StringBundler(5 +
15751                                                    (orderByComparator.getOrderByFields().length * 2));
15752                            }
15753                            else {
15754                                    query = new StringBundler(5);
15755                            }
15756    
15757                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15758    
15759                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15760    
15761                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15762    
15763                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15764    
15765                            if (orderByComparator != null) {
15766                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15767                                            orderByComparator);
15768                            }
15769                            else
15770                             if (pagination) {
15771                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15772                            }
15773    
15774                            String sql = query.toString();
15775    
15776                            Session session = null;
15777    
15778                            try {
15779                                    session = openSession();
15780    
15781                                    Query q = session.createQuery(sql);
15782    
15783                                    QueryPos qPos = QueryPos.getInstance(q);
15784    
15785                                    qPos.add(classNameId);
15786    
15787                                    qPos.add(classPK);
15788    
15789                                    qPos.add(status);
15790    
15791                                    if (!pagination) {
15792                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15793                                                            start, end, false);
15794    
15795                                            Collections.sort(list);
15796    
15797                                            list = Collections.unmodifiableList(list);
15798                                    }
15799                                    else {
15800                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15801                                                            start, end);
15802                                    }
15803    
15804                                    cacheResult(list);
15805    
15806                                    finderCache.putResult(finderPath, finderArgs, list);
15807                            }
15808                            catch (Exception e) {
15809                                    finderCache.removeResult(finderPath, finderArgs);
15810    
15811                                    throw processException(e);
15812                            }
15813                            finally {
15814                                    closeSession(session);
15815                            }
15816                    }
15817    
15818                    return list;
15819            }
15820    
15821            /**
15822             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15823             *
15824             * @param classNameId the class name ID
15825             * @param classPK the class p k
15826             * @param status the status
15827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15828             * @return the first matching message-boards message
15829             * @throws NoSuchMessageException if a matching message-boards message could not be found
15830             */
15831            @Override
15832            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15833                    int status, OrderByComparator<MBMessage> orderByComparator)
15834                    throws NoSuchMessageException {
15835                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15836                                    orderByComparator);
15837    
15838                    if (mbMessage != null) {
15839                            return mbMessage;
15840                    }
15841    
15842                    StringBundler msg = new StringBundler(8);
15843    
15844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15845    
15846                    msg.append("classNameId=");
15847                    msg.append(classNameId);
15848    
15849                    msg.append(", classPK=");
15850                    msg.append(classPK);
15851    
15852                    msg.append(", status=");
15853                    msg.append(status);
15854    
15855                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15856    
15857                    throw new NoSuchMessageException(msg.toString());
15858            }
15859    
15860            /**
15861             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15862             *
15863             * @param classNameId the class name ID
15864             * @param classPK the class p k
15865             * @param status the status
15866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15867             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15868             */
15869            @Override
15870            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15871                    int status, OrderByComparator<MBMessage> orderByComparator) {
15872                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15873                                    orderByComparator);
15874    
15875                    if (!list.isEmpty()) {
15876                            return list.get(0);
15877                    }
15878    
15879                    return null;
15880            }
15881    
15882            /**
15883             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15884             *
15885             * @param classNameId the class name ID
15886             * @param classPK the class p k
15887             * @param status the status
15888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15889             * @return the last matching message-boards message
15890             * @throws NoSuchMessageException if a matching message-boards message could not be found
15891             */
15892            @Override
15893            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15894                    int status, OrderByComparator<MBMessage> orderByComparator)
15895                    throws NoSuchMessageException {
15896                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15897                                    orderByComparator);
15898    
15899                    if (mbMessage != null) {
15900                            return mbMessage;
15901                    }
15902    
15903                    StringBundler msg = new StringBundler(8);
15904    
15905                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15906    
15907                    msg.append("classNameId=");
15908                    msg.append(classNameId);
15909    
15910                    msg.append(", classPK=");
15911                    msg.append(classPK);
15912    
15913                    msg.append(", status=");
15914                    msg.append(status);
15915    
15916                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15917    
15918                    throw new NoSuchMessageException(msg.toString());
15919            }
15920    
15921            /**
15922             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15923             *
15924             * @param classNameId the class name ID
15925             * @param classPK the class p k
15926             * @param status the status
15927             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15928             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15929             */
15930            @Override
15931            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15932                    int status, OrderByComparator<MBMessage> orderByComparator) {
15933                    int count = countByC_C_S(classNameId, classPK, status);
15934    
15935                    if (count == 0) {
15936                            return null;
15937                    }
15938    
15939                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15940                                    count - 1, count, orderByComparator);
15941    
15942                    if (!list.isEmpty()) {
15943                            return list.get(0);
15944                    }
15945    
15946                    return null;
15947            }
15948    
15949            /**
15950             * 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;.
15951             *
15952             * @param messageId the primary key of the current message-boards message
15953             * @param classNameId the class name ID
15954             * @param classPK the class p k
15955             * @param status the status
15956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15957             * @return the previous, current, and next message-boards message
15958             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
15959             */
15960            @Override
15961            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15962                    long classNameId, long classPK, int status,
15963                    OrderByComparator<MBMessage> orderByComparator)
15964                    throws NoSuchMessageException {
15965                    MBMessage mbMessage = findByPrimaryKey(messageId);
15966    
15967                    Session session = null;
15968    
15969                    try {
15970                            session = openSession();
15971    
15972                            MBMessage[] array = new MBMessageImpl[3];
15973    
15974                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15975                                            classPK, status, orderByComparator, true);
15976    
15977                            array[1] = mbMessage;
15978    
15979                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15980                                            classPK, status, orderByComparator, false);
15981    
15982                            return array;
15983                    }
15984                    catch (Exception e) {
15985                            throw processException(e);
15986                    }
15987                    finally {
15988                            closeSession(session);
15989                    }
15990            }
15991    
15992            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15993                    MBMessage mbMessage, long classNameId, long classPK, int status,
15994                    OrderByComparator<MBMessage> orderByComparator, boolean previous) {
15995                    StringBundler query = null;
15996    
15997                    if (orderByComparator != null) {
15998                            query = new StringBundler(6 +
15999                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16000                                            (orderByComparator.getOrderByFields().length * 3));
16001                    }
16002                    else {
16003                            query = new StringBundler(5);
16004                    }
16005    
16006                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16007    
16008                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16009    
16010                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16011    
16012                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16013    
16014                    if (orderByComparator != null) {
16015                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16016    
16017                            if (orderByConditionFields.length > 0) {
16018                                    query.append(WHERE_AND);
16019                            }
16020    
16021                            for (int i = 0; i < orderByConditionFields.length; i++) {
16022                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16023                                    query.append(orderByConditionFields[i]);
16024    
16025                                    if ((i + 1) < orderByConditionFields.length) {
16026                                            if (orderByComparator.isAscending() ^ previous) {
16027                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16028                                            }
16029                                            else {
16030                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16031                                            }
16032                                    }
16033                                    else {
16034                                            if (orderByComparator.isAscending() ^ previous) {
16035                                                    query.append(WHERE_GREATER_THAN);
16036                                            }
16037                                            else {
16038                                                    query.append(WHERE_LESSER_THAN);
16039                                            }
16040                                    }
16041                            }
16042    
16043                            query.append(ORDER_BY_CLAUSE);
16044    
16045                            String[] orderByFields = orderByComparator.getOrderByFields();
16046    
16047                            for (int i = 0; i < orderByFields.length; i++) {
16048                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16049                                    query.append(orderByFields[i]);
16050    
16051                                    if ((i + 1) < orderByFields.length) {
16052                                            if (orderByComparator.isAscending() ^ previous) {
16053                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16054                                            }
16055                                            else {
16056                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16057                                            }
16058                                    }
16059                                    else {
16060                                            if (orderByComparator.isAscending() ^ previous) {
16061                                                    query.append(ORDER_BY_ASC);
16062                                            }
16063                                            else {
16064                                                    query.append(ORDER_BY_DESC);
16065                                            }
16066                                    }
16067                            }
16068                    }
16069                    else {
16070                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16071                    }
16072    
16073                    String sql = query.toString();
16074    
16075                    Query q = session.createQuery(sql);
16076    
16077                    q.setFirstResult(0);
16078                    q.setMaxResults(2);
16079    
16080                    QueryPos qPos = QueryPos.getInstance(q);
16081    
16082                    qPos.add(classNameId);
16083    
16084                    qPos.add(classPK);
16085    
16086                    qPos.add(status);
16087    
16088                    if (orderByComparator != null) {
16089                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16090    
16091                            for (Object value : values) {
16092                                    qPos.add(value);
16093                            }
16094                    }
16095    
16096                    List<MBMessage> list = q.list();
16097    
16098                    if (list.size() == 2) {
16099                            return list.get(1);
16100                    }
16101                    else {
16102                            return null;
16103                    }
16104            }
16105    
16106            /**
16107             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16108             *
16109             * @param classNameId the class name ID
16110             * @param classPK the class p k
16111             * @param status the status
16112             */
16113            @Override
16114            public void removeByC_C_S(long classNameId, long classPK, int status) {
16115                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
16116                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16117                            remove(mbMessage);
16118                    }
16119            }
16120    
16121            /**
16122             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16123             *
16124             * @param classNameId the class name ID
16125             * @param classPK the class p k
16126             * @param status the status
16127             * @return the number of matching message-boards messages
16128             */
16129            @Override
16130            public int countByC_C_S(long classNameId, long classPK, int status) {
16131                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
16132    
16133                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16134    
16135                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
16136    
16137                    if (count == null) {
16138                            StringBundler query = new StringBundler(4);
16139    
16140                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16141    
16142                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16143    
16144                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16145    
16146                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16147    
16148                            String sql = query.toString();
16149    
16150                            Session session = null;
16151    
16152                            try {
16153                                    session = openSession();
16154    
16155                                    Query q = session.createQuery(sql);
16156    
16157                                    QueryPos qPos = QueryPos.getInstance(q);
16158    
16159                                    qPos.add(classNameId);
16160    
16161                                    qPos.add(classPK);
16162    
16163                                    qPos.add(status);
16164    
16165                                    count = (Long)q.uniqueResult();
16166    
16167                                    finderCache.putResult(finderPath, finderArgs, count);
16168                            }
16169                            catch (Exception e) {
16170                                    finderCache.removeResult(finderPath, finderArgs);
16171    
16172                                    throw processException(e);
16173                            }
16174                            finally {
16175                                    closeSession(session);
16176                            }
16177                    }
16178    
16179                    return count.intValue();
16180            }
16181    
16182            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
16183            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
16184            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
16185            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16186                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16187                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
16188                            new String[] {
16189                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16190                                    Boolean.class.getName(),
16191                                    
16192                            Integer.class.getName(), Integer.class.getName(),
16193                                    OrderByComparator.class.getName()
16194                            });
16195            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
16196                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16197                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16198                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
16199                            new String[] {
16200                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16201                                    Boolean.class.getName()
16202                            },
16203                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16204                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16205                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16206                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
16207                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16208            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16209                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16210                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
16211                            new String[] {
16212                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16213                                    Boolean.class.getName()
16214                            });
16215    
16216            /**
16217             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16218             *
16219             * @param groupId the group ID
16220             * @param categoryId the category ID
16221             * @param threadId the thread ID
16222             * @param answer the answer
16223             * @return the matching message-boards messages
16224             */
16225            @Override
16226            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16227                    long threadId, boolean answer) {
16228                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
16229                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16230            }
16231    
16232            /**
16233             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16234             *
16235             * <p>
16236             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16237             * </p>
16238             *
16239             * @param groupId the group ID
16240             * @param categoryId the category ID
16241             * @param threadId the thread ID
16242             * @param answer the answer
16243             * @param start the lower bound of the range of message-boards messages
16244             * @param end the upper bound of the range of message-boards messages (not inclusive)
16245             * @return the range of matching message-boards messages
16246             */
16247            @Override
16248            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16249                    long threadId, boolean answer, int start, int end) {
16250                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16251                            null);
16252            }
16253    
16254            /**
16255             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16256             *
16257             * <p>
16258             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16259             * </p>
16260             *
16261             * @param groupId the group ID
16262             * @param categoryId the category ID
16263             * @param threadId the thread ID
16264             * @param answer the answer
16265             * @param start the lower bound of the range of message-boards messages
16266             * @param end the upper bound of the range of message-boards messages (not inclusive)
16267             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16268             * @return the ordered range of matching message-boards messages
16269             */
16270            @Override
16271            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16272                    long threadId, boolean answer, int start, int end,
16273                    OrderByComparator<MBMessage> orderByComparator) {
16274                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
16275                            orderByComparator, true);
16276            }
16277    
16278            /**
16279             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16280             *
16281             * <p>
16282             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16283             * </p>
16284             *
16285             * @param groupId the group ID
16286             * @param categoryId the category ID
16287             * @param threadId the thread ID
16288             * @param answer the answer
16289             * @param start the lower bound of the range of message-boards messages
16290             * @param end the upper bound of the range of message-boards messages (not inclusive)
16291             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16292             * @param retrieveFromCache whether to retrieve from the finder cache
16293             * @return the ordered range of matching message-boards messages
16294             */
16295            @Override
16296            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
16297                    long threadId, boolean answer, int start, int end,
16298                    OrderByComparator<MBMessage> orderByComparator,
16299                    boolean retrieveFromCache) {
16300                    boolean pagination = true;
16301                    FinderPath finderPath = null;
16302                    Object[] finderArgs = null;
16303    
16304                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16305                                    (orderByComparator == null)) {
16306                            pagination = false;
16307                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
16308                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16309                    }
16310                    else {
16311                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
16312                            finderArgs = new Object[] {
16313                                            groupId, categoryId, threadId, answer,
16314                                            
16315                                            start, end, orderByComparator
16316                                    };
16317                    }
16318    
16319                    List<MBMessage> list = null;
16320    
16321                    if (retrieveFromCache) {
16322                            list = (List<MBMessage>)finderCache.getResult(finderPath,
16323                                            finderArgs, this);
16324    
16325                            if ((list != null) && !list.isEmpty()) {
16326                                    for (MBMessage mbMessage : list) {
16327                                            if ((groupId != mbMessage.getGroupId()) ||
16328                                                            (categoryId != mbMessage.getCategoryId()) ||
16329                                                            (threadId != mbMessage.getThreadId()) ||
16330                                                            (answer != mbMessage.getAnswer())) {
16331                                                    list = null;
16332    
16333                                                    break;
16334                                            }
16335                                    }
16336                            }
16337                    }
16338    
16339                    if (list == null) {
16340                            StringBundler query = null;
16341    
16342                            if (orderByComparator != null) {
16343                                    query = new StringBundler(6 +
16344                                                    (orderByComparator.getOrderByFields().length * 2));
16345                            }
16346                            else {
16347                                    query = new StringBundler(6);
16348                            }
16349    
16350                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16351    
16352                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16353    
16354                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16355    
16356                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16357    
16358                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16359    
16360                            if (orderByComparator != null) {
16361                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16362                                            orderByComparator);
16363                            }
16364                            else
16365                             if (pagination) {
16366                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16367                            }
16368    
16369                            String sql = query.toString();
16370    
16371                            Session session = null;
16372    
16373                            try {
16374                                    session = openSession();
16375    
16376                                    Query q = session.createQuery(sql);
16377    
16378                                    QueryPos qPos = QueryPos.getInstance(q);
16379    
16380                                    qPos.add(groupId);
16381    
16382                                    qPos.add(categoryId);
16383    
16384                                    qPos.add(threadId);
16385    
16386                                    qPos.add(answer);
16387    
16388                                    if (!pagination) {
16389                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16390                                                            start, end, false);
16391    
16392                                            Collections.sort(list);
16393    
16394                                            list = Collections.unmodifiableList(list);
16395                                    }
16396                                    else {
16397                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16398                                                            start, end);
16399                                    }
16400    
16401                                    cacheResult(list);
16402    
16403                                    finderCache.putResult(finderPath, finderArgs, list);
16404                            }
16405                            catch (Exception e) {
16406                                    finderCache.removeResult(finderPath, finderArgs);
16407    
16408                                    throw processException(e);
16409                            }
16410                            finally {
16411                                    closeSession(session);
16412                            }
16413                    }
16414    
16415                    return list;
16416            }
16417    
16418            /**
16419             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16420             *
16421             * @param groupId the group ID
16422             * @param categoryId the category ID
16423             * @param threadId the thread ID
16424             * @param answer the answer
16425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16426             * @return the first matching message-boards message
16427             * @throws NoSuchMessageException if a matching message-boards message could not be found
16428             */
16429            @Override
16430            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
16431                    long threadId, boolean answer,
16432                    OrderByComparator<MBMessage> orderByComparator)
16433                    throws NoSuchMessageException {
16434                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
16435                                    threadId, answer, orderByComparator);
16436    
16437                    if (mbMessage != null) {
16438                            return mbMessage;
16439                    }
16440    
16441                    StringBundler msg = new StringBundler(10);
16442    
16443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16444    
16445                    msg.append("groupId=");
16446                    msg.append(groupId);
16447    
16448                    msg.append(", categoryId=");
16449                    msg.append(categoryId);
16450    
16451                    msg.append(", threadId=");
16452                    msg.append(threadId);
16453    
16454                    msg.append(", answer=");
16455                    msg.append(answer);
16456    
16457                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16458    
16459                    throw new NoSuchMessageException(msg.toString());
16460            }
16461    
16462            /**
16463             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16464             *
16465             * @param groupId the group ID
16466             * @param categoryId the category ID
16467             * @param threadId the thread ID
16468             * @param answer the answer
16469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16470             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16471             */
16472            @Override
16473            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
16474                    long threadId, boolean answer,
16475                    OrderByComparator<MBMessage> orderByComparator) {
16476                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16477                                    answer, 0, 1, orderByComparator);
16478    
16479                    if (!list.isEmpty()) {
16480                            return list.get(0);
16481                    }
16482    
16483                    return null;
16484            }
16485    
16486            /**
16487             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16488             *
16489             * @param groupId the group ID
16490             * @param categoryId the category ID
16491             * @param threadId the thread ID
16492             * @param answer the answer
16493             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16494             * @return the last matching message-boards message
16495             * @throws NoSuchMessageException if a matching message-boards message could not be found
16496             */
16497            @Override
16498            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
16499                    long threadId, boolean answer,
16500                    OrderByComparator<MBMessage> orderByComparator)
16501                    throws NoSuchMessageException {
16502                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
16503                                    threadId, answer, orderByComparator);
16504    
16505                    if (mbMessage != null) {
16506                            return mbMessage;
16507                    }
16508    
16509                    StringBundler msg = new StringBundler(10);
16510    
16511                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16512    
16513                    msg.append("groupId=");
16514                    msg.append(groupId);
16515    
16516                    msg.append(", categoryId=");
16517                    msg.append(categoryId);
16518    
16519                    msg.append(", threadId=");
16520                    msg.append(threadId);
16521    
16522                    msg.append(", answer=");
16523                    msg.append(answer);
16524    
16525                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16526    
16527                    throw new NoSuchMessageException(msg.toString());
16528            }
16529    
16530            /**
16531             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16532             *
16533             * @param groupId the group ID
16534             * @param categoryId the category ID
16535             * @param threadId the thread ID
16536             * @param answer the answer
16537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16538             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16539             */
16540            @Override
16541            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
16542                    long threadId, boolean answer,
16543                    OrderByComparator<MBMessage> orderByComparator) {
16544                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
16545    
16546                    if (count == 0) {
16547                            return null;
16548                    }
16549    
16550                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
16551                                    answer, count - 1, count, orderByComparator);
16552    
16553                    if (!list.isEmpty()) {
16554                            return list.get(0);
16555                    }
16556    
16557                    return null;
16558            }
16559    
16560            /**
16561             * 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;.
16562             *
16563             * @param messageId the primary key of the current message-boards message
16564             * @param groupId the group ID
16565             * @param categoryId the category ID
16566             * @param threadId the thread ID
16567             * @param answer the answer
16568             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16569             * @return the previous, current, and next message-boards message
16570             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16571             */
16572            @Override
16573            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
16574                    long categoryId, long threadId, boolean answer,
16575                    OrderByComparator<MBMessage> orderByComparator)
16576                    throws NoSuchMessageException {
16577                    MBMessage mbMessage = findByPrimaryKey(messageId);
16578    
16579                    Session session = null;
16580    
16581                    try {
16582                            session = openSession();
16583    
16584                            MBMessage[] array = new MBMessageImpl[3];
16585    
16586                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16587                                            categoryId, threadId, answer, orderByComparator, true);
16588    
16589                            array[1] = mbMessage;
16590    
16591                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
16592                                            categoryId, threadId, answer, orderByComparator, false);
16593    
16594                            return array;
16595                    }
16596                    catch (Exception e) {
16597                            throw processException(e);
16598                    }
16599                    finally {
16600                            closeSession(session);
16601                    }
16602            }
16603    
16604            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
16605                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16606                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16607                    boolean previous) {
16608                    StringBundler query = null;
16609    
16610                    if (orderByComparator != null) {
16611                            query = new StringBundler(7 +
16612                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16613                                            (orderByComparator.getOrderByFields().length * 3));
16614                    }
16615                    else {
16616                            query = new StringBundler(6);
16617                    }
16618    
16619                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16620    
16621                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16622    
16623                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16624    
16625                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16626    
16627                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16628    
16629                    if (orderByComparator != null) {
16630                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16631    
16632                            if (orderByConditionFields.length > 0) {
16633                                    query.append(WHERE_AND);
16634                            }
16635    
16636                            for (int i = 0; i < orderByConditionFields.length; i++) {
16637                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16638                                    query.append(orderByConditionFields[i]);
16639    
16640                                    if ((i + 1) < orderByConditionFields.length) {
16641                                            if (orderByComparator.isAscending() ^ previous) {
16642                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16643                                            }
16644                                            else {
16645                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16646                                            }
16647                                    }
16648                                    else {
16649                                            if (orderByComparator.isAscending() ^ previous) {
16650                                                    query.append(WHERE_GREATER_THAN);
16651                                            }
16652                                            else {
16653                                                    query.append(WHERE_LESSER_THAN);
16654                                            }
16655                                    }
16656                            }
16657    
16658                            query.append(ORDER_BY_CLAUSE);
16659    
16660                            String[] orderByFields = orderByComparator.getOrderByFields();
16661    
16662                            for (int i = 0; i < orderByFields.length; i++) {
16663                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16664                                    query.append(orderByFields[i]);
16665    
16666                                    if ((i + 1) < orderByFields.length) {
16667                                            if (orderByComparator.isAscending() ^ previous) {
16668                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16669                                            }
16670                                            else {
16671                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16672                                            }
16673                                    }
16674                                    else {
16675                                            if (orderByComparator.isAscending() ^ previous) {
16676                                                    query.append(ORDER_BY_ASC);
16677                                            }
16678                                            else {
16679                                                    query.append(ORDER_BY_DESC);
16680                                            }
16681                                    }
16682                            }
16683                    }
16684                    else {
16685                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16686                    }
16687    
16688                    String sql = query.toString();
16689    
16690                    Query q = session.createQuery(sql);
16691    
16692                    q.setFirstResult(0);
16693                    q.setMaxResults(2);
16694    
16695                    QueryPos qPos = QueryPos.getInstance(q);
16696    
16697                    qPos.add(groupId);
16698    
16699                    qPos.add(categoryId);
16700    
16701                    qPos.add(threadId);
16702    
16703                    qPos.add(answer);
16704    
16705                    if (orderByComparator != null) {
16706                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16707    
16708                            for (Object value : values) {
16709                                    qPos.add(value);
16710                            }
16711                    }
16712    
16713                    List<MBMessage> list = q.list();
16714    
16715                    if (list.size() == 2) {
16716                            return list.get(1);
16717                    }
16718                    else {
16719                            return null;
16720                    }
16721            }
16722    
16723            /**
16724             * 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;.
16725             *
16726             * @param groupId the group ID
16727             * @param categoryId the category ID
16728             * @param threadId the thread ID
16729             * @param answer the answer
16730             * @return the matching message-boards messages that the user has permission to view
16731             */
16732            @Override
16733            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16734                    long threadId, boolean answer) {
16735                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16736                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16737            }
16738    
16739            /**
16740             * 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;.
16741             *
16742             * <p>
16743             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16744             * </p>
16745             *
16746             * @param groupId the group ID
16747             * @param categoryId the category ID
16748             * @param threadId the thread ID
16749             * @param answer the answer
16750             * @param start the lower bound of the range of message-boards messages
16751             * @param end the upper bound of the range of message-boards messages (not inclusive)
16752             * @return the range of matching message-boards messages that the user has permission to view
16753             */
16754            @Override
16755            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16756                    long threadId, boolean answer, int start, int end) {
16757                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16758                            start, end, null);
16759            }
16760    
16761            /**
16762             * 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;.
16763             *
16764             * <p>
16765             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16766             * </p>
16767             *
16768             * @param groupId the group ID
16769             * @param categoryId the category ID
16770             * @param threadId the thread ID
16771             * @param answer the answer
16772             * @param start the lower bound of the range of message-boards messages
16773             * @param end the upper bound of the range of message-boards messages (not inclusive)
16774             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16775             * @return the ordered range of matching message-boards messages that the user has permission to view
16776             */
16777            @Override
16778            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16779                    long threadId, boolean answer, int start, int end,
16780                    OrderByComparator<MBMessage> orderByComparator) {
16781                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16782                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16783                                    end, orderByComparator);
16784                    }
16785    
16786                    StringBundler query = null;
16787    
16788                    if (orderByComparator != null) {
16789                            query = new StringBundler(6 +
16790                                            (orderByComparator.getOrderByFields().length * 2));
16791                    }
16792                    else {
16793                            query = new StringBundler(7);
16794                    }
16795    
16796                    if (getDB().isSupportsInlineDistinct()) {
16797                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16798                    }
16799                    else {
16800                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16801                    }
16802    
16803                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16804    
16805                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16806    
16807                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16808    
16809                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16810    
16811                    if (!getDB().isSupportsInlineDistinct()) {
16812                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16813                    }
16814    
16815                    if (orderByComparator != null) {
16816                            if (getDB().isSupportsInlineDistinct()) {
16817                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16818                                            orderByComparator, true);
16819                            }
16820                            else {
16821                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16822                                            orderByComparator, true);
16823                            }
16824                    }
16825                    else {
16826                            if (getDB().isSupportsInlineDistinct()) {
16827                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16828                            }
16829                            else {
16830                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16831                            }
16832                    }
16833    
16834                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16835                                    MBMessage.class.getName(),
16836                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16837    
16838                    Session session = null;
16839    
16840                    try {
16841                            session = openSession();
16842    
16843                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
16844    
16845                            if (getDB().isSupportsInlineDistinct()) {
16846                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16847                            }
16848                            else {
16849                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16850                            }
16851    
16852                            QueryPos qPos = QueryPos.getInstance(q);
16853    
16854                            qPos.add(groupId);
16855    
16856                            qPos.add(categoryId);
16857    
16858                            qPos.add(threadId);
16859    
16860                            qPos.add(answer);
16861    
16862                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16863                    }
16864                    catch (Exception e) {
16865                            throw processException(e);
16866                    }
16867                    finally {
16868                            closeSession(session);
16869                    }
16870            }
16871    
16872            /**
16873             * 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;.
16874             *
16875             * @param messageId the primary key of the current message-boards message
16876             * @param groupId the group ID
16877             * @param categoryId the category ID
16878             * @param threadId the thread ID
16879             * @param answer the answer
16880             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16881             * @return the previous, current, and next message-boards message
16882             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
16883             */
16884            @Override
16885            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16886                    long groupId, long categoryId, long threadId, boolean answer,
16887                    OrderByComparator<MBMessage> orderByComparator)
16888                    throws NoSuchMessageException {
16889                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16890                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16891                                    threadId, answer, orderByComparator);
16892                    }
16893    
16894                    MBMessage mbMessage = findByPrimaryKey(messageId);
16895    
16896                    Session session = null;
16897    
16898                    try {
16899                            session = openSession();
16900    
16901                            MBMessage[] array = new MBMessageImpl[3];
16902    
16903                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16904                                            groupId, categoryId, threadId, answer, orderByComparator,
16905                                            true);
16906    
16907                            array[1] = mbMessage;
16908    
16909                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16910                                            groupId, categoryId, threadId, answer, orderByComparator,
16911                                            false);
16912    
16913                            return array;
16914                    }
16915                    catch (Exception e) {
16916                            throw processException(e);
16917                    }
16918                    finally {
16919                            closeSession(session);
16920                    }
16921            }
16922    
16923            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16924                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16925                    boolean answer, OrderByComparator<MBMessage> orderByComparator,
16926                    boolean previous) {
16927                    StringBundler query = null;
16928    
16929                    if (orderByComparator != null) {
16930                            query = new StringBundler(8 +
16931                                            (orderByComparator.getOrderByConditionFields().length * 3) +
16932                                            (orderByComparator.getOrderByFields().length * 3));
16933                    }
16934                    else {
16935                            query = new StringBundler(7);
16936                    }
16937    
16938                    if (getDB().isSupportsInlineDistinct()) {
16939                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16940                    }
16941                    else {
16942                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16943                    }
16944    
16945                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16946    
16947                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16948    
16949                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16950    
16951                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16952    
16953                    if (!getDB().isSupportsInlineDistinct()) {
16954                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16955                    }
16956    
16957                    if (orderByComparator != null) {
16958                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16959    
16960                            if (orderByConditionFields.length > 0) {
16961                                    query.append(WHERE_AND);
16962                            }
16963    
16964                            for (int i = 0; i < orderByConditionFields.length; i++) {
16965                                    if (getDB().isSupportsInlineDistinct()) {
16966                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16967                                    }
16968                                    else {
16969                                            query.append(_ORDER_BY_ENTITY_TABLE);
16970                                    }
16971    
16972                                    query.append(orderByConditionFields[i]);
16973    
16974                                    if ((i + 1) < orderByConditionFields.length) {
16975                                            if (orderByComparator.isAscending() ^ previous) {
16976                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16977                                            }
16978                                            else {
16979                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16980                                            }
16981                                    }
16982                                    else {
16983                                            if (orderByComparator.isAscending() ^ previous) {
16984                                                    query.append(WHERE_GREATER_THAN);
16985                                            }
16986                                            else {
16987                                                    query.append(WHERE_LESSER_THAN);
16988                                            }
16989                                    }
16990                            }
16991    
16992                            query.append(ORDER_BY_CLAUSE);
16993    
16994                            String[] orderByFields = orderByComparator.getOrderByFields();
16995    
16996                            for (int i = 0; i < orderByFields.length; i++) {
16997                                    if (getDB().isSupportsInlineDistinct()) {
16998                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16999                                    }
17000                                    else {
17001                                            query.append(_ORDER_BY_ENTITY_TABLE);
17002                                    }
17003    
17004                                    query.append(orderByFields[i]);
17005    
17006                                    if ((i + 1) < orderByFields.length) {
17007                                            if (orderByComparator.isAscending() ^ previous) {
17008                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17009                                            }
17010                                            else {
17011                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17012                                            }
17013                                    }
17014                                    else {
17015                                            if (orderByComparator.isAscending() ^ previous) {
17016                                                    query.append(ORDER_BY_ASC);
17017                                            }
17018                                            else {
17019                                                    query.append(ORDER_BY_DESC);
17020                                            }
17021                                    }
17022                            }
17023                    }
17024                    else {
17025                            if (getDB().isSupportsInlineDistinct()) {
17026                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17027                            }
17028                            else {
17029                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17030                            }
17031                    }
17032    
17033                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17034                                    MBMessage.class.getName(),
17035                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17036    
17037                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
17038    
17039                    q.setFirstResult(0);
17040                    q.setMaxResults(2);
17041    
17042                    if (getDB().isSupportsInlineDistinct()) {
17043                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17044                    }
17045                    else {
17046                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17047                    }
17048    
17049                    QueryPos qPos = QueryPos.getInstance(q);
17050    
17051                    qPos.add(groupId);
17052    
17053                    qPos.add(categoryId);
17054    
17055                    qPos.add(threadId);
17056    
17057                    qPos.add(answer);
17058    
17059                    if (orderByComparator != null) {
17060                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17061    
17062                            for (Object value : values) {
17063                                    qPos.add(value);
17064                            }
17065                    }
17066    
17067                    List<MBMessage> list = q.list();
17068    
17069                    if (list.size() == 2) {
17070                            return list.get(1);
17071                    }
17072                    else {
17073                            return null;
17074                    }
17075            }
17076    
17077            /**
17078             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
17079             *
17080             * @param groupId the group ID
17081             * @param categoryId the category ID
17082             * @param threadId the thread ID
17083             * @param answer the answer
17084             */
17085            @Override
17086            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
17087                    boolean answer) {
17088                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
17089                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17090                            remove(mbMessage);
17091                    }
17092            }
17093    
17094            /**
17095             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17096             *
17097             * @param groupId the group ID
17098             * @param categoryId the category ID
17099             * @param threadId the thread ID
17100             * @param answer the answer
17101             * @return the number of matching message-boards messages
17102             */
17103            @Override
17104            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
17105                    boolean answer) {
17106                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
17107    
17108                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17109    
17110                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
17111    
17112                    if (count == null) {
17113                            StringBundler query = new StringBundler(5);
17114    
17115                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17116    
17117                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17118    
17119                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17120    
17121                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17122    
17123                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17124    
17125                            String sql = query.toString();
17126    
17127                            Session session = null;
17128    
17129                            try {
17130                                    session = openSession();
17131    
17132                                    Query q = session.createQuery(sql);
17133    
17134                                    QueryPos qPos = QueryPos.getInstance(q);
17135    
17136                                    qPos.add(groupId);
17137    
17138                                    qPos.add(categoryId);
17139    
17140                                    qPos.add(threadId);
17141    
17142                                    qPos.add(answer);
17143    
17144                                    count = (Long)q.uniqueResult();
17145    
17146                                    finderCache.putResult(finderPath, finderArgs, count);
17147                            }
17148                            catch (Exception e) {
17149                                    finderCache.removeResult(finderPath, finderArgs);
17150    
17151                                    throw processException(e);
17152                            }
17153                            finally {
17154                                    closeSession(session);
17155                            }
17156                    }
17157    
17158                    return count.intValue();
17159            }
17160    
17161            /**
17162             * 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;.
17163             *
17164             * @param groupId the group ID
17165             * @param categoryId the category ID
17166             * @param threadId the thread ID
17167             * @param answer the answer
17168             * @return the number of matching message-boards messages that the user has permission to view
17169             */
17170            @Override
17171            public int filterCountByG_C_T_A(long groupId, long categoryId,
17172                    long threadId, boolean answer) {
17173                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17174                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17175                    }
17176    
17177                    StringBundler query = new StringBundler(5);
17178    
17179                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17180    
17181                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17182    
17183                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17184    
17185                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17186    
17187                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17188    
17189                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17190                                    MBMessage.class.getName(),
17191                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17192    
17193                    Session session = null;
17194    
17195                    try {
17196                            session = openSession();
17197    
17198                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17199    
17200                            q.addScalar(COUNT_COLUMN_NAME,
17201                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17202    
17203                            QueryPos qPos = QueryPos.getInstance(q);
17204    
17205                            qPos.add(groupId);
17206    
17207                            qPos.add(categoryId);
17208    
17209                            qPos.add(threadId);
17210    
17211                            qPos.add(answer);
17212    
17213                            Long count = (Long)q.uniqueResult();
17214    
17215                            return count.intValue();
17216                    }
17217                    catch (Exception e) {
17218                            throw processException(e);
17219                    }
17220                    finally {
17221                            closeSession(session);
17222                    }
17223            }
17224    
17225            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17226            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17227            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17228            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17229            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17230                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17231                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
17232                            new String[] {
17233                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17234                                    Integer.class.getName(),
17235                                    
17236                            Integer.class.getName(), Integer.class.getName(),
17237                                    OrderByComparator.class.getName()
17238                            });
17239            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
17240                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17241                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17242                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
17243                            new String[] {
17244                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17245                                    Integer.class.getName()
17246                            },
17247                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17248                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17249                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17250                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17251                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17252            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17253                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17254                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
17255                            new String[] {
17256                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17257                                    Integer.class.getName()
17258                            });
17259    
17260            /**
17261             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17262             *
17263             * @param groupId the group ID
17264             * @param categoryId the category ID
17265             * @param threadId the thread ID
17266             * @param status the status
17267             * @return the matching message-boards messages
17268             */
17269            @Override
17270            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17271                    long threadId, int status) {
17272                    return findByG_C_T_S(groupId, categoryId, threadId, status,
17273                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17274            }
17275    
17276            /**
17277             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17278             *
17279             * <p>
17280             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17281             * </p>
17282             *
17283             * @param groupId the group ID
17284             * @param categoryId the category ID
17285             * @param threadId the thread ID
17286             * @param status the status
17287             * @param start the lower bound of the range of message-boards messages
17288             * @param end the upper bound of the range of message-boards messages (not inclusive)
17289             * @return the range of matching message-boards messages
17290             */
17291            @Override
17292            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17293                    long threadId, int status, int start, int end) {
17294                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17295                            null);
17296            }
17297    
17298            /**
17299             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17300             *
17301             * <p>
17302             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17303             * </p>
17304             *
17305             * @param groupId the group ID
17306             * @param categoryId the category ID
17307             * @param threadId the thread ID
17308             * @param status the status
17309             * @param start the lower bound of the range of message-boards messages
17310             * @param end the upper bound of the range of message-boards messages (not inclusive)
17311             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17312             * @return the ordered range of matching message-boards messages
17313             */
17314            @Override
17315            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17316                    long threadId, int status, int start, int end,
17317                    OrderByComparator<MBMessage> orderByComparator) {
17318                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
17319                            orderByComparator, true);
17320            }
17321    
17322            /**
17323             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17324             *
17325             * <p>
17326             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17327             * </p>
17328             *
17329             * @param groupId the group ID
17330             * @param categoryId the category ID
17331             * @param threadId the thread ID
17332             * @param status the status
17333             * @param start the lower bound of the range of message-boards messages
17334             * @param end the upper bound of the range of message-boards messages (not inclusive)
17335             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17336             * @param retrieveFromCache whether to retrieve from the finder cache
17337             * @return the ordered range of matching message-boards messages
17338             */
17339            @Override
17340            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
17341                    long threadId, int status, int start, int end,
17342                    OrderByComparator<MBMessage> orderByComparator,
17343                    boolean retrieveFromCache) {
17344                    boolean pagination = true;
17345                    FinderPath finderPath = null;
17346                    Object[] finderArgs = null;
17347    
17348                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17349                                    (orderByComparator == null)) {
17350                            pagination = false;
17351                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
17352                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
17353                    }
17354                    else {
17355                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
17356                            finderArgs = new Object[] {
17357                                            groupId, categoryId, threadId, status,
17358                                            
17359                                            start, end, orderByComparator
17360                                    };
17361                    }
17362    
17363                    List<MBMessage> list = null;
17364    
17365                    if (retrieveFromCache) {
17366                            list = (List<MBMessage>)finderCache.getResult(finderPath,
17367                                            finderArgs, this);
17368    
17369                            if ((list != null) && !list.isEmpty()) {
17370                                    for (MBMessage mbMessage : list) {
17371                                            if ((groupId != mbMessage.getGroupId()) ||
17372                                                            (categoryId != mbMessage.getCategoryId()) ||
17373                                                            (threadId != mbMessage.getThreadId()) ||
17374                                                            (status != mbMessage.getStatus())) {
17375                                                    list = null;
17376    
17377                                                    break;
17378                                            }
17379                                    }
17380                            }
17381                    }
17382    
17383                    if (list == null) {
17384                            StringBundler query = null;
17385    
17386                            if (orderByComparator != null) {
17387                                    query = new StringBundler(6 +
17388                                                    (orderByComparator.getOrderByFields().length * 2));
17389                            }
17390                            else {
17391                                    query = new StringBundler(6);
17392                            }
17393    
17394                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17395    
17396                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17397    
17398                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17399    
17400                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17401    
17402                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17403    
17404                            if (orderByComparator != null) {
17405                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17406                                            orderByComparator);
17407                            }
17408                            else
17409                             if (pagination) {
17410                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17411                            }
17412    
17413                            String sql = query.toString();
17414    
17415                            Session session = null;
17416    
17417                            try {
17418                                    session = openSession();
17419    
17420                                    Query q = session.createQuery(sql);
17421    
17422                                    QueryPos qPos = QueryPos.getInstance(q);
17423    
17424                                    qPos.add(groupId);
17425    
17426                                    qPos.add(categoryId);
17427    
17428                                    qPos.add(threadId);
17429    
17430                                    qPos.add(status);
17431    
17432                                    if (!pagination) {
17433                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17434                                                            start, end, false);
17435    
17436                                            Collections.sort(list);
17437    
17438                                            list = Collections.unmodifiableList(list);
17439                                    }
17440                                    else {
17441                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17442                                                            start, end);
17443                                    }
17444    
17445                                    cacheResult(list);
17446    
17447                                    finderCache.putResult(finderPath, finderArgs, list);
17448                            }
17449                            catch (Exception e) {
17450                                    finderCache.removeResult(finderPath, finderArgs);
17451    
17452                                    throw processException(e);
17453                            }
17454                            finally {
17455                                    closeSession(session);
17456                            }
17457                    }
17458    
17459                    return list;
17460            }
17461    
17462            /**
17463             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17464             *
17465             * @param groupId the group ID
17466             * @param categoryId the category ID
17467             * @param threadId the thread ID
17468             * @param status the status
17469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17470             * @return the first matching message-boards message
17471             * @throws NoSuchMessageException if a matching message-boards message could not be found
17472             */
17473            @Override
17474            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
17475                    long threadId, int status,
17476                    OrderByComparator<MBMessage> orderByComparator)
17477                    throws NoSuchMessageException {
17478                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
17479                                    threadId, status, orderByComparator);
17480    
17481                    if (mbMessage != null) {
17482                            return mbMessage;
17483                    }
17484    
17485                    StringBundler msg = new StringBundler(10);
17486    
17487                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17488    
17489                    msg.append("groupId=");
17490                    msg.append(groupId);
17491    
17492                    msg.append(", categoryId=");
17493                    msg.append(categoryId);
17494    
17495                    msg.append(", threadId=");
17496                    msg.append(threadId);
17497    
17498                    msg.append(", status=");
17499                    msg.append(status);
17500    
17501                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17502    
17503                    throw new NoSuchMessageException(msg.toString());
17504            }
17505    
17506            /**
17507             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17508             *
17509             * @param groupId the group ID
17510             * @param categoryId the category ID
17511             * @param threadId the thread ID
17512             * @param status the status
17513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17514             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17515             */
17516            @Override
17517            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
17518                    long threadId, int status,
17519                    OrderByComparator<MBMessage> orderByComparator) {
17520                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17521                                    status, 0, 1, orderByComparator);
17522    
17523                    if (!list.isEmpty()) {
17524                            return list.get(0);
17525                    }
17526    
17527                    return null;
17528            }
17529    
17530            /**
17531             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17532             *
17533             * @param groupId the group ID
17534             * @param categoryId the category ID
17535             * @param threadId the thread ID
17536             * @param status the status
17537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17538             * @return the last matching message-boards message
17539             * @throws NoSuchMessageException if a matching message-boards message could not be found
17540             */
17541            @Override
17542            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
17543                    long threadId, int status,
17544                    OrderByComparator<MBMessage> orderByComparator)
17545                    throws NoSuchMessageException {
17546                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
17547                                    threadId, status, orderByComparator);
17548    
17549                    if (mbMessage != null) {
17550                            return mbMessage;
17551                    }
17552    
17553                    StringBundler msg = new StringBundler(10);
17554    
17555                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17556    
17557                    msg.append("groupId=");
17558                    msg.append(groupId);
17559    
17560                    msg.append(", categoryId=");
17561                    msg.append(categoryId);
17562    
17563                    msg.append(", threadId=");
17564                    msg.append(threadId);
17565    
17566                    msg.append(", status=");
17567                    msg.append(status);
17568    
17569                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17570    
17571                    throw new NoSuchMessageException(msg.toString());
17572            }
17573    
17574            /**
17575             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17576             *
17577             * @param groupId the group ID
17578             * @param categoryId the category ID
17579             * @param threadId the thread ID
17580             * @param status the status
17581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17582             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17583             */
17584            @Override
17585            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
17586                    long threadId, int status,
17587                    OrderByComparator<MBMessage> orderByComparator) {
17588                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
17589    
17590                    if (count == 0) {
17591                            return null;
17592                    }
17593    
17594                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
17595                                    status, count - 1, count, orderByComparator);
17596    
17597                    if (!list.isEmpty()) {
17598                            return list.get(0);
17599                    }
17600    
17601                    return null;
17602            }
17603    
17604            /**
17605             * 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;.
17606             *
17607             * @param messageId the primary key of the current message-boards message
17608             * @param groupId the group ID
17609             * @param categoryId the category ID
17610             * @param threadId the thread ID
17611             * @param status the status
17612             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17613             * @return the previous, current, and next message-boards message
17614             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17615             */
17616            @Override
17617            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
17618                    long categoryId, long threadId, int status,
17619                    OrderByComparator<MBMessage> orderByComparator)
17620                    throws NoSuchMessageException {
17621                    MBMessage mbMessage = findByPrimaryKey(messageId);
17622    
17623                    Session session = null;
17624    
17625                    try {
17626                            session = openSession();
17627    
17628                            MBMessage[] array = new MBMessageImpl[3];
17629    
17630                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17631                                            categoryId, threadId, status, orderByComparator, true);
17632    
17633                            array[1] = mbMessage;
17634    
17635                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
17636                                            categoryId, threadId, status, orderByComparator, false);
17637    
17638                            return array;
17639                    }
17640                    catch (Exception e) {
17641                            throw processException(e);
17642                    }
17643                    finally {
17644                            closeSession(session);
17645                    }
17646            }
17647    
17648            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
17649                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17650                    int status, OrderByComparator<MBMessage> orderByComparator,
17651                    boolean previous) {
17652                    StringBundler query = null;
17653    
17654                    if (orderByComparator != null) {
17655                            query = new StringBundler(7 +
17656                                            (orderByComparator.getOrderByConditionFields().length * 3) +
17657                                            (orderByComparator.getOrderByFields().length * 3));
17658                    }
17659                    else {
17660                            query = new StringBundler(6);
17661                    }
17662    
17663                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17664    
17665                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17666    
17667                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17668    
17669                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17670    
17671                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17672    
17673                    if (orderByComparator != null) {
17674                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17675    
17676                            if (orderByConditionFields.length > 0) {
17677                                    query.append(WHERE_AND);
17678                            }
17679    
17680                            for (int i = 0; i < orderByConditionFields.length; i++) {
17681                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17682                                    query.append(orderByConditionFields[i]);
17683    
17684                                    if ((i + 1) < orderByConditionFields.length) {
17685                                            if (orderByComparator.isAscending() ^ previous) {
17686                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17687                                            }
17688                                            else {
17689                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17690                                            }
17691                                    }
17692                                    else {
17693                                            if (orderByComparator.isAscending() ^ previous) {
17694                                                    query.append(WHERE_GREATER_THAN);
17695                                            }
17696                                            else {
17697                                                    query.append(WHERE_LESSER_THAN);
17698                                            }
17699                                    }
17700                            }
17701    
17702                            query.append(ORDER_BY_CLAUSE);
17703    
17704                            String[] orderByFields = orderByComparator.getOrderByFields();
17705    
17706                            for (int i = 0; i < orderByFields.length; i++) {
17707                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17708                                    query.append(orderByFields[i]);
17709    
17710                                    if ((i + 1) < orderByFields.length) {
17711                                            if (orderByComparator.isAscending() ^ previous) {
17712                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17713                                            }
17714                                            else {
17715                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17716                                            }
17717                                    }
17718                                    else {
17719                                            if (orderByComparator.isAscending() ^ previous) {
17720                                                    query.append(ORDER_BY_ASC);
17721                                            }
17722                                            else {
17723                                                    query.append(ORDER_BY_DESC);
17724                                            }
17725                                    }
17726                            }
17727                    }
17728                    else {
17729                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17730                    }
17731    
17732                    String sql = query.toString();
17733    
17734                    Query q = session.createQuery(sql);
17735    
17736                    q.setFirstResult(0);
17737                    q.setMaxResults(2);
17738    
17739                    QueryPos qPos = QueryPos.getInstance(q);
17740    
17741                    qPos.add(groupId);
17742    
17743                    qPos.add(categoryId);
17744    
17745                    qPos.add(threadId);
17746    
17747                    qPos.add(status);
17748    
17749                    if (orderByComparator != null) {
17750                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17751    
17752                            for (Object value : values) {
17753                                    qPos.add(value);
17754                            }
17755                    }
17756    
17757                    List<MBMessage> list = q.list();
17758    
17759                    if (list.size() == 2) {
17760                            return list.get(1);
17761                    }
17762                    else {
17763                            return null;
17764                    }
17765            }
17766    
17767            /**
17768             * 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;.
17769             *
17770             * @param groupId the group ID
17771             * @param categoryId the category ID
17772             * @param threadId the thread ID
17773             * @param status the status
17774             * @return the matching message-boards messages that the user has permission to view
17775             */
17776            @Override
17777            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17778                    long threadId, int status) {
17779                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17780                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17781            }
17782    
17783            /**
17784             * 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;.
17785             *
17786             * <p>
17787             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17788             * </p>
17789             *
17790             * @param groupId the group ID
17791             * @param categoryId the category ID
17792             * @param threadId the thread ID
17793             * @param status the status
17794             * @param start the lower bound of the range of message-boards messages
17795             * @param end the upper bound of the range of message-boards messages (not inclusive)
17796             * @return the range of matching message-boards messages that the user has permission to view
17797             */
17798            @Override
17799            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17800                    long threadId, int status, int start, int end) {
17801                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17802                            start, end, null);
17803            }
17804    
17805            /**
17806             * 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;.
17807             *
17808             * <p>
17809             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17810             * </p>
17811             *
17812             * @param groupId the group ID
17813             * @param categoryId the category ID
17814             * @param threadId the thread ID
17815             * @param status the status
17816             * @param start the lower bound of the range of message-boards messages
17817             * @param end the upper bound of the range of message-boards messages (not inclusive)
17818             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17819             * @return the ordered range of matching message-boards messages that the user has permission to view
17820             */
17821            @Override
17822            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17823                    long threadId, int status, int start, int end,
17824                    OrderByComparator<MBMessage> orderByComparator) {
17825                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17826                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17827                                    end, orderByComparator);
17828                    }
17829    
17830                    StringBundler query = null;
17831    
17832                    if (orderByComparator != null) {
17833                            query = new StringBundler(6 +
17834                                            (orderByComparator.getOrderByFields().length * 2));
17835                    }
17836                    else {
17837                            query = new StringBundler(7);
17838                    }
17839    
17840                    if (getDB().isSupportsInlineDistinct()) {
17841                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17842                    }
17843                    else {
17844                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17845                    }
17846    
17847                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17848    
17849                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17850    
17851                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17852    
17853                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17854    
17855                    if (!getDB().isSupportsInlineDistinct()) {
17856                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17857                    }
17858    
17859                    if (orderByComparator != null) {
17860                            if (getDB().isSupportsInlineDistinct()) {
17861                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17862                                            orderByComparator, true);
17863                            }
17864                            else {
17865                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17866                                            orderByComparator, true);
17867                            }
17868                    }
17869                    else {
17870                            if (getDB().isSupportsInlineDistinct()) {
17871                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17872                            }
17873                            else {
17874                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17875                            }
17876                    }
17877    
17878                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17879                                    MBMessage.class.getName(),
17880                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17881    
17882                    Session session = null;
17883    
17884                    try {
17885                            session = openSession();
17886    
17887                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
17888    
17889                            if (getDB().isSupportsInlineDistinct()) {
17890                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17891                            }
17892                            else {
17893                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17894                            }
17895    
17896                            QueryPos qPos = QueryPos.getInstance(q);
17897    
17898                            qPos.add(groupId);
17899    
17900                            qPos.add(categoryId);
17901    
17902                            qPos.add(threadId);
17903    
17904                            qPos.add(status);
17905    
17906                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17907                    }
17908                    catch (Exception e) {
17909                            throw processException(e);
17910                    }
17911                    finally {
17912                            closeSession(session);
17913                    }
17914            }
17915    
17916            /**
17917             * 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;.
17918             *
17919             * @param messageId the primary key of the current message-boards message
17920             * @param groupId the group ID
17921             * @param categoryId the category ID
17922             * @param threadId the thread ID
17923             * @param status the status
17924             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17925             * @return the previous, current, and next message-boards message
17926             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
17927             */
17928            @Override
17929            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17930                    long groupId, long categoryId, long threadId, int status,
17931                    OrderByComparator<MBMessage> orderByComparator)
17932                    throws NoSuchMessageException {
17933                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17934                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17935                                    threadId, status, orderByComparator);
17936                    }
17937    
17938                    MBMessage mbMessage = findByPrimaryKey(messageId);
17939    
17940                    Session session = null;
17941    
17942                    try {
17943                            session = openSession();
17944    
17945                            MBMessage[] array = new MBMessageImpl[3];
17946    
17947                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17948                                            groupId, categoryId, threadId, status, orderByComparator,
17949                                            true);
17950    
17951                            array[1] = mbMessage;
17952    
17953                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17954                                            groupId, categoryId, threadId, status, orderByComparator,
17955                                            false);
17956    
17957                            return array;
17958                    }
17959                    catch (Exception e) {
17960                            throw processException(e);
17961                    }
17962                    finally {
17963                            closeSession(session);
17964                    }
17965            }
17966    
17967            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17968                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17969                    int status, OrderByComparator<MBMessage> orderByComparator,
17970                    boolean previous) {
17971                    StringBundler query = null;
17972    
17973                    if (orderByComparator != null) {
17974                            query = new StringBundler(8 +
17975                                            (orderByComparator.getOrderByConditionFields().length * 3) +
17976                                            (orderByComparator.getOrderByFields().length * 3));
17977                    }
17978                    else {
17979                            query = new StringBundler(7);
17980                    }
17981    
17982                    if (getDB().isSupportsInlineDistinct()) {
17983                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17984                    }
17985                    else {
17986                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17987                    }
17988    
17989                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17990    
17991                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17992    
17993                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17994    
17995                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17996    
17997                    if (!getDB().isSupportsInlineDistinct()) {
17998                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17999                    }
18000    
18001                    if (orderByComparator != null) {
18002                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18003    
18004                            if (orderByConditionFields.length > 0) {
18005                                    query.append(WHERE_AND);
18006                            }
18007    
18008                            for (int i = 0; i < orderByConditionFields.length; i++) {
18009                                    if (getDB().isSupportsInlineDistinct()) {
18010                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18011                                    }
18012                                    else {
18013                                            query.append(_ORDER_BY_ENTITY_TABLE);
18014                                    }
18015    
18016                                    query.append(orderByConditionFields[i]);
18017    
18018                                    if ((i + 1) < orderByConditionFields.length) {
18019                                            if (orderByComparator.isAscending() ^ previous) {
18020                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18021                                            }
18022                                            else {
18023                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18024                                            }
18025                                    }
18026                                    else {
18027                                            if (orderByComparator.isAscending() ^ previous) {
18028                                                    query.append(WHERE_GREATER_THAN);
18029                                            }
18030                                            else {
18031                                                    query.append(WHERE_LESSER_THAN);
18032                                            }
18033                                    }
18034                            }
18035    
18036                            query.append(ORDER_BY_CLAUSE);
18037    
18038                            String[] orderByFields = orderByComparator.getOrderByFields();
18039    
18040                            for (int i = 0; i < orderByFields.length; i++) {
18041                                    if (getDB().isSupportsInlineDistinct()) {
18042                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18043                                    }
18044                                    else {
18045                                            query.append(_ORDER_BY_ENTITY_TABLE);
18046                                    }
18047    
18048                                    query.append(orderByFields[i]);
18049    
18050                                    if ((i + 1) < orderByFields.length) {
18051                                            if (orderByComparator.isAscending() ^ previous) {
18052                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18053                                            }
18054                                            else {
18055                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18056                                            }
18057                                    }
18058                                    else {
18059                                            if (orderByComparator.isAscending() ^ previous) {
18060                                                    query.append(ORDER_BY_ASC);
18061                                            }
18062                                            else {
18063                                                    query.append(ORDER_BY_DESC);
18064                                            }
18065                                    }
18066                            }
18067                    }
18068                    else {
18069                            if (getDB().isSupportsInlineDistinct()) {
18070                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18071                            }
18072                            else {
18073                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18074                            }
18075                    }
18076    
18077                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18078                                    MBMessage.class.getName(),
18079                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18080    
18081                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
18082    
18083                    q.setFirstResult(0);
18084                    q.setMaxResults(2);
18085    
18086                    if (getDB().isSupportsInlineDistinct()) {
18087                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18088                    }
18089                    else {
18090                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18091                    }
18092    
18093                    QueryPos qPos = QueryPos.getInstance(q);
18094    
18095                    qPos.add(groupId);
18096    
18097                    qPos.add(categoryId);
18098    
18099                    qPos.add(threadId);
18100    
18101                    qPos.add(status);
18102    
18103                    if (orderByComparator != null) {
18104                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18105    
18106                            for (Object value : values) {
18107                                    qPos.add(value);
18108                            }
18109                    }
18110    
18111                    List<MBMessage> list = q.list();
18112    
18113                    if (list.size() == 2) {
18114                            return list.get(1);
18115                    }
18116                    else {
18117                            return null;
18118                    }
18119            }
18120    
18121            /**
18122             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
18123             *
18124             * @param groupId the group ID
18125             * @param categoryId the category ID
18126             * @param threadId the thread ID
18127             * @param status the status
18128             */
18129            @Override
18130            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
18131                    int status) {
18132                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
18133                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18134                            remove(mbMessage);
18135                    }
18136            }
18137    
18138            /**
18139             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18140             *
18141             * @param groupId the group ID
18142             * @param categoryId the category ID
18143             * @param threadId the thread ID
18144             * @param status the status
18145             * @return the number of matching message-boards messages
18146             */
18147            @Override
18148            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18149                    int status) {
18150                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
18151    
18152                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18153    
18154                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18155    
18156                    if (count == null) {
18157                            StringBundler query = new StringBundler(5);
18158    
18159                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18160    
18161                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18162    
18163                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18164    
18165                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18166    
18167                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18168    
18169                            String sql = query.toString();
18170    
18171                            Session session = null;
18172    
18173                            try {
18174                                    session = openSession();
18175    
18176                                    Query q = session.createQuery(sql);
18177    
18178                                    QueryPos qPos = QueryPos.getInstance(q);
18179    
18180                                    qPos.add(groupId);
18181    
18182                                    qPos.add(categoryId);
18183    
18184                                    qPos.add(threadId);
18185    
18186                                    qPos.add(status);
18187    
18188                                    count = (Long)q.uniqueResult();
18189    
18190                                    finderCache.putResult(finderPath, finderArgs, count);
18191                            }
18192                            catch (Exception e) {
18193                                    finderCache.removeResult(finderPath, finderArgs);
18194    
18195                                    throw processException(e);
18196                            }
18197                            finally {
18198                                    closeSession(session);
18199                            }
18200                    }
18201    
18202                    return count.intValue();
18203            }
18204    
18205            /**
18206             * 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;.
18207             *
18208             * @param groupId the group ID
18209             * @param categoryId the category ID
18210             * @param threadId the thread ID
18211             * @param status the status
18212             * @return the number of matching message-boards messages that the user has permission to view
18213             */
18214            @Override
18215            public int filterCountByG_C_T_S(long groupId, long categoryId,
18216                    long threadId, int status) {
18217                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18218                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18219                    }
18220    
18221                    StringBundler query = new StringBundler(5);
18222    
18223                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18224    
18225                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18226    
18227                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18228    
18229                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18230    
18231                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18232    
18233                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18234                                    MBMessage.class.getName(),
18235                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18236    
18237                    Session session = null;
18238    
18239                    try {
18240                            session = openSession();
18241    
18242                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
18243    
18244                            q.addScalar(COUNT_COLUMN_NAME,
18245                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18246    
18247                            QueryPos qPos = QueryPos.getInstance(q);
18248    
18249                            qPos.add(groupId);
18250    
18251                            qPos.add(categoryId);
18252    
18253                            qPos.add(threadId);
18254    
18255                            qPos.add(status);
18256    
18257                            Long count = (Long)q.uniqueResult();
18258    
18259                            return count.intValue();
18260                    }
18261                    catch (Exception e) {
18262                            throw processException(e);
18263                    }
18264                    finally {
18265                            closeSession(session);
18266                    }
18267            }
18268    
18269            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
18270            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18271            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
18272            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
18273            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18274                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18275                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
18276                            new String[] {
18277                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18278                                    Integer.class.getName(),
18279                                    
18280                            Integer.class.getName(), Integer.class.getName(),
18281                                    OrderByComparator.class.getName()
18282                            });
18283            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
18284                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18285                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18286                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
18287                            new String[] {
18288                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18289                                    Integer.class.getName()
18290                            },
18291                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
18292                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
18293                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
18294                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18295                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18296            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18297                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18298                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
18299                            new String[] {
18300                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18301                                    Integer.class.getName()
18302                            });
18303    
18304            /**
18305             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18306             *
18307             * @param userId the user ID
18308             * @param classNameId the class name ID
18309             * @param classPK the class p k
18310             * @param status the status
18311             * @return the matching message-boards messages
18312             */
18313            @Override
18314            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18315                    long classPK, int status) {
18316                    return findByU_C_C_S(userId, classNameId, classPK, status,
18317                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18318            }
18319    
18320            /**
18321             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18322             *
18323             * <p>
18324             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18325             * </p>
18326             *
18327             * @param userId the user ID
18328             * @param classNameId the class name ID
18329             * @param classPK the class p k
18330             * @param status the status
18331             * @param start the lower bound of the range of message-boards messages
18332             * @param end the upper bound of the range of message-boards messages (not inclusive)
18333             * @return the range of matching message-boards messages
18334             */
18335            @Override
18336            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18337                    long classPK, int status, int start, int end) {
18338                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18339                            null);
18340            }
18341    
18342            /**
18343             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18344             *
18345             * <p>
18346             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18347             * </p>
18348             *
18349             * @param userId the user ID
18350             * @param classNameId the class name ID
18351             * @param classPK the class p k
18352             * @param status the status
18353             * @param start the lower bound of the range of message-boards messages
18354             * @param end the upper bound of the range of message-boards messages (not inclusive)
18355             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18356             * @return the ordered range of matching message-boards messages
18357             */
18358            @Override
18359            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18360                    long classPK, int status, int start, int end,
18361                    OrderByComparator<MBMessage> orderByComparator) {
18362                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
18363                            orderByComparator, true);
18364            }
18365    
18366            /**
18367             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18368             *
18369             * <p>
18370             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18371             * </p>
18372             *
18373             * @param userId the user ID
18374             * @param classNameId the class name ID
18375             * @param classPK the class p k
18376             * @param status the status
18377             * @param start the lower bound of the range of message-boards messages
18378             * @param end the upper bound of the range of message-boards messages (not inclusive)
18379             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18380             * @param retrieveFromCache whether to retrieve from the finder cache
18381             * @return the ordered range of matching message-boards messages
18382             */
18383            @Override
18384            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
18385                    long classPK, int status, int start, int end,
18386                    OrderByComparator<MBMessage> orderByComparator,
18387                    boolean retrieveFromCache) {
18388                    boolean pagination = true;
18389                    FinderPath finderPath = null;
18390                    Object[] finderArgs = null;
18391    
18392                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18393                                    (orderByComparator == null)) {
18394                            pagination = false;
18395                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
18396                            finderArgs = new Object[] { userId, classNameId, classPK, status };
18397                    }
18398                    else {
18399                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
18400                            finderArgs = new Object[] {
18401                                            userId, classNameId, classPK, status,
18402                                            
18403                                            start, end, orderByComparator
18404                                    };
18405                    }
18406    
18407                    List<MBMessage> list = null;
18408    
18409                    if (retrieveFromCache) {
18410                            list = (List<MBMessage>)finderCache.getResult(finderPath,
18411                                            finderArgs, this);
18412    
18413                            if ((list != null) && !list.isEmpty()) {
18414                                    for (MBMessage mbMessage : list) {
18415                                            if ((userId != mbMessage.getUserId()) ||
18416                                                            (classNameId != mbMessage.getClassNameId()) ||
18417                                                            (classPK != mbMessage.getClassPK()) ||
18418                                                            (status != mbMessage.getStatus())) {
18419                                                    list = null;
18420    
18421                                                    break;
18422                                            }
18423                                    }
18424                            }
18425                    }
18426    
18427                    if (list == null) {
18428                            StringBundler query = null;
18429    
18430                            if (orderByComparator != null) {
18431                                    query = new StringBundler(6 +
18432                                                    (orderByComparator.getOrderByFields().length * 2));
18433                            }
18434                            else {
18435                                    query = new StringBundler(6);
18436                            }
18437    
18438                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18439    
18440                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18441    
18442                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18443    
18444                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18445    
18446                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18447    
18448                            if (orderByComparator != null) {
18449                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18450                                            orderByComparator);
18451                            }
18452                            else
18453                             if (pagination) {
18454                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18455                            }
18456    
18457                            String sql = query.toString();
18458    
18459                            Session session = null;
18460    
18461                            try {
18462                                    session = openSession();
18463    
18464                                    Query q = session.createQuery(sql);
18465    
18466                                    QueryPos qPos = QueryPos.getInstance(q);
18467    
18468                                    qPos.add(userId);
18469    
18470                                    qPos.add(classNameId);
18471    
18472                                    qPos.add(classPK);
18473    
18474                                    qPos.add(status);
18475    
18476                                    if (!pagination) {
18477                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18478                                                            start, end, false);
18479    
18480                                            Collections.sort(list);
18481    
18482                                            list = Collections.unmodifiableList(list);
18483                                    }
18484                                    else {
18485                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18486                                                            start, end);
18487                                    }
18488    
18489                                    cacheResult(list);
18490    
18491                                    finderCache.putResult(finderPath, finderArgs, list);
18492                            }
18493                            catch (Exception e) {
18494                                    finderCache.removeResult(finderPath, finderArgs);
18495    
18496                                    throw processException(e);
18497                            }
18498                            finally {
18499                                    closeSession(session);
18500                            }
18501                    }
18502    
18503                    return list;
18504            }
18505    
18506            /**
18507             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18508             *
18509             * @param userId the user ID
18510             * @param classNameId the class name ID
18511             * @param classPK the class p k
18512             * @param status the status
18513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18514             * @return the first matching message-boards message
18515             * @throws NoSuchMessageException if a matching message-boards message could not be found
18516             */
18517            @Override
18518            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
18519                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18520                    throws NoSuchMessageException {
18521                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
18522                                    classPK, status, orderByComparator);
18523    
18524                    if (mbMessage != null) {
18525                            return mbMessage;
18526                    }
18527    
18528                    StringBundler msg = new StringBundler(10);
18529    
18530                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18531    
18532                    msg.append("userId=");
18533                    msg.append(userId);
18534    
18535                    msg.append(", classNameId=");
18536                    msg.append(classNameId);
18537    
18538                    msg.append(", classPK=");
18539                    msg.append(classPK);
18540    
18541                    msg.append(", status=");
18542                    msg.append(status);
18543    
18544                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18545    
18546                    throw new NoSuchMessageException(msg.toString());
18547            }
18548    
18549            /**
18550             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18551             *
18552             * @param userId the user ID
18553             * @param classNameId the class name ID
18554             * @param classPK the class p k
18555             * @param status the status
18556             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18557             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18558             */
18559            @Override
18560            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
18561                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18562                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18563                                    status, 0, 1, orderByComparator);
18564    
18565                    if (!list.isEmpty()) {
18566                            return list.get(0);
18567                    }
18568    
18569                    return null;
18570            }
18571    
18572            /**
18573             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18574             *
18575             * @param userId the user ID
18576             * @param classNameId the class name ID
18577             * @param classPK the class p k
18578             * @param status the status
18579             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18580             * @return the last matching message-boards message
18581             * @throws NoSuchMessageException if a matching message-boards message could not be found
18582             */
18583            @Override
18584            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
18585                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator)
18586                    throws NoSuchMessageException {
18587                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
18588                                    status, orderByComparator);
18589    
18590                    if (mbMessage != null) {
18591                            return mbMessage;
18592                    }
18593    
18594                    StringBundler msg = new StringBundler(10);
18595    
18596                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18597    
18598                    msg.append("userId=");
18599                    msg.append(userId);
18600    
18601                    msg.append(", classNameId=");
18602                    msg.append(classNameId);
18603    
18604                    msg.append(", classPK=");
18605                    msg.append(classPK);
18606    
18607                    msg.append(", status=");
18608                    msg.append(status);
18609    
18610                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18611    
18612                    throw new NoSuchMessageException(msg.toString());
18613            }
18614    
18615            /**
18616             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18617             *
18618             * @param userId the user ID
18619             * @param classNameId the class name ID
18620             * @param classPK the class p k
18621             * @param status the status
18622             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18623             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18624             */
18625            @Override
18626            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
18627                    long classPK, int status, OrderByComparator<MBMessage> orderByComparator) {
18628                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
18629    
18630                    if (count == 0) {
18631                            return null;
18632                    }
18633    
18634                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
18635                                    status, count - 1, count, orderByComparator);
18636    
18637                    if (!list.isEmpty()) {
18638                            return list.get(0);
18639                    }
18640    
18641                    return null;
18642            }
18643    
18644            /**
18645             * 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;.
18646             *
18647             * @param messageId the primary key of the current message-boards message
18648             * @param userId the user ID
18649             * @param classNameId the class name ID
18650             * @param classPK the class p k
18651             * @param status the status
18652             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18653             * @return the previous, current, and next message-boards message
18654             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
18655             */
18656            @Override
18657            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
18658                    long classNameId, long classPK, int status,
18659                    OrderByComparator<MBMessage> orderByComparator)
18660                    throws NoSuchMessageException {
18661                    MBMessage mbMessage = findByPrimaryKey(messageId);
18662    
18663                    Session session = null;
18664    
18665                    try {
18666                            session = openSession();
18667    
18668                            MBMessage[] array = new MBMessageImpl[3];
18669    
18670                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18671                                            classNameId, classPK, status, orderByComparator, true);
18672    
18673                            array[1] = mbMessage;
18674    
18675                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
18676                                            classNameId, classPK, status, orderByComparator, false);
18677    
18678                            return array;
18679                    }
18680                    catch (Exception e) {
18681                            throw processException(e);
18682                    }
18683                    finally {
18684                            closeSession(session);
18685                    }
18686            }
18687    
18688            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
18689                    MBMessage mbMessage, long userId, long classNameId, long classPK,
18690                    int status, OrderByComparator<MBMessage> orderByComparator,
18691                    boolean previous) {
18692                    StringBundler query = null;
18693    
18694                    if (orderByComparator != null) {
18695                            query = new StringBundler(7 +
18696                                            (orderByComparator.getOrderByConditionFields().length * 3) +
18697                                            (orderByComparator.getOrderByFields().length * 3));
18698                    }
18699                    else {
18700                            query = new StringBundler(6);
18701                    }
18702    
18703                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18704    
18705                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18706    
18707                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18708    
18709                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18710    
18711                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18712    
18713                    if (orderByComparator != null) {
18714                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18715    
18716                            if (orderByConditionFields.length > 0) {
18717                                    query.append(WHERE_AND);
18718                            }
18719    
18720                            for (int i = 0; i < orderByConditionFields.length; i++) {
18721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18722                                    query.append(orderByConditionFields[i]);
18723    
18724                                    if ((i + 1) < orderByConditionFields.length) {
18725                                            if (orderByComparator.isAscending() ^ previous) {
18726                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18727                                            }
18728                                            else {
18729                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18730                                            }
18731                                    }
18732                                    else {
18733                                            if (orderByComparator.isAscending() ^ previous) {
18734                                                    query.append(WHERE_GREATER_THAN);
18735                                            }
18736                                            else {
18737                                                    query.append(WHERE_LESSER_THAN);
18738                                            }
18739                                    }
18740                            }
18741    
18742                            query.append(ORDER_BY_CLAUSE);
18743    
18744                            String[] orderByFields = orderByComparator.getOrderByFields();
18745    
18746                            for (int i = 0; i < orderByFields.length; i++) {
18747                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18748                                    query.append(orderByFields[i]);
18749    
18750                                    if ((i + 1) < orderByFields.length) {
18751                                            if (orderByComparator.isAscending() ^ previous) {
18752                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18753                                            }
18754                                            else {
18755                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18756                                            }
18757                                    }
18758                                    else {
18759                                            if (orderByComparator.isAscending() ^ previous) {
18760                                                    query.append(ORDER_BY_ASC);
18761                                            }
18762                                            else {
18763                                                    query.append(ORDER_BY_DESC);
18764                                            }
18765                                    }
18766                            }
18767                    }
18768                    else {
18769                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18770                    }
18771    
18772                    String sql = query.toString();
18773    
18774                    Query q = session.createQuery(sql);
18775    
18776                    q.setFirstResult(0);
18777                    q.setMaxResults(2);
18778    
18779                    QueryPos qPos = QueryPos.getInstance(q);
18780    
18781                    qPos.add(userId);
18782    
18783                    qPos.add(classNameId);
18784    
18785                    qPos.add(classPK);
18786    
18787                    qPos.add(status);
18788    
18789                    if (orderByComparator != null) {
18790                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18791    
18792                            for (Object value : values) {
18793                                    qPos.add(value);
18794                            }
18795                    }
18796    
18797                    List<MBMessage> list = q.list();
18798    
18799                    if (list.size() == 2) {
18800                            return list.get(1);
18801                    }
18802                    else {
18803                            return null;
18804                    }
18805            }
18806    
18807            /**
18808             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18809             *
18810             * @param userId the user ID
18811             * @param classNameId the class name ID
18812             * @param classPK the class p k
18813             * @param status the status
18814             */
18815            @Override
18816            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18817                    int status) {
18818                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18819                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18820                            remove(mbMessage);
18821                    }
18822            }
18823    
18824            /**
18825             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18826             *
18827             * @param userId the user ID
18828             * @param classNameId the class name ID
18829             * @param classPK the class p k
18830             * @param status the status
18831             * @return the number of matching message-boards messages
18832             */
18833            @Override
18834            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18835                    int status) {
18836                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18837    
18838                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18839    
18840                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
18841    
18842                    if (count == null) {
18843                            StringBundler query = new StringBundler(5);
18844    
18845                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18846    
18847                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18848    
18849                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18850    
18851                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18852    
18853                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18854    
18855                            String sql = query.toString();
18856    
18857                            Session session = null;
18858    
18859                            try {
18860                                    session = openSession();
18861    
18862                                    Query q = session.createQuery(sql);
18863    
18864                                    QueryPos qPos = QueryPos.getInstance(q);
18865    
18866                                    qPos.add(userId);
18867    
18868                                    qPos.add(classNameId);
18869    
18870                                    qPos.add(classPK);
18871    
18872                                    qPos.add(status);
18873    
18874                                    count = (Long)q.uniqueResult();
18875    
18876                                    finderCache.putResult(finderPath, finderArgs, count);
18877                            }
18878                            catch (Exception e) {
18879                                    finderCache.removeResult(finderPath, finderArgs);
18880    
18881                                    throw processException(e);
18882                            }
18883                            finally {
18884                                    closeSession(session);
18885                            }
18886                    }
18887    
18888                    return count.intValue();
18889            }
18890    
18891            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18892            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18893            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18894            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18895    
18896            public MBMessagePersistenceImpl() {
18897                    setModelClass(MBMessage.class);
18898            }
18899    
18900            /**
18901             * Caches the message-boards message in the entity cache if it is enabled.
18902             *
18903             * @param mbMessage the message-boards message
18904             */
18905            @Override
18906            public void cacheResult(MBMessage mbMessage) {
18907                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18908                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18909    
18910                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18911                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18912                            mbMessage);
18913    
18914                    mbMessage.resetOriginalValues();
18915            }
18916    
18917            /**
18918             * Caches the message-boards messages in the entity cache if it is enabled.
18919             *
18920             * @param mbMessages the message-boards messages
18921             */
18922            @Override
18923            public void cacheResult(List<MBMessage> mbMessages) {
18924                    for (MBMessage mbMessage : mbMessages) {
18925                            if (entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18926                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18927                                    cacheResult(mbMessage);
18928                            }
18929                            else {
18930                                    mbMessage.resetOriginalValues();
18931                            }
18932                    }
18933            }
18934    
18935            /**
18936             * Clears the cache for all message-boards messages.
18937             *
18938             * <p>
18939             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18940             * </p>
18941             */
18942            @Override
18943            public void clearCache() {
18944                    entityCache.clearCache(MBMessageImpl.class);
18945    
18946                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
18947                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18948                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18949            }
18950    
18951            /**
18952             * Clears the cache for the message-boards message.
18953             *
18954             * <p>
18955             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
18956             * </p>
18957             */
18958            @Override
18959            public void clearCache(MBMessage mbMessage) {
18960                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18961                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18962    
18963                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18964                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18965    
18966                    clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18967            }
18968    
18969            @Override
18970            public void clearCache(List<MBMessage> mbMessages) {
18971                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18972                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18973    
18974                    for (MBMessage mbMessage : mbMessages) {
18975                            entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18976                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18977    
18978                            clearUniqueFindersCache((MBMessageModelImpl)mbMessage);
18979                    }
18980            }
18981    
18982            protected void cacheUniqueFindersCache(
18983                    MBMessageModelImpl mbMessageModelImpl, boolean isNew) {
18984                    if (isNew) {
18985                            Object[] args = new Object[] {
18986                                            mbMessageModelImpl.getUuid(),
18987                                            mbMessageModelImpl.getGroupId()
18988                                    };
18989    
18990                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18991                                    Long.valueOf(1));
18992                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18993                                    mbMessageModelImpl);
18994                    }
18995                    else {
18996                            if ((mbMessageModelImpl.getColumnBitmask() &
18997                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18998                                    Object[] args = new Object[] {
18999                                                    mbMessageModelImpl.getUuid(),
19000                                                    mbMessageModelImpl.getGroupId()
19001                                            };
19002    
19003                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
19004                                            Long.valueOf(1));
19005                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
19006                                            mbMessageModelImpl);
19007                            }
19008                    }
19009            }
19010    
19011            protected void clearUniqueFindersCache(
19012                    MBMessageModelImpl mbMessageModelImpl) {
19013                    Object[] args = new Object[] {
19014                                    mbMessageModelImpl.getUuid(), mbMessageModelImpl.getGroupId()
19015                            };
19016    
19017                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19018                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19019    
19020                    if ((mbMessageModelImpl.getColumnBitmask() &
19021                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
19022                            args = new Object[] {
19023                                            mbMessageModelImpl.getOriginalUuid(),
19024                                            mbMessageModelImpl.getOriginalGroupId()
19025                                    };
19026    
19027                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19028                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19029                    }
19030            }
19031    
19032            /**
19033             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
19034             *
19035             * @param messageId the primary key for the new message-boards message
19036             * @return the new message-boards message
19037             */
19038            @Override
19039            public MBMessage create(long messageId) {
19040                    MBMessage mbMessage = new MBMessageImpl();
19041    
19042                    mbMessage.setNew(true);
19043                    mbMessage.setPrimaryKey(messageId);
19044    
19045                    String uuid = PortalUUIDUtil.generate();
19046    
19047                    mbMessage.setUuid(uuid);
19048    
19049                    mbMessage.setCompanyId(companyProvider.getCompanyId());
19050    
19051                    return mbMessage;
19052            }
19053    
19054            /**
19055             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19056             *
19057             * @param messageId the primary key of the message-boards message
19058             * @return the message-boards message that was removed
19059             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19060             */
19061            @Override
19062            public MBMessage remove(long messageId) throws NoSuchMessageException {
19063                    return remove((Serializable)messageId);
19064            }
19065    
19066            /**
19067             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19068             *
19069             * @param primaryKey the primary key of the message-boards message
19070             * @return the message-boards message that was removed
19071             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19072             */
19073            @Override
19074            public MBMessage remove(Serializable primaryKey)
19075                    throws NoSuchMessageException {
19076                    Session session = null;
19077    
19078                    try {
19079                            session = openSession();
19080    
19081                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19082                                            primaryKey);
19083    
19084                            if (mbMessage == null) {
19085                                    if (_log.isWarnEnabled()) {
19086                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19087                                    }
19088    
19089                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19090                                            primaryKey);
19091                            }
19092    
19093                            return remove(mbMessage);
19094                    }
19095                    catch (NoSuchMessageException nsee) {
19096                            throw nsee;
19097                    }
19098                    catch (Exception e) {
19099                            throw processException(e);
19100                    }
19101                    finally {
19102                            closeSession(session);
19103                    }
19104            }
19105    
19106            @Override
19107            protected MBMessage removeImpl(MBMessage mbMessage) {
19108                    mbMessage = toUnwrappedModel(mbMessage);
19109    
19110                    Session session = null;
19111    
19112                    try {
19113                            session = openSession();
19114    
19115                            if (!session.contains(mbMessage)) {
19116                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19117                                                    mbMessage.getPrimaryKeyObj());
19118                            }
19119    
19120                            if (mbMessage != null) {
19121                                    session.delete(mbMessage);
19122                            }
19123                    }
19124                    catch (Exception e) {
19125                            throw processException(e);
19126                    }
19127                    finally {
19128                            closeSession(session);
19129                    }
19130    
19131                    if (mbMessage != null) {
19132                            clearCache(mbMessage);
19133                    }
19134    
19135                    return mbMessage;
19136            }
19137    
19138            @Override
19139            public MBMessage updateImpl(MBMessage mbMessage) {
19140                    mbMessage = toUnwrappedModel(mbMessage);
19141    
19142                    boolean isNew = mbMessage.isNew();
19143    
19144                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19145    
19146                    if (Validator.isNull(mbMessage.getUuid())) {
19147                            String uuid = PortalUUIDUtil.generate();
19148    
19149                            mbMessage.setUuid(uuid);
19150                    }
19151    
19152                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
19153    
19154                    Date now = new Date();
19155    
19156                    if (isNew && (mbMessage.getCreateDate() == null)) {
19157                            if (serviceContext == null) {
19158                                    mbMessage.setCreateDate(now);
19159                            }
19160                            else {
19161                                    mbMessage.setCreateDate(serviceContext.getCreateDate(now));
19162                            }
19163                    }
19164    
19165                    if (!mbMessageModelImpl.hasSetModifiedDate()) {
19166                            if (serviceContext == null) {
19167                                    mbMessage.setModifiedDate(now);
19168                            }
19169                            else {
19170                                    mbMessage.setModifiedDate(serviceContext.getModifiedDate(now));
19171                            }
19172                    }
19173    
19174                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
19175    
19176                    if (userId > 0) {
19177                            long companyId = mbMessage.getCompanyId();
19178    
19179                            long groupId = mbMessage.getGroupId();
19180    
19181                            long messageId = 0;
19182    
19183                            if (!isNew) {
19184                                    messageId = mbMessage.getPrimaryKey();
19185                            }
19186    
19187                            try {
19188                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
19189                                                    userId,
19190                                                    com.liferay.message.boards.kernel.model.MBMessage.class.getName(),
19191                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
19192                                                    mbMessage.getSubject(), null));
19193                            }
19194                            catch (SanitizerException se) {
19195                                    throw new SystemException(se);
19196                            }
19197                    }
19198    
19199                    Session session = null;
19200    
19201                    try {
19202                            session = openSession();
19203    
19204                            if (mbMessage.isNew()) {
19205                                    session.save(mbMessage);
19206    
19207                                    mbMessage.setNew(false);
19208                            }
19209                            else {
19210                                    mbMessage = (MBMessage)session.merge(mbMessage);
19211                            }
19212                    }
19213                    catch (Exception e) {
19214                            throw processException(e);
19215                    }
19216                    finally {
19217                            closeSession(session);
19218                    }
19219    
19220                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19221    
19222                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
19223                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19224                    }
19225    
19226                    else {
19227                            if ((mbMessageModelImpl.getColumnBitmask() &
19228                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
19229                                    Object[] args = new Object[] {
19230                                                    mbMessageModelImpl.getOriginalUuid()
19231                                            };
19232    
19233                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19234                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19235                                            args);
19236    
19237                                    args = new Object[] { mbMessageModelImpl.getUuid() };
19238    
19239                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
19240                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
19241                                            args);
19242                            }
19243    
19244                            if ((mbMessageModelImpl.getColumnBitmask() &
19245                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
19246                                    Object[] args = new Object[] {
19247                                                    mbMessageModelImpl.getOriginalUuid(),
19248                                                    mbMessageModelImpl.getOriginalCompanyId()
19249                                            };
19250    
19251                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19252                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19253                                            args);
19254    
19255                                    args = new Object[] {
19256                                                    mbMessageModelImpl.getUuid(),
19257                                                    mbMessageModelImpl.getCompanyId()
19258                                            };
19259    
19260                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
19261                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
19262                                            args);
19263                            }
19264    
19265                            if ((mbMessageModelImpl.getColumnBitmask() &
19266                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
19267                                    Object[] args = new Object[] {
19268                                                    mbMessageModelImpl.getOriginalGroupId()
19269                                            };
19270    
19271                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19272                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19273                                            args);
19274    
19275                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
19276    
19277                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
19278                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
19279                                            args);
19280                            }
19281    
19282                            if ((mbMessageModelImpl.getColumnBitmask() &
19283                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
19284                                    Object[] args = new Object[] {
19285                                                    mbMessageModelImpl.getOriginalCompanyId()
19286                                            };
19287    
19288                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19289                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19290                                            args);
19291    
19292                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
19293    
19294                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
19295                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
19296                                            args);
19297                            }
19298    
19299                            if ((mbMessageModelImpl.getColumnBitmask() &
19300                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
19301                                    Object[] args = new Object[] {
19302                                                    mbMessageModelImpl.getOriginalUserId()
19303                                            };
19304    
19305                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19306                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19307                                            args);
19308    
19309                                    args = new Object[] { mbMessageModelImpl.getUserId() };
19310    
19311                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
19312                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
19313                                            args);
19314                            }
19315    
19316                            if ((mbMessageModelImpl.getColumnBitmask() &
19317                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
19318                                    Object[] args = new Object[] {
19319                                                    mbMessageModelImpl.getOriginalThreadId()
19320                                            };
19321    
19322                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19323                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19324                                            args);
19325    
19326                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19327    
19328                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
19329                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
19330                                            args);
19331                            }
19332    
19333                            if ((mbMessageModelImpl.getColumnBitmask() &
19334                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
19335                                    Object[] args = new Object[] {
19336                                                    mbMessageModelImpl.getOriginalThreadId()
19337                                            };
19338    
19339                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19340                                            args);
19341                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19342                                            args);
19343    
19344                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
19345    
19346                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
19347                                            args);
19348                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
19349                                            args);
19350                            }
19351    
19352                            if ((mbMessageModelImpl.getColumnBitmask() &
19353                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
19354                                    Object[] args = new Object[] {
19355                                                    mbMessageModelImpl.getOriginalGroupId(),
19356                                                    mbMessageModelImpl.getOriginalUserId()
19357                                            };
19358    
19359                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19360                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19361                                            args);
19362    
19363                                    args = new Object[] {
19364                                                    mbMessageModelImpl.getGroupId(),
19365                                                    mbMessageModelImpl.getUserId()
19366                                            };
19367    
19368                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
19369                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
19370                                            args);
19371                            }
19372    
19373                            if ((mbMessageModelImpl.getColumnBitmask() &
19374                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
19375                                    Object[] args = new Object[] {
19376                                                    mbMessageModelImpl.getOriginalGroupId(),
19377                                                    mbMessageModelImpl.getOriginalCategoryId()
19378                                            };
19379    
19380                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19381                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19382                                            args);
19383    
19384                                    args = new Object[] {
19385                                                    mbMessageModelImpl.getGroupId(),
19386                                                    mbMessageModelImpl.getCategoryId()
19387                                            };
19388    
19389                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
19390                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
19391                                            args);
19392                            }
19393    
19394                            if ((mbMessageModelImpl.getColumnBitmask() &
19395                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
19396                                    Object[] args = new Object[] {
19397                                                    mbMessageModelImpl.getOriginalGroupId(),
19398                                                    mbMessageModelImpl.getOriginalStatus()
19399                                            };
19400    
19401                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19402                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19403                                            args);
19404    
19405                                    args = new Object[] {
19406                                                    mbMessageModelImpl.getGroupId(),
19407                                                    mbMessageModelImpl.getStatus()
19408                                            };
19409    
19410                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
19411                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
19412                                            args);
19413                            }
19414    
19415                            if ((mbMessageModelImpl.getColumnBitmask() &
19416                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
19417                                    Object[] args = new Object[] {
19418                                                    mbMessageModelImpl.getOriginalCompanyId(),
19419                                                    mbMessageModelImpl.getOriginalStatus()
19420                                            };
19421    
19422                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19423                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19424                                            args);
19425    
19426                                    args = new Object[] {
19427                                                    mbMessageModelImpl.getCompanyId(),
19428                                                    mbMessageModelImpl.getStatus()
19429                                            };
19430    
19431                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
19432                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
19433                                            args);
19434                            }
19435    
19436                            if ((mbMessageModelImpl.getColumnBitmask() &
19437                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
19438                                    Object[] args = new Object[] {
19439                                                    mbMessageModelImpl.getOriginalUserId(),
19440                                                    mbMessageModelImpl.getOriginalClassNameId()
19441                                            };
19442    
19443                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19444                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19445                                            args);
19446    
19447                                    args = new Object[] {
19448                                                    mbMessageModelImpl.getUserId(),
19449                                                    mbMessageModelImpl.getClassNameId()
19450                                            };
19451    
19452                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
19453                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
19454                                            args);
19455                            }
19456    
19457                            if ((mbMessageModelImpl.getColumnBitmask() &
19458                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
19459                                    Object[] args = new Object[] {
19460                                                    mbMessageModelImpl.getOriginalClassNameId(),
19461                                                    mbMessageModelImpl.getOriginalClassPK()
19462                                            };
19463    
19464                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19465                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19466                                            args);
19467    
19468                                    args = new Object[] {
19469                                                    mbMessageModelImpl.getClassNameId(),
19470                                                    mbMessageModelImpl.getClassPK()
19471                                            };
19472    
19473                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
19474                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
19475                                            args);
19476                            }
19477    
19478                            if ((mbMessageModelImpl.getColumnBitmask() &
19479                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
19480                                    Object[] args = new Object[] {
19481                                                    mbMessageModelImpl.getOriginalThreadId(),
19482                                                    mbMessageModelImpl.getOriginalParentMessageId()
19483                                            };
19484    
19485                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19486                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19487                                            args);
19488    
19489                                    args = new Object[] {
19490                                                    mbMessageModelImpl.getThreadId(),
19491                                                    mbMessageModelImpl.getParentMessageId()
19492                                            };
19493    
19494                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
19495                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
19496                                            args);
19497                            }
19498    
19499                            if ((mbMessageModelImpl.getColumnBitmask() &
19500                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
19501                                    Object[] args = new Object[] {
19502                                                    mbMessageModelImpl.getOriginalThreadId(),
19503                                                    mbMessageModelImpl.getOriginalAnswer()
19504                                            };
19505    
19506                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19507                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19508                                            args);
19509    
19510                                    args = new Object[] {
19511                                                    mbMessageModelImpl.getThreadId(),
19512                                                    mbMessageModelImpl.getAnswer()
19513                                            };
19514    
19515                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
19516                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
19517                                            args);
19518                            }
19519    
19520                            if ((mbMessageModelImpl.getColumnBitmask() &
19521                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
19522                                    Object[] args = new Object[] {
19523                                                    mbMessageModelImpl.getOriginalThreadId(),
19524                                                    mbMessageModelImpl.getOriginalStatus()
19525                                            };
19526    
19527                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19528                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19529                                            args);
19530    
19531                                    args = new Object[] {
19532                                                    mbMessageModelImpl.getThreadId(),
19533                                                    mbMessageModelImpl.getStatus()
19534                                            };
19535    
19536                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
19537                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
19538                                            args);
19539                            }
19540    
19541                            if ((mbMessageModelImpl.getColumnBitmask() &
19542                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
19543                                    Object[] args = new Object[] {
19544                                                    mbMessageModelImpl.getOriginalThreadId(),
19545                                                    mbMessageModelImpl.getOriginalStatus()
19546                                            };
19547    
19548                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19549                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19550                                            args);
19551    
19552                                    args = new Object[] {
19553                                                    mbMessageModelImpl.getThreadId(),
19554                                                    mbMessageModelImpl.getStatus()
19555                                            };
19556    
19557                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
19558                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
19559                                            args);
19560                            }
19561    
19562                            if ((mbMessageModelImpl.getColumnBitmask() &
19563                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
19564                                    Object[] args = new Object[] {
19565                                                    mbMessageModelImpl.getOriginalGroupId(),
19566                                                    mbMessageModelImpl.getOriginalUserId(),
19567                                                    mbMessageModelImpl.getOriginalStatus()
19568                                            };
19569    
19570                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19571                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19572                                            args);
19573    
19574                                    args = new Object[] {
19575                                                    mbMessageModelImpl.getGroupId(),
19576                                                    mbMessageModelImpl.getUserId(),
19577                                                    mbMessageModelImpl.getStatus()
19578                                            };
19579    
19580                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
19581                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
19582                                            args);
19583                            }
19584    
19585                            if ((mbMessageModelImpl.getColumnBitmask() &
19586                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
19587                                    Object[] args = new Object[] {
19588                                                    mbMessageModelImpl.getOriginalGroupId(),
19589                                                    mbMessageModelImpl.getOriginalCategoryId(),
19590                                                    mbMessageModelImpl.getOriginalThreadId()
19591                                            };
19592    
19593                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19594                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19595                                            args);
19596    
19597                                    args = new Object[] {
19598                                                    mbMessageModelImpl.getGroupId(),
19599                                                    mbMessageModelImpl.getCategoryId(),
19600                                                    mbMessageModelImpl.getThreadId()
19601                                            };
19602    
19603                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
19604                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
19605                                            args);
19606                            }
19607    
19608                            if ((mbMessageModelImpl.getColumnBitmask() &
19609                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
19610                                    Object[] args = new Object[] {
19611                                                    mbMessageModelImpl.getOriginalGroupId(),
19612                                                    mbMessageModelImpl.getOriginalCategoryId(),
19613                                                    mbMessageModelImpl.getOriginalStatus()
19614                                            };
19615    
19616                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19617                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19618                                            args);
19619    
19620                                    args = new Object[] {
19621                                                    mbMessageModelImpl.getGroupId(),
19622                                                    mbMessageModelImpl.getCategoryId(),
19623                                                    mbMessageModelImpl.getStatus()
19624                                            };
19625    
19626                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
19627                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
19628                                            args);
19629                            }
19630    
19631                            if ((mbMessageModelImpl.getColumnBitmask() &
19632                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
19633                                    Object[] args = new Object[] {
19634                                                    mbMessageModelImpl.getOriginalUserId(),
19635                                                    mbMessageModelImpl.getOriginalClassNameId(),
19636                                                    mbMessageModelImpl.getOriginalClassPK()
19637                                            };
19638    
19639                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19640                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19641                                            args);
19642    
19643                                    args = new Object[] {
19644                                                    mbMessageModelImpl.getUserId(),
19645                                                    mbMessageModelImpl.getClassNameId(),
19646                                                    mbMessageModelImpl.getClassPK()
19647                                            };
19648    
19649                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
19650                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
19651                                            args);
19652                            }
19653    
19654                            if ((mbMessageModelImpl.getColumnBitmask() &
19655                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
19656                                    Object[] args = new Object[] {
19657                                                    mbMessageModelImpl.getOriginalUserId(),
19658                                                    mbMessageModelImpl.getOriginalClassNameId(),
19659                                                    mbMessageModelImpl.getOriginalStatus()
19660                                            };
19661    
19662                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19663                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19664                                            args);
19665    
19666                                    args = new Object[] {
19667                                                    mbMessageModelImpl.getUserId(),
19668                                                    mbMessageModelImpl.getClassNameId(),
19669                                                    mbMessageModelImpl.getStatus()
19670                                            };
19671    
19672                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
19673                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
19674                                            args);
19675                            }
19676    
19677                            if ((mbMessageModelImpl.getColumnBitmask() &
19678                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
19679                                    Object[] args = new Object[] {
19680                                                    mbMessageModelImpl.getOriginalClassNameId(),
19681                                                    mbMessageModelImpl.getOriginalClassPK(),
19682                                                    mbMessageModelImpl.getOriginalStatus()
19683                                            };
19684    
19685                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19686                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19687                                            args);
19688    
19689                                    args = new Object[] {
19690                                                    mbMessageModelImpl.getClassNameId(),
19691                                                    mbMessageModelImpl.getClassPK(),
19692                                                    mbMessageModelImpl.getStatus()
19693                                            };
19694    
19695                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
19696                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
19697                                            args);
19698                            }
19699    
19700                            if ((mbMessageModelImpl.getColumnBitmask() &
19701                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
19702                                    Object[] args = new Object[] {
19703                                                    mbMessageModelImpl.getOriginalGroupId(),
19704                                                    mbMessageModelImpl.getOriginalCategoryId(),
19705                                                    mbMessageModelImpl.getOriginalThreadId(),
19706                                                    mbMessageModelImpl.getOriginalAnswer()
19707                                            };
19708    
19709                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19710                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19711                                            args);
19712    
19713                                    args = new Object[] {
19714                                                    mbMessageModelImpl.getGroupId(),
19715                                                    mbMessageModelImpl.getCategoryId(),
19716                                                    mbMessageModelImpl.getThreadId(),
19717                                                    mbMessageModelImpl.getAnswer()
19718                                            };
19719    
19720                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
19721                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
19722                                            args);
19723                            }
19724    
19725                            if ((mbMessageModelImpl.getColumnBitmask() &
19726                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
19727                                    Object[] args = new Object[] {
19728                                                    mbMessageModelImpl.getOriginalGroupId(),
19729                                                    mbMessageModelImpl.getOriginalCategoryId(),
19730                                                    mbMessageModelImpl.getOriginalThreadId(),
19731                                                    mbMessageModelImpl.getOriginalStatus()
19732                                            };
19733    
19734                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19735                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19736                                            args);
19737    
19738                                    args = new Object[] {
19739                                                    mbMessageModelImpl.getGroupId(),
19740                                                    mbMessageModelImpl.getCategoryId(),
19741                                                    mbMessageModelImpl.getThreadId(),
19742                                                    mbMessageModelImpl.getStatus()
19743                                            };
19744    
19745                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
19746                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
19747                                            args);
19748                            }
19749    
19750                            if ((mbMessageModelImpl.getColumnBitmask() &
19751                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
19752                                    Object[] args = new Object[] {
19753                                                    mbMessageModelImpl.getOriginalUserId(),
19754                                                    mbMessageModelImpl.getOriginalClassNameId(),
19755                                                    mbMessageModelImpl.getOriginalClassPK(),
19756                                                    mbMessageModelImpl.getOriginalStatus()
19757                                            };
19758    
19759                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19760                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19761                                            args);
19762    
19763                                    args = new Object[] {
19764                                                    mbMessageModelImpl.getUserId(),
19765                                                    mbMessageModelImpl.getClassNameId(),
19766                                                    mbMessageModelImpl.getClassPK(),
19767                                                    mbMessageModelImpl.getStatus()
19768                                            };
19769    
19770                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
19771                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
19772                                            args);
19773                            }
19774                    }
19775    
19776                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19777                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage, false);
19778    
19779                    clearUniqueFindersCache(mbMessageModelImpl);
19780                    cacheUniqueFindersCache(mbMessageModelImpl, isNew);
19781    
19782                    mbMessage.resetOriginalValues();
19783    
19784                    return mbMessage;
19785            }
19786    
19787            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19788                    if (mbMessage instanceof MBMessageImpl) {
19789                            return mbMessage;
19790                    }
19791    
19792                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19793    
19794                    mbMessageImpl.setNew(mbMessage.isNew());
19795                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19796    
19797                    mbMessageImpl.setUuid(mbMessage.getUuid());
19798                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19799                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19800                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19801                    mbMessageImpl.setUserId(mbMessage.getUserId());
19802                    mbMessageImpl.setUserName(mbMessage.getUserName());
19803                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19804                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19805                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19806                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19807                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19808                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19809                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19810                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19811                    mbMessageImpl.setSubject(mbMessage.getSubject());
19812                    mbMessageImpl.setBody(mbMessage.getBody());
19813                    mbMessageImpl.setFormat(mbMessage.getFormat());
19814                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19815                    mbMessageImpl.setPriority(mbMessage.getPriority());
19816                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19817                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19818                    mbMessageImpl.setLastPublishDate(mbMessage.getLastPublishDate());
19819                    mbMessageImpl.setStatus(mbMessage.getStatus());
19820                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19821                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19822                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19823    
19824                    return mbMessageImpl;
19825            }
19826    
19827            /**
19828             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
19829             *
19830             * @param primaryKey the primary key of the message-boards message
19831             * @return the message-boards message
19832             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19833             */
19834            @Override
19835            public MBMessage findByPrimaryKey(Serializable primaryKey)
19836                    throws NoSuchMessageException {
19837                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19838    
19839                    if (mbMessage == null) {
19840                            if (_log.isWarnEnabled()) {
19841                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19842                            }
19843    
19844                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19845                                    primaryKey);
19846                    }
19847    
19848                    return mbMessage;
19849            }
19850    
19851            /**
19852             * Returns the message-boards message with the primary key or throws a {@link NoSuchMessageException} if it could not be found.
19853             *
19854             * @param messageId the primary key of the message-boards message
19855             * @return the message-boards message
19856             * @throws NoSuchMessageException if a message-boards message with the primary key could not be found
19857             */
19858            @Override
19859            public MBMessage findByPrimaryKey(long messageId)
19860                    throws NoSuchMessageException {
19861                    return findByPrimaryKey((Serializable)messageId);
19862            }
19863    
19864            /**
19865             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19866             *
19867             * @param primaryKey the primary key of the message-boards message
19868             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19869             */
19870            @Override
19871            public MBMessage fetchByPrimaryKey(Serializable primaryKey) {
19872                    MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19873                                    MBMessageImpl.class, primaryKey);
19874    
19875                    if (mbMessage == _nullMBMessage) {
19876                            return null;
19877                    }
19878    
19879                    if (mbMessage == null) {
19880                            Session session = null;
19881    
19882                            try {
19883                                    session = openSession();
19884    
19885                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19886                                                    primaryKey);
19887    
19888                                    if (mbMessage != null) {
19889                                            cacheResult(mbMessage);
19890                                    }
19891                                    else {
19892                                            entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19893                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19894                                    }
19895                            }
19896                            catch (Exception e) {
19897                                    entityCache.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19898                                            MBMessageImpl.class, primaryKey);
19899    
19900                                    throw processException(e);
19901                            }
19902                            finally {
19903                                    closeSession(session);
19904                            }
19905                    }
19906    
19907                    return mbMessage;
19908            }
19909    
19910            /**
19911             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19912             *
19913             * @param messageId the primary key of the message-boards message
19914             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19915             */
19916            @Override
19917            public MBMessage fetchByPrimaryKey(long messageId) {
19918                    return fetchByPrimaryKey((Serializable)messageId);
19919            }
19920    
19921            @Override
19922            public Map<Serializable, MBMessage> fetchByPrimaryKeys(
19923                    Set<Serializable> primaryKeys) {
19924                    if (primaryKeys.isEmpty()) {
19925                            return Collections.emptyMap();
19926                    }
19927    
19928                    Map<Serializable, MBMessage> map = new HashMap<Serializable, MBMessage>();
19929    
19930                    if (primaryKeys.size() == 1) {
19931                            Iterator<Serializable> iterator = primaryKeys.iterator();
19932    
19933                            Serializable primaryKey = iterator.next();
19934    
19935                            MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19936    
19937                            if (mbMessage != null) {
19938                                    map.put(primaryKey, mbMessage);
19939                            }
19940    
19941                            return map;
19942                    }
19943    
19944                    Set<Serializable> uncachedPrimaryKeys = null;
19945    
19946                    for (Serializable primaryKey : primaryKeys) {
19947                            MBMessage mbMessage = (MBMessage)entityCache.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19948                                            MBMessageImpl.class, primaryKey);
19949    
19950                            if (mbMessage == null) {
19951                                    if (uncachedPrimaryKeys == null) {
19952                                            uncachedPrimaryKeys = new HashSet<Serializable>();
19953                                    }
19954    
19955                                    uncachedPrimaryKeys.add(primaryKey);
19956                            }
19957                            else {
19958                                    map.put(primaryKey, mbMessage);
19959                            }
19960                    }
19961    
19962                    if (uncachedPrimaryKeys == null) {
19963                            return map;
19964                    }
19965    
19966                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
19967                                    1);
19968    
19969                    query.append(_SQL_SELECT_MBMESSAGE_WHERE_PKS_IN);
19970    
19971                    for (Serializable primaryKey : uncachedPrimaryKeys) {
19972                            query.append(String.valueOf(primaryKey));
19973    
19974                            query.append(StringPool.COMMA);
19975                    }
19976    
19977                    query.setIndex(query.index() - 1);
19978    
19979                    query.append(StringPool.CLOSE_PARENTHESIS);
19980    
19981                    String sql = query.toString();
19982    
19983                    Session session = null;
19984    
19985                    try {
19986                            session = openSession();
19987    
19988                            Query q = session.createQuery(sql);
19989    
19990                            for (MBMessage mbMessage : (List<MBMessage>)q.list()) {
19991                                    map.put(mbMessage.getPrimaryKeyObj(), mbMessage);
19992    
19993                                    cacheResult(mbMessage);
19994    
19995                                    uncachedPrimaryKeys.remove(mbMessage.getPrimaryKeyObj());
19996                            }
19997    
19998                            for (Serializable primaryKey : uncachedPrimaryKeys) {
19999                                    entityCache.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20000                                            MBMessageImpl.class, primaryKey, _nullMBMessage);
20001                            }
20002                    }
20003                    catch (Exception e) {
20004                            throw processException(e);
20005                    }
20006                    finally {
20007                            closeSession(session);
20008                    }
20009    
20010                    return map;
20011            }
20012    
20013            /**
20014             * Returns all the message-boards messages.
20015             *
20016             * @return the message-boards messages
20017             */
20018            @Override
20019            public List<MBMessage> findAll() {
20020                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20021            }
20022    
20023            /**
20024             * Returns a range of all the message-boards messages.
20025             *
20026             * <p>
20027             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20028             * </p>
20029             *
20030             * @param start the lower bound of the range of message-boards messages
20031             * @param end the upper bound of the range of message-boards messages (not inclusive)
20032             * @return the range of message-boards messages
20033             */
20034            @Override
20035            public List<MBMessage> findAll(int start, int end) {
20036                    return findAll(start, end, null);
20037            }
20038    
20039            /**
20040             * Returns an ordered range of all the message-boards messages.
20041             *
20042             * <p>
20043             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20044             * </p>
20045             *
20046             * @param start the lower bound of the range of message-boards messages
20047             * @param end the upper bound of the range of message-boards messages (not inclusive)
20048             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20049             * @return the ordered range of message-boards messages
20050             */
20051            @Override
20052            public List<MBMessage> findAll(int start, int end,
20053                    OrderByComparator<MBMessage> orderByComparator) {
20054                    return findAll(start, end, orderByComparator, true);
20055            }
20056    
20057            /**
20058             * Returns an ordered range of all the message-boards messages.
20059             *
20060             * <p>
20061             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
20062             * </p>
20063             *
20064             * @param start the lower bound of the range of message-boards messages
20065             * @param end the upper bound of the range of message-boards messages (not inclusive)
20066             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20067             * @param retrieveFromCache whether to retrieve from the finder cache
20068             * @return the ordered range of message-boards messages
20069             */
20070            @Override
20071            public List<MBMessage> findAll(int start, int end,
20072                    OrderByComparator<MBMessage> orderByComparator,
20073                    boolean retrieveFromCache) {
20074                    boolean pagination = true;
20075                    FinderPath finderPath = null;
20076                    Object[] finderArgs = null;
20077    
20078                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20079                                    (orderByComparator == null)) {
20080                            pagination = false;
20081                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20082                            finderArgs = FINDER_ARGS_EMPTY;
20083                    }
20084                    else {
20085                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20086                            finderArgs = new Object[] { start, end, orderByComparator };
20087                    }
20088    
20089                    List<MBMessage> list = null;
20090    
20091                    if (retrieveFromCache) {
20092                            list = (List<MBMessage>)finderCache.getResult(finderPath,
20093                                            finderArgs, this);
20094                    }
20095    
20096                    if (list == null) {
20097                            StringBundler query = null;
20098                            String sql = null;
20099    
20100                            if (orderByComparator != null) {
20101                                    query = new StringBundler(2 +
20102                                                    (orderByComparator.getOrderByFields().length * 2));
20103    
20104                                    query.append(_SQL_SELECT_MBMESSAGE);
20105    
20106                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20107                                            orderByComparator);
20108    
20109                                    sql = query.toString();
20110                            }
20111                            else {
20112                                    sql = _SQL_SELECT_MBMESSAGE;
20113    
20114                                    if (pagination) {
20115                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20116                                    }
20117                            }
20118    
20119                            Session session = null;
20120    
20121                            try {
20122                                    session = openSession();
20123    
20124                                    Query q = session.createQuery(sql);
20125    
20126                                    if (!pagination) {
20127                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20128                                                            start, end, false);
20129    
20130                                            Collections.sort(list);
20131    
20132                                            list = Collections.unmodifiableList(list);
20133                                    }
20134                                    else {
20135                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20136                                                            start, end);
20137                                    }
20138    
20139                                    cacheResult(list);
20140    
20141                                    finderCache.putResult(finderPath, finderArgs, list);
20142                            }
20143                            catch (Exception e) {
20144                                    finderCache.removeResult(finderPath, finderArgs);
20145    
20146                                    throw processException(e);
20147                            }
20148                            finally {
20149                                    closeSession(session);
20150                            }
20151                    }
20152    
20153                    return list;
20154            }
20155    
20156            /**
20157             * Removes all the message-boards messages from the database.
20158             *
20159             */
20160            @Override
20161            public void removeAll() {
20162                    for (MBMessage mbMessage : findAll()) {
20163                            remove(mbMessage);
20164                    }
20165            }
20166    
20167            /**
20168             * Returns the number of message-boards messages.
20169             *
20170             * @return the number of message-boards messages
20171             */
20172            @Override
20173            public int countAll() {
20174                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
20175                                    FINDER_ARGS_EMPTY, this);
20176    
20177                    if (count == null) {
20178                            Session session = null;
20179    
20180                            try {
20181                                    session = openSession();
20182    
20183                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20184    
20185                                    count = (Long)q.uniqueResult();
20186    
20187                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
20188                                            count);
20189                            }
20190                            catch (Exception e) {
20191                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
20192                                            FINDER_ARGS_EMPTY);
20193    
20194                                    throw processException(e);
20195                            }
20196                            finally {
20197                                    closeSession(session);
20198                            }
20199                    }
20200    
20201                    return count.intValue();
20202            }
20203    
20204            @Override
20205            public Set<String> getBadColumnNames() {
20206                    return _badColumnNames;
20207            }
20208    
20209            @Override
20210            protected Map<String, Integer> getTableColumnsMap() {
20211                    return MBMessageModelImpl.TABLE_COLUMNS_MAP;
20212            }
20213    
20214            /**
20215             * Initializes the message-boards message persistence.
20216             */
20217            public void afterPropertiesSet() {
20218            }
20219    
20220            public void destroy() {
20221                    entityCache.removeCache(MBMessageImpl.class.getName());
20222                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
20223                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20224                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20225            }
20226    
20227            @BeanReference(type = CompanyProviderWrapper.class)
20228            protected CompanyProvider companyProvider;
20229            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
20230            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
20231            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
20232            private static final String _SQL_SELECT_MBMESSAGE_WHERE_PKS_IN = "SELECT mbMessage FROM MBMessage mbMessage WHERE messageId IN (";
20233            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
20234            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
20235            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
20236            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
20237            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
20238            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
20239                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
20240            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
20241                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
20242            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
20243            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
20244            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
20245            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
20246            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
20247            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
20248            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
20249            private static final Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
20250            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
20251                                    "uuid"
20252                            });
20253            private static final MBMessage _nullMBMessage = new MBMessageImpl() {
20254                            @Override
20255                            public Object clone() {
20256                                    return this;
20257                            }
20258    
20259                            @Override
20260                            public CacheModel<MBMessage> toCacheModel() {
20261                                    return _nullMBMessageCacheModel;
20262                            }
20263                    };
20264    
20265            private static final CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
20266                            @Override
20267                            public MBMessage toEntityModel() {
20268                                    return _nullMBMessage;
20269                            }
20270                    };
20271    }